Skip to content
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

Resource table tracks child relationships #6779

Merged
merged 10 commits into from
Aug 1, 2023
Merged

Conversation

pchickey
Copy link
Contributor

@pchickey pchickey commented Jul 26, 2023

First off, change all wasmtime_wasi::preview2::TableError cases to trap when converting to a filesystem::Error, streams::Error, etc. This is required by the shift to resources. No tests fail because of this change!

Introduce the tracking of children to wasmtime_wasi::preview2::Table. This required:

  • a new pub method push_child indicating the parent
  • Bookkeeping in a private struct TableEntry { entry: Box<dyn Any...>, parent: Option<u32>, children: BTreeSet<u32> }. This is the simplest datastructure that could possibly work.
  • deletion checks that an entry has no children, and updates bookkeeping on the parent if the entry has one.
  • re-defining OccupiedEntry to not use HashMap's directly, because we need to handle deletion bookkeeping.

There is only one child resource in wasmtime-wasi at the moment: a HostPollable::TableEntry is a pollable resource which refers to a parent with the { index: u32, ...}. We changed push_host_pollable method on the table extension trait to push that variant with push_child.

I added a unit test to poll.rs showing that a HostPollable::TableEntry treats the given index as a parent.

I added an integration test to command-tests demonstrating correct management of child lifetimes exits correctly, and incorrect management traps with TableError::HasChildren.

This fixes a crash vector merged as part of #6556

@pchickey pchickey marked this pull request as ready for review July 27, 2023 00:09
@pchickey pchickey requested a review from a team as a code owner July 27, 2023 00:09
@pchickey pchickey requested review from alexcrichton and removed request for a team July 27, 2023 00:09
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Jul 27, 2023
Copy link
Member

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me!

crates/test-programs/build.rs Outdated Show resolved Hide resolved
Comment on lines +78 to +81
// 0, 1 and 2 are formerly (preview 1) for stdio. To prevent users from assuming these
// indicies are still valid ways to access stdio, they are deliberately left empty.
// Once we have a full implementation of resources, this confusion should hopefully be
// impossible :)
Copy link
Member

Choose a reason for hiding this comment

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

Great comment!

Pat Hickey and others added 2 commits July 31, 2023 17:00
Co-authored-by: Trevor Elliott <telliott@fastly.com>
@pchickey pchickey enabled auto-merge August 1, 2023 00:30
@pchickey pchickey added this pull request to the merge queue Aug 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 1, 2023
@pchickey pchickey added this pull request to the merge queue Aug 1, 2023
Merged via the queue into main with commit 0d4ad61 Aug 1, 2023
21 checks passed
@pchickey pchickey deleted the pch/resource_lifetimes branch August 1, 2023 04:22
geekbeast pushed a commit to geekbeast/wasmtime that referenced this pull request Aug 1, 2023
* main: (47 commits)
  Add core dump support to the runtime (bytecodealliance#6513)
  Resource table tracks child relationships (bytecodealliance#6779)
  Wasmtime: Move `OnDemandInstanceAllocator` to its own module (bytecodealliance#6790)
  wasi: Test the stdio streams implementation (bytecodealliance#6764)
  Don't generate same-named imports in fact modules (bytecodealliance#6783)
  Wasmtime: Add support for Wasm tail calls (bytecodealliance#6774)
  Cranelift: Fix `ABIMachineSpec::gen_add_imm` for riscv64 (bytecodealliance#6780)
  Update the wasm-tools family of crates, disallow empty component types (bytecodealliance#6777)
  Fix broken link to WASI API documentation (bytecodealliance#6775)
  A bunch of cleanups for cranelift-codegen-meta (bytecodealliance#6772)
  Implement component-to-component calls with resources (bytecodealliance#6769)
  Ignore async_stack_size if async_support is disabled (bytecodealliance#6771)
  A bunch of minor cleanups (bytecodealliance#6767)
  Fix flaky tests in preview2 streams (bytecodealliance#6763)
  Refactor and simplify component trampolines (bytecodealliance#6751)
  Cranelift: Implement tail calls on riscv64 (bytecodealliance#6749)
  WASI Preview 2: rewrite streams and pollable implementation (bytecodealliance#6556)
  cranelift-wasm: Add support for translating Wasm tail calls to CLIF (bytecodealliance#6760)
  Cranelift: Get tail calls working on aarch64 (bytecodealliance#6723)
  Implement component model resources in Wasmtime (bytecodealliance#6691)
  ...
eduardomourar pushed a commit to eduardomourar/wasmtime that referenced this pull request Aug 18, 2023
* change all TableError cases to trap, instead of return a runtime error

this is going to be required as part of the shift to resources! so lets
do it right now and see how many things break

* delete dead code

* Scaffold out changes to table to track parent and children

* fill in more parent/child todos

* finish plumbing, HostPollable::TableEntry uses Table::push_child

* command-tests: show that wasm that manages stream pollable lifetime wrong traps

* Update crates/test-programs/build.rs

Co-authored-by: Trevor Elliott <telliott@fastly.com>

* doc comments

* doc fixes. OccupiedEntry made pub.

---------

Co-authored-by: Trevor Elliott <telliott@fastly.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants