-
Notifications
You must be signed in to change notification settings - Fork 13
Aliasing outer imported modules forces modules to have per-instance runtime state #28
Comments
The issue, as written, wasn't 100% clear to me, but after clarifying with Alex, here is my summary / reinterpretation: Modules have historically been static, self-describing things, and if we allow inner modules to close over their outer modules' imports, then we lose that property. Is the module linking proposal intentionally trading away this property to gain module-level closures, or was this an oversight? |
Good question! I think this is indeed intentional and valuable. One useful pattern it enables is preventing O(n^2) blowup of module types in module dependency trees. Although the syntax needs to be updated, I have an old gist that illustrates this -- in particular, see the use of the outer module's module imports by Conceptually, I wouldn't think of this as giving modules state but, rather, think of modules as functions that produce tuples of values (instances) when applied (instantiated). Thus, modules are basically function values and, in your example, function PARENT(b) {
function a() {
let _ = b()
}
return {a}
} In a JS engine, |
Ok makes sense, just wanted to confirm! You're right that this came up during implementation where I realized that third thing will be needed, but it shouldn't be the end of the world to implement it! |
One thing I tripped over recently when updating wasmtime's as proposed in #26 is that I believe when you alias an outer module's imported module then you're forcing each instantation to create new modules with new state.
For example a simple module like:
each time you instantiate
$PARENT
then the"a"
export will have different state because it has to reference whatever module was imported.I was under the impression, however, that this was likely not intended. Does validation need to ensure that
outer
module aliases only refer to locally-defined modules? Or is this an intended feature and consequence for engines to implement?The text was updated successfully, but these errors were encountered: