Repository navigation
yeast: Make rule guard context read-only - #22910
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 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
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
force-pushed
the
tausbn/yeast-read-only-rule-guards
branch
from
October 28, 2026 10:38
a4ae8df to
a02604b
Compare
tausbn
marked this pull request as ready for review
October 28, 2026 11:54
paldepind
approved these changes
Oct 28, 2026
paldepind
left a comment
Contributor
There was a problem hiding this comment.
LGTM. If we don't need the mutability, then this is definitely simpler.
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.

Top-level rule guards currently get a mutable copy of the
ctxuser 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).