Stream: wasm

Topic: What is the rationale for the ref.func side condition?


view this post on Zulip Julien Cretin (ia0) (Aug 16 2022 at 09:10):

Hi! The ref.func validation rule has a x \in C.refs side condition. My understanding is that this limits usage of ref.func in code segment to only reference functions that are also referenced outside the code segment (essentially in global and table segments). I'm not sure why this is needed and couldn't find a rationale in the spec. Could someone help me understand? Thanks!

view this post on Zulip Alex Crichton (Aug 16 2022 at 14:32):

If I remember the discussion around this right the rough idea was that for streaming compilers you'd know ahead of time by the time you reach the code section whether something is exported from the module or not. What you'd do with that information I'm not 100% sure, though, in a streaming context.

In Wasmtime we sort of use this information to infer what set of trampolines need to be created to enter the module. Given the set of "possibly exported" functions, those in C.refs, it dictates which type signatures need a trampoline generated. We don't really benefit much from the streaming requirement though since Cranelift is a more heavyweight compiler than a streaming baseline compiler.

view this post on Zulip Julien Cretin (ia0) (Aug 17 2022 at 10:00):

I see thanks! So it's a validity restriction on modules for to allow for streaming compilers to be possible rather than for soundness (or some other execution-related requirement).


Last updated: Oct 23 2024 at 20:03 UTC