Skip to content

Conversation

@silesmo
Copy link
Member

@silesmo silesmo commented May 28, 2023

Adds the initial pass for the parsing of resources and shared handles.

Do we want to store resources as a TypeDefKind? I assume we might want to move this to an indexmap of resources and just store a resource id in handles?

@sunfishcode

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parsing and syntax looks good to me!

My instinct here is that resources would be better off not being a TypeDefKind, because it's my understanding they'll never be first-class. The only place they can ever appear is as the referent of handles, and also, handles don't refer to anything other than resources.

@silesmo
Copy link
Member Author

silesmo commented May 31, 2023

The parsing and syntax looks good to me!

My instinct here is that resources would be better off not being a TypeDefKind, because it's my understanding they'll never be first-class. The only place they can ever appear is as the referent of handles, and also, handles don't refer to anything other than resources.

Yes that makes sense. I was unsure if we wanted to support types other than resources in the future. If that's not the case then I will change resources to not be TypeDefKind.

@sunfishcode
Copy link
Member

Looks good!

@sunfishcode sunfishcode enabled auto-merge (squash) May 31, 2023 23:42
@sunfishcode sunfishcode merged commit 7f01895 into bytecodealliance:main Jun 1, 2023
@alexcrichton
Copy link
Member

Thanks for working on this!

@silesmo are you able to fill work on filling out the remaining todo!()? I think there'll be a fair amount of design work to get them all filled out, but we can hopefully help out with them over time too.

Additionally would you be up for updating WIT.md upstream with the changes here? I think it's good to keep a documentation record of what this crate supports, even if it's worded along the lines of "this will change in the future" to ensure there's somewhere documenting what's supported.

@silesmo
Copy link
Member Author

silesmo commented Jun 2, 2023

Thanks for working on this!

@silesmo are you able to fill work on filling out the remaining todo!()? I think there'll be a fair amount of design work to get them all filled out, but we can hopefully help out with them over time too.

Additionally would you be up for updating WIT.md upstream with the changes here? I think it's good to keep a documentation record of what this crate supports, even if it's worded along the lines of "this will change in the future" to ensure there's somewhere documenting what's supported.

@alexcrichton Yes, my plan is to start working on that this weekend!

Yes I agree, I will make sure to update the documentation as well :)

alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Jun 14, 2023
This commit changes the representation of resources and their methods in
the `wit-parser` crate as implemented originally in bytecodealliance#1053. Previously
methods related to a resource were strung as a separate list of methods
from each `Resource` type which provided a nested view of functions for
bindings generators to interpret. This representation, however, does not
allow for methods or constructors to actually refer to the resource type
itself because the resource type can't be created until the method list
is created, a cyclic dependency.

To handle this problem this commit removes the nested list of functions
and instead places all resource methods and functions and such within
the normal single list of functions within an interface. This represents
a "flattened" version of all functions available within an interface or
world and aligns with the WebAssembly representation of how these will
work. The names of these functions are not valid identifiers and have
the component-model mangling along the lines of `[method]foo.bar` for
example.

My hope is that in the future as bindings generators are worked on
various helper methods can be added to automatically group functions
based on their kind to avoid any issues. Otherwise though this will
likely "break" all existing code generators when resources are
introduced because the names aren't valid identifiers in any language.
I think this is a good thing, however, as that way it can't be forgotten
to handle the resources case and failures will be "loud" in theory.

This commit changes a number of other miscellaneous details such as:

* Type resolution no longer needs to consider types referenced by
  methods of resources as dependencies which reflects how this will all
  look in a wasm binary format where resources are declared before their
  member functions are declared.

* Parsing has been updated to address some minor issues here and there
  and additionally has some new names to remove the old "value" concept
  which is no longer a thing.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Jun 14, 2023
This commit changes the representation of resources and their methods in
the `wit-parser` crate as implemented originally in bytecodealliance#1053. Previously
methods related to a resource were strung as a separate list of methods
from each `Resource` type which provided a nested view of functions for
bindings generators to interpret. This representation, however, does not
allow for methods or constructors to actually refer to the resource type
itself because the resource type can't be created until the method list
is created, a cyclic dependency.

To handle this problem this commit removes the nested list of functions
and instead places all resource methods and functions and such within
the normal single list of functions within an interface. This represents
a "flattened" version of all functions available within an interface or
world and aligns with the WebAssembly representation of how these will
work. The names of these functions are not valid identifiers and have
the component-model mangling along the lines of `[method]foo.bar` for
example.

