Add compile-time typestates and infallible accessors - #277
Merged
jasongraffius merged 4 commits intoAug 17, 2026
Conversation
rust: Ignore Cargo build artifacts in .gitignore
yi-json
marked this pull request as draft
August 3, 2026 21:52
yi-json
marked this pull request as ready for review
August 3, 2026 21:53
yi-json
force-pushed
the
rust_dev_typestates
branch
from
August 5, 2026 15:06
b3952e7 to
fc18c79
Compare
yi-json
force-pushed
the
rust_dev_typestates
branch
2 times, most recently
from
August 8, 2026 18:42
b412d57 to
df0546c
Compare
yi-json
force-pushed
the
rust_dev_typestates
branch
from
August 11, 2026 21:09
df0546c to
01bb309
Compare
yi-json
force-pushed
the
rust_dev_typestates
branch
from
August 13, 2026 20:24
01bb309 to
ee226fb
Compare
Introduce compile-time typestate tracking (UncheckedState, CompleteState) and the CheckComplete trait to statically track struct layout validity. Update the Rust code generator and runtime to parameterize generated views by typestate, enabling infallible read() access on CompleteState views.
yi-json
force-pushed
the
rust_dev_typestates
branch
from
August 14, 2026 18:29
ee226fb to
e08eea5
Compare
jasongraffius
approved these changes
Aug 17, 2026
jasongraffius
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, looks like some of the verification checks are failing, try reformatting the python with black.
Introduce dedicated Writer types to support typestate-tracked, infallible mutations.
yi-json
force-pushed
the
rust_dev_typestates
branch
from
August 17, 2026 17:24
e08eea5 to
2de1e0f
Compare
yi-json
commented
Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Foundation: Compile-time Type States and Checked Field Accessors
This PR adds optional compile-time typestate tracking (
UncheckedState,CompleteState) to the experimental Rust runtime and compiler backend.The main goal is to let callers read fields infallibly via
.read()without.try_read().unwrap()or.expect()calls in consumer code once a view is validated with.check_complete(). Furthermore, it introduces a self-consumingWriterpattern (write_<field>(self, val) -> <Typename>Writer<S, NextState>) that safely tracks typestates on mutation and degrades layout-affecting fields back toUncheckedState.All generated views default to
ST: State = UncheckedState, so existing code continues to compile and work without breaking any changesWhat's included in this stack:
rust: Implement compile-time typestates and infallible read accessors:UncheckedState,CompleteState) and traits (State,IsComplete,CheckComplete,InfallibleRead) intypestate.rs.emboss_codegen_rust.pyand templates) to parameterize generatedstruct views by typestate (
<TypeName><S, ST = UncheckedState>) and implementCheckComplete..read()access onCompleteStateviews.rust: Implement self-consuming Typestate Writer for safe mutations:<TypeName>Writer<S, ST>types and.into_writer()conversions.write_<field>(self, val)setters directly on generatedWritertypes.layout (e.g. dynamic offsets/sizes) degrades the returned
WritertoUncheckedState, while writing tofixed non-layout fields preserves
CompleteState.dynamic_size_test.rsTesting
cargo testinruntime/experimental/rustbazel test //compiler/back_end/experimental/rust/testcode/...