-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Some information about a module doesn't get passed down to one of the text2abstract operations that need it:
wasm-semantics/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md
Lines 837 to 849 in b353017
| rule #t2aModule<ctx(... funcIds: FIDS) #as C>(#module(... types: TS, funcs: FS, tables: TABS, mems: MS, globals: GS, elem: EL, data: DAT, start: S, importDefns: IS, exports: ES, metadata: #meta(... id: OID))) | |
| => #module( ... types: #t2aDefns<C>(TS) | |
| , funcs: #t2aDefns<C>(FS) | |
| , tables: #t2aDefns<C>(TABS) | |
| , mems: #t2aDefns<C>(MS) | |
| , globals: #t2aDefns<C>(GS) | |
| , elem: #t2aDefns<C>(EL) | |
| , data: #t2aDefns<C>(DAT) | |
| , start: #t2aDefns<C>(S) | |
| , importDefns: #t2aDefns<C>(IS) | |
| , exports: #t2aDefns<C>(ES) | |
| , metadata: #meta(... id: OID, funcIds: FIDS, filename: .String) | |
| ) |
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:
wasm-semantics/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md
Lines 883 to 888 in b353017
| rule #t2aDefn<ctx(... typeIds: TIDS) #as C>(( func OID:OptionalId T:TypeUse LS:LocalDecls IS:Instrs )) | |
| => #func(... type: typeUse2typeIdx(T, TIDS) | |
| , locals: locals2vectype(LS) | |
| , body: #t2aInstrs <#updateLocalIds(C, #ids2Idxs(T, LS))>(IS) | |
| , metadata: #meta(... id: OID, localIds: #ids2Idxs(T, LS)) | |
| ) |
wasm-semantics/pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md
Lines 1309 to 1325 in b353017
| syntax Map ::= #ids2Idxs(TypeUse, LocalDecls) [function, total] | |
| | #ids2Idxs(Int, TypeUse, LocalDecls) [function, total] | |
| // ------------------------------------------------------------------------- | |
| rule #ids2Idxs(TU, LDS) => #ids2Idxs(0, TU, LDS) | |
| rule #ids2Idxs(_, .TypeDecls, .LocalDecls) => .Map | |
| rule #ids2Idxs(N, (type _) , LDS) => #ids2Idxs(N, .TypeDecls, LDS) | |
| rule #ids2Idxs(N, (type _) TDS, LDS) => #ids2Idxs(N, TDS , LDS) | |
| rule #ids2Idxs(N, (param ID:Identifier _) TDS, LDS) | |
| => (ID |-> N) #ids2Idxs(N +Int 1, TDS, LDS) | |
| rule #ids2Idxs(N, (param _) TDS, LDS) => #ids2Idxs(N +Int 1, TDS, LDS) | |
| rule #ids2Idxs(N, _TD:TypeDecl TDS, LDS) => #ids2Idxs(N , TDS, LDS) [owise] | |
| rule #ids2Idxs(N, .TypeDecls, local ID:Identifier _ LDS:LocalDecls) | |
| => (ID |-> N) #ids2Idxs(N +Int 1, .TypeDecls, LDS) | |
| rule #ids2Idxs(N, .TypeDecls, _LD:LocalDecl LDS) => #ids2Idxs(N +Int 1, .TypeDecls, LDS) [owise] |