Skip to content

Conversation

rossberg
Copy link
Member

@rossberg rossberg commented Oct 1, 2015

Inspired by Dan's larger patch (#98), this one introduces sugar to define a label directly as part of a block, loop, or switch. A loop allows up to two labels, one to exit, the other to continue the loop.

The patch also redefines return as sugar for a break, slightly simplifying the spec, and making the core language compositional (you can now substitute function bodies, up to variable renaming).

@lukewagner
Copy link
Member

So in both this and #98, I'm wondering if it's a good idea to desugar ops into other ops in host/parser.mly b/c that does sorta make them vanish from spec/ (in particular ast.ml) which is what I'm considering "the spec". I definitely like simplifying the spec, but I feel that the type of complexity I want to avoid is cross-cutting concerns or ad hoc stuff; adding new cases that are almost the same as other cases seems like no big deal; we're not defining a calculus here and nobody is trying to print out wasm semantics on a poster (thought I bet with K we could... ;).

Alternatively, there is another strategy that has already been on my mind: since there is already some collapsing going on where many "ops" (that have different names in AstSemantics.md) are given a single ML constructor in ast.ml, I was wondering if it would make sense to have two ML AST datatypes: a "surface" AST that is generated by parser.mly and has exactly 1 constructor for every AstSemantics.md op name, and a "kernel" AST that is basically what we have now (including your PR). Then, the first thing we do in spec/ is to desugar the surface AST into the kernel AST (and thus all of check.ml and eval.ml would stay the same). That way, we're making the desugaring very clear in "the spec".

@rossberg
Copy link
Member Author

rossberg commented Oct 1, 2015 via email

@lukewagner
Copy link
Member

Great!

@rossberg
Copy link
Member Author

rossberg commented Oct 1, 2015

One question of course is what to do with the use and resolution of symbolic names. I think it would be inadequate to have those appear inside spec, since they are purely an artifact of the textual representation. So I'll probably leave that in the parser, although it is the actual tricky part of the logic -- the remaining desugaring is super trivial atm.

@lukewagner
Copy link
Member

Agreed.

@AndrewScheidecker
Copy link
Contributor

Could this also get rid of label? It seems redundant if block has a branch target.

I also think it's less confusing to call break branch once it can be used to continue loops.

@rossberg
Copy link
Member Author

rossberg commented Oct 2, 2015

It's only surface syntactic sugar for label, so no, at least not yet.

I'd be fine with branch, but I actually think break still is more accurate, since it isn't an arbitrary jump, but always terminates a surrounding expression. This applies to the continue label as well, which terminates the loop's body.

@AndrewScheidecker
Copy link
Contributor

It's only surface syntactic sugar for label, so no, at least not yet.

I mean that you could get rid of the label node in the sugared syntax.

@rossberg
Copy link
Member Author

rossberg commented Oct 5, 2015 via email

@rossberg
Copy link
Member Author

Superseded by #117

@rossberg rossberg deleted the cleanup-labels branch May 18, 2017 11:15
alexcrichton pushed a commit to alexcrichton/spec that referenced this pull request Nov 18, 2019
rossberg pushed a commit that referenced this pull request Feb 11, 2021
dhil pushed a commit to dhil/webassembly-spec that referenced this pull request Mar 2, 2023
This PR adds the dependency to multi-value to the exception handling proposal text and to the README. 

I wrote an explanation of this dependency on the proposal text, but it's easier to see this once the verification and execution steps of `br_on_exn` and of `try` blocks are written out, as done [here](WebAssembly/exception-handling#87 (comment)) by @rossberg :

Validation:

```
ft = t1* -> t2*
C, label t2* |- e1* : t1* -> t2*
C, label t2* |- e2* : exnref -> t2*
-----------------------------------
C |- try ft e1* catch e2* end : ft

C_label(l) = C_exn(x) = t*
-------------------------------------
C |- br_on_exn l x : exnref -> exnref
```

Execution: 

```
v^n (try ft e1* catch e2* end)  -->  catch_m{e2*} (label_m{} v^n e1* end) end)
  (iff ft = t1^n -> t2^m)
S; F; catch_m{e*} T[v^n (throw a)] end  -->  S; F; label_m{} (exn a v^n) e* end
  (iff S_exn(a) = {typ t^n})

F; (exn a v*) (br_on_exn l x)  -->  F; v* (br l)
  (iff F_exn(x) = a)
```

Concerning the functionality of `try`-`catch` blocks, note especially the passing of `v^n` values into a `label_m{}`.
Concerning the functionality of `br_on_exn`, note especially the execution step resulting in a `br` instruction.
dhil pushed a commit to dhil/webassembly-spec that referenced this pull request Mar 2, 2023
…bAssembly#115)

This reverts commit 10d6c6c.

This reverts WebAssembly#96, which squashed all upstream commits into one, which
was not the recommended way in
https://github.com/WebAssembly/proposals/blob/master/howto.md#syncing-with-upstream-changes.

This leaves README.md untouched because WebAssembly#99 made significant changes on
top of the merged version already.
rossberg pushed a commit that referenced this pull request Nov 7, 2024
Interpreter:

- Fixed evaluation of v128 load/store instructions to work with i64
- Reworked bulk operation execution to still reduce to well-typed instructions for i32
- Added missing size check to table allocation
- Various minor refactorings and clean-ups

Tests:

- Added tests for size check in i64 table and memory type limits

Split out from #1839
dhil added a commit to dhil/webassembly-spec that referenced this pull request Dec 3, 2024
* Fix validation of `switch`.

The validation of `switch` was not working as intended when the
"switcher" and "switchee" had different continuation type immediates.

The fix is to replace the current continuation from the argument list
with the switched-to continuation. The previous thing happened to be
working when the "switcher" and "switchee" used the same continuation
type immediate.

I also noticed a bug in the testsuite runner. It was not running the stack switching tests since commit WebAssembly/stack-switching@70086b9. I have added the "stack-switching" subdirectory to the test script runner such that the tests are now being run again by `make test`.

Resolves WebAssembly#98.

* Update interpreter/valid/valid.ml

Co-authored-by: Andreas Rossberg <rossberg@mpi-sws.org>

---------

Co-authored-by: Andreas Rossberg <rossberg@mpi-sws.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants