@@ -31,6 +31,12 @@ use super::schema::{
3131use super :: ty_visitor:: TyCollector ;
3232use super :: util:: { def_id_to_inst, fn_inst_for_ty} ;
3333
34+ /// Placeholder type used when the precise pointee type of an allocation cannot
35+ /// be recovered from the surrounding context.
36+ fn opaque_placeholder_ty ( ) -> stable_mir:: ty:: Ty {
37+ stable_mir:: ty:: Ty :: to_val ( 0 )
38+ }
39+
3440struct InternedValueCollector < ' tcx , ' local > {
3541 tcx : TyCtxt < ' tcx > ,
3642 locals : & ' local [ LocalDecl ] ,
@@ -57,12 +63,12 @@ fn field_for_offset(l: LayoutShape, offset: usize) -> Option<usize> {
5763 }
5864}
5965
60- fn get_prov_ty ( ty : stable_mir:: ty:: Ty , offset : & usize ) -> Option < stable_mir:: ty:: Ty > {
66+ fn get_prov_ty ( ty : stable_mir:: ty:: Ty , offset : usize ) -> Option < stable_mir:: ty:: Ty > {
6167 use stable_mir:: ty:: RigidTy ;
6268 let ty_kind = ty. kind ( ) ;
6369 // if ty is a pointer, box, or Ref, expect no offset and dereference
6470 if let Some ( ty) = ty_kind. builtin_deref ( true ) {
65- assert ! ( * offset == 0 ) ;
71+ assert ! ( offset == 0 ) ;
6672 return Some ( ty. ty ) ;
6773 }
6874
@@ -87,14 +93,14 @@ fn get_prov_ty(ty: stable_mir::ty::Ty, offset: &usize) -> Option<stable_mir::ty:
8793 }
8894 // For other structs, consult layout to determine field type
8995 RigidTy :: Adt ( adt_def, args) if ty_kind. is_struct ( ) => {
90- let field_idx = field_for_offset ( layout, * offset) . unwrap ( ) ;
96+ let field_idx = field_for_offset ( layout, offset) . unwrap ( ) ;
9197 // NB struct, single variant
9298 let fields = adt_def. variants ( ) . pop ( ) . map ( |v| v. fields ( ) ) . unwrap ( ) ;
9399 fields. get ( field_idx) . map ( |f| f. ty_with_args ( args) )
94100 }
95101 RigidTy :: Adt ( _adt_def, _args) if ty_kind. is_enum ( ) => {
96102 // we have to figure out which variant we are dealing with (requires the data)
97- match field_for_offset ( layout, * offset) {
103+ match field_for_offset ( layout, offset) {
98104 None =>
99105 // FIXME we'd have to figure out which variant we are dealing with (requires the data)
100106 {
@@ -108,7 +114,7 @@ fn get_prov_ty(ty: stable_mir::ty::Ty, offset: &usize) -> Option<stable_mir::ty:
108114 }
109115 }
110116 RigidTy :: Tuple ( fields) => {
111- let field_idx = field_for_offset ( layout, * offset) ?;
117+ let field_idx = field_for_offset ( layout, offset) ?;
112118 fields. get ( field_idx) . copied ( )
113119 }
114120 RigidTy :: FnPtr ( _) => None ,
@@ -122,14 +128,14 @@ fn get_prov_ty(ty: stable_mir::ty::Ty, offset: &usize) -> Option<stable_mir::ty:
122128 } ;
123129 match ref_ty {
124130 None => None ,
125- Some ( ty) => get_prov_ty ( ty, & 0 ) ,
131+ Some ( ty) => get_prov_ty ( ty, 0 ) ,
126132 }
127133}
128134
129135fn collect_alloc (
130136 val_collector : & mut InternedValueCollector ,
131137 ty : stable_mir:: ty:: Ty ,
132- offset : & usize ,
138+ offset : usize ,
133139 val : stable_mir:: mir:: alloc:: AllocId ,
134140) {
135141 let entry = val_collector. visited_allocs . entry ( val) ;
@@ -160,10 +166,10 @@ fn collect_alloc(
160166 . ptrs
161167 . iter ( )
162168 . for_each ( |( prov_offset, prov) | {
163- collect_alloc ( val_collector, p_ty, prov_offset, prov. 0 ) ;
169+ collect_alloc ( val_collector, p_ty, * prov_offset, prov. 0 ) ;
164170 } ) ;
165171 } else {
166- entry. or_insert ( ( stable_mir :: ty :: Ty :: to_val ( 0 ) , global_alloc. clone ( ) ) ) ;
172+ entry. or_insert ( ( opaque_placeholder_ty ( ) , global_alloc. clone ( ) ) ) ;
167173 }
168174 }
169175 GlobalAlloc :: Static ( _) | GlobalAlloc :: VTable ( _, _) => {
@@ -190,7 +196,7 @@ fn collect_alloc(
190196 } else {
191197 // Could not recover a precise pointee type; use an opaque 0-valued Ty
192198 // as a conservative placeholder.
193- entry. or_insert ( ( stable_mir :: ty :: Ty :: to_val ( 0 ) , global_alloc. clone ( ) ) ) ;
199+ entry. or_insert ( ( opaque_placeholder_ty ( ) , global_alloc. clone ( ) ) ) ;
194200 }
195201 } else {
196202 entry. or_insert ( ( ty, global_alloc. clone ( ) ) ) ;
@@ -280,7 +286,7 @@ impl MirVisitor for InternedValueCollector<'_, '_> {
280286 . provenance
281287 . ptrs
282288 . iter ( )
283- . for_each ( |( offset, prov) | collect_alloc ( self , constant. ty ( ) , offset, prov. 0 ) ) ;
289+ . for_each ( |( offset, prov) | collect_alloc ( self , constant. ty ( ) , * offset, prov. 0 ) ) ;
284290 }
285291 ConstantKind :: Ty ( ty_const) => {
286292 if let TyConstKind :: Value ( ..) = ty_const. kind ( ) {
0 commit comments