Skip to content

Implement fused adapters for (list T) types#4558

Merged
alexcrichton merged 3 commits intobytecodealliance:mainfrom
alexcrichton:adapt-list
Aug 1, 2022
Merged

Implement fused adapters for (list T) types#4558
alexcrichton merged 3 commits intobytecodealliance:mainfrom
alexcrichton:adapt-list

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit implements one of the two remaining types for adapter
fusion, lists. This implementation is particularly tricky for a number
of reasons:

  • Lists have a number of validity checks which need to be carefully
    implemented. For example the byte length of the list passed to
    allocation in the destination module could overflow the 32-bit index
    space. Additionally lists in 32-bit memories need a check that their
    final address is in-bounds in the address space.

  • In the effort to go ahead and support memory64 at the lowest layers
    this is where much of the magic happens. Lists are naturally always
    stored in memory and shifting between 64/32-bit address spaces
    is done here. This notably required plumbing an Options around
    during flattening/size/alignment calculations due to the size/types of
    lists changing depending on the memory configuration.

I've also added a small factc program in this commit which should
hopefully assist in exploring and debugging adapter modules. This takes
as input a component (text or binary format) and then generates an
adapter module for all component function signatures found internally.

This commit notably does not include tests for lists. I tried to figure
out a good way to add these but I felt like there were too many cases to
test and the tests would otherwise be extremely verbose. Instead I think
the best testing strategy for this commit will be through #4537 which
should be relatively extensible to testing adapters between modules in
addition to host-based lifting/lowering.

@alexcrichton alexcrichton requested a review from fitzgen July 29, 2022 19:08
@alexcrichton alexcrichton marked this pull request as ready for review July 29, 2022 19:08
This commit implements one of the two remaining types for adapter
fusion, lists. This implementation is particularly tricky for a number
of reasons:

* Lists have a number of validity checks which need to be carefully
  implemented. For example the byte length of the list passed to
  allocation in the destination module could overflow the 32-bit index
  space. Additionally lists in 32-bit memories need a check that their
  final address is in-bounds in the address space.

* In the effort to go ahead and support memory64 at the lowest layers
  this is where much of the magic happens. Lists are naturally always
  stored in memory and shifting between 64/32-bit address spaces
  is done here. This notably required plumbing an `Options` around
  during flattening/size/alignment calculations due to the size/types of
  lists changing depending on the memory configuration.

I've also added a small `factc` program in this commit which should
hopefully assist in exploring and debugging adapter modules. This takes
as input a component (text or binary format) and then generates an
adapter module for all component function signatures found internally.

This commit notably does not include tests for lists. I tried to figure
out a good way to add these but I felt like there were too many cases to
test and the tests would otherwise be extremely verbose. Instead I think
the best testing strategy for this commit will be through bytecodealliance#4537 which
should be relatively extensible to testing adapters between modules in
addition to host-based lifting/lowering.
* Skip overflow checks on byte sizes for 0-size types
* Skip the copy loop entirely when src/dst are both 0
* Skip the increments of src/dst pointers if either is 0-size
When a list/string has a 0-byte-size the base pointer is no longer
verified to be in-bounds to match the supposedly desired adapter
semantics where no trap happens because no turn of the loop happens.
@alexcrichton
Copy link
Copy Markdown
Member Author

I've updated this with some initial support for WebAssembly/component-model#78 as well where zero-size lists (either with zero length or with zero-sized-types) and zero-size strings skip all in-bounds-ness-checks. This updated a few existing tests and trap semantics to match the adapters that are generated.

This does sort of make me wonder how to fuzz this eventually but I don't think I have a great idea at this time.

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Aug 1, 2022
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 1, 2022

Subscribe to Label Action

cc @peterhuene

Details This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Copy Markdown
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Looks great!

@alexcrichton alexcrichton merged commit fb59de1 into bytecodealliance:main Aug 1, 2022
@alexcrichton alexcrichton deleted the adapt-list branch August 1, 2022 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants