@@ -15,6 +15,7 @@ use rustc_index::IndexVec;
1515use rustc_middle:: mir:: { self , BasicBlock , Local } ;
1616use rustc_middle:: ty:: { self as mir_ty, TyCtxt } ;
1717use rustc_span:: def_id:: { DefId , LocalDefId } ;
18+ use rustc_span:: symbol:: Symbol ;
1819
1920use crate :: analyze;
2021use crate :: annot:: { AnnotFormula , AnnotParser , Resolver } ;
@@ -24,11 +25,38 @@ use crate::refine::{self, BasicBlockType, TypeBuilder};
2425use crate :: rty;
2526
2627mod annot;
28+ mod annot_fn;
2729mod basic_block;
2830mod crate_;
2931mod did_cache;
3032mod local_def;
3133
34+ pub fn mir_borrowck_skip_formula_fn (
35+ tcx : rustc_middle:: ty:: TyCtxt < ' _ > ,
36+ local_def_id : rustc_span:: def_id:: LocalDefId ,
37+ ) -> rustc_middle:: query:: queries:: mir_borrowck:: ProvidedValue {
38+ // TODO: unify impl with local_def::Analyzer
39+ let is_annotated_as_formula_fn = tcx
40+ . get_attrs_by_path ( local_def_id. to_def_id ( ) , & analyze:: annot:: formula_fn_path ( ) )
41+ . next ( )
42+ . is_some ( ) ;
43+
44+ if is_annotated_as_formula_fn {
45+ tracing:: debug!( ?local_def_id, "skipping borrow check for formula fn" ) ;
46+ let dummy_result = rustc_middle:: mir:: BorrowCheckResult {
47+ concrete_opaque_types : Default :: default ( ) ,
48+ closure_requirements : None ,
49+ used_mut_upvars : Default :: default ( ) ,
50+ tainted_by_errors : None ,
51+ } ;
52+ return tcx. arena . alloc ( dummy_result) ;
53+ }
54+
55+ ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
56+ . queries
57+ . mir_borrowck ) ( tcx, local_def_id)
58+ }
59+
3260pub fn local_of_function_param ( idx : rty:: FunctionParamIdx ) -> Local {
3361 Local :: from ( idx. index ( ) + 1 )
3462}
@@ -155,6 +183,9 @@ pub struct Analyzer<'tcx> {
155183 /// (at least for every defs referenced by local def bodies)
156184 defs : HashMap < DefId , DefTy < ' tcx > > ,
157185
186+ /// Collection of functions with `#[thrust::formula_fn]` attribute.
187+ formula_fns : HashMap < DefId , annot_fn:: FormulaFn < ' tcx > > ,
188+
158189 /// Resulting CHC system.
159190 system : Rc < RefCell < chc:: System > > ,
160191
@@ -181,12 +212,14 @@ impl<'tcx> Analyzer<'tcx> {
181212impl < ' tcx > Analyzer < ' tcx > {
182213 pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
183214 let defs = Default :: default ( ) ;
215+ let formula_fns = Default :: default ( ) ;
184216 let system = Default :: default ( ) ;
185217 let basic_blocks = Default :: default ( ) ;
186218 let enum_defs = Default :: default ( ) ;
187219 Self {
188220 tcx,
189221 defs,
222+ formula_fns,
190223 system,
191224 basic_blocks,
192225 def_ids : did_cache:: DefIdCache :: new ( tcx) ,
@@ -346,6 +379,11 @@ impl<'tcx> Analyzer<'tcx> {
346379 Some ( expected)
347380 }
348381
382+ pub fn register_formula_fn ( & mut self , def_id : DefId , formula_fn : annot_fn:: FormulaFn < ' tcx > ) {
383+ tracing:: info!( def_id = ?def_id, formula_fn = %formula_fn. display( ) , "register_formula_fn" ) ;
384+ self . formula_fns . insert ( def_id, formula_fn) ;
385+ }
386+
349387 pub fn register_basic_block_ty (
350388 & mut self ,
351389 def_id : LocalDefId ,
0 commit comments