Skip to content

Commit

Permalink
rustup: update to nightly-2024-11-22 (~1.84).
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 9, 2024
1 parent 8eb874a commit 4c256b6
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 152 deletions.
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use std::{env, fs, mem};
/// `cargo publish`. We need to figure out a way to do this properly, but let's hardcode it for now :/
//const REQUIRED_RUST_TOOLCHAIN: &str = include_str!("../../rust-toolchain.toml");
const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain]
channel = "nightly-2024-10-12"
channel = "nightly-2024-11-22"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 1bc403daadbebb553ccc211a0a8eebb73989665f"#;
# commit_hash = b19329a37cedf2027517ae22c87cf201f93d776e"#;

fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
Expand Down
105 changes: 54 additions & 51 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_index::Idx;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::query::Providers;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::{
self, Const, CoroutineArgs, CoroutineArgsExt as _, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty,
TyCtxt, TyKind, UintTy,
self, Const, CoroutineArgs, CoroutineArgsExt as _, FloatTy, IntTy, PolyFnSig, Ty, TyCtxt,
TyKind, UintTy,
};
use rustc_middle::ty::{GenericArgsRef, ScalarInt};
use rustc_middle::{bug, span_bug};
Expand All @@ -23,10 +22,10 @@ use rustc_span::def_id::DefId;
use rustc_span::{Span, Symbol};
use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use rustc_target::abi::{
Abi, Align, FieldsShape, LayoutS, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding,
VariantIdx, Variants,
Align, BackendRepr, FieldsShape, LayoutData, Primitive, ReprFlags, ReprOptions, Scalar, Size,
TagEncoding, VariantIdx, Variants,
};
use rustc_target::spec::abi::Abi as SpecAbi;
use rustc_target::spec::abi::Abi;
use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::fmt;
Expand All @@ -47,8 +46,8 @@ pub(crate) fn provide(providers: &mut Providers) {
let result = (rustc_interface::DEFAULT_QUERY_PROVIDERS.fn_sig)(tcx, def_id);
result.map_bound(|outer| {
outer.map_bound(|mut inner| {
if let SpecAbi::C { .. } = inner.abi {
inner.abi = SpecAbi::Unadjusted;
if let Abi::C { .. } = inner.abi {
inner.abi = Abi::Unadjusted;
}
inner
})
Expand Down Expand Up @@ -98,22 +97,21 @@ pub(crate) fn provide(providers: &mut Providers) {
Ok(readjust_fn_abi(tcx, result?))
};

// FIXME(eddyb) remove this by deriving `Clone` for `LayoutS` upstream.
// FIXME(eddyb) the `S` suffix is a naming antipattern, rename upstream.
// FIXME(eddyb) remove this by deriving `Clone` for `LayoutData` upstream.
fn clone_layout<FieldIdx: Idx, VariantIdx: Idx>(
layout: &LayoutS<FieldIdx, VariantIdx>,
) -> LayoutS<FieldIdx, VariantIdx> {
let LayoutS {
layout: &LayoutData<FieldIdx, VariantIdx>,
) -> LayoutData<FieldIdx, VariantIdx> {
let LayoutData {
ref fields,
ref variants,
abi,
backend_repr,
largest_niche,
align,
size,
max_repr_align,
unadjusted_abi_align,
} = *layout;
LayoutS {
LayoutData {
fields: match *fields {
FieldsShape::Primitive => FieldsShape::Primitive,
FieldsShape::Union(count) => FieldsShape::Union(count),
Expand Down Expand Up @@ -151,7 +149,7 @@ pub(crate) fn provide(providers: &mut Providers) {
variants: variants.clone(),
},
},
abi,
backend_repr,
largest_niche,
align,
size,
Expand All @@ -171,7 +169,7 @@ pub(crate) fn provide(providers: &mut Providers) {
};

if hide_niche {
layout = tcx.mk_layout(LayoutS {
layout = tcx.mk_layout(LayoutData {
largest_niche: None,
..clone_layout(layout.0.0)
});
Expand All @@ -192,6 +190,10 @@ pub(crate) fn provide(providers: &mut Providers) {
// an option (may require Rust-GPU distinguishing between "SPIR-V interface"
// and "Rust-facing" types, which is even worse when the `OpTypeVector`s
// may be e.g. nested in `struct`s/arrays/etc. - at least buffers are easy).
//
// FIXME(eddyb) maybe using `#[spirv(vector)]` and `BackendRepr::Memory`,
// no claims at `rustc`-understood SIMD whatsoever, would be enough?
// (i.e. only SPIR-V caring about such a type vs a struct/array)
providers.check_well_formed = |tcx, def_id| {
let trivial_struct = match tcx.hir_node_by_def_id(def_id) {
rustc_hir::Node::Item(item) => match item.kind {
Expand Down Expand Up @@ -263,6 +265,14 @@ pub(crate) fn provide(providers: &mut Providers) {

(rustc_interface::DEFAULT_QUERY_PROVIDERS.check_well_formed)(tcx, def_id)
};

// HACK(eddyb) work around https://github.com/rust-lang/rust/pull/132173
// (and further changes from https://github.com/rust-lang/rust/pull/132843)
// starting to ban SIMD ABI misuse (or at least starting to warn about it).
//
// FIXME(eddyb) same as the FIXME comment on `check_well_formed`:
// need to migrate away from `#[repr(simd)]` ASAP.
providers.check_mono_item = |_, _| {};
}

/// If a struct contains a pointer to itself, even indirectly, then doing a naiive recursive walk
Expand Down Expand Up @@ -450,9 +460,9 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {

// Note: ty.layout is orthogonal to ty.ty, e.g. `ManuallyDrop<Result<isize, isize>>` has abi
// `ScalarPair`.
// There's a few layers that we go through here. First we inspect layout.abi, then if relevant, layout.fields, etc.
match self.abi {
Abi::Uninhabited => SpirvType::Adt {
// There's a few layers that we go through here. First we inspect layout.backend_repr, then if relevant, layout.fields, etc.
match self.backend_repr {
BackendRepr::Uninhabited => SpirvType::Adt {
def_id: def_id_for_spirv_type_adt(*self),
size: Some(Size::ZERO),
align: Align::from_bytes(0).unwrap(),
Expand All @@ -461,13 +471,13 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
field_names: None,
}
.def_with_name(cx, span, TyLayoutNameKey::from(*self)),
Abi::Scalar(scalar) => trans_scalar(cx, span, *self, scalar, Size::ZERO),
Abi::ScalarPair(a, b) => {
// NOTE(eddyb) unlike `Abi::Scalar`'s simpler newtype-unpacking
// behavior, `Abi::ScalarPair` can be composed in two ways:
// * two `Abi::Scalar` fields (and any number of ZST fields),
BackendRepr::Scalar(scalar) => trans_scalar(cx, span, *self, scalar, Size::ZERO),
BackendRepr::ScalarPair(a, b) => {
// NOTE(eddyb) unlike `BackendRepr::Scalar`'s simpler newtype-unpacking
// behavior, `BackendRepr::ScalarPair` can be composed in two ways:
// * two `BackendRepr::Scalar` fields (and any number of ZST fields),
// gets handled the same as a `struct { a, b }`, further below
// * an `Abi::ScalarPair` field (and any number of ZST fields),
// * an `BackendRepr::ScalarPair` field (and any number of ZST fields),
// which requires more work to allow taking a reference to
// that field, and there are two potential approaches:
// 1. wrapping that field's SPIR-V type in a single-field
Expand All @@ -477,7 +487,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
// 2. reusing that field's SPIR-V type, instead of defining
// a new one, offering the `(a, b)` shape `rustc_codegen_ssa`
// expects, while letting noop pointercasts access the sole
// `Abi::ScalarPair` field - this is the approach taken here
// `BackendRepr::ScalarPair` field - this is the approach taken here
let mut non_zst_fields = (0..self.fields.count())
.map(|i| (i, self.field(cx, i)))
.filter(|(_, field)| !field.is_zst());
Expand All @@ -491,7 +501,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
if self.fields.offset(i) == Size::ZERO
&& field.size == self.size
&& field.align == self.align
&& field.abi == self.abi
&& field.backend_repr == self.backend_repr
{
return field.spirv_type(span, cx);
}
Expand Down Expand Up @@ -532,15 +542,15 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
}
.def_with_name(cx, span, TyLayoutNameKey::from(*self))
}
Abi::Vector { element, count } => {
BackendRepr::Vector { element, count } => {
let elem_spirv = trans_scalar(cx, span, *self, element, Size::ZERO);
SpirvType::Vector {
element: elem_spirv,
count: count as u32,
}
.def(span, cx)
}
Abi::Aggregate { sized: _ } => trans_aggregate(cx, span, *self),
BackendRepr::Memory { sized: _ } => trans_aggregate(cx, span, *self),
}
}
}
Expand All @@ -553,8 +563,8 @@ pub fn scalar_pair_element_backend_type<'tcx>(
ty: TyAndLayout<'tcx>,
index: usize,
) -> Word {
let [a, b] = match ty.layout.abi() {
Abi::ScalarPair(a, b) => [a, b],
let [a, b] = match ty.layout.backend_repr() {
BackendRepr::ScalarPair(a, b) => [a, b],
other => span_bug!(
span,
"scalar_pair_element_backend_type invalid abi: {:?}",
Expand Down Expand Up @@ -901,7 +911,7 @@ fn trans_intrinsic_type<'tcx>(
// ) -> P {
// let adt_def = const_.ty.ty_adt_def().unwrap();
// assert!(adt_def.is_enum());
// let destructured = cx.tcx.destructure_const(ParamEnv::reveal_all().and(const_));
// let destructured = cx.tcx.destructure_const(TypingEnv::fully_monomorphized().and(const_));
// let idx = destructured.variant.unwrap();
// let value = const_.ty.discriminant_for_variant(cx.tcx, idx).unwrap().val as u64;
// <_>::from_u64(value).unwrap()
Expand Down Expand Up @@ -974,24 +984,17 @@ fn trans_intrinsic_type<'tcx>(
cx: &CodegenCx<'tcx>,
const_: Const<'tcx>,
) -> Result<P, ErrorGuaranteed> {
const_
.eval(cx.tcx, ParamEnv::reveal_all(), DUMMY_SP)
.map_err(|e| match e {
ErrorHandled::Reported(reported_error_info, _) => {
Some(reported_error_info.into())
}
ErrorHandled::TooGeneric(_) => None,
})
.and_then(|(const_ty, const_val)| {
assert!(const_ty.is_integral());
P::from_scalar_int(const_val.try_to_scalar_int().ok_or(None)?).ok_or(None)
})
.map_err(|already_reported| {
already_reported.unwrap_or_else(|| {
cx.tcx
.dcx()
.err(format!("invalid value for Image const generic: {const_}"))
})
let (const_val, const_ty) = const_
.try_to_valtree()
.expect("expected monomorphic const in codegen");
assert!(const_ty.is_integral());
const_val
.try_to_scalar_int()
.and_then(P::from_scalar_int)
.ok_or_else(|| {
cx.tcx
.dcx()
.err(format!("invalid value for Image const generic: {const_}"))
})
}

Expand Down
18 changes: 4 additions & 14 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Ty};
use rustc_span::Span;
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
use rustc_target::abi::{Align, BackendRepr, Scalar, Size, WrappingRange};
use smallvec::SmallVec;
use std::borrow::Cow;
use std::cell::Cell;
Expand Down Expand Up @@ -1523,7 +1523,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
place.val.align,
);
OperandValue::Immediate(self.to_immediate(llval, place.layout))
} else if let Abi::ScalarPair(a, b) = place.layout.abi {
} else if let BackendRepr::ScalarPair(a, b) = place.layout.backend_repr {
let b_offset = a
.primitive()
.size(self)
Expand Down Expand Up @@ -2668,16 +2668,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
// ignore
}

fn instrprof_increment(
&mut self,
_fn_name: Self::Value,
_hash: Self::Value,
_num_counters: Self::Value,
_index: Self::Value,
) {
todo!()
}

fn call(
&mut self,
callee_ty: Self::Type,
Expand Down Expand Up @@ -3176,8 +3166,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {

let layout = self.layout_of(ty);

let scalar = match layout.abi {
Abi::Scalar(scalar) => Some(scalar.primitive()),
let scalar = match layout.backend_repr {
BackendRepr::Scalar(scalar) => Some(scalar.primitive()),
_ => None,
};
let debug_printf_fmt = match (spec, scalar) {
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallBuilderMethods};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{FnDef, Instance, ParamEnv, Ty, TyKind};
use rustc_middle::ty::{FnDef, Instance, Ty, TyKind, TypingEnv};
use rustc_middle::{bug, ty};
use rustc_span::Span;
use rustc_span::sym;
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
llresult: Self::Value,
_span: Span,
) -> Result<(), ty::Instance<'tcx>> {
let callee_ty = instance.ty(self.tcx, ParamEnv::reveal_all());
let callee_ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized());

let (def_id, fn_args) = match *callee_ty.kind() {
FnDef(def_id, fn_args) => (def_id, fn_args),
Expand All @@ -85,7 +85,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
let sig = callee_ty.fn_sig(self.tcx);
let sig = self
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), sig);
.normalize_erasing_late_bound_regions(TypingEnv::fully_monomorphized(), sig);
let arg_tys = sig.inputs();
let name = self.tcx.item_name(def_id);

Expand Down
16 changes: 10 additions & 6 deletions crates/rustc_codegen_spirv/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use rustc_errors::{Diag, DiagMessage};
use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::{Instance, Ty, TyCtxt, TypingEnv};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
Expand Down Expand Up @@ -175,6 +175,10 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {
todo!()
}

fn get_dbg_loc(&self) -> Option<Self::DILocation> {
None
}

fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
todo!()
}
Expand Down Expand Up @@ -264,9 +268,9 @@ impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> {
type DILocation = <CodegenCx<'tcx> as BackendTypes>::DILocation;
}

impl<'a, 'tcx> HasParamEnv<'tcx> for Builder<'a, 'tcx> {
fn param_env(&self) -> ParamEnv<'tcx> {
self.cx.param_env()
impl<'a, 'tcx> HasTypingEnv<'tcx> for Builder<'a, 'tcx> {
fn typing_env(&self) -> TypingEnv<'tcx> {
self.cx.typing_env()
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
use rustc_middle::ty::{self, Instance, ParamEnv, TypeVisitableExt};
use rustc_middle::ty::{self, Instance, TypeVisitableExt, TypingEnv};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::abi::Align;
Expand Down Expand Up @@ -257,7 +257,7 @@ impl<'tcx> CodegenCx<'tcx> {
"get_static() should always hit the cache for statics defined in the same CGU, but did not for `{def_id:?}`"
);

let ty = instance.ty(self.tcx, ParamEnv::reveal_all());
let ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized());
let sym = self.tcx.symbol_name(instance).name;
let span = self.tcx.def_span(def_id);
let g = self.declare_global(span, self.layout_of(ty).spirv_type(span, self));
Expand Down Expand Up @@ -289,7 +289,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'tcx> {
symbol_name: &str,
) {
let instance = Instance::mono(self.tcx, def_id);
let ty = instance.ty(self.tcx, ParamEnv::reveal_all());
let ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized());
let span = self.tcx.def_span(def_id);
let spvty = self.layout_of(ty).spirv_type(span, self);
let linkage = match linkage {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<'tcx> CodegenCx<'tcx> {
if is_ref
&& !value_layout
.ty
.is_freeze(self.tcx, ty::ParamEnv::reveal_all()) =>
.is_freeze(self.tcx, ty::TypingEnv::fully_monomorphized()) =>
{
hir::Mutability::Mut
}
Expand Down
Loading

0 comments on commit 4c256b6

Please sign in to comment.