-
Notifications
You must be signed in to change notification settings - Fork 14
Reduction semantics #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Reduction semantics #109
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -833,6 +833,126 @@ events and only `(on $e switch)` handlers can handle `switch` | |||||
events. The handler search continues past handlers for the wrong kind | ||||||
of event, even if they use the correct tag. | ||||||
|
||||||
#### Store extensions | ||||||
|
||||||
* A store component `tags` for allocated tags (from the exception | ||||||
handling proposal) | ||||||
- `S ::= {..., tags <taginst>*}` | ||||||
|
||||||
* A *tag instance* represents a control tag (from the exception | ||||||
handling proposal) | ||||||
- `taginst ::= {type <tagtype>}` | ||||||
|
||||||
* New store component `conts` for allocated continuations | ||||||
- `S ::= {..., conts <cont>?*}` | ||||||
|
||||||
* A continuation is a context annotated with its hole's arity | ||||||
- `cont ::= (E : n)` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sidenote: the Iris-WasmFX mechanisation stores more than just the arity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is interesting. Is that merely for convenience (i.e., not having to guess the type non-deterministically in the proof), or would soundness actually break without fixing the types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is so that the logical relation can later have more to go on. The type soundness could be proved in a mechanisation that only decorates contexts with the arity |
||||||
|
||||||
|
||||||
#### Administrative instructions | ||||||
|
||||||
* `(ref.cont a)` represents a continuation value, where `a` is a *continuation address* indexing into the store's `conts` component | ||||||
- `ref.cont a : [] -> [(ref $ct)]` | ||||||
- iff `S.conts[a] = epsilon \/ S.conts[a] = (E : n)` | ||||||
- and `$ct ~~ cont $ft` | ||||||
- and `$ft ~~ [t1^n] -> [t2*]` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would also need to require that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no, empty isn't the same as being undefined. This says that |
||||||
|
||||||
* `(prompt{<hdl>*} <instr>* end)` represents an active handler | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sidenote: the Iris-WasmFX mechanisation adds one more immediate argument to the |
||||||
- `(prompt{((a $l) | (b switch))*}? instr* end) : [t1*] -> [t2*]` | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- iff `instr* : [t1*] -> [t2*]` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This explanation does not mention what typing context is used. Here, the body |
||||||
- and `(S.tags[a].type ~~ [te1*] -> [te2*])*` | ||||||
- and `(S.tags[b].type ~~ [] -> [te2*])*` | ||||||
- and `(label $l : [te1'* (ref null? $ct')])*` | ||||||
- and `([te1*] <: [te1'*])*` | ||||||
- and `($ct' ~~ cont $ft')*` | ||||||
- and `([te2*] -> [t2*] <: $ft')*` | ||||||
|
||||||
The administrative structure `hdl` is defined as. | ||||||
``` | ||||||
hdl ::= (<tagaddr> $l) hdl | (<tagaddr> switch) | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
``` | ||||||
|
||||||
#### Handler contexts | ||||||
|
||||||
``` | ||||||
H^ea ::= | ||||||
_ | ||||||
val* H^ea instr* | ||||||
label_n{instr*} H^ea end | ||||||
frame_n{F} H^ea end | ||||||
catch{...} H^ea end | ||||||
prompt{hdl*} H^ea end (iff ea notin ea'*) | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
``` | ||||||
|
||||||
|
||||||
#### Reduction | ||||||
|
||||||
* `S; F; (ref.null t) (cont.new $ct) --> S; F; trap` | ||||||
|
||||||
* `S; F; (ref.func fa) (cont.new $ct) --> S'; F; (ref.cont |S.conts|)` | ||||||
- iff `S' = S with conts += (E : n)` | ||||||
- and `E = _ (invoke fa)` | ||||||
- and `$ct ~~ cont $ft` | ||||||
- and `$ft ~~ [t1^n] -> [t2*]` | ||||||
|
||||||
* `S; F; (ref.null t) (cont.bind $ct $ct') --> S; F; trap` | ||||||
|
||||||
* `S; F; (ref.cont ca) (cont.bind $ct $ct') --> S; F; trap` | ||||||
- iff `S.conts[ca] = epsilon` | ||||||
|
||||||
* `S; F; v^n (ref.cont ca) (cont.bind $ct $ct') --> S'; F; (ref.const |S.conts|)` | ||||||
- iff `S.conts[ca] = (E' : n')` | ||||||
- and `$ct' ~~ cont $ft'` | ||||||
- and `$ft' ~~ [t1'*] -> [t2'*]` | ||||||
- and `n = n' - |t1'*|` | ||||||
- and `S' = S with conts[ca] = epsilon with conts += (E : |t1'*|)` | ||||||
- and `E = E'[v^n _]` | ||||||
|
||||||
* `S; F; (ref.null t) (resume $ct (on $e $l)*) --> S; F; trap` | ||||||
|
||||||
* `S; F; (ref.cont ca) (resume $ct (on $e $l)*) --> S; F; trap` | ||||||
- iff `S.conts[ca] = epsilon` | ||||||
|
||||||
* `S; F; v^n (ref.cont ca) (resume $ct hdl*) --> S'; F; prompt{hdl*} E[v^n] end` | ||||||
- iff `S.conts[ca] = (E : n)` | ||||||
- and `(ea = F.tags[$t])*` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is missing here. Neither ea* nor $t* are bound. Moreover, the defined syntax of hdl on the l.h.s. and r.h.s. is different, i.e., there's a meta type mismatch. I'd suggest to unify the syntax of hdl for resume and prompt by having it contain a |
||||||
- and `S' = S with conts[ca] = epsilon` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
||||||
* `S; F; (ref.null t) (resume_throw $ct $e (on $t $l)*) --> S; F; trap` | ||||||
|
||||||
* `S; F; (ref.cont ca) (resume_throw $ct $e (on $t $l)*) --> S; F; trap` | ||||||
- iff `S.conts[ca] = epsilon` | ||||||
|
||||||
* `S; F; v^m (ref.cont ca) (resume_throw $ct $e hdl*) --> S'; F; prompt{hdl*} E[v^m (throw $e)] end` | ||||||
- iff `S.conts[ca] = (E : n)` | ||||||
- and `(ea = F.tags[$t])*` | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- and `S.tags[F.tags[$e]].type ~~ [t1^m] -> [t2*]` | ||||||
- and `S' = S with conts[ca] = epsilon` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as for |
||||||
|
||||||
* `S; F; (prompt{(e $l)*}? v* end) --> S; F; v*` | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
* `S; F; (prompt H^ea[(suspend $e)] end) --> S; F; trap` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this rule was for barrier, so is obsolete? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think you are right. Though, shouldn't we have a rule that specifies when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the wasm semantics is modular, e.g. if |
||||||
- iff `ea = F.tags[$e]` | ||||||
|
||||||
* `S; F; (prompt{hdl1* (ea $l) hdl2*} H^ea[v^n (suspend $e)] end) --> S'; F; v^n (ref.cont |S.conts|) (br $l)` | ||||||
- iff `ea notin ea1*` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that the very definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. Though, it isn't defined in the document currently as far as I can tell. |
||||||
- and `ea = F.tags[$e]` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, |
||||||
- and `S.tags[ea].type ~~ [t1^n] -> [t2^m]` | ||||||
- and `S' = S with conts += (H^ea : m)` | ||||||
|
||||||
* `S; F; (prompt{hdl1* (ea switch) hdl2*} H^ea[v^n (ref.cont ca) (switch $ct $e)] end) --> S''; F; prompt{hdl1* (ea switch) hdl2*} E[v^n (ref.cont |S.conts|)] end` | ||||||
- iff `S.conts[ca] = (E : n')` | ||||||
- and `n' = 1 + n` | ||||||
- and `ea notin ea1*` | ||||||
dhil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- and `ea = F.tags[$e]` | ||||||
- and `$ct ~~ cont $ft` | ||||||
- and `$ft ~~ [t1* (ref $ct2)] -> [t2*]` | ||||||
- and `$ct2 ~~ cont $ft2` | ||||||
- and `$ft2 ~~ [t1'^m] -> [t2'*]` | ||||||
- and `S' = S with conts[ca] = epsilon` | ||||||
- and `S'' = S' with conts += (H^ea : m)` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sidenote: the Iris-WasmFX mechanisation does not yet have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: the Iris-WasmFX mechanisation now has the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the first instance of ea in hdl* is of the wrong form (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No trap. We always pick the first match (left to right). Any later instances are effectively shadowed. You are right that this behaviour should be mentioned in the explainer, if it isn't already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little confused. Imagine I have a switch instruction that targets the tag address Or is there something enforcing that anywhere a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are correct. I think it is already mentioned in the explainer somewhere, at least informally, that |
||||||
|
||||||
### Binary format | ||||||
|
||||||
We extend the binary format of composite types, heap types, and instructions. | ||||||
|
@@ -856,7 +976,7 @@ The opcode for heap types is encoded as an `s33`. | |||||
|
||||||
#### Instructions | ||||||
|
||||||
We use the use the opcode space `0xe0-0xe5` for the seven new instructions. | ||||||
We use the use the opcode space `0xe0-0xe5` for the six new instructions. | ||||||
|
||||||
| Opcode | Instruction | Immediates | | ||||||
| ------ | ------------------------ | ---------- | | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.