Skip to content

Commit

Permalink
rustup: update to nightly-2024-10-12 (~1.83).
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 9, 2024
1 parent 8bd9bf4 commit 8eb874a
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 70 deletions.
7 changes: 5 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-09-01"
channel = "nightly-2024-10-12"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = a7399ba69d37b019677a9c47fe89ceb8dd82db2d"#;
# commit_hash = 1bc403daadbebb553ccc211a0a8eebb73989665f"#;

fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
Expand Down Expand Up @@ -194,6 +194,9 @@ mod win {",
);
} else if relative_path == Path::new("src/mir/operand.rs") {
src = src.replace("alloca(field.size,", "typed_alloca(llfield_ty,");

// HACK(eddyb) non-array `#[repr(simd)]` workaround (see `src/abi.rs`).
src = src.replace("if constant_ty.is_simd() {", "if false {");
}

fs::write(out_path, src)?;
Expand Down
91 changes: 89 additions & 2 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use itertools::Itertools;
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
Expand All @@ -22,7 +23,8 @@ 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, Scalar, Size, TagEncoding, VariantIdx, Variants,
Abi, Align, FieldsShape, LayoutS, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding,
VariantIdx, Variants,
};
use rustc_target::spec::abi::Abi as SpecAbi;
use std::cell::RefCell;
Expand Down Expand Up @@ -157,6 +159,7 @@ pub(crate) fn provide(providers: &mut Providers) {
unadjusted_abi_align,
}
}

providers.layout_of = |tcx, key| {
let TyAndLayout { ty, mut layout } =
(rustc_interface::DEFAULT_QUERY_PROVIDERS.layout_of)(tcx, key)?;
Expand All @@ -176,6 +179,90 @@ pub(crate) fn provide(providers: &mut Providers) {

Ok(TyAndLayout { ty, layout })
};

// HACK(eddyb) work around https://github.com/rust-lang/rust/pull/129403
// banning "struct-style" `#[repr(simd)]` (in favor of "array-newtype-style"),
// by simply bypassing "type definition WF checks" for affected types, which:
// - can only really be sound for types with trivial field types, that are
// either completely non-generic (covering most `#[repr(simd)]` `struct`s),
// or *at most* one generic type parameter with no bounds/where clause
// - relies on upstream `layout_of` not having had the non-array logic removed
//
// FIXME(eddyb) remove this once migrating beyond `#[repr(simd)]` becomes
// 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).
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 {
rustc_hir::ItemKind::Struct(
_,
&rustc_hir::Generics {
params:
&[]
| &[
rustc_hir::GenericParam {
kind:
rustc_hir::GenericParamKind::Type {
default: None,
synthetic: false,
},
..
},
],
predicates: &[],
has_where_clause_predicates: false,
where_clause_span: _,
span: _,
},
) => Some(tcx.adt_def(def_id)),
_ => None,
},
_ => None,
};
let valid_non_array_simd_struct = trivial_struct.is_some_and(|adt_def| {
let ReprOptions {
int: None,
align: None,
pack: None,
flags: ReprFlags::IS_SIMD,
field_shuffle_seed: _,
} = adt_def.repr()
else {
return false;
};
if adt_def.destructor(tcx).is_some() {
return false;
}

let field_types = adt_def
.non_enum_variant()
.fields
.iter()
.map(|f| tcx.type_of(f.did).instantiate_identity());
field_types.dedup().exactly_one().is_ok_and(|elem_ty| {
matches!(
elem_ty.kind(),
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Param(_)
)
})
});

if valid_non_array_simd_struct {
tcx.dcx()
.struct_span_warn(
tcx.def_span(def_id),
"[Rust-GPU] temporarily re-allowing old-style `#[repr(simd)]` (with fields)",
)
.with_note("removed upstream by https://github.com/rust-lang/rust/pull/129403")
.with_note("in favor of the new `#[repr(simd)] struct TxN([T; N]);` style")
.with_note("(taking effect since `nightly-2024-09-12` / `1.83.0` stable)")
.emit();
return Ok(());
}

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

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

