@@ -3,12 +3,12 @@ use rustc_index::vec::IndexVec;
3
3
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
4
4
use rustc_middle:: mir;
5
5
use rustc_middle:: ty;
6
+ use rustc_middle:: ty:: layout:: TyAndLayout ;
6
7
use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
7
8
use rustc_session:: config:: DebugInfo ;
8
9
use rustc_span:: symbol:: { kw, Symbol } ;
9
10
use rustc_span:: { BytePos , Span } ;
10
- use rustc_target:: abi:: Abi ;
11
- use rustc_target:: abi:: Size ;
11
+ use rustc_target:: abi:: { Abi , Size , VariantIdx } ;
12
12
13
13
use super :: operand:: { OperandRef , OperandValue } ;
14
14
use super :: place:: PlaceRef ;
@@ -76,6 +76,33 @@ impl<'tcx, S: Copy, L: Copy> DebugScope<S, L> {
76
76
}
77
77
}
78
78
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
+
79
106
struct DebugInfoOffset < T > {
80
107
/// Offset from the `base` used to calculate the debuginfo offset.
81
108
direct_offset : Size ,
@@ -86,12 +113,17 @@ struct DebugInfoOffset<T> {
86
113
result : T ,
87
114
}
88
115
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
+ > (
90
122
bx : & mut Bx ,
91
123
local : mir:: Local ,
92
124
var : & PerLocalVarDebugInfo < ' tcx , Bx :: DIVariable > ,
93
- base : PlaceRef < ' tcx , Bx :: Value > ,
94
- ) -> DebugInfoOffset < PlaceRef < ' tcx , Bx :: Value > > {
125
+ base : L ,
126
+ ) -> DebugInfoOffset < L > {
95
127
let mut direct_offset = Size :: ZERO ;
96
128
// FIXME(eddyb) use smallvec here.
97
129
let mut indirect_offsets = vec ! [ ] ;
@@ -101,16 +133,15 @@ fn calculate_debuginfo_offset<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
101
133
match * elem {
102
134
mir:: ProjectionElem :: Deref => {
103
135
indirect_offsets. push ( Size :: ZERO ) ;
104
- place = bx . load_operand ( place) . deref ( bx. cx ( ) ) ;
136
+ place = place. deref ( bx) ;
105
137
}
106
138
mir:: ProjectionElem :: Field ( field, _) => {
107
- let i = field. index ( ) ;
108
139
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 ) ;
111
142
}
112
143
mir:: ProjectionElem :: Downcast ( _, variant) => {
113
- place = place. project_downcast ( bx, variant) ;
144
+ place = place. downcast ( bx, variant) ;
114
145
}
115
146
_ => span_bug ! (
116
147
var. source_info. span,
0 commit comments