@@ -33,6 +33,7 @@ pub struct Analyzer<'tcx, 'ctx> {
3333 basic_block : BasicBlock ,
3434 body : Cow < ' tcx , Body < ' tcx > > ,
3535
36+ type_builder : TypeBuilder < ' tcx > ,
3637 env : Env ,
3738 local_decls : IndexVec < Local , mir:: LocalDecl < ' tcx > > ,
3839 // TODO: remove this
@@ -56,10 +57,6 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
5657 self . ctx . basic_block_ty ( self . local_def_id , bb)
5758 }
5859
59- fn type_builder ( & self ) -> TypeBuilder < ' tcx > {
60- TypeBuilder :: new ( self . tcx , self . local_def_id . to_def_id ( ) )
61- }
62-
6360 fn bind_local ( & mut self , local : Local , rty : rty:: RefinedType < Var > ) {
6461 let rty = if self . is_mut_local ( local) {
6562 // elaboration:
@@ -226,7 +223,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
226223 let rty_args: IndexVec < _ , _ > = args
227224 . types ( )
228225 . map ( |ty| {
229- self . type_builder ( )
226+ self . type_builder
230227 . for_template ( & mut self . ctx )
231228 . with_scope ( & self . env )
232229 . build_refined ( ty)
@@ -440,7 +437,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
440437 // TODO: move this to well-known defs?
441438 Some ( ( def_id, args) ) if self . is_box_new ( def_id) => {
442439 let inner_ty = self
443- . type_builder ( )
440+ . type_builder
444441 . for_template ( & mut self . ctx )
445442 . build ( args. type_at ( 0 ) )
446443 . vacuous ( ) ;
@@ -454,7 +451,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
454451 rty:: FunctionType :: new ( [ param] . into_iter ( ) . collect ( ) , ret) . into ( )
455452 }
456453 Some ( ( def_id, args) ) if self . is_mem_swap ( def_id) => {
457- let inner_ty = self . type_builder ( ) . build ( args. type_at ( 0 ) ) . vacuous ( ) ;
454+ let inner_ty = self . type_builder . build ( args. type_at ( 0 ) ) . vacuous ( ) ;
458455 let param1 =
459456 rty:: RefinedType :: unrefined ( rty:: PointerType :: mut_to ( inner_ty. clone ( ) ) . into ( ) ) ;
460457 let param2 =
@@ -472,15 +469,16 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
472469 rty:: FunctionType :: new ( [ param1, param2] . into_iter ( ) . collect ( ) , ret) . into ( )
473470 }
474471 Some ( ( def_id, args) ) => {
475- if ! args. is_empty ( ) {
476- tracing:: warn!( ?args, ?def_id, "generic args ignored" ) ;
472+ if args. consts ( ) . next ( ) . is_some ( ) {
473+ tracing:: warn!( ?args, ?def_id, "const generic args ignored" ) ;
477474 }
478- self . ctx
479- . def_ty ( def_id)
480- . expect ( "unknown def" )
481- . ty
482- . clone ( )
483- . vacuous ( )
475+ let ty_args = args
476+ . types ( )
477+ . map ( |ty| rty:: RefinedType :: unrefined ( self . type_builder . build ( ty) ) )
478+ . collect ( ) ;
479+ let mut def_ty = self . ctx . def_ty ( def_id) . expect ( "unknown def" ) . clone ( ) ;
480+ def_ty. instantiate_ty_params ( ty_args) ;
481+ def_ty. ty . vacuous ( )
484482 }
485483 _ => self . operand_type ( func. clone ( ) ) . ty ,
486484 } ;
@@ -541,7 +539,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
541539 }
542540
543541 fn add_prophecy_var ( & mut self , statement_index : usize , ty : mir_ty:: Ty < ' tcx > ) {
544- let ty = self . type_builder ( ) . build ( ty) ;
542+ let ty = self . type_builder . build ( ty) ;
545543 let temp_var = self . env . push_temp_var ( ty. vacuous ( ) ) ;
546544 self . prophecy_vars . insert ( statement_index, temp_var) ;
547545 tracing:: debug!( stmt_idx = %statement_index, temp_var = ?temp_var, "add_prophecy_var" ) ;
@@ -562,7 +560,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
562560 referent : mir:: Place < ' tcx > ,
563561 prophecy_ty : mir_ty:: Ty < ' tcx > ,
564562 ) -> rty:: RefinedType < Var > {
565- let prophecy_ty = self . type_builder ( ) . build ( prophecy_ty) ;
563+ let prophecy_ty = self . type_builder . build ( prophecy_ty) ;
566564 let prophecy = self . env . push_temp_var ( prophecy_ty. vacuous ( ) ) ;
567565 let place = self . elaborate_place_for_borrow ( & referent) ;
568566 self . env . borrow_place ( place, prophecy) . into ( )
@@ -675,7 +673,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
675673
676674 let decl = self . local_decls [ destination] . clone ( ) ;
677675 let rty = self
678- . type_builder ( )
676+ . type_builder
679677 . for_template ( & mut self . ctx )
680678 . with_scope ( & self . env )
681679 . build_refined ( decl. ty ) ;
@@ -749,7 +747,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
749747 #[ tracing:: instrument( skip( self ) ) ]
750748 fn ret_template ( & mut self ) -> rty:: RefinedType < Var > {
751749 let ret_ty = self . body . local_decls [ mir:: RETURN_PLACE ] . ty ;
752- self . type_builder ( )
750+ self . type_builder
753751 . for_template ( & mut self . ctx )
754752 . with_scope ( & self . env )
755753 . build_refined ( ret_ty)
@@ -955,13 +953,15 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
955953 let env = ctx. new_env ( ) ;
956954 let local_decls = body. local_decls . clone ( ) ;
957955 let prophecy_vars = Default :: default ( ) ;
956+ let type_builder = TypeBuilder :: new ( tcx, local_def_id. to_def_id ( ) ) ;
958957 Self {
959958 ctx,
960959 tcx,
961960 local_def_id,
962961 drop_points,
963962 basic_block,
964963 body,
964+ type_builder,
965965 env,
966966 local_decls,
967967 prophecy_vars,
@@ -989,6 +989,11 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
989989 self
990990 }
991991
992+ pub fn type_builder ( & mut self , type_builder : TypeBuilder < ' tcx > ) -> & mut Self {
993+ self . type_builder = type_builder;
994+ self
995+ }
996+
992997 pub fn run ( & mut self , expected : & BasicBlockType ) {
993998 let span = tracing:: info_span!( "bb" , bb = ?self . basic_block) ;
994999 let _guard = span. enter ( ) ;
0 commit comments