Skip to content

yeast: Make rule guard context read-only - #22910

Merged
tausbn merged 1 commit into
mainfrom
tausbn/yeast-read-only-rule-guards
Oct 28, 2026
Merged

tausbn merged 1 commit into
mainfrom
tausbn/yeast-read-only-rule-guards

Conversation

@tausbn

@tausbn tausbn commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Top-level rule guards currently get a mutable copy of the ctx user context. If the guard succeeds, this copy is used to replace the existing context and the rule body is executed.

However, this design is somewhat problematic: first of all, it's questionable to do such mutation in the first place, and secondly if we ever want to embed guards deeper inside of a rule, then for consistency we would expect these to be mutable as well. This would entail a lot of unnecessary context cloning and bookkeeping for a "feature" that will likely never be used.

Thus, I opted to simply make the access to the user context read-only inside of the guard body (as in: we only pass it an immutable reference).

@tausbn tausbn added the no-change-note-required This PR does not need a change note label Oct 27, 2026
@tausbn
tausbn requested a max review from Copilot October 27, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test duplicates existing enabled-context coverage, leaving nested context propagation and caller isolation untested.

1 open issue
What changed in this PR

Makes YEAST rule guards borrow user context immutably, avoiding context cloning for rejected guards while preserving private, mutable context clones for transforms.

Changes:

  • Change the guard API and generated closures to use immutable context references.
  • Move context cloning until after a guard succeeds.
  • Update tests, documentation, and examples for read-only guard access.
File Description
shared/​yeast/​tests/​test.rs Adapt guard tests to read context without mutation.
shared/​yeast/​src/​lib.rs Make guards immutable and delay transform-context cloning.
shared/​yeast/​doc/​yeast.md Explain read-only context access and revise the example.
shared/​yeast-macros/​src/​lower.rs Generate immutable context parameters for guard closures.
shared/​yeast-macros/​src/​lib.rs Update macro documentation to describe read-only guards.

Review effort: Max

Comment thread shared/yeast/tests/test.rs
Top-level rule guards currently get a mutable copy of the `ctx` user
context. If the guard succeeds, this copy is used to replace the
existing context and the rule body is executed.

However, this design is somewhat problematic: first of all, it's
questionable to do such mutation in the first place, and secondly if we
ever want to embed guards deeper inside of a rule, then for consistency
we would expect these to be mutable as well. This would entail a lot of
unnecessary context cloning and bookkeeping for a "feature" that will
likely never be used.

Thus, I opted to simply make the access to the user context read-only
inside of the guard body (as in: we only pass it an immutable
reference).
@tausbn
tausbn force-pushed the tausbn/yeast-read-only-rule-guards branch from a4ae8df to a02604b Compare October 28, 2026 10:38
@tausbn
tausbn marked this pull request as ready for review October 28, 2026 11:54
@tausbn
tausbn requested a review from a team as a code owner October 28, 2026 11:54

@paldepind paldepind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. If we don't need the mutability, then this is definitely simpler.

@tausbn
tausbn merged commit a1d3db7 into main Oct 28, 2026
22 checks passed
@tausbn
tausbn deleted the tausbn/yeast-read-only-rule-guards branch October 28, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants