WebAssembly / WebAssembly/binaryen

wasm-ctor-eval: Handle cycles with non-nullable content

Open
#5,913 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

(module
 (type $A (sub final (struct (field (mut (ref struct))))))
 (type $B (struct ))

 (import "a" "b" (func $import))

 (func "test"
  (local $temp (ref $A))
  (struct.set $A 0
   (local.tee $temp
    (struct.new $A
     (struct.new_default $B)
    )
   )
   (local.get $temp)
  )
  ;; Stop evalling here, forcing us to serialize what we've seen so far in this
  ;; function, including its locals
  ;;
  ;; The local $temp contains a struct with a cycle now, and the cycle is on a
  ;; field that is mutable but *non*-nullable, so we can't use the usual trick
  ;; of writing a null initial value and fixing it up later. Instead, we need to
  ;; write some other type of value initially.
  (call $import)
 )
)
$ wasm-ctor-eval a.wat -all --ctors=test --kept-exports=test
trying to eval test
wasm-ctor-eval: wasm-ctor-eval.cpp:757: bool {anonymous}::CtorEvalExternalInterface::applyGlobalsToModule()::InitFixer::handleChild(wasm::Expression*&, wasm::Expression*, wasm::Index): Assertion `isNullableAndMutable(parent, fieldIndex)' failed.
Aborted

The input module cleverly creates a cycle using a non-nullable field by creating a temporary object just for that purpose. wasm-ctor-eval would need to be similarly clever, which seems difficult in general...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the shown wasm-ctor-eval command and inspect wasm-ctor-eval.cpp around InitFixer::handleChild at the assertion on line 757. Trace how cycles are serialized when fields are mutable but non-nullable. Done means the provided module and comparable non-nullable cycles no longer abort during constructor evaluation.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.