Anchor macro-emitted model paths at the crate root - #256
Merged
Conversation
`thrust_models` is injected as a crate-root `mod` of the crate under verification, so the unqualified `thrust_models::…` paths the annotation macros expanded to only resolved at the crate root. Every annotation on an item inside a `mod` failed with E0433, leaving a program unable to be both modularised and specified. `crate::` resolves the same way under edition 2015, which the driver currently uses, and under 2018+. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxfDwbBfdK9zRC7jBRCArW
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Several independently modified macro emission paths lack nested-module regression coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Anchors generated model paths at the crate root so annotations work inside modules.
Changes:
- Updated all macro emission sites to use
crate::thrust_models. - Updated implication expansion unit tests.
- Added pass/fail UI tests for modular annotations and invariants.
File summaries
| File | Description |
|---|---|
thrust-macros/src/rty.rs |
Anchors refinement binder model types. |
thrust-macros/src/pre_post.rs |
Anchors closure contract markers. |
thrust-macros/src/invariant.rs |
Anchors invariant markers. |
thrust-macros/src/ghost.rs |
Anchors ghost markers. |
thrust-macros/src/formula.rs |
Anchors implication expansion and expectations. |
thrust-macros/src/formula_fn_type_lowering.rs |
Anchors generated model types and bounds. |
tests/ui/pass/mod_invariant.rs |
Adds passing modular invariant coverage. |
tests/ui/fail/mod_invariant.rs |
Adds failing modular invariant coverage. |
tests/ui/pass/mod_annot.rs |
Adds passing modular contract coverage. |
tests/ui/fail/mod_annot.rs |
Adds failing modular contract coverage. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+4
to
+6
| mod math { | ||
| #[thrust_macros::requires(true)] | ||
| #[thrust_macros::ensures(result >= a && result >= b)] |
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.
Fixes #252.
thrust_modelsis injected as a crate-rootmodof the crate under verification, so the unqualifiedthrust_models::…paths the annotation macros expanded to only resolved at the crate root. Every annotation on an item inside amodfailed withE0433, leaving a program unable to be both modularised and specified.Every emission site now writes
crate::thrust_models::…:formula_fn_type_lowering.rs—<T as Model>::Tyfor parameters and return type,model::Closure<F>, and theModel/PartialEqwhere-predicatesrty.rs— the binder type ofparam/ret/siginvariant.rs—__invariant_markerghost.rs—__ghost_markerformula.rs—impliesfor==>pre_post.rs—closure_precondition/closure_postconditioncrate::resolves the same way under edition 2015, which the driver currently uses, and under 2018+.Two UI test pairs cover annotations inside a
mod:mod_annot(requires/ensureson a function in a module) andmod_invariant(invariant!in a module).Verification
cargo test— 338 UI tests and the unit tests pass, no regression against the existing 334;cargo fmt --all -- --checkandcargo clippy -- -D warningsare clean.safe, and breaking its assertion tostart + 11reportsUnsat, so the module case is checked in both directions.ghost!,sig,pre!/post!and#[thrust::predicate]inside amodwere checked separately.crate::resolves under edition 2015 was confirmed by compiling a crate-root-privatemodreferenced from a submodule withrustc --edition 2015.🤖 Generated with Claude Code
https://claude.ai/code/session_01LxfDwbBfdK9zRC7jBRCArW
Generated by Claude Code