-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix ref.null semantics #478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch! This is rather annoying, if only ref.null didn't have this dreaded type annotation...
Unfortunately, I think the fix isn't quite as easy as that. Because (ref.null ht) is defined to be a value, and values must never reduce, otherwise the Progress statement is compromised.
So we need to syntactically distinguish reduced null refs from non-reduced ones. We could do it based on the shape of the ht, which is probably fine for now (you'll need to add a side condition to the grammar of reference values), but is a bit hacky and not very robust.
Long-term, I think the cleaner fix is to make the type annotation optional. Then the reduction rule would remove it. And the typing rule for valid-ref would only allow unannotated ref.null and assign it type (ref null bot).
But changing the syntax of reference values like that requires more adjustments throughout the spec, and even the JS API spec. The interpreter should be adjusted as well then. That's quite a bit of work, so perhaps for later.
Wouldn't having |
See my reply on the other issue. Also, ref.null is already standardised as part of Wasm 2.0 (as is ref.func, btw), so we cannot change it anymore. |
document/core/exec/runtime.rst
Outdated
@@ -47,7 +47,7 @@ Any of the aformentioned references can furthermore be wrapped up as an *externa | |||
\production{vector} & \vecc &::=& | |||
\V128.\CONST~\i128 \\ | |||
\production{reference} & \reff &::=& | |||
\REFNULL~t \\&&|& | |||
\REFNULL~t & (\iff t \neq \typeidx) \\&&|& |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct in spirit, but technically, since meta variables are existentially quantified, a negation like this doesn't do the right thing – you can always take a different type index to make it true. I think you need to say some like "t = absheaptype ∨ t = deftype". Or perhaps spell it out as \REFNULL~\absheaptype~|~\REFNULL~\deftype
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
.. note:: | ||
No formal reduction rule is required for this instruction, since the |REFNULL| instruction is already a :ref:`value <syntax-val>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a variation of this note still applies, since we only reduce some ref.null's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Andreas Rossberg <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Problem
This is the semantics of
ref.null ht
in the current specification.But I think simply pushing
ref.null ht
is problematic.Example
Consider the following example, which is simplified version of "test-sub" in ref_test.wast.
According to the semantics of
ref.test
, we first need to get the reference type ofref.null $t0
.However, the typeindex
$t0
is not ok under empty context.Suggested change
In the reference interpreter, type index of
ref.null $t0
is substituted before pushed.Therefore, I fixed the semantics according to the reference interpreter.