Skip to content

Support user-defined predicate call in annotation#22

Merged
coeff-aij merged 16 commits into
coord-e:mainfrom
coeff-aij:annot-preds-call
Jan 21, 2026
Merged

Support user-defined predicate call in annotation#22
coeff-aij merged 16 commits into
coord-e:mainfrom
coeff-aij:annot-preds-call

Conversation

@coeff-aij

@coeff-aij coeff-aij commented Jan 12, 2026

Copy link
Copy Markdown
Collaborator

This extention allows users to call arbitrary user-defined predicates (e.g., is_double(x, result)) within annotations.
Currently, a dedicated syntax for defining user-defined predicates is not yet supported. Therefore, users must define them using the #![thrust::raw_define()] (introduced in #21 ) attribute for now.

  • Usage
    The predicate is_double() defined using #![thrust::raw_define()] can be called in the annotations such as #[thrust::ensures()]:
#![feature(custom_inner_attributes)]
#![thrust::raw_define("(define-fun is_double ((x Int) (doubled_x Int)) Bool
    (=
        (* x 2)
        doubled_x
    )
)")]

#[thrust::requires(true)]
#[thrust::ensures(is_double(x, result))]
fn double(x: i64) -> i64 {
    x + x
}

@coeff-aij coeff-aij marked this pull request as ready for review January 12, 2026 11:10
@coord-e coord-e self-requested a review January 13, 2026 14:13
Comment thread src/chc.rs Outdated
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UserDefinedPred {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This struct seems to be unused. I think it's more natural to rename UserDefinedPredSymbol to UserDefinedPred and remove this one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Originally I defined this struct to implement a parser for definitions of user-defined predicates. If the parser is implemented in the future, it might be fine to leave this definition as is.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I’d like to avoid leaving unused structs because it makes the intent harder to understand later. Requirements might change by the time we write the parser for the definitions, so I don’t think there's a need to define them speculatively right now. (Either way, I think cargo clippy or something will probably flag it.)

Comment thread src/chc.rs Outdated
Comment thread src/chc.rs Outdated
Comment thread src/annot.rs Outdated
@coeff-aij

Copy link
Copy Markdown
Collaborator Author

I reflected the comments in above review.

@coord-e coord-e left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

mostly LGTM, please rebase after merging #21

Comment thread src/chc.rs
Pred::Matcher(p)
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please add impl From<UserDefinedPred> for Pred

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added it.

@coord-e coord-e left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you!

@coeff-aij

Copy link
Copy Markdown
Collaborator Author

I accidentally deleted the tests in git rebase. I have restored them.
Is it okay to squash-merge this PR?

@coord-e coord-e left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it okay to squash-merge this PR?

okay, please!

fn main() {
let a = 3;
assert!(double(a) == 6);
} No newline at end of file

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please add newline at the end of file (same for tests/ui/pass/annot_preds_raw_command_multi.rs)

@coeff-aij coeff-aij merged commit bd871bf into coord-e:main Jan 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants