WebAssembly / interface-types

Other
641 stars 57 forks source link

Weak Imports #48

Open jgravelle-google opened 5 years ago

jgravelle-google commented 5 years ago

Should we model weak imports as a Bindings-layer feature?

It's a feature that can be expressed in terms of bindings, it affects how modules are wired together, and it's a weaker constraint on the environment than wasm imports (which state "give me this or I will fail to instantiate").

At a first stab, we can describe this feature with no new wasm-core functionality, by for example adding a pair of bindings, one to wrap the imported object (with either the object if present, or something that traps if not), and a boolean global to check if the import succeeded or not.

Maybe not for MVP which makes the timing awkward? Or maybe it's compelling enough to add.

This was mentioned in this morning's WASI meeting, @sunfishcode more thoughts? Previous discussions: https://github.com/WebAssembly/WASI/issues/36 , https://github.com/WebAssembly/design/issues/1281

fgmccabe commented 5 years ago

IMO, you do not need a specific 'weak import' concept if you use 'web interoperability bindings'. In the case where an actual import is not provided, you can provide a stub 'implementation' via the binding lambda.

On Thu, Jul 18, 2019 at 9:34 AM Jacob Gravelle notifications@github.com wrote:

Should we model weak imports as a Bindings-layer feature?

It's a feature that can be expressed in terms of bindings, it affects how modules are wired together, and it's a weaker constraint on the environment than wasm imports (which state "give me this or I will fail to instantiate").

At a first stab, we can describe this feature with no new wasm-core functionality, by for example adding a pair of bindings, one to wrap the imported object (with either the object if present, or something that traps if not), and a boolean global to check if the import succeeded or not.

Maybe not for MVP which makes the timing awkward? Or maybe it's compelling enough to add.

This was mentioned in this morning's WASI meeting, @sunfishcode https://github.com/sunfishcode more thoughts? Previous discussions: WebAssembly/WASI#36 https://github.com/WebAssembly/WASI/issues/36 , WebAssembly/design#1281 https://github.com/WebAssembly/design/issues/1281

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/WebAssembly/webidl-bindings/issues/48?email_source=notifications&email_token=AAQAXUADYIEEMAWXMFMB57TQACLPTA5CNFSM4IE5POR2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HABVIGA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQAXUHD5V57VA6NUBTEW4DQACLPTANCNFSM4IE5PORQ .

-- Francis McCabe SWE

jgravelle-google commented 5 years ago

In the case where an actual import is not provided, you can provide a stub 'implementation' via the binding lambda.

That's the core idea I think. Something like

(@bindings weak-import "external" "global"
  (if-present Integer-as-i32) ;; import binding
  (if-absent (i32.const 0)) ;; default value
)