Repository navigation
Conversation
1d09c08 to
94986d5
Compare
| assert_eq!(path.len(), 1); | ||
| TypeId { | ||
| index: path[0] as u32, | ||
| unique_id: res.contextually_unique_id, | ||
| } |
There was a problem hiding this comment.
This is almost certainly incorrect, @alexcrichton what's the right way to go from a ResourceId to a TypeId?
There was a problem hiding this comment.
Heh no worries! There's a few things that will need to change here. The first is that the usize index of path, IIRC, are indices into self.exports. That means that you'll look at self.exports[path[0]] for example and extract out the TypeId from there. You should be able to assert that it's a ComponentEntityType::Type and return the created field for the TypeId return value here.
Additionally though you won't be able to assert that the path length is 1. For example this module:
(component
(type (export "x") (instance
(export $x "x" (instance
(export "x" (type (sub resource)))
))
))
)trips the assertion. A more complete example that doesn't validate today but should then validate with your PR is:
(component
(type (export "x") (instance
(export $i "i" (instance
(export "x" (type (sub resource)))
))
(alias export $i "x" (type $x))
(export "f" (func (param "x" (borrow $x))))
))
)
alexcrichton
left a comment
There was a problem hiding this comment.
Thanks for this! I believe that this is the correct approach instead of validate_and_register_named_types. The distinguishing feature there is that when an instance type is exported it shouldn't mutate self and add more exported resources since the resources are only considered exported for that one singular type itself and nothing else.
| @@ -0,0 +1,30 @@ | |||
| ;; RUN: validate % --features component-model | |||
There was a problem hiding this comment.
Oh for these kinds of tests they can go into tests/local/* to get a few extra tests related to printing and such.
| @@ -0,0 +1,30 @@ | |||
| ;; RUN: validate % --features component-model | |||
|
|
|||
| (component | |||
There was a problem hiding this comment.
Also it might be good to add a more minimal test case in addition to this one:
(component
(type (export "x") (instance
(export $x "x" (type (sub resource)))
(export "f" (func (param "x" (borrow $x))))
))
)There was a problem hiding this comment.
I've moved the tests into tests/local/component-model, and added this one.
| assert_eq!(path.len(), 1); | ||
| TypeId { | ||
| index: path[0] as u32, | ||
| unique_id: res.contextually_unique_id, | ||
| } |
There was a problem hiding this comment.
Heh no worries! There's a few things that will need to change here. The first is that the usize index of path, IIRC, are indices into self.exports. That means that you'll look at self.exports[path[0]] for example and extract out the TypeId from there. You should be able to assert that it's a ComponentEntityType::Type and return the created field for the TypeId return value here.
Additionally though you won't be able to assert that the path length is 1. For example this module:
(component
(type (export "x") (instance
(export $x "x" (instance
(export "x" (type (sub resource)))
))
))
)trips the assertion. A more complete example that doesn't validate today but should then validate with your PR is:
(component
(type (export "x") (instance
(export $i "i" (instance
(export "x" (type (sub resource)))
))
(alias export $i "x" (type $x))
(export "f" (func (param "x" (borrow $x))))
))
)| Type::ComponentInstance(ty) => { | ||
| let mut with_resources = HashSet::new(); | ||
|
|
||
| let set = if ty.explicit_resources.is_empty() { |
There was a problem hiding this comment.
While a bit subtle, I think that this check may want to look at the defined_resources list rather than look at the explicit_resources map. The reason for that is that concrete instances will have an empty list there but the instance types, which this PR is fixing, may not have an empty defined_resources list. On the other hand though it's frequent for any kind of instance to have an explicit_resources array set, so this I don't think is the right branch in the implementation.
The reason for this is that the set of exported resources should be only judiciously added to and for normal instances everywhere the previous additions to the set should already be taken care of. In effect by adding all explicit_resources it's forcing this check to basically pass.
So, in other words, I think this check should be refactored to look more like:
let set = if ty.defined_resources.is_empty() {
set
} else {
with_resources = set.clone();
for resource in ty.defined_resources.iter() {
with_resources.insert(ty.type_id_of(resource));
}
&with_resources
};or something along those lines where type_id_of is the body of the loop in the explicit_resources method you added. Either that or rename the added explicit_resources to defined_resources and have the same loop you have today returning an iterator (actually after typing this out I prefer the latter style here which you already have)
There was a problem hiding this comment.
Wouldn't only looking at defined_resources mean that the test you mentioned above wouldn't work?
(component
(type (export "x") (instance
(export $i "i" (instance
(export "x" (type (sub resource)))
))
(alias export $i "x" (type $x))
(export "f" (func (param "x" (borrow $x))))
))
)
|
After some discussion with @alexcrichton I'm going to close this. We can work around this bug with the upcoming wit encoding changes, and there are some dragons lurking in how we convert resource ids back to type ids. |
Currently, validation of the following component fails, as the resource
ris not viewed as exported when validating the export of$types'. (More specifically, it's the use ofrin the methodr.foothat causes the error, asris not viewed as exported at that point.)This PR addresses that by augmenting the set of named types when processing an
ComponentInstanceexport, extending the set with the explicitly exported resources in that instance.An alternate approach would be to extend the special handling of instances in
validate_and_register_named_typesto theComponentEntityType::Typecase as well, which would be a more targeted change than the one this PR currently proposes.