Fold invariant_context into context - #231
Draft
coord-e wants to merge 1 commit into
Draft
Conversation
`#[thrust_macros::context]` stamped each method of an `impl`/`trait` with the
enclosing header, while `#[thrust_macros::invariant_context]` threaded the same
header -- plus the host signature -- into the `invariant!` calls in a function body.
Two attributes for one question: what does the code inside this item see?
They become one. `#[thrust_macros::context]` now takes a function as well, and on an
`impl`/`trait` it threads every method's body as it stamps it, so a method carrying a
loop invariant no longer needs an attribute of its own:
#[thrust_macros::context]
impl Counter {
fn run(&mut self) -> i64 {
while rand() {
thrust_macros::invariant!(|init: Self, self: &mut Self| ..);
}
}
}
Threading a body that names no such macro leaves it alone, rather than extending its
where clause with `Model` predicates nothing asked for: with every method of a
`#[context]` item threaded, those bounds would otherwise land on methods that have no
formula to justify them.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJ6XNNsSBdPkAzrWHftvqV
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.
#[thrust_macros::context]stamped each method of animpl/traitwith the enclosing header, while#[thrust_macros::invariant_context]threaded the same header — plus the host signature — into theinvariant!calls in a function body. Two attributes for one question: what does the code inside this item see?They become one.
#[thrust_macros::context]now takes a function as well, and on animpl/traitit threads every method's body as it stamps it, so a method carrying a loop invariant no longer needs an attribute of its own:A free function still opts in explicitly, with
#[thrust_macros::context]in place of the old name.Not extending a where clause nothing asked for
Threading a body that names no spec macro now leaves it alone.
invariant_contextextended the host's where clause with theModelpredicates unconditionally, which was fine while it was opt-in per function; with every method of a#[context]item threaded, those bounds would otherwise land on methods that have no formula to justify them.Changes
context.rsfnas well as animpl/trait;ContextInjectormoves here frominvariant_context.rs, which is deletedtests/ui#[thrust_macros::context], methods drop the attribute entirelyNo behaviour change for the analyzer; the macro expansion each test produces is the same as before.
Generated by Claude Code