-
Notifications
You must be signed in to change notification settings - Fork 1
Support Rust syntax in thrust::predicate bodies #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,40 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> { | |
| } | ||
|
|
||
| fn define_as_predicate(&self, pred: chc::UserDefinedPred) { | ||
| let sig = self.ctx.fn_sig(self.local_def_id.to_def_id()); | ||
| let arg_sorts = sig | ||
| .inputs() | ||
| .iter() | ||
| .map(|input_ty| self.type_builder.build(*input_ty).to_sort()); | ||
|
|
||
| // A predicate marked `formula_fn` carries a Rust-expression body that has | ||
| // been translated into a `chc::Formula`; otherwise the body is a raw | ||
| // SMT-LIB2 string literal. | ||
| if self.is_annotated_as_formula_fn() { | ||
| // Name the parameters `v{i}` to match how `chc::TermVarIdx` renders the | ||
| // formula's variables (see `chc::UserDefinedPredBody::Formula`). | ||
| let arg_name_and_sorts = arg_sorts | ||
| .enumerate() | ||
| .map(|(i, sort)| (format!("v{i}"), sort)) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| let formula_fn = self | ||
| .ctx | ||
| .formula_fn_with_args(self.local_def_id, self.tcx.mk_args(&[])) | ||
| .expect("predicate formula function is not registered"); | ||
| let formula = formula_fn | ||
| .formula() | ||
| .clone() | ||
| .map_var(|idx| chc::TermVarIdx::from(idx.index())); | ||
|
|
||
| self.ctx.system.borrow_mut().push_pred_define_formula( | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is newly reachable with this PR: Generated by Claude Code |
||
| pred, | ||
| chc::UserDefinedPredSig::from(arg_name_and_sorts), | ||
| formula, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // function's body | ||
| use rustc_hir::{Block, Expr, ExprKind}; | ||
|
|
||
|
|
@@ -88,12 +122,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> { | |
| .to_string() | ||
| }); | ||
|
|
||
| let sig = self.ctx.fn_sig(self.local_def_id.to_def_id()); | ||
| let arg_sorts = sig | ||
| .inputs() | ||
| .iter() | ||
| .map(|input_ty| self.type_builder.build(*input_ty).to_sort()); | ||
|
|
||
| let arg_name_and_sorts = arg_names.into_iter().zip(arg_sorts).collect::<Vec<_>>(); | ||
|
|
||
| self.ctx.system.borrow_mut().push_pred_define( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mk_args(&[])discards the predicate's generic args. For a Rust-bodied predicate declared in a trait default body or inside a genericimpl,formula_fn_with_argsreachesEarlyBinder::instantiatewith an empty arg list and ICEs with "type parameter out of range".Every other
formula_fn_with_argscall site (analyze.rs:760/782/859, local_def.rs:837) threads through realgeneric_args.crate_::placeholder_generic_args(crate_.rs:193) exists for exactly this case — it is currently private, so it would need to be reachable from here.Generated by Claude Code