@@ -3,12 +3,12 @@ use rustc_index::vec::IndexVec;
33use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
44use rustc_middle:: mir;
55use rustc_middle:: ty;
6+ use rustc_middle:: ty:: layout:: TyAndLayout ;
67use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
78use rustc_session:: config:: DebugInfo ;
89use rustc_span:: symbol:: { kw, Symbol } ;
910use rustc_span:: { BytePos , Span } ;
10- use rustc_target:: abi:: Abi ;
11- use rustc_target:: abi:: Size ;
11+ use rustc_target:: abi:: { Abi , Size , VariantIdx } ;
1212
1313use super :: operand:: { OperandRef , OperandValue } ;
1414use super :: place:: PlaceRef ;
@@ -76,6 +76,33 @@ impl<'tcx, S: Copy, L: Copy> DebugScope<S, L> {
7676 }
7777}
7878
79+ trait DebugInfoOffsetLocation < ' tcx , Bx > {
80+ fn deref ( & self , bx : & mut Bx ) -> Self ;
81+ fn layout ( & self ) -> TyAndLayout < ' tcx > ;
82+ fn project_field ( & self , bx : & mut Bx , field : mir:: Field ) -> Self ;
83+ fn downcast ( & self , bx : & mut Bx , variant : VariantIdx ) -> Self ;
84+ }
85+
86+ impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > DebugInfoOffsetLocation < ' tcx , Bx >
87+ for PlaceRef < ' tcx , Bx :: Value >
88+ {
89+ fn deref ( & self , bx : & mut Bx ) -> Self {
90+ bx. load_operand ( * self ) . deref ( bx. cx ( ) )
91+ }
92+
93+ fn layout ( & self ) -> TyAndLayout < ' tcx > {
94+ self . layout
95+ }
96+
97+ fn project_field ( & self , bx : & mut Bx , field : mir:: Field ) -> Self {
98+ PlaceRef :: project_field ( * self , bx, field. index ( ) )
99+ }
100+
101+ fn downcast ( & self , bx : & mut Bx , variant : VariantIdx ) -> Self {
102+ self . project_downcast ( bx, variant)
103+ }
104+ }
105+
79106struct DebugInfoOffset < T > {
80107 /// Offset from the `base` used to calculate the debuginfo offset.
81108 direct_offset : Size ,
@@ -86,12 +113,17 @@ struct DebugInfoOffset<T> {
86113 result : T ,
87114}
88115
89- fn calculate_debuginfo_offset < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
116+ fn calculate_debuginfo_offset <
117+ ' a ,
118+ ' tcx ,
119+ Bx : BuilderMethods < ' a , ' tcx > ,
120+ L : DebugInfoOffsetLocation < ' tcx , Bx > ,
121+ > (
90122 bx : & mut Bx ,
91123 local : mir:: Local ,
92124 var : & PerLocalVarDebugInfo < ' tcx , Bx :: DIVariable > ,
93- base : PlaceRef < ' tcx , Bx :: Value > ,
94- ) -> DebugInfoOffset < PlaceRef < ' tcx , Bx :: Value > > {
125+ base : L ,
126+ ) -> DebugInfoOffset < L > {
95127 let mut direct_offset = Size :: ZERO ;
96128 // FIXME(eddyb) use smallvec here.
97129 let mut indirect_offsets = vec ! [ ] ;
@@ -101,16 +133,15 @@ fn calculate_debuginfo_offset<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
101133 match * elem {
102134 mir:: ProjectionElem :: Deref => {
103135 indirect_offsets. push ( Size :: ZERO ) ;
104- place = bx . load_operand ( place) . deref ( bx. cx ( ) ) ;
136+ place = place. deref ( bx) ;
105137 }
106138 mir:: ProjectionElem :: Field ( field, _) => {
107- let i = field. index ( ) ;
108139 let offset = indirect_offsets. last_mut ( ) . unwrap_or ( & mut direct_offset) ;
109- * offset += place. layout . fields . offset ( i ) ;
110- place = place. project_field ( bx, i ) ;
140+ * offset += place. layout ( ) . fields . offset ( field . index ( ) ) ;
141+ place = place. project_field ( bx, field ) ;
111142 }
112143 mir:: ProjectionElem :: Downcast ( _, variant) => {
113- place = place. project_downcast ( bx, variant) ;
144+ place = place. downcast ( bx, variant) ;
114145 }
115146 _ => span_bug ! (
116147 var. source_info. span,
0 commit comments