/// Only pub for `LayoutTypeMethods::scalar_pair_element_backend_type`. Think about what you're
/// Only pub for `LayoutTypeCodegenMethods::scalar_pair_element_backend_type`. Think about what you're
/// doing before calling this.
pub fn scalar_pair_element_backend_type<'tcx>(
cx: &CodegenCx<'tcx>,
Expand Down
7 changes: 5 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
use super::Builder;
use crate::abi::ConvSpirvType;
use crate::builder_spirv::{BuilderCursor, SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
use crate::codegen_cx::CodegenCx;
use crate::custom_insts::{CustomInst, CustomOp};
use crate::spirv_type::SpirvType;
use itertools::Itertools;
Expand All @@ -16,9 +17,9 @@ use rustc_codegen_ssa::common::{
};
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::BaseTypeMethods;
use rustc_codegen_ssa::traits::{
BackendTypes, BuilderMethods, ConstMethods, LayoutTypeMethods, OverflowOp,
BackendTypes, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
LayoutTypeCodegenMethods, OverflowOp,
};
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::bug;
Expand Down Expand Up @@ -958,6 +959,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
type CodegenCx = CodegenCx<'tcx>;

fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self {
let cursor = cx.builder.select_block_by_id(llbb);
// FIXME(eddyb) change `Self::Function` to be more like a function index.
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rspirv::dr::Operand;
use rspirv::spirv::GLOp;
use rustc_codegen_ssa::mir::operand::OperandRef;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallMethods};
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::{bug, ty};
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Builder<'_, '_> {
}
}

impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
fn codegen_intrinsic_call(
&mut self,
instance: Instance<'tcx>,
Expand Down Expand Up @@ -360,15 +360,15 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
cond
}

fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Value) -> Self::Value {
fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Metadata) -> Self::Value {
todo!()
}

fn type_checked_load(
&mut self,
_llvtable: Self::Value,
_vtable_byte_offset: u64,
_typeid: Self::Value,
_typeid: Self::Metadata,
) -> Self::Value {
todo!()
}
Expand Down
19 changes: 11 additions & 8 deletions crates/rustc_codegen_spirv/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use rspirv::spirv::Word;
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{
AbiBuilderMethods, ArgAbiMethods, BackendTypes, BuilderMethods, CoverageInfoBuilderMethods,
DebugInfoBuilderMethods, HasCodegen, StaticBuilderMethods, TypeMembershipMethods,
AbiBuilderMethods, ArgAbiBuilderMethods, BackendTypes, BuilderMethods,
CoverageInfoBuilderMethods, DebugInfoBuilderMethods, StaticBuilderMethods,
TypeMembershipCodegenMethods,
};
use rustc_errors::{Diag, DiagMessage};
use rustc_middle::mir::coverage::CoverageKind;
Expand Down Expand Up @@ -170,6 +171,10 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {
todo!()
}

fn clear_dbg_loc(&mut self) {
todo!()
}

fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
todo!()
}
Expand All @@ -179,7 +184,7 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {
}
}

impl<'a, 'tcx> ArgAbiMethods<'tcx> for Builder<'a, 'tcx> {
impl<'a, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'a, 'tcx> {
fn store_fn_arg(
&mut self,
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
Expand Down Expand Up @@ -247,7 +252,9 @@ impl<'a, 'tcx> StaticBuilderMethods for Builder<'a, 'tcx> {

impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> {
type Value = <CodegenCx<'tcx> as BackendTypes>::Value;
type Metadata = <CodegenCx<'tcx> as BackendTypes>::Metadata;
type Function = <CodegenCx<'tcx> as BackendTypes>::Function;

type BasicBlock = <CodegenCx<'tcx> as BackendTypes>::BasicBlock;
type Type = <CodegenCx<'tcx> as BackendTypes>::Type;
type Funclet = <CodegenCx<'tcx> as BackendTypes>::Funclet;
Expand All @@ -257,10 +264,6 @@ impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> {
type DILocation = <CodegenCx<'tcx> as BackendTypes>::DILocation;
}

impl<'a, 'tcx> HasCodegen<'tcx> for Builder<'a, 'tcx> {
type CodegenCx = CodegenCx<'tcx>;
}

impl<'a, 'tcx> HasParamEnv<'tcx> for Builder<'a, 'tcx> {
fn param_env(&self) -> ParamEnv<'tcx> {
self.cx.param_env()
Expand Down Expand Up @@ -308,4 +311,4 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, 'tcx> {
}
}

