WebAssembly / component-model

Repository for design and specification of the Component Model
Other
933 stars 79 forks source link

Should "all types are exported properly" be validated in instance types? #186

Closed alexcrichton closed 1 year ago

alexcrichton commented 1 year ago

I left a comment on the PR for the initial implementation of resources with some more info, but the gist is a question of whether or not this is a valid component:

(component $C
  (import "foo" (instance $i
    (type $baz' (record))
    (export $baz "baz" (type (eq $baz')))
    (type $bar' (record (field "baz" $baz)))
    (export $bar "bar" (type (eq $bar')))
  ))
  (alias export $i "bar" (type $bar))
  (type $ME (instance
    (alias outer $C $bar (type $bar'))
    (export $bar "bar" (type (eq $bar')))
  ))
)

Specifically the $ME type exports a named record $bar which internally refers to another record $baz, but the type $ME doesn't export the $baz type. This means that in isolation $ME is not a valid instance, but in the context of this component it's valid since the $baz type is imported via the "foo" import.

My heavy-handed solution to this problem arising was to completely disable all validation of "are types properly exported/imported/named/etc" for instance type definitions. When the instance type is attached to a concrete component or a component type, however, validation runs. So for example if "foo" wasn't imported then this would be an invalid component.

I wanted to confirm though that this was reasonable behavior?

lukewagner commented 1 year ago

I agree that the example should be valid and that the approach you describe of not requiring the "all types named" property for instance types sounds right.

The only part I don't follow is the last bit about "if "foo" wasn't imported ...": it wouldn't be valid because you can't alias export an instance type (only an instance), but I think that's not what you're getting at; however I can't tell what example you have in mind.

alexcrichton commented 1 year ago

Ok sounds good! Also good point! I don't have an example in mind per se, but I'll stick to the "don't validate instances and instead defer their validation to when they get attached to components" logic

lukewagner commented 1 year ago

I think this matches the current wording in Binary.md, so closing as resolved, but feel free to reopen if otherwise.