-
Notifications
You must be signed in to change notification settings - Fork 79
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
Namespacing for Worlds #177
Comments
I expected those import to actually be something like this (by including the namespace at the world level and converting the identifiers to snake case): (import "wasi_http_types" "new_fields" (func (;4;) (type 5)))
...
(import "wasi_http_default_outgoing_http" "handle" (func (;14;) (type 9))) |
Great question! So when compiling a component, the names used for the core imports and exports are completely encapsulated inside the component and so they can be arbitrarily chosen by the toolchain. Rather, it is the imports and exports in the containing component that are meant to identify the imported/exported interface uniquely to the outside world (specifically, using the (component
(import "types" (id "wasi:http/types") (instance
(export "new-fields" (func ...))
(export "fields-entries" (func ...))
...
))
(import "default-outgoing-HTTP" (id "wasi:http/outgoing-handler") (instance
(export "handle" (func ...))
))
...
(core module
(import "types" "new-fields" (func ...))
(import "types" "fields-entries" (func ...))
...
(import "default-outgoing-HTTP" "handle" (func ...))
)
...
) That being said, if hosts wanted to implement core imports directly (so that they could accept core modules that were not wrapped by components), that would be an argument for somehow mangling the (cc @peterhuene @alexcrichton @pchickey @sunfishcode b/c this relates to what we've been talking about w.r.t |
I agree with Luke that at the component model level there's enough namespacing and such that I don't think there's any changes in the spec necessary. At the tooling level though thinking about this it seems like we may want different conventions around naming and/or transformation from WIT to the component model. For example while I think it makes sense for a In some sense I would expect the name |
@alexcrichton, taking into consideration the union of worlds proposal, we might need to consider the target world namespace and renamed imports while mangling them, right? E.g. cloud-core proposal. |
Sorry I'm not quite sure what you mean? Can you elaborate more? |
If I have a world:
I implicitly get several imports to go with it:
If I'm understanding the situation here, the main issue is that "streams" and "types" aren't good import names for the purposes of avoiding name conflicts or identifying the original source of an interface in a component. As an incremental improvement on the current situation, could we adopt a convention of including a prefix in every interface name, i.e. |
Although transitive interface dependencies get implicitly imported with their default world http-server {
import my-streams: io.streams
import my-types: http.types
export handler: http.incoming-handler
} and there would be no That all being said, I can see how |
I've been trying to figure out the best way to solve this and I'm not coming up with something that "feels right", unfortunately, but I do have a few ideas perhaps. To me the problem here is the automatic flat injection of transitive dependencies of interfaces into a One option, as recommended here, is to mangle more "stuff" into the name. WIT, for example, has a package namespace and a document namespace that are currently entirely unused when converting to components. That could mean, for example, that the
would become:
which would largely solve the problem I think. This means that authors of packages, as usual, are cognizant of their own naming choices but need not concern themselves with the naming choices of others. This still doesn't feel like a perfect solution, though. For example package names themselves could still conflict (e.g. same package from two different registries). Another option for this perhaps would be to translate worlds to WIT differently. For example the above world could be translated to a component as: (component
(import "wasi-http" (instance
(export "types" (instance
(export "request" ...)
))
))
;; ...
) where top-level imports are package imports which have their own structure internally. This means that the "elaboration" of a world still has to worry about clashes between same-named packages but that somehow to me feels a bit better to resolve in this context (or maybe it's the same, unsure). This is a more significant change, however. Neither way really feels like a great way forward to me. I'm having difficulty figuring out a better possibility though. |
Thinking about this some more, perhaps there's a nice solution if we revisit the structure of externname ::= <name> (id <URL>)? The original expectation was that the More-recently, though, we've been talking about splitting out the separate cases of To me, this suggests considering an alternative factoring like: externname::= (id <ID>)
| <name> (url <URL>)? where Fleshing this idea out a bit more, in a Wit context, we could mostly start writing the interface "wasi:http/types" {
resource incoming-request { ... }
resource response-outparam { ... }
}
interface "wasi:http/incoming-handler" {
use "wasi:http/types".{incoming-request, response-outparam}
handle: func(request: incoming-request, response: response-outparam)
}
default world "wasi:http/server" {
export "wasi:http/incoming-handler"
} Note that in a world context, the WDYT? |
For the Binary format, I like the proposed changes of the For the WIT IDL, I believe it will get verbose really quick besides requiring the current interface definitions to be updated. |
I think we can follow the import map approach from the HTML spec to keep a little bit simpler and allow evolving over time. The way I see it they can be placed in two locations:
|
I wonder if, due to the fact that Wit will mostly be (1) not super long, (2) written infrequently and read many many times, if the usual approach we'd take for source code programs (indirecting through a map) isn't worth the complexity. Additionally, it seems like the inline- |
Personally I don't think we should go the route of the inline ids like you mentioned with Additionally I think another drawback is that if everything is written inline then it makes it harder to fork a package and modify it. For example if someone wanted to experiment with an updated version of Finally I feel like the ID here is somewhat, although not entirely, orthogonal to the namespacing issue at hand with how imports are modelled. Even if IDs were all present that's still not solving the problem of "what's the kebab-string". That's where I think we'd still need something like I mentioned above where the package/document structure is perhaps reflected through nested instances, meaning that everything becomes namespaced. In such a world the "id" is only really necessary in the top-level package and while everything else inside it could have an "id" it may not be necessary. |
I guess there's two separable design changes I suggested in my last comment and it might be useful to start by just focusing on the first:
Just focusing on #1, and setting aside precisely how we derive the |
As far as I understood the concept of extending externname metadata, we were including version constraints, and package resolution information in this structured format. I like that framing, but when considering this adjustment would be concerned about singular IDs firstly being representable and secondly being used correctly in the WIT format. Portability benefits for developer files are important - and this does create a difference between WIT and component binaries in this regards. Perhaps there's another way to remove unnecessary internal naming, while still aligning on structured metadata and unified internal pathing conventions. I can try and put together some further suggestions if that would be useful. |
I've made a proposal to help solve this issue at #193 which I'm hoping will address a number of related issues at the same time. I'd appreciate it if others could take the time to review (apologies it's long) and provide feedback! |
My understanding is that right now there is a single namespace in the context with WIT. That can cause some confusion as you can see in this discussion here. For the case of wasi:http/outgoing-handler, the imports identifiers are resolved as follows:
Is there a plan to add a namespace based on the world name to avoid name collisions?
The text was updated successfully, but these errors were encountered: