@@ -619,10 +619,6 @@ impl Primitive {
619
619
}
620
620
}
621
621
622
- /// Path through fields of nested structures.
623
- // FIXME(eddyb) use small vector optimization for the common case.
624
- pub type FieldPath = Vec < u32 > ;
625
-
626
622
/// A structure, a product type in ADT terms.
627
623
#[ derive( PartialEq , Eq , Hash , Debug ) ]
628
624
pub struct Struct {
@@ -848,20 +844,19 @@ impl<'a, 'tcx> Struct {
848
844
fn non_zero_field_in_type ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
849
845
param_env : ty:: ParamEnv < ' tcx > ,
850
846
ty : Ty < ' tcx > )
851
- -> Result < Option < ( Size , Primitive , FieldPath ) > , LayoutError < ' tcx > > {
847
+ -> Result < Option < ( Size , Primitive ) > , LayoutError < ' tcx > > {
852
848
let layout = ty. layout ( tcx, param_env) ?;
853
849
match ( layout, & ty. sty ) {
854
850
( & Scalar { non_zero : true , value, .. } , _) => {
855
- Ok ( Some ( ( Size :: from_bytes ( 0 ) , value, vec ! [ ] ) ) )
851
+ Ok ( Some ( ( Size :: from_bytes ( 0 ) , value) ) )
856
852
}
857
853
( & CEnum { non_zero : true , discr, .. } , _) => {
858
- Ok ( Some ( ( Size :: from_bytes ( 0 ) , Int ( discr) , vec ! [ ] ) ) )
854
+ Ok ( Some ( ( Size :: from_bytes ( 0 ) , Int ( discr) ) ) )
859
855
}
860
856
861
857
( & FatPointer { non_zero : true , .. } , _) => {
862
858
Ok ( Some ( ( layout. field_offset ( tcx, FAT_PTR_ADDR , None ) ,
863
- Pointer ,
864
- vec ! [ FAT_PTR_ADDR as u32 ] ) ) )
859
+ Pointer ) ) )
865
860
}
866
861
867
862
// Is this the NonZero lang item wrapping a pointer or integer type?
@@ -873,15 +868,12 @@ impl<'a, 'tcx> Struct {
873
868
// FIXME(eddyb) also allow floating-point types here.
874
869
Scalar { value : value @ Int ( _) , non_zero : false } |
875
870
Scalar { value : value @ Pointer , non_zero : false } => {
876
- Ok ( Some ( ( layout. field_offset ( tcx, 0 , None ) ,
877
- value,
878
- vec ! [ 0 ] ) ) )
871
+ Ok ( Some ( ( layout. field_offset ( tcx, 0 , None ) , value) ) )
879
872
}
880
873
FatPointer { non_zero : false , .. } => {
881
874
Ok ( Some ( ( layout. field_offset ( tcx, 0 , None ) +
882
875
field. field_offset ( tcx, FAT_PTR_ADDR , None ) ,
883
- Pointer ,
884
- vec ! [ FAT_PTR_ADDR as u32 , 0 ] ) ) )
876
+ Pointer ) ) )
885
877
}
886
878
_ => Ok ( None )
887
879
}
@@ -890,31 +882,22 @@ impl<'a, 'tcx> Struct {
890
882
// Perhaps one of the fields of this struct is non-zero
891
883
// let's recurse and find out
892
884
( & Univariant { ref variant, .. } , & ty:: TyAdt ( def, substs) ) if def. is_struct ( ) => {
893
- Struct :: non_zero_field (
885
+ variant . non_zero_field (
894
886
tcx,
895
887
param_env,
896
888
def. struct_variant ( ) . fields . iter ( ) . map ( |field| {
897
889
field. ty ( tcx, substs)
898
- } ) ,
899
- & variant. offsets )
890
+ } ) )
900
891
}
901
892
902
893
// Perhaps one of the upvars of this closure is non-zero
903
894
( & Univariant { ref variant, .. } , & ty:: TyClosure ( def, substs) ) => {
904
895
let upvar_tys = substs. upvar_tys ( def, tcx) ;
905
- Struct :: non_zero_field (
906
- tcx,
907
- param_env,
908
- upvar_tys,
909
- & variant. offsets )
896
+ variant. non_zero_field ( tcx, param_env, upvar_tys)
910
897
}
911
898
// Can we use one of the fields in this tuple?
912
899
( & Univariant { ref variant, .. } , & ty:: TyTuple ( tys, _) ) => {
913
- Struct :: non_zero_field (
914
- tcx,
915
- param_env,
916
- tys. iter ( ) . cloned ( ) ,
917
- & variant. offsets )
900
+ variant. non_zero_field ( tcx, param_env, tys. iter ( ) . cloned ( ) )
918
901
}
919
902
920
903
// Is this a fixed-size array of something non-zero
@@ -927,11 +910,7 @@ impl<'a, 'tcx> Struct {
927
910
}
928
911
}
929
912
if count. val . to_const_int ( ) . unwrap ( ) . to_u64 ( ) . unwrap ( ) != 0 {
930
- Struct :: non_zero_field (
931
- tcx,
932
- param_env,
933
- Some ( ety) . into_iter ( ) ,
934
- & [ Size :: from_bytes ( 0 ) ] )
913
+ Struct :: non_zero_field_in_type ( tcx, param_env, ety)
935
914
} else {
936
915
Ok ( None )
937
916
}
@@ -953,17 +932,15 @@ impl<'a, 'tcx> Struct {
953
932
/// Find the offset of a non-zero leaf field, starting from
954
933
/// the given set of fields and recursing through aggregates.
955
934
/// Returns Some((offset, primitive, source_path)) on success.
956
- fn non_zero_field < I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
935
+ fn non_zero_field < I > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
957
936
param_env : ty:: ParamEnv < ' tcx > ,
958
- fields : I ,
959
- offsets : & [ Size ] )
960
- -> Result < Option < ( Size , Primitive , FieldPath ) > , LayoutError < ' tcx > >
937
+ fields : I )
938
+ -> Result < Option < ( Size , Primitive ) > , LayoutError < ' tcx > >
961
939
where I : Iterator < Item =Ty < ' tcx > > {
962
- for ( i , ty ) in fields. enumerate ( ) {
940
+ for ( ty , & field_offset ) in fields. zip ( & self . offsets ) {
963
941
let r = Struct :: non_zero_field_in_type ( tcx, param_env, ty) ?;
964
- if let Some ( ( offset, primitive, mut source_path) ) = r {
965
- source_path. push ( i as u32 ) ;
966
- return Ok ( Some ( ( offsets[ i] + offset, primitive, source_path) ) ) ;
942
+ if let Some ( ( offset, primitive) ) = r {
943
+ return Ok ( Some ( ( field_offset + offset, primitive) ) ) ;
967
944
}
968
945
}
969
946
Ok ( None )
@@ -1152,8 +1129,6 @@ pub enum Layout {
1152
1129
nonnull : Struct ,
1153
1130
discr : Primitive ,
1154
1131
discr_offset : Size ,
1155
- /// Like discr_offset, but the source field path. For debuginfo.
1156
- discrfield_source : FieldPath
1157
1132
}
1158
1133
}
1159
1134
@@ -1452,11 +1427,9 @@ impl<'a, 'tcx> Layout {
1452
1427
. collect :: < Result < Vec < _ > , _ > > ( ) ?,
1453
1428
& def. repr , StructKind :: AlwaysSizedUnivariant , ty) ?;
1454
1429
1455
- let field = Struct :: non_zero_field ( tcx,
1456
- param_env,
1457
- variants[ discr] . iter ( ) . cloned ( ) ,
1458
- & st. offsets ) ?;
1459
- let ( offset, primitive, mut path_source) = if let Some ( f) = field { f }
1430
+ let field = st. non_zero_field ( tcx, param_env,
1431
+ variants[ discr] . iter ( ) . cloned ( ) ) ?;
1432
+ let ( offset, primitive) = if let Some ( f) = field { f }
1460
1433
else { continue } ;
1461
1434
1462
1435
// FIXME(eddyb) should take advantage of a newtype.
@@ -1468,15 +1441,11 @@ impl<'a, 'tcx> Layout {
1468
1441
} ) ;
1469
1442
}
1470
1443
1471
- // We have to fix the source path here.
1472
- path_source. reverse ( ) ;
1473
-
1474
1444
return success ( StructWrappedNullablePointer {
1475
1445
nndiscr : discr as u64 ,
1476
1446
nonnull : st,
1477
1447
discr : primitive,
1478
1448
discr_offset : offset,
1479
- discrfield_source : path_source
1480
1449
} ) ;
1481
1450
}
1482
1451
}
@@ -1875,8 +1844,7 @@ impl<'a, 'tcx> Layout {
1875
1844
Layout :: StructWrappedNullablePointer { nonnull : ref variant_layout,
1876
1845
nndiscr,
1877
1846
discr : _,
1878
- discr_offset : _,
1879
- discrfield_source : _ } => {
1847
+ discr_offset : _ } => {
1880
1848
debug ! ( "print-type-size t: `{:?}` adt struct-wrapped nullable nndiscr {} is {:?}" ,
1881
1849
ty, nndiscr, variant_layout) ;
1882
1850
let variant_def = & adt_def. variants [ nndiscr as usize ] ;
@@ -2418,13 +2386,11 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Layout
2418
2386
ref nonnull,
2419
2387
ref discr,
2420
2388
discr_offset,
2421
- ref discrfield_source
2422
2389
} => {
2423
2390
nndiscr. hash_stable ( hcx, hasher) ;
2424
2391
nonnull. hash_stable ( hcx, hasher) ;
2425
2392
discr. hash_stable ( hcx, hasher) ;
2426
2393
discr_offset. hash_stable ( hcx, hasher) ;
2427
- discrfield_source. hash_stable ( hcx, hasher) ;
2428
2394
}
2429
2395
}
2430
2396
}
0 commit comments