@@ -6,7 +6,7 @@ use crate::codegen_cx::CodegenCx;
6
6
use crate :: spirv_type:: SpirvType ;
7
7
use rspirv:: spirv:: { StorageClass , Word } ;
8
8
use rustc_data_structures:: fx:: FxHashMap ;
9
- use rustc_errors:: ErrorReported ;
9
+ use rustc_errors:: ErrorGuaranteed ;
10
10
use rustc_index:: vec:: Idx ;
11
11
use rustc_middle:: ty:: layout:: { FnAbiOf , LayoutOf , TyAndLayout } ;
12
12
use rustc_middle:: ty:: query:: { ExternProviders , Providers } ;
@@ -21,7 +21,7 @@ use rustc_span::Span;
21
21
use rustc_span:: DUMMY_SP ;
22
22
use rustc_target:: abi:: call:: { ArgAbi , ArgAttributes , FnAbi , PassMode } ;
23
23
use rustc_target:: abi:: {
24
- Abi , Align , FieldsShape , Layout , Primitive , Scalar , Size , TagEncoding , VariantIdx , Variants ,
24
+ Abi , Align , FieldsShape , LayoutS , Primitive , Scalar , Size , TagEncoding , VariantIdx , Variants ,
25
25
} ;
26
26
use rustc_target:: spec:: abi:: Abi as SpecAbi ;
27
27
use std:: cell:: RefCell ;
@@ -92,17 +92,18 @@ pub(crate) fn provide(providers: &mut Providers) {
92
92
Ok ( readjust_fn_abi ( tcx, result?) )
93
93
} ;
94
94
95
- // FIXME(eddyb) remove this by deriving `Clone` for `Layout` upstream.
96
- fn clone_layout ( layout : & Layout ) -> Layout {
97
- let Layout {
95
+ // FIXME(eddyb) remove this by deriving `Clone` for `LayoutS` upstream.
96
+ // FIXME(eddyb) the `S` suffix is a naming antipattern, rename upstream.
97
+ fn clone_layout < ' a > ( layout : & LayoutS < ' a > ) -> LayoutS < ' a > {
98
+ let LayoutS {
98
99
ref fields,
99
100
ref variants,
100
101
abi,
101
102
largest_niche,
102
103
align,
103
104
size,
104
105
} = * layout;
105
- Layout {
106
+ LayoutS {
106
107
fields : match * fields {
107
108
FieldsShape :: Primitive => FieldsShape :: Primitive ,
108
109
FieldsShape :: Union ( count) => FieldsShape :: Union ( count) ,
@@ -137,7 +138,7 @@ pub(crate) fn provide(providers: &mut Providers) {
137
138
} ,
138
139
} ,
139
140
tag_field,
140
- variants : variants. iter ( ) . map ( clone_layout ) . collect ( ) ,
141
+ variants : variants. clone ( ) ,
141
142
} ,
142
143
} ,
143
144
abi,
@@ -157,9 +158,9 @@ pub(crate) fn provide(providers: &mut Providers) {
157
158
} ;
158
159
159
160
if hide_niche {
160
- layout = tcx. arena . alloc ( Layout {
161
+ layout = tcx. intern_layout ( LayoutS {
161
162
largest_niche : None ,
162
- ..clone_layout ( layout)
163
+ ..clone_layout ( layout. 0 . 0 )
163
164
} ) ;
164
165
}
165
166
@@ -341,10 +342,10 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
341
342
fn spirv_type ( & self , mut span : Span , cx : & CodegenCx < ' tcx > ) -> Word {
342
343
if let TyKind :: Adt ( adt, substs) = * self . ty . kind ( ) {
343
344
if span == DUMMY_SP {
344
- span = cx. tcx . def_span ( adt. did ) ;
345
+ span = cx. tcx . def_span ( adt. did ( ) ) ;
345
346
}
346
347
347
- let attrs = AggregatedSpirvAttributes :: parse ( cx, cx. tcx . get_attrs ( adt. did ) ) ;
348
+ let attrs = AggregatedSpirvAttributes :: parse ( cx, cx. tcx . get_attrs ( adt. did ( ) ) ) ;
348
349
349
350
if let Some ( intrinsic_type_attr) = attrs. intrinsic_type . map ( |attr| attr. value ) {
350
351
if let Ok ( spirv_type) =
@@ -368,8 +369,8 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
368
369
field_names : None ,
369
370
}
370
371
. def_with_name ( cx, span, TyLayoutNameKey :: from ( * self ) ) ,
371
- Abi :: Scalar ( ref scalar) => trans_scalar ( cx, span, * self , scalar, Size :: ZERO ) ,
372
- Abi :: ScalarPair ( ref a , ref b) => {
372
+ Abi :: Scalar ( scalar) => trans_scalar ( cx, span, * self , scalar, Size :: ZERO ) ,
373
+ Abi :: ScalarPair ( a , b) => {
373
374
// NOTE(eddyb) unlike `Abi::Scalar`'s simpler newtype-unpacking
374
375
// behavior, `Abi::ScalarPair` can be composed in two ways:
375
376
// * two `Abi::Scalar` fields (and any number of ZST fields),
@@ -419,7 +420,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
419
420
if let TyKind :: Adt ( adt, _) = self . ty . kind ( ) {
420
421
if let Variants :: Single { index } = self . variants {
421
422
for i in self . fields . index_by_increasing_offset ( ) {
422
- let field = & adt. variants [ index] . fields [ i] ;
423
+ let field = & adt. variants ( ) [ index] . fields [ i] ;
423
424
field_names. push ( field. name . to_ident_string ( ) ) ;
424
425
}
425
426
}
@@ -438,7 +439,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
438
439
}
439
440
. def_with_name ( cx, span, TyLayoutNameKey :: from ( * self ) )
440
441
}
441
- Abi :: Vector { ref element, count } => {
442
+ Abi :: Vector { element, count } => {
442
443
let elem_spirv = trans_scalar ( cx, span, * self , element, Size :: ZERO ) ;
443
444
SpirvType :: Vector {
444
445
element : elem_spirv,
@@ -459,7 +460,7 @@ pub fn scalar_pair_element_backend_type<'tcx>(
459
460
ty : TyAndLayout < ' tcx > ,
460
461
index : usize ,
461
462
) -> Word {
462
- let [ a, b] = match & ty. layout . abi {
463
+ let [ a, b] = match ty. layout . abi ( ) {
463
464
Abi :: ScalarPair ( a, b) => [ a, b] ,
464
465
other => span_bug ! (
465
466
span,
@@ -486,7 +487,7 @@ fn trans_scalar<'tcx>(
486
487
cx : & CodegenCx < ' tcx > ,
487
488
span : Span ,
488
489
ty : TyAndLayout < ' tcx > ,
489
- scalar : & Scalar ,
490
+ scalar : Scalar ,
490
491
offset : Size ,
491
492
) -> Word {
492
493
if scalar. is_bool ( ) {
@@ -697,7 +698,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
697
698
field_offsets. push ( offset) ;
698
699
if let Variants :: Single { index } = ty. variants {
699
700
if let TyKind :: Adt ( adt, _) = ty. ty . kind ( ) {
700
- let field = & adt. variants [ index] . fields [ i] ;
701
+ let field = & adt. variants ( ) [ index] . fields [ i] ;
701
702
field_names. push ( field. name . to_ident_string ( ) ) ;
702
703
} else {
703
704
field_names. push ( format ! ( "{}" , i) ) ;
@@ -730,7 +731,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
730
731
/// (not in itself an issue, but it makes error reporting harder).
731
732
fn def_id_for_spirv_type_adt ( layout : TyAndLayout < ' _ > ) -> Option < DefId > {
732
733
match * layout. ty . kind ( ) {
733
- TyKind :: Adt ( def, _) => Some ( def. did ) ,
734
+ TyKind :: Adt ( def, _) => Some ( def. did ( ) ) ,
734
735
TyKind :: Foreign ( def_id) | TyKind :: Closure ( def_id, _) | TyKind :: Generator ( def_id, ..) => {
735
736
Some ( def_id)
736
737
}
@@ -762,8 +763,8 @@ impl fmt::Display for TyLayoutNameKey<'_> {
762
763
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
763
764
write ! ( f, "{}" , self . ty) ?;
764
765
if let ( TyKind :: Adt ( def, _) , Some ( index) ) = ( self . ty . kind ( ) , self . variant ) {
765
- if def. is_enum ( ) && !def. variants . is_empty ( ) {
766
- write ! ( f, "::{}" , def. variants[ index] . name) ?;
766
+ if def. is_enum ( ) && !def. variants ( ) . is_empty ( ) {
767
+ write ! ( f, "::{}" , def. variants( ) [ index] . name) ?;
767
768
}
768
769
}
769
770
if let ( TyKind :: Generator ( _, _, _) , Some ( index) ) = ( self . ty . kind ( ) , self . variant ) {
@@ -779,15 +780,15 @@ fn trans_intrinsic_type<'tcx>(
779
780
ty : TyAndLayout < ' tcx > ,
780
781
substs : SubstsRef < ' tcx > ,
781
782
intrinsic_type_attr : IntrinsicType ,
782
- ) -> Result < Word , ErrorReported > {
783
+ ) -> Result < Word , ErrorGuaranteed > {
783
784
match intrinsic_type_attr {
784
785
IntrinsicType :: GenericImageType => {
785
786
// see SpirvType::sizeof
786
787
if ty. size != Size :: from_bytes ( 4 ) {
787
- cx. tcx
788
+ return Err ( cx
789
+ . tcx
788
790
. sess
789
- . err ( "#[spirv(generic_image)] type must have size 4" ) ;
790
- return Err ( ErrorReported ) ;
791
+ . err ( "#[spirv(generic_image)] type must have size 4" ) ) ;
791
792
}
792
793
793
794
// fn type_from_variant_discriminant<'tcx, P: FromPrimitive>(
@@ -828,10 +829,10 @@ fn trans_intrinsic_type<'tcx>(
828
829
TyKind :: Float ( FloatTy :: F32 ) => SpirvType :: Float ( 32 ) . def ( span, cx) ,
829
830
TyKind :: Float ( FloatTy :: F64 ) => SpirvType :: Float ( 64 ) . def ( span, cx) ,
830
831
_ => {
831
- cx. tcx
832
+ return Err ( cx
833
+ . tcx
832
834
. sess
833
- . span_err ( span, "Invalid sampled type to `Image`." ) ;
834
- return Err ( ErrorReported ) ;
835
+ . span_err ( span, "Invalid sampled type to `Image`." ) ) ;
835
836
}
836
837
} ;
837
838
@@ -846,17 +847,15 @@ fn trans_intrinsic_type<'tcx>(
846
847
fn const_int_value < ' tcx , P : FromPrimitive > (
847
848
cx : & CodegenCx < ' tcx > ,
848
849
const_ : Const < ' tcx > ,
849
- ) -> Result < P , ErrorReported > {
850
+ ) -> Result < P , ErrorGuaranteed > {
850
851
assert ! ( const_. ty( ) . is_integral( ) ) ;
851
852
let value = const_. eval_bits ( cx. tcx , ParamEnv :: reveal_all ( ) , const_. ty ( ) ) ;
852
853
match P :: from_u128 ( value) {
853
854
Some ( v) => Ok ( v) ,
854
- None => {
855
- cx. tcx
856
- . sess
857
- . err ( & format ! ( "Invalid value for Image const generic: {}" , value) ) ;
858
- Err ( ErrorReported )
859
- }
855
+ None => Err ( cx
856
+ . tcx
857
+ . sess
858
+ . err ( & format ! ( "Invalid value for Image const generic: {}" , value) ) ) ,
860
859
}
861
860
}
862
861
@@ -881,8 +880,7 @@ fn trans_intrinsic_type<'tcx>(
881
880
IntrinsicType :: Sampler => {
882
881
// see SpirvType::sizeof
883
882
if ty. size != Size :: from_bytes ( 4 ) {
884
- cx. tcx . sess . err ( "#[spirv(sampler)] type must have size 4" ) ;
885
- return Err ( ErrorReported ) ;
883
+ return Err ( cx. tcx . sess . err ( "#[spirv(sampler)] type must have size 4" ) ) ;
886
884
}
887
885
Ok ( SpirvType :: Sampler . def ( span, cx) )
888
886
}
@@ -893,10 +891,10 @@ fn trans_intrinsic_type<'tcx>(
893
891
IntrinsicType :: SampledImage => {
894
892
// see SpirvType::sizeof
895
893
if ty. size != Size :: from_bytes ( 4 ) {
896
- cx. tcx
894
+ return Err ( cx
895
+ . tcx
897
896
. sess
898
- . err ( "#[spirv(sampled_image)] type must have size 4" ) ;
899
- return Err ( ErrorReported ) ;
897
+ . err ( "#[spirv(sampled_image)] type must have size 4" ) ) ;
900
898
}
901
899
902
900
// We use a generic to indicate the underlying image type of the sampled image.
@@ -906,18 +904,18 @@ fn trans_intrinsic_type<'tcx>(
906
904
let image_type = cx. layout_of ( image_ty) . spirv_type ( span, cx) ;
907
905
Ok ( SpirvType :: SampledImage { image_type } . def ( span, cx) )
908
906
} else {
909
- cx. tcx
907
+ Err ( cx
908
+ . tcx
910
909
. sess
911
- . err ( "#[spirv(sampled_image)] type must have a generic image type" ) ;
912
- Err ( ErrorReported )
910
+ . err ( "#[spirv(sampled_image)] type must have a generic image type" ) )
913
911
}
914
912
}
915
913
IntrinsicType :: RuntimeArray => {
916
914
if ty. size != Size :: from_bytes ( 4 ) {
917
- cx. tcx
915
+ return Err ( cx
916
+ . tcx
918
917
. sess
919
- . err ( "#[spirv(runtime_array)] type must have size 4" ) ;
920
- return Err ( ErrorReported ) ;
918
+ . err ( "#[spirv(runtime_array)] type must have size 4" ) ) ;
921
919
}
922
920
923
921
// We use a generic to indicate the underlying element type.
@@ -926,10 +924,10 @@ fn trans_intrinsic_type<'tcx>(
926
924
let element = cx. layout_of ( elem_ty) . spirv_type ( span, cx) ;
927
925
Ok ( SpirvType :: RuntimeArray { element } . def ( span, cx) )
928
926
} else {
929
- cx. tcx
927
+ Err ( cx
928
+ . tcx
930
929
. sess
931
- . err ( "#[spirv(runtime_array)] type must have a generic element type" ) ;
932
- Err ( ErrorReported )
930
+ . err ( "#[spirv(runtime_array)] type must have a generic element type" ) )
933
931
}
934
932
}
935
933
IntrinsicType :: Matrix => {
@@ -941,28 +939,27 @@ fn trans_intrinsic_type<'tcx>(
941
939
. map ( |i| ty. field ( cx, i) . spirv_type ( span, cx) )
942
940
. collect :: < Vec < _ > > ( ) ;
943
941
if field_types. len ( ) < 2 {
944
- cx. tcx
942
+ return Err ( cx
943
+ . tcx
945
944
. sess
946
- . span_err ( span, "#[spirv(matrix)] type must have at least two fields" ) ;
947
- return Err ( ErrorReported ) ;
945
+ . span_err ( span, "#[spirv(matrix)] type must have at least two fields" ) ) ;
948
946
}
949
947
let elem_type = field_types[ 0 ] ;
950
948
if !field_types. iter ( ) . all ( |& ty| ty == elem_type) {
951
- cx. tcx . sess . span_err (
949
+ return Err ( cx. tcx . sess . span_err (
952
950
span,
953
951
"#[spirv(matrix)] type fields must all be the same type" ,
954
- ) ;
955
- return Err ( ErrorReported ) ;
952
+ ) ) ;
956
953
}
957
954
match cx. lookup_type ( elem_type) {
958
955
SpirvType :: Vector { .. } => ( ) ,
959
956
ty => {
960
- cx. tcx
957
+ return Err ( cx
958
+ . tcx
961
959
. sess
962
960
. struct_span_err ( span, "#[spirv(matrix)] type fields must all be vectors" )
963
961
. note ( & format ! ( "field type is {}" , ty. debug( elem_type, cx) ) )
964
- . emit ( ) ;
965
- return Err ( ErrorReported ) ;
962
+ . emit ( ) ) ;
966
963
}
967
964
}
968
965
0 commit comments