Skip to content

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

Open
@gtrepta

Description

@gtrepta

Some information about a module doesn't get passed down to one of the text2abstract operations that need it:

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:

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))
)

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions