Implement #[thrust::formula_fn] and requires/ensures annotation using it#65
Merged
Implement #[thrust::formula_fn] and requires/ensures annotation using it#65
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for expressing requires/ensures annotations via actual Rust functions marked with #[thrust::formula_fn], and referencing those functions from annotated code using #[thrust::requires_path] / #[thrust::ensures_path].
Changes:
- Introduce
AnnotFnTranslatorto translate Rust HIR expressions in#[thrust::formula_fn]bodies intochc::Formula. - Add
requires_path/ensures_pathextraction by scanning attributed path statements inside function bodies. - Extend the injected
std.rsmodel types (Int/Mut/Box/Array) with trait ops used by formula functions, and skip MIR borrowck for formula functions.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/analyze/annot_fn.rs |
New HIR→chc::Formula translator for #[thrust::formula_fn]. |
src/analyze.rs |
Registers formula functions, caches translated formulas, extracts requires_path/ensures_path, and adds a borrowck-skip query provider for formula fns. |
src/analyze/local_def.rs |
Threads generic_args through annotation extraction and recognizes path-based requires/ensures. |
src/analyze/crate_.rs |
Registers #[thrust::formula_fn] items and skips normal analysis for them. |
src/analyze/annot.rs |
Adds attribute paths for formula_fn, requires_path, ensures_path, and model constructors. |
src/analyze/did_cache.rs |
Caches DefIds for Mut::new / Box::new model constructors and searches impl items for annotated defs. |
src/main.rs |
Overrides mir_borrowck to skip borrow-checking formula functions. |
src/lib.rs |
Exposes the borrowck override hook and adds rustc crate imports needed for query override wiring. |
std.rs |
Adds operator traits and constructors (Mut::new, Box::new, arithmetic/eq/ord) required by formula function expressions; adjusts extern spec swap to be a tail call. |
tests/ui/pass/annot_formula_fn.rs |
New passing UI test for requires/ensures via formula_fn + *_path. |
tests/ui/fail/annot_formula_fn.rs |
New failing UI test (unsat) for requires/ensures via formula_fn + *_path. |
tests/ui/pass/annot_formula_fn_mut.rs |
New passing UI test for mut-term reasoning via formula_fn. |
tests/ui/fail/annot_formula_fn_mut.rs |
New failing UI test for mut-term reasoning via formula_fn. |
tests/ui/pass/annot_mut_term_formula_fn.rs |
New passing UI test for Mut::new usage in ensures formula. |
tests/ui/fail/annot_mut_term_formula_fn.rs |
New failing UI test variant (unsat). |
tests/ui/pass/annot_mut_term_formula_fn_poly.rs |
New passing UI test covering generic swap annotated via *_path. |
tests/ui/fail/annot_mut_term_formula_fn_poly.rs |
New failing UI test variant (unsat). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
668226f to
0a2fa77
Compare
0a2fa77 to
abe5984
Compare
This was referenced Mar 31, 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.
for #57
#[thrust::formula_fn]allows building chc::Formula with Rust expression. annot_fn:AnnotFnTranslator translates Rust HIR into chc::Formula. Users can specify formula_fn as requires/ensures annotations by specifying them using#[thrust::requires_path]and#[thrust::ensures_path].Basic integer arithmetic and box/mut operations are supported. Support for ADTs and existentials will be added later.