My hope is that in the future as bindings generators are worked on
various helper methods can be added to automatically group functions
based on their kind to avoid any issues. Otherwise though this will
likely "break" all existing code generators when resources are
introduced because the names aren't valid identifiers in any language.
I think this is a good thing, however, as that way it can't be forgotten
to handle the resources case and failures will be "loud" in theory.

This commit changes a number of other miscellaneous details such as:

* Type resolution no longer needs to consider types referenced by
  methods of resources as dependencies which reflects how this will all
  look in a wasm binary format where resources are declared before their
  member functions are declared.

* Parsing has been updated to address some minor issues here and there
  and additionally has some new names to remove the old "value" concept
  which is no longer a thing.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Jun 16, 2023
This commit changes the representation of resources and their methods in
the `wit-parser` crate as implemented originally in bytecodealliance#1053. Previously
methods related to a resource were strung as a separate list of methods
from each `Resource` type which provided a nested view of functions for
bindings generators to interpret. This representation, however, does not
allow for methods or constructors to actually refer to the resource type
itself because the resource type can't be created until the method list
is created, a cyclic dependency.

To handle this problem this commit removes the nested list of functions
and instead places all resource methods and functions and such within
the normal single list of functions within an interface. This represents
a "flattened" version of all functions available within an interface or
world and aligns with the WebAssembly representation of how these will
work. The names of these functions are not valid identifiers and have
the component-model mangling along the lines of `[method]foo.bar` for
example.

My hope is that in the future as bindings generators are worked on
various helper methods can be added to automatically group functions
based on their kind to avoid any issues. Otherwise though this will
likely "break" all existing code generators when resources are
introduced because the names aren't valid identifiers in any language.
I think this is a good thing, however, as that way it can't be forgotten
to handle the resources case and failures will be "loud" in theory.

This commit changes a number of other miscellaneous details such as:

* Type resolution no longer needs to consider types referenced by
  methods of resources as dependencies which reflects how this will all
  look in a wasm binary format where resources are declared before their
  member functions are declared.

* Parsing has been updated to address some minor issues here and there
  and additionally has some new names to remove the old "value" concept
  which is no longer a thing.
alexcrichton added a commit that referenced this pull request Jun 16, 2023
* Change data representation of resource methods

This commit changes the representation of resources and their methods in
the `wit-parser` crate as implemented originally in #1053. Previously
methods related to a resource were strung as a separate list of methods
from each `Resource` type which provided a nested view of functions for
bindings generators to interpret. This representation, however, does not
allow for methods or constructors to actually refer to the resource type
itself because the resource type can't be created until the method list
is created, a cyclic dependency.

To handle this problem this commit removes the nested list of functions
and instead places all resource methods and functions and such within
the normal single list of functions within an interface. This represents
a "flattened" version of all functions available within an interface or
world and aligns with the WebAssembly representation of how these will
work. The names of these functions are not valid identifiers and have
the component-model mangling along the lines of `[method]foo.bar` for
example.

My hope is that in the future as bindings generators are worked on
various helper methods can be added to automatically group functions
based on their kind to avoid any issues. Otherwise though this will
likely "break" all existing code generators when resources are
introduced because the names aren't valid identifiers in any language.
I think this is a good thing, however, as that way it can't be forgotten
to handle the resources case and failures will be "loud" in theory.

This commit changes a number of other miscellaneous details such as:

* Type resolution no longer needs to consider types referenced by
  methods of resources as dependencies which reflects how this will all
  look in a wasm binary format where resources are declared before their
  member functions are declared.

* Parsing has been updated to address some minor issues here and there
  and additionally has some new names to remove the old "value" concept
  which is no longer a thing.

* Fix resources-in-worlds with methods

Additionally be sure to update ids listed in `FunctionKind` during
merging.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Jul 11, 2023
Releases recent changes such as:

* More support for the gc proposal. bytecodealliance#1045 bytecodealliance#1059
* Support for resources throughout most tooling. bytecodealliance#1053 bytecodealliance#1068 bytecodealliance#1070 bytecodealliance#1082
  bytecodealliance#1079 bytecodealliance#1083 bytecodealliance#1084 bytecodealliance#1105 bytecodealliance#1113 bytecodealliance#1116
* Support for `include` in WIT files. bytecodealliance#1054 bytecodealliance#1085 bytecodealliance#1088
* WIT worlds may now be rejected if the same interface can be "reached"
  as both an import and an export simultaneously. bytecodealliance#1081 bytecodealliance#1107
