@@ -16,7 +16,7 @@ use charon_lib::ast::Rvalue as CharonRvalue;
1616use charon_lib:: ast:: Span as CharonSpan ;
1717use charon_lib:: ast:: meta:: { AttrInfo , Loc , RawSpan } ;
1818use charon_lib:: ast:: types:: Ty as CharonTy ;
19- use charon_lib:: ast:: { AbortKind , Body as CharonBody , Var , VarId , make_locals_generator } ;
19+ use charon_lib:: ast:: { AbortKind , Body as CharonBody , Var , VarId } ;
2020use charon_lib:: ast:: {
2121 AnyTransId , Assert , BodyId , BuiltinTy , Disambiguator , FileName , FunDecl , FunSig , GenericArgs ,
2222 GenericParams , IntegerTy , ItemKind , ItemMeta , ItemOpacity , Literal , LiteralTy , Name , Opaque ,
@@ -39,14 +39,16 @@ use charon_lib::ullbc_ast::{
3939 Terminator as CharonTerminator ,
4040} ;
4141use charon_lib:: { error_assert, error_or_panic} ;
42+ use rustc_data_structures:: fx:: FxHashMap ;
4243use rustc_errors:: MultiSpan ;
4344use rustc_middle:: ty:: TyCtxt ;
4445use rustc_smir:: rustc_internal;
4546use rustc_span:: def_id:: DefId as InternalDefId ;
4647use stable_mir:: abi:: PassMode ;
48+ use stable_mir:: mir:: VarDebugInfoContents ;
4749use stable_mir:: mir:: mono:: Instance ;
4850use stable_mir:: mir:: {
49- BasicBlock , BinOp , Body , BorrowKind , CastKind , ConstOperand , Mutability , Operand , Place ,
51+ BasicBlock , BinOp , Body , BorrowKind , CastKind , ConstOperand , Local , Mutability , Operand , Place ,
5052 ProjectionElem , Rvalue , Statement , StatementKind , SwitchTargets , Terminator , TerminatorKind ,
5153} ;
5254use stable_mir:: ty:: {
@@ -64,6 +66,7 @@ pub struct Context<'a, 'tcx> {
6466 instance : Instance ,
6567 translated : & ' a mut TranslatedCrate ,
6668 errors : & ' a mut ErrorCtx < ' tcx > ,
69+ local_names : FxHashMap < Local , String > ,
6770}
6871
6972impl < ' a , ' tcx > Context < ' a , ' tcx > {
@@ -75,7 +78,17 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
7578 translated : & ' a mut TranslatedCrate ,
7679 errors : & ' a mut ErrorCtx < ' tcx > ,
7780 ) -> Self {
78- Self { tcx, instance, translated, errors }
81+ let mut local_names = FxHashMap :: default ( ) ;
82+ // populate names of locals
83+ for info in instance. body ( ) . unwrap ( ) . var_debug_info {
84+ if let VarDebugInfoContents :: Place ( p) = info. value {
85+ if p. projection . is_empty ( ) {
86+ local_names. insert ( p. local , info. name ) ;
87+ }
88+ }
89+ }
90+
91+ Self { tcx, instance, translated, errors, local_names }
7992 }
8093
8194 fn tcx ( & self ) -> TyCtxt < ' tcx > {
@@ -466,12 +479,11 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
466479 // - the input arguments
467480 // - the remaining locals, used for the intermediate computations
468481 let mut locals = Vector :: new ( ) ;
469- {
470- let mut add_variable = make_locals_generator ( & mut locals) ;
471- mir_body. local_decls ( ) . for_each ( |( _, local) | {
472- add_variable ( self . translate_ty ( local. ty ) ) ;
473- } ) ;
474- }
482+ mir_body. local_decls ( ) . for_each ( |( local, local_decl) | {
483+ let ty = self . translate_ty ( local_decl. ty ) ;
484+ let name = self . local_names . get ( & local) ;
485+ locals. push_with ( |index| Var { index, name : name. cloned ( ) , ty } ) ;
486+ } ) ;
475487 locals
476488 }
477489
0 commit comments