Stream: git-wasmtime

Topic: wasmtime / PR #15130 Evaluate trapping active element seg...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 07:14):

po-nuvai opened PR #15130 from po-nuvai:fix-15036-elem-eval-order to bytecodealliance:main:

Active element segments whose expressions may trap (struct.new* / array.new*) are now evaluated up front, alongside passive segments, into a hidden segment slot that wasm code cannot access. They are then copied into their table in the normal active-segment order and dropped. This means a trapping element expression no longer leaves earlier writes behind in imported tables, matching the spec. Segments that cannot trap keep the existing fast path.

The cow-order-trapping-elem-expr.wast test expected the old behavior (an earlier segment's write remaining in the imported table), so it is updated to expect an uninitialized element instead.

Fixes #15036

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.md

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 07:14):

po-nuvai removed the review request for wasmtime-compiler-reviewers from PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 07:14):

po-nuvai requested cfallin for a review on PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 07:14):

po-nuvai requested wasmtime-compiler-reviewers for a review on PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 07:14):

po-nuvai requested wasmtime-core-reviewers for a review on PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 20:53):

:thumbs_up: cfallin submitted PR review:

This approach seems plausible to me. It might be worthwhile to cite the relevant bit of the Wasm standard's description of instantiation that gives the relevant side-effect ordering here, too, just for reader clarity?

cc @alexcrichton perhaps for a second look just to ensure I haven't missed something subtle, too...

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 21:31):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 21:31):

:speech_balloon: alexcrichton created PR review comment:

Could these two fields be stored as an enum instead of side-by-side? That I think might better represent the invariant here where the elements are either defined directly (in which case they can't trap and also don't ever get reflected in vm::Instance)

view this post on Zulip Wasmtime GitHub notifications bot (Nov 03 2026 at 21:31):

:speech_balloon: alexcrichton created PR review comment:

For staged here -- I think this only applies to imported tables, right? For locally-defined tables the staged bit I don't think should be necessary. (and will help speed up initialization of those tables a bit)

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:33):

po-nuvai updated PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:34):

:memo: po-nuvai submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:34):

:speech_balloon: po-nuvai created PR review comment:

Done, thanks! It's now a TableSegmentInit enum.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:36):

po-nuvai commented on PR #15130:

@cfallin Thanks! Added a comment linking to the spec's instantiation algorithm in 548129882f.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:42):

:memo: po-nuvai submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:42):

:speech_balloon: po-nuvai created PR review comment:

Good point about avoiding the cost for local tables! I think the target table of the
trapping segment itself isn't quite the right condition though: in the first test case from
#15036 the trapping segment targets a local table ($t2), but an earlier segment writes to
the imported table, so without staging $f would still be visible. (This is the case at Good point about avoiding the cost for local tables! I think the target table of the
trapping segment itself isn't quite the right condition though: in the first test case from
#15036 the trapping segment targets a local table ($t2), but an earlier segment writes to
the imported table, so without staging $f would still be visible. (This is the case at
line 31 of issue15036.wast.)

How about skipping staging entirely when the module has no imported tables? Then nothing
outside the instance can observe a partial initialization. Does that sound right to you?

line 31 of issue15036.wast.)

How about skipping staging entirely when the module has no imported tables? Then nothing
outside the instance can observe a partial initialization. Does that sound right to you?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:43):

:speech_balloon: po-nuvai edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:43):

po-nuvai requested alexcrichton for a review on PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 02:43):

po-nuvai requested cfallin for a review on PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 04:44):

po-nuvai updated PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 04:46):

po-nuvai commented on PR #15130:

While testing I found that the staged path crashed when compiling modules with 64-bit tables: the copy used the table's index type for the length instead of i32 like table.init. Fixed in 2204077acc, with a new test in issue15036.wast.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 15:35):

:speech_balloon: alexcrichton created PR review comment:

Oh I see and yeah that makes sense. Instead of looking for imported tables vs not, how about a local bool while translating element segments, something like side_effects_visible and once a segment applies to an imported table that flips to true, and the condition for using staged requires side_effects_visible && may_trap?

Mostly I'm hopeful we can avoid initializing an entire element segment for a module with a defined table where the side effects aren't visible because it'd help optimize instantiation a bit.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 15:35):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 18:52):

po-nuvai updated PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 18:54):

:memo: po-nuvai submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 18:54):

:speech_balloon: po-nuvai created PR review comment:

Done in <12b358d908> , thanks!

The flag also counts the current segment, since a trapping segment that writes to an imported table must still be staged (test case 2 in issue15036.wast covers this).

I also added a test for a trapping segment before any imported table write, which is now evaluated in place.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:04):

:thumbs_up: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:04):

alexcrichton added PR #15130 Evaluate trapping active element segments before table writes to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 21:33):

:check: alexcrichton merged PR #15130.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 21:33):

alexcrichton removed PR #15130 Evaluate trapping active element segments before table writes from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 06 2026 at 05:55):

po-nuvai requested alexcrichton for a review on PR #15130.


Last updated: Nov 19 2026 at 20:05 UTC