WebAssembly / reference-types

Proposal for adding basic reference types (anyref)
https://webassembly.github.io/reference-types/
Other
162 stars 40 forks source link

Constant Expressions constraint #134

Closed lum1n0us closed 3 years ago

lum1n0us commented 3 years ago

https://github.com/WebAssembly/reference-types/blob/063d34eda68108fac28d783beaf501c23e9e38d0/test/core/data.wast#L480

according to the Specification, it doesn't look like an invalid one.

Note: Currently, constant expressions occurring as initializers of globals are further constrained in that contained global.get instructions are only allowed to refer to imported globals. This is enforced in the validation rule for modules by constraining the context C accordingly.

may be it is

(assert_invalid
   (module 
     (global (mut i32) (i32.const 7)
     (memory 1)
     (data (global.get 0))
   )
   "constant expression required"
)
rossberg commented 3 years ago

This is invalid because the constant expression is referring to a mutable global. That's never legal.

lum1n0us commented 3 years ago

yeah, but I also notice there is no such description in either latest spec(https://webassembly.github.io/spec/core/index.html) or the spec of reference type(https://webassembly.github.io/reference-types/core/).

rossberg commented 3 years ago

It's in the definition of constant expressions: https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions

lum1n0us commented 3 years ago

I mean the restriction about mutable imported globals can not be used in constant expressions. It just said "contained global.get instructions are only allowed to refer to imported globals".


From: Andreas Rossberg notifications@github.com Sent: Wednesday, February 24, 2021 3:40 PM To: WebAssembly/reference-types reference-types@noreply.github.com Cc: He, Liang liang.he@intel.com; Author author@noreply.github.com Subject: Re: [WebAssembly/reference-types] Constant Expressions constraint (#134)

It's in the definition of constant expressions: https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/WebAssembly/reference-types/issues/134#issuecomment-784865248, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AO2CJMP4BMNJO4W7IZX6QDDTASUN7ANCNFSM4YBWKO2A.

rossberg commented 3 years ago

Please look at the section I just linked, it says that the type of a global used in a const expression must be const.

lum1n0us commented 3 years ago

OK, you got me. You are right. Thanks.


From: Andreas Rossberg notifications@github.com Sent: Wednesday, February 24, 2021 4:05 PM To: WebAssembly/reference-types reference-types@noreply.github.com Cc: He, Liang liang.he@intel.com; Author author@noreply.github.com Subject: Re: [WebAssembly/reference-types] Constant Expressions constraint (#134)

Please look at the section I just linked, it says that the type of a global used in a const expression must be const.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/WebAssembly/reference-types/issues/134#issuecomment-784879118, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AO2CJMKJ6ZLB5V3762RMA5TTASXMNANCNFSM4YBWKO2A.