* Support for registry metadata in `wasm-tools metadata`. bytecodealliance#1060
* A new subcommand `wasm-tools component targets`. bytecodealliance#1089
* An `--out-dir` argument is supported on `wasm-tools component wit` to
  print the entire `Resolve` instead of just one package. bytecodealliance#1108
* Miscellaneous bug fixes and improvements. bytecodealliance#1061 bytecodealliance#1065 bytecodealliance#1074 bytecodealliance#1073 bytecodealliance#1078 bytecodealliance#1077
  bytecodealliance#1072 bytecodealliance#1086 bytecodealliance#1091 bytecodealliance#1094 bytecodealliance#1114 bytecodealliance#1106
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Jul 11, 2023
Releases recent changes such as:

* More support for the gc proposal.
  [bytecodealliance#1045](bytecodealliance#1045)
  [bytecodealliance#1059](bytecodealliance#1059)
* Support for resources throughout most tooling.
  [bytecodealliance#1053](bytecodealliance#1053)
  [bytecodealliance#1068](bytecodealliance#1068)
  [bytecodealliance#1070](bytecodealliance#1070)
  [bytecodealliance#1082](bytecodealliance#1082)
  [bytecodealliance#1079](bytecodealliance#1079)
  [bytecodealliance#1083](bytecodealliance#1083)
  [bytecodealliance#1084](bytecodealliance#1084)
  [bytecodealliance#1105](bytecodealliance#1105)
  [bytecodealliance#1113](bytecodealliance#1113)
  [bytecodealliance#1116](bytecodealliance#1116)
* Support for `include` in WIT files.
  [bytecodealliance#1054](bytecodealliance#1054)
  [bytecodealliance#1085](bytecodealliance#1085)
  [bytecodealliance#1088](bytecodealliance#1088)
* WIT worlds may now be rejected if the same interface can be "reached"
  as both an import and an export simultaneously.
  [bytecodealliance#1081](bytecodealliance#1081)
  [bytecodealliance#1107](bytecodealliance#1107)
* Support for registry metadata in `wasm-tools metadata`.
  [bytecodealliance#1060](bytecodealliance#1060)
* A new subcommand `wasm-tools component targets`.
  [bytecodealliance#1089](bytecodealliance#1089)
* An `--out-dir` argument is supported on `wasm-tools component wit` to
  print the entire `Resolve` instead of just one package.
  [bytecodealliance#1108](bytecodealliance#1108)
* Miscellaneous bug fixes and improvements.
  [bytecodealliance#1061](bytecodealliance#1061)
  [bytecodealliance#1065](bytecodealliance#1065)
  [bytecodealliance#1074](bytecodealliance#1074)
  [bytecodealliance#1073](bytecodealliance#1073)
  [bytecodealliance#1078](bytecodealliance#1078)
  [bytecodealliance#1077](bytecodealliance#1077)
  [bytecodealliance#1072](bytecodealliance#1072)
  [bytecodealliance#1086](bytecodealliance#1086)
  [bytecodealliance#1091](bytecodealliance#1091)
  [bytecodealliance#1094](bytecodealliance#1094)
  [bytecodealliance#1114](bytecodealliance#1114)
  [bytecodealliance#1106](bytecodealliance#1106)
alexcrichton added a commit that referenced this pull request Jul 11, 2023
Releases recent changes such as:

* More support for the gc proposal.
  [#1045](#1045)
  [#1059](#1059)
* Support for resources throughout most tooling.
  [#1053](#1053)
  [#1068](#1068)
  [#1070](#1070)
  [#1082](#1082)
  [#1079](#1079)
  [#1083](#1083)
  [#1084](#1084)
  [#1105](#1105)
  [#1113](#1113)
  [#1116](#1116)
* Support for `include` in WIT files.
  [#1054](#1054)
  [#1085](#1085)
  [#1088](#1088)
* WIT worlds may now be rejected if the same interface can be "reached"
  as both an import and an export simultaneously.
  [#1081](#1081)
  [#1107](#1107)
* Support for registry metadata in `wasm-tools metadata`.
  [#1060](#1060)
* A new subcommand `wasm-tools component targets`.
  [#1089](#1089)
* An `--out-dir` argument is supported on `wasm-tools component wit` to
  print the entire `Resolve` instead of just one package.
  [#1108](#1108)
* Miscellaneous bug fixes and improvements.
  [#1061](#1061)
  [#1065](#1065)
  [#1074](#1074)
  [#1073](#1073)
  [#1078](#1078)
  [#1077](#1077)
  [#1072](#1072)
  [#1086](#1086)
  [#1091](#1091)
  [#1094](#1094)
  [#1114](#1114)
  [#1106](#1106)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants