Skip to content

Commit 3e04f62

Browse files
committed
rustup: update to nightly-2022-04-01.
1 parent f0baf78 commit 3e04f62

24 files changed

+277
-227
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::codegen_cx::CodegenCx;
66
use crate::spirv_type::SpirvType;
77
use rspirv::spirv::{StorageClass, Word};
88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_errors::ErrorReported;
9+
use rustc_errors::ErrorGuaranteed;
1010
use rustc_index::vec::Idx;
1111
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
1212
use rustc_middle::ty::query::{ExternProviders, Providers};
@@ -21,7 +21,7 @@ use rustc_span::Span;
2121
use rustc_span::DUMMY_SP;
2222
use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode};
2323
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,
2525
};
2626
use rustc_target::spec::abi::Abi as SpecAbi;
2727
use std::cell::RefCell;
@@ -92,17 +92,18 @@ pub(crate) fn provide(providers: &mut Providers) {
9292
Ok(readjust_fn_abi(tcx, result?))
9393
};
9494

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 {
9899
ref fields,
99100
ref variants,
100101
abi,
101102
largest_niche,
102103
align,
103104
size,
104105
} = *layout;
105-
Layout {
106+
LayoutS {
106107
fields: match *fields {
107108
FieldsShape::Primitive => FieldsShape::Primitive,
108109
FieldsShape::Union(count) => FieldsShape::Union(count),
@@ -137,7 +138,7 @@ pub(crate) fn provide(providers: &mut Providers) {
137138
},
138139
},
139140
tag_field,
140-
variants: variants.iter().map(clone_layout).collect(),
141+
variants: variants.clone(),
141142
},
142143
},
143144
abi,
@@ -157,9 +158,9 @@ pub(crate) fn provide(providers: &mut Providers) {
157158
};
158159

159160
if hide_niche {
160-
layout = tcx.arena.alloc(Layout {
161+
layout = tcx.intern_layout(LayoutS {
161162
largest_niche: None,
162-
..clone_layout(layout)
163+
..clone_layout(layout.0 .0)
163164
});
164165
}
165166

@@ -341,10 +342,10 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
341342
fn spirv_type(&self, mut span: Span, cx: &CodegenCx<'tcx>) -> Word {
342343
if let TyKind::Adt(adt, substs) = *self.ty.kind() {
343344
if span == DUMMY_SP {
344-
span = cx.tcx.def_span(adt.did);
345+
span = cx.tcx.def_span(adt.did());
345346
}
346347

347-
let attrs = AggregatedSpirvAttributes::parse(cx, cx.tcx.get_attrs(adt.did));
348+
let attrs = AggregatedSpirvAttributes::parse(cx, cx.tcx.get_attrs(adt.did()));
348349

349350
if let Some(intrinsic_type_attr) = attrs.intrinsic_type.map(|attr| attr.value) {
350351
if let Ok(spirv_type) =
@@ -368,8 +369,8 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
368369
field_names: None,
369370
}
370371
.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) => {
373374
// NOTE(eddyb) unlike `Abi::Scalar`'s simpler newtype-unpacking
374375
// behavior, `Abi::ScalarPair` can be composed in two ways:
375376
// * two `Abi::Scalar` fields (and any number of ZST fields),
@@ -419,7 +420,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
419420
if let TyKind::Adt(adt, _) = self.ty.kind() {
420421
if let Variants::Single { index } = self.variants {
421422
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];
423424
field_names.push(field.name.to_ident_string());
424425
}
425426
}
@@ -438,7 +439,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
438439
}
439440
.def_with_name(cx, span, TyLayoutNameKey::from(*self))
440441
}
441-
Abi::Vector { ref element, count } => {
442+
Abi::Vector { element, count } => {
442443
let elem_spirv = trans_scalar(cx, span, *self, element, Size::ZERO);
443444
SpirvType::Vector {
444445
element: elem_spirv,
@@ -459,7 +460,7 @@ pub fn scalar_pair_element_backend_type<'tcx>(
459460
ty: TyAndLayout<'tcx>,
460461
index: usize,
461462
) -> Word {
462-
let [a, b] = match &ty.layout.abi {
463+
let [a, b] = match ty.layout.abi() {
463464
Abi::ScalarPair(a, b) => [a, b],
464465
other => span_bug!(
465466
span,
@@ -486,7 +487,7 @@ fn trans_scalar<'tcx>(
486487
cx: &CodegenCx<'tcx>,
487488
span: Span,
488489
ty: TyAndLayout<'tcx>,
489-
scalar: &Scalar,
490+
scalar: Scalar,
490491
offset: Size,
491492
) -> Word {
492493
if scalar.is_bool() {
@@ -697,7 +698,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
697698
field_offsets.push(offset);
698699
if let Variants::Single { index } = ty.variants {
699700
if let TyKind::Adt(adt, _) = ty.ty.kind() {
700-
let field = &adt.variants[index].fields[i];
701+
let field = &adt.variants()[index].fields[i];
701702
field_names.push(field.name.to_ident_string());
702703
} else {
703704
field_names.push(format!("{}", i));
@@ -730,7 +731,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
730731
/// (not in itself an issue, but it makes error reporting harder).
731732
fn def_id_for_spirv_type_adt(layout: TyAndLayout<'_>) -> Option<DefId> {
732733
match *layout.ty.kind() {
733-
TyKind::Adt(def, _) => Some(def.did),
734+
TyKind::Adt(def, _) => Some(def.did()),
734735
TyKind::Foreign(def_id) | TyKind::Closure(def_id, _) | TyKind::Generator(def_id, ..) => {
735736
Some(def_id)
736737
}
@@ -762,8 +763,8 @@ impl fmt::Display for TyLayoutNameKey<'_> {
762763
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
763764
write!(f, "{}", self.ty)?;
764765
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)?;
767768
}
768769
}
769770
if let (TyKind::Generator(_, _, _), Some(index)) = (self.ty.kind(), self.variant) {
@@ -779,15 +780,15 @@ fn trans_intrinsic_type<'tcx>(
779780
ty: TyAndLayout<'tcx>,
780781
substs: SubstsRef<'tcx>,
781782
intrinsic_type_attr: IntrinsicType,
782-
) -> Result<Word, ErrorReported> {
783+
) -> Result<Word, ErrorGuaranteed> {
783784
match intrinsic_type_attr {
784785
IntrinsicType::GenericImageType => {
785786
// see SpirvType::sizeof
786787
if ty.size != Size::from_bytes(4) {
787-
cx.tcx
788+
return Err(cx
789+
.tcx
788790
.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"));
791792
}
792793

793794
// fn type_from_variant_discriminant<'tcx, P: FromPrimitive>(
@@ -828,10 +829,10 @@ fn trans_intrinsic_type<'tcx>(
828829
TyKind::Float(FloatTy::F32) => SpirvType::Float(32).def(span, cx),
829830
TyKind::Float(FloatTy::F64) => SpirvType::Float(64).def(span, cx),
830831
_ => {
831-
cx.tcx
832+
return Err(cx
833+
.tcx
832834
.sess
833-
.span_err(span, "Invalid sampled type to `Image`.");
834-
return Err(ErrorReported);
835+
.span_err(span, "Invalid sampled type to `Image`."));
835836
}
836837
};
837838

@@ -846,17 +847,15 @@ fn trans_intrinsic_type<'tcx>(
846847
fn const_int_value<'tcx, P: FromPrimitive>(
847848
cx: &CodegenCx<'tcx>,
848849
const_: Const<'tcx>,
849-
) -> Result<P, ErrorReported> {
850+
) -> Result<P, ErrorGuaranteed> {
850851
assert!(const_.ty().is_integral());
851852
let value = const_.eval_bits(cx.tcx, ParamEnv::reveal_all(), const_.ty());
852853
match P::from_u128(value) {
853854
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))),
860859
}
861860
}
862861

@@ -881,8 +880,7 @@ fn trans_intrinsic_type<'tcx>(
881880
IntrinsicType::Sampler => {
882881
// see SpirvType::sizeof
883882
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"));
886884
}
887885
Ok(SpirvType::Sampler.def(span, cx))
888886
}
@@ -893,10 +891,10 @@ fn trans_intrinsic_type<'tcx>(
893891
IntrinsicType::SampledImage => {
894892
// see SpirvType::sizeof
895893
if ty.size != Size::from_bytes(4) {
896-
cx.tcx
894+
return Err(cx
895+
.tcx
897896
.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"));
900898
}
901899

902900
// We use a generic to indicate the underlying image type of the sampled image.
@@ -906,18 +904,18 @@ fn trans_intrinsic_type<'tcx>(
906904
let image_type = cx.layout_of(image_ty).spirv_type(span, cx);
907905
Ok(SpirvType::SampledImage { image_type }.def(span, cx))
908906
} else {
909-
cx.tcx
907+
Err(cx
908+
.tcx
910909
.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"))
913911
}
914912
}
915913
IntrinsicType::RuntimeArray => {
916914
if ty.size != Size::from_bytes(4) {
917-
cx.tcx
915+
return Err(cx
916+
.tcx
918917
.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"));
921919
}
922920

923921
// We use a generic to indicate the underlying element type.
@@ -926,10 +924,10 @@ fn trans_intrinsic_type<'tcx>(
926924
let element = cx.layout_of(elem_ty).spirv_type(span, cx);
927925
Ok(SpirvType::RuntimeArray { element }.def(span, cx))
928926
} else {
929-
cx.tcx
927+
Err(cx
928+
.tcx
930929
.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"))
933931
}
934932
}
935933
IntrinsicType::Matrix => {
@@ -941,28 +939,27 @@ fn trans_intrinsic_type<'tcx>(
941939
.map(|i| ty.field(cx, i).spirv_type(span, cx))
942940
.collect::<Vec<_>>();
943941
if field_types.len() < 2 {
944-
cx.tcx
942+
return Err(cx
943+
.tcx
945944
.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"));
948946
}
949947
let elem_type = field_types[0];
950948
if !field_types.iter().all(|&ty| ty == elem_type) {
951-
cx.tcx.sess.span_err(
949+
return Err(cx.tcx.sess.span_err(
952950
span,
953951
"#[spirv(matrix)] type fields must all be the same type",
954-
);
955-
return Err(ErrorReported);
952+
));
956953
}
957954
match cx.lookup_type(elem_type) {
958955
SpirvType::Vector { .. } => (),
959956
ty => {
960-
cx.tcx
957+
return Err(cx
958+
.tcx
961959
.sess
962960
.struct_span_err(span, "#[spirv(matrix)] type fields must all be vectors")
963961
.note(&format!("field type is {}", ty.debug(elem_type, cx)))
964-
.emit();
965-
return Err(ErrorReported);
962+
.emit());
966963
}
967964
}
968965

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ impl CheckSpirvAttrVisitor<'_> {
363363
}
364364
};
365365
match valid_target {
366-
Err(Expected(expected_target)) => self.tcx.sess.span_err(
367-
span,
368-
&format!(
369-
"attribute is only valid on a {}, not on a {}",
370-
expected_target, target
371-
),
372-
),
366+
Err(Expected(expected_target)) => {
367+
self.tcx.sess.span_err(
368+
span,
369+
&format!(
370+
"attribute is only valid on a {}, not on a {}",
371+
expected_target, target
372+
),
373+
);
374+
}
373375
Ok(()) => match aggregated_attrs.try_insert_attr(parsed_attr, span) {
374376
Ok(()) => {}
375377
Err(MultipleAttrs {

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,18 +917,18 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
917917
place.align,
918918
);
919919
OperandValue::Immediate(self.to_immediate(llval, place.layout))
920-
} else if let Abi::ScalarPair(ref a, ref b) = place.layout.abi {
920+
} else if let Abi::ScalarPair(a, b) = place.layout.abi {
921921
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
922922

923923
let pair_ty = place.layout.spirv_type(self.span(), self);
924-
let mut load = |i, scalar: &Scalar, align| {
924+
let mut load = |i, scalar: Scalar, align| {
925925
let llptr = self.struct_gep(pair_ty, place.llval, i as u64);
926926
let load = self.load(
927927
self.scalar_pair_element_backend_type(place.layout, i, false),
928928
llptr,
929929
align,
930930
);
931-
self.to_immediate_scalar(load, *scalar)
931+
self.to_immediate_scalar(load, scalar)
932932
};
933933

934934
OperandValue::Pair(
@@ -2214,7 +2214,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
22142214
self.intcast(val, dest_ty, false)
22152215
}
22162216

2217-
fn apply_attrs_to_cleanup_callsite(&mut self, _llret: Self::Value) {
2217+
fn do_not_inline(&mut self, _llret: Self::Value) {
22182218
// Ignore
22192219
}
22202220
}

0 commit comments

Comments
 (0)