Skip to content

Instantly share code, notes, and snippets.

@lukewagner
Last active February 10, 2021 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukewagner/d662cbe7b58281672053dab4118d25b7 to your computer and use it in GitHub Desktop.
Save lukewagner/d662cbe7b58281672053dab4118d25b7 to your computer and use it in GitHub Desktop.
;; Each of these 4 modules is independently published. Note that, while there is a non-trivial amount of type-y
;; boilerplate, it is proportional in size to only the *direct* dependencies.
(module $A
(type $Wasi (instance ...))
(import "wasi" (instance (type $Wasi)))
(func (export "a") ...)
)
(module $B
(type $Wasi (instance ...))
(import "wasi" (instance $wasi (type $Wasi)))
(import "A:1.x" (module $A
(import "wasi" (instance (type $Wasi)))
(export "a" (func))
))
(instance $a (instantiate $A (instance $wasi)))
(func (export "b") ...)
)
(module $C
(type $Wasi (instance ...))
(import "wasi" (instance $wasi (type $Wasi)))
(import "B:1.x" (module $B
(import "wasi" (instance $wasi (type $Wasi)))
(export "b" (func))
))
(instance $b (instantiate $B (instance $wasi)))
(func (export "c") ...)
)
(module $D
(type $Wasi (instance ...))
(import "wasi" (instance $wasi (type $Wasi)))
(import "C:1.x" (module $C
(import "wasi" (instance $wasi (type $Wasi)))
(export "c" (func))
))
(instance $c (instantiate $C (instance $wasi)))
(func (export "d") ...)
)
;; Invoking 'link' on $D produces the following linked module. Notice that the amount of module-type-y
;; boilerplate is O(n) where n is the number of transitive dependencies, not O(n^2). Without the
;; wrapper modules, it would be O(n^2).
(module
(type $Wasi (instance ...))
(import "A:1.0.0:sha256..." (module $A
(import "wasi" (instance (type $Wasi)))
(export "a" (func $a))
))
(import "B:1.0.0:sha256..." (module $B
(import "wasi" (instance (type $Wasi)))
(import "A:1.x" (module
(import "wasi" (instance (type $Wasi)))
(export "a" (func))
))
(export "b" (func $b))
))
(module $B_wrap
(import "wasi" (instance $wasi (type $Wasi)))
(instance $b (instantiate $B (instance $wasi) (module $A)))
(export "b" (func $b.$b))
)
(import "C:1.0.0:sha256..." (module $C
(import "wasi" (instance (type $Wasi)))
(import "B:1.x" (module
(import "wasi" (instance $wasi (type $Wasi)))
(export "b" (func))
))
(export "c" (func $c))
))
(module $C_wrap
(import "wasi" (instance $wasi (type $Wasi)))
(instance $c (instantiate $C (instance $wasi) (module $B_wrap)))
(export "c" (func $c.$c))
)
(import "D:1.0.0:sha256..." (module $D
(import "wasi" (instance (type $Wasi)))
(import "C:1.x" (module
(import "wasi" (instance $wasi (type $Wasi)))
(export "c" (func))
))
(export "d" (func))
))
(instance $d (instantiate $D (instance $wasi) (module $C_wrap)))
(export $d)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment