WebAssembly/module-linking

Nested parent aliases

Closed this issue · 4 comments

Currently, parent aliases can only refer to the innermost parent. When nesting multiple levels, it may be necessary to reference definitions from an even outer scope. While this could be expressed by inserting an alias on each level and chaining them up, it seems natural enable parent aliases to point to any enclosing scope directly.

For example, instead of

(module
  (type (func))
  (module
    (alias parent (type 0))
    (module
      (alias parent (type 0))
      (func (type 0))
    )
  )
)

directly allow

(module
  (type (func))
  (module
    (module
      (alias (parent 1) (type 0))
      (func (type 0))
    )
  )
)

where the parent is indexed relatively (de Bruijn-style), with the innermost one being 0. If omitted, it defaults to 0.

Or as a symbolic shorthand (cf. #19):

(module $A
  (type $ t(func))
  (module $B
    (module $C
      (func (type (parent $A) $t))
    )
  )
)

where we allow to use the symbolic name of modules to name parents.

This becomes more relevant once type imports induce more complicated type dependencies.

That makes sense to me.

FWIW, "parent" can mean many things, so I would also have a preference for replacing that keyword with outer or something similar, especially when an outer scope may be both a module or a module/instance type (cf. #21).

Good point. Now that you mention it, I also have a distinct notion of "parent" brewing in a totally different context.

Fixed with #26