impl<'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'tcx> {}
impl<'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'tcx> {}
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rspirv::spirv::{
};
use rspirv::{binary::Assemble, binary::Disassemble};
use rustc_arena::DroplessArena;
use rustc_codegen_ssa::traits::ConstMethods as _;
use rustc_codegen_ssa::traits::ConstCodegenMethods as _;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_middle::bug;
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::abi::ConvSpirvType;
use crate::builder_spirv::{SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
use crate::spirv_type::SpirvType;
use rspirv::spirv::Word;
use rustc_codegen_ssa::traits::{ConstMethods, MiscMethods, StaticMethods};
use rustc_codegen_ssa::traits::{ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods};
use rustc_middle::bug;
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar, alloc_range};
use rustc_middle::ty::layout::LayoutOf;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
}

impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
impl<'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'tcx> {
fn const_null(&self, t: Self::Type) -> Self::Value {
self.constant_null(t)
}
Expand Down Expand Up @@ -253,10 +253,10 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
self.get_fn_addr(instance.polymorphize(self.tcx)),
self.data_layout().instruction_address_space,
),
GlobalAlloc::VTable(vty, trait_ref) => {
GlobalAlloc::VTable(vty, dyn_ty) => {
let alloc = self
.tcx
.global_alloc(self.tcx.vtable_allocation((vty, trait_ref)))
.global_alloc(self.tcx.vtable_allocation((vty, dyn_ty.principal())))
.unwrap_memory();
let pointee = match self.lookup_type(ty) {
SpirvType::Pointer { pointee } => pointee,
Expand Down
12 changes: 6 additions & 6 deletions crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::spirv_type::SpirvType;
use itertools::Itertools;
use rspirv::spirv::{FunctionControl, LinkageType, StorageClass, Word};
use rustc_attr::InlineAttr;
use rustc_codegen_ssa::traits::{PreDefineMethods, StaticMethods};
use rustc_codegen_ssa::traits::{PreDefineCodegenMethods, StaticCodegenMethods};
use rustc_hir::def::DefKind;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
Expand Down Expand Up @@ -58,9 +58,9 @@ impl<'tcx> CodegenCx<'tcx> {
}

// The call graph of how this is reachable is a little tangled, so:
// MiscMethods::get_fn -> get_fn_ext -> declare_fn_ext
// MiscMethods::get_fn_addr -> get_fn_ext -> declare_fn_ext
// PreDefineMethods::predefine_fn -> declare_fn_ext
// MiscCodegenMethods::get_fn -> get_fn_ext -> declare_fn_ext
// MiscCodegenMethods::get_fn_addr -> get_fn_ext -> declare_fn_ext
// PreDefineCodegenMethods::predefine_fn -> declare_fn_ext
fn declare_fn_ext(&self, instance: Instance<'tcx>, linkage: Option<LinkageType>) -> SpirvValue {
let def_id = instance.def_id();

Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
}

impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> {
impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'tcx> {
fn predefine_static(
&self,
def_id: DefId,
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> {
}
}

impl<'tcx> StaticMethods for CodegenCx<'tcx> {
impl<'tcx> StaticCodegenMethods for CodegenCx<'tcx> {
fn static_addr_of(&self, cv: Self::Value, _align: Align, _kind: Option<&str>) -> Self::Value {
self.def_constant(self.type_ptr_to(cv.ty), SpirvConst::PtrTo {
pointee: cv.def_cx(self),
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 @@ -11,7 +11,7 @@ use rspirv::dr::Operand;
use rspirv::spirv::{
Capability, Decoration, Dim, ExecutionModel, FunctionControl, StorageClass, Word,
};
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::MultiSpan;
use rustc_hir as hir;
Expand Down
Loading

0 comments on commit 8eb874a

Please sign in to comment.