runtimeverification / wasm-semantics

A Prototype Formal Semantics of WebAssembly in K
Other
74 stars 18 forks source link

Function signatures aren't available during `Text2Abstract` on function definitions #663

Open gtrepta opened 1 week ago

gtrepta commented 1 week ago

Some information about a module doesn't get passed down to one of the text2abstract operations that need it: https://github.com/runtimeverification/wasm-semantics/blob/b353017e7178731daa12cba75dc81fd69e20a81f/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md?plain=1#L837-L849

On line 839, t2aDefns is invoked on the functions of the module with the context C. However, this context doesn't contain the signatures for the types in the module, only their ids. So, when t2a goes to calculate the indices of the variables in a function body, it doesn't have the function parameters for named types.

Here's an example from the wasm tests func.wast that fails because of this:

(module
  (type $sig (func (param i32) (result i32)))

  (func (export "f") (type $sig)
    (local $var i32)
    (local.get $var)
  )
)

(assert_return (invoke "f" (i32.const 42)) (i32.const 0))

$var here is assigned index 0. But, it should be 1, as the (param i32) in the function signature is at index 0 already. So, when "f" gets invoked, (local.get 0) is evaluated and returned, which is where the 42 that was passed in is at.

Relevant rules:

https://github.com/runtimeverification/wasm-semantics/blob/b353017e7178731daa12cba75dc81fd69e20a81f/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md?plain=1#L883-L888

https://github.com/runtimeverification/wasm-semantics/blob/b353017e7178731daa12cba75dc81fd69e20a81f/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md?plain=1#L1309-L1325