Skip to content

preview2: refactor WasiCtxBuilder impl, and make WasiCtx fields private#6652

Merged
alexcrichton merged 2 commits into
mainfrom
pch/one_way_to_create_builder
Jun 27, 2023
Merged

preview2: refactor WasiCtxBuilder impl, and make WasiCtx fields private#6652
alexcrichton merged 2 commits into
mainfrom
pch/one_way_to_create_builder

Conversation

@pchickey
Copy link
Copy Markdown
Contributor

The optional-fields WasiCtxBuilder was an intermediate stepping stone which has outlived its usefulness - there is now only one sensible default value for each field, so we no longer need to expose the Default (empty) constructor.

There is no need for the WasiCtx::builder method being an alias for default, and it creates user confusion.

Finally, the WasiCtx itself is a private implementation detail for use in this crate only. The WasiCtxBuilder is the only way to customize its contents. We don't want to let users modify the fields of WasiCtx after it has been used by a wasm guest, because the guest may have made assumptions that fields won't change - e.g. the stderr field is fetched once by the adapter and assumed to always be the same, environment variables are copied into libc once and assumed to always be the same.

The optional-fields WasiCtxBuilder was an intermediate stepping stone
which has outlived its usefulness - there is now only one sensible
default value for each field, so we no longer need to expose the Default
(empty) constructor.

There is no need for the WasiCtx::builder method being an alias for
default, and it creates user confusion.

Finally, the WasiCtx itself is a private implementation detail for use
in this crate only. The WasiCtxBuilder is the only way to customize
its contents. We don't want to let users modify the fields of WasiCtx
after it has been used by a wasm guest, because the guest may have made
assumptions that fields won't change - e.g. the stderr field is fetched
once by the adapter and assumed to always be the same, environment
variables are copied into libc once and assumed to always be the same.
@pchickey pchickey marked this pull request as ready for review June 27, 2023 19:24
@pchickey pchickey requested a review from a team as a code owner June 27, 2023 19:24
@pchickey pchickey requested review from alexcrichton and itsrainy and removed request for a team and itsrainy June 27, 2023 19:24
@alexcrichton alexcrichton enabled auto-merge June 27, 2023 19:31
@alexcrichton alexcrichton added this pull request to the merge queue Jun 27, 2023
@github-actions github-actions Bot added the wasi Issues pertaining to WASI label Jun 27, 2023
Merged via the queue into main with commit 9d0bf8b Jun 27, 2023
@alexcrichton alexcrichton deleted the pch/one_way_to_create_builder branch June 27, 2023 22:01
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