-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index spaces feel inconsistent about what they might or might not contain #11
Comments
+1 this is something I've repeatedly run up against as well. It seems like we might as well "use the type system" a little bit to ensure that e.g. a function we are lifting is actually a core function and not a component function. |
I think you're right that the index space division is rather ad hoc; it's attempting to balance a few competing goals and compromising as a result, but maybe it's not the right compromise. So there's a pretty clear core wasm convention (which, if we're embedding core wasm into components, I think we should maintain) that the The big irregularity with the current scheme that you mentioned that bugs me too is that components and modules are in different index spaces; if they followed the function/instance convention, they'd share a single index space. My main hangup here is that if we put both components/modules into the same index space, we'd have to pick a single shared Finally: the type index space doesn't contain module instance types only because there's no need for them at the moment. If the need arose, there's no reason we couldn't add them (and/or core function types as well). |
I agree with your thinking, although I don't know how best to solve this. In implementing this it feels inconsistent that modules/components are separate but their instances and functions are not, so I just wanted to raise the issue. |
Ok, having had a bit more time to think about this and run the idea by more folks, I think it's a good idea to be more regular here and split the function, instance and type index spaces into component-vs-core. I think there could be also be a nice organizing principle that we could adopt: if hopefully-maybe one day module linking is added to core wasm (as originally proposed), it would be nice if the binary encoding and validation logic for core {module, instance, type} sections could be shared between the component and core layers. Thus, a design criteria for these sections would be that they would also make sense when embedded in a core module (and thus probably not look too different than the original proposed binary format). Core functions are the outlier here: The big remaining question is how to express this split syntactically. I need to play with this a bit more before posting a proposed new syntax, but I'm happy to hear any ideas on this. I just wanted to give an update in the meantime (I need to finish off the canonical ABI PR before digging into this). |
Ok, I kinda like this idea of pretending that module-linking has already been added to core wasm; it gives us a nice regular scheme for syntactically and binarily separating out component-level and core-level index spaces:
So, as an example, I would write: (component
(import "foo" (instance $foo ;; creates a component instance type definition
(export "bar" (func (param string)))
))
(alias export $foo "bar" (func $foo_bar)) ;; component-level alias
(import "libc" (core module $Libc ;; creates a core module type definition
(export "memory" (memory 1))
(export "realloc" (func (param i32 i32) (result i32)))
))
(core instance $libc (instantiate $Libc)) ;; note: no (module $Libc) needed
(core alias export $libc "mem" (memory $mem)) ;; core-level alias adds core memory index
(core alias export $libc "realloc" (func $realloc)) ;; core-level alias adds core function index
(core $foo_bar_ (canon.lower ;; see comment below
(memory $mem) (realloc $realloc) ;; indexes core index spaces b/c canon.lower says so
$foo_bar ;; indexes the component function index space b/c canon.lower says so
))
(core module $Main ;; all core definitions inside here
(import "libc" "memory" (memory 1))
(import "libc" "realloc" (func (param i32 i32) (result i32)))
(import "foo" "bar" (func (param i32 i32)))
(func (export "baz") ...)
)
(core instance $main (instantiate $Main
(with "libc" (instance $libc))
(with "foo" (instance (export "bar" (func $foo_bar_))))
))
(core alias export $main "baz" (func $main_baz_))
(func $baz_run (canon.lift
(func (param string))
(memory $mem) (realloc $realloc) ;; indexes core index spaces b/c canon.lower says so
$main_baz_ ;; indexes the core function index space b/c canon.lower says so
))
(export "baz" (func $baz_run)) ;; indexes component function index space
) So the only tricky thing here is
But then, just like we have the following syntactic abbreviations in Explainer.md:
we could also have:
and this is what I used in the code sample above. However, I don't know if this abbreviation is too magical. You could make the case that the rewrite rule happens in the component layer before the rewritten text (the right-hand side) is handed down to the core text parser. 🤷 WDYT? |
Prefixing things with |
So my thinking here is that, when you have a |
Seems reasonable to me! |
This should be fixed by #29. |
Personally I get confused about the various index spaces that are introduced in the component model:
Personally I keep getting lost about which index space includes what. For example just now I wasn't sure if modules and components were in the same index space because their instances are in the same index space.
Would it be possible to separate these index spaces? For example could the function and index spaces be split between module/component types?
The text was updated successfully, but these errors were encountered: