Skip to content
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

Control flow operators type checking #272

Closed
naturaltransformation opened this issue Apr 6, 2016 · 7 comments
Closed

Control flow operators type checking #272

naturaltransformation opened this issue Apr 6, 2016 · 7 comments

Comments

@naturaltransformation
Copy link
Contributor

Returns are desugared into brs, which may yield a value, before type checking, but the design docs require that return not yield a value https://github.com/WebAssembly/design/blob/master/AstSemantics.md#yielding-values-from-control-constructs. This behavior is used in certain test cases. Is this seeming discrepancy resolved somehow? Thanks!

@rossberg
Copy link
Member

rossberg commented Apr 6, 2016

I'm not sure I understand. A br does not yield a value either. Can you give an example?

@naturaltransformation
Copy link
Contributor Author

For example, in labels.wast's misc2 function the body type checks (i32.xor (return (i32.const 1)) (i32.const 2)). Also, (func (result i32) (if (i32.const 1) (return (i32.const 0)) (return (i32.const 1)))) type checks.

@rossberg
Copy link
Member

rossberg commented Apr 6, 2016

Yes. But this is intentional: any operator that unconditionally transfers control is fully polymorphic, in order to e.g. allow it in branches whose siblings do yield some value. Same as in all other typed (expression) languages.

The design doc's formulation that something does "not yield a value" may be a bit misleading: it is only meant to describe the operational semantics, not typing.

@rossberg
Copy link
Member

rossberg commented Apr 6, 2016

What's surprising about your second example, btw?

@naturaltransformation
Copy link
Contributor Author

Ah! Thank you! Oh, no, the second example isn't surprising by itself, just surprising in the context of interpreting the design docs clause as imposing a static semantics. That is very helpful. It would be great to clarify that in the design docs. I can take a pass at doing that if it doesn't get in anyone's way.

@naturaltransformation
Copy link
Contributor Author

Since there is no section or document in the design docs that describes the type system, would it be fair to say that the spec is (already) definitive in this matter?

@rossberg
Copy link
Member

rossberg commented Apr 6, 2016

Yes, pretty much. Spelling out all details of a type system in prose isn't very compelling anyway.

ngzhian added a commit to ngzhian/spec that referenced this issue Nov 4, 2021
shr_u is a bit more tricky due for I8 and I16. E.g. -128 in I8 has all
top bits set (sign extended) in an int32, and shr_u using Int's
implementation will result in 0xffffffc0, instead of 0x000000c0. But we
can't simply change the implementation, since parsing relies on this
behavior. I'll figure that out in a later patch.
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

No branches or pull requests

2 participants