Skip to content

rustup: update to nightly-2025-05-09 (~1.88) and Rust 2024 edition. #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9282a64
intrinsics: use `GLOp::RoundEven` for `round_ties_even`.
eddyb May 7, 2025
b737a46
rustup: update to `nightly-2024-12-01`.
eddyb May 6, 2025
8dff45e
Update target specs (remove os=unknown, add crt-static-respected).
eddyb May 2, 2025
9f5dcf9
Fix new `clippy::unnecessary_map_or` warnings.
eddyb May 10, 2025
8e21493
rustup: update to `nightly-2024-12-10`.
eddyb May 6, 2025
fcfa371
rustup: update to `nightly-2024-12-15`.
eddyb May 6, 2025
680e6be
rustup: update to `nightly-2024-12-16`.
eddyb May 6, 2025
020fde2
builder: always `pointercast` first before attempting to merge `OpAcc…
eddyb May 7, 2025
e0f3be2
rustup: update to `nightly-2024-12-17`.
eddyb May 6, 2025
5ed558e
rustup: update to `nightly-2024-12-20`.
eddyb May 6, 2025
179571f
rustup: update to `nightly-2024-12-25`.
eddyb May 6, 2025
e4a9099
rustup: update to `nightly-2025-01-03` (~1.85).
eddyb May 4, 2025
bf7c2e6
Fix new `clippy::precedence` warnings.
eddyb May 10, 2025
ff54cd7
rustfmt using `nightly-2025-02-16`.
eddyb May 7, 2025
1e6d631
rustup: update to `nightly-2025-02-16` (~1.86).
eddyb May 7, 2025
7a0f1a2
Fix new clippy warnings.
eddyb May 10, 2025
f9c818d
rustc_codegen_spirv: switch to Rust 2024 edition.
eddyb May 7, 2025
3930056
rustup: update to `nightly-2025-03-29` (~1.87).
eddyb May 7, 2025
8ab84c7
abi: more workarounds for old-style `#[repr(simd)] struct`s.
eddyb May 7, 2025
e88f042
Fix new clippy warnings.
eddyb May 12, 2025
0517dff
rustup: update to `nightly-2025-04-13`.
eddyb May 12, 2025
4fcac6a
rustup: update to `nightly-2025-04-14`.
eddyb May 12, 2025
ed6e575
abi: unhide `bool`'s niche, breaking `Option<bool>` for Rust-GPU but …
eddyb May 12, 2025
3104930
Switch all crates to Rust 2024 edition.
LegNeato Apr 30, 2025
2961102
rustup: update to `nightly-2025-04-27`.
eddyb May 12, 2025
c78aae9
Fix new `clippy::uninlined_format_args` warnings.
eddyb May 12, 2025
4bd5f2d
rustup to `nightly-2025-04-28`
LegNeato Apr 30, 2025
45c42ca
rustup: update to `nightly-2025-05-09` (~1.88).
eddyb May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustflags = [
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ members = [
[workspace.package]
version = "0.9.0"
authors = ["rust-gpu developers", "Embark <[email protected]>"]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-gpu/rust-gpu"

Expand Down
57 changes: 52 additions & 5 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,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-11-22"
channel = "nightly-2025-05-09"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = b19329a37cedf2027517ae22c87cf201f93d776e"#;
# commit_hash = 50aa04180709189a03dde5fd1c05751b2625ed37"#;

fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
Expand Down Expand Up @@ -159,9 +159,9 @@ fn generate_pqp_cg_ssa() -> Result<(), Box<dyn Error>> {
}
}

// HACK(eddyb) remove `windows` dependency (from MSVC linker output
// parsing, which `rustc_codegen_spirv` will never invoke anyway).
if relative_path == Path::new("src/back/link.rs") {
// HACK(eddyb) remove `windows` dependency (from MSVC linker output
// parsing, which `rustc_codegen_spirv` will never invoke anyway).
src = src.replace(
"#[cfg(not(windows))]
fn escape_linker_output(",
Expand All @@ -179,6 +179,36 @@ mod win {",
"#[cfg(any())]
mod win {",
);
// HACK(eddyb) remove `object` dependency (for Windows `raw_dylib`
// handling, which `rustc_codegen_spirv` will never invoke anyway).
src = src.replace("mod raw_dylib;", "// mod raw_dylib;");
src = src.replace(
"
for output_path in raw_dylib::",
"
#[cfg(any())]
for output_path in raw_dylib::",
);
src = src.replace(
"
for link_path in raw_dylib::",
"
#[cfg(any())]
for link_path in raw_dylib::",
);
}
if relative_path == Path::new("src/back/metadata.rs") {
// HACK(eddyb) remove `object` dependency.
src = src.replace(
"
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {",
"
pub(crate) fn create_object_file(_: &Session) -> Option<write::Object<'static>> {
None
}
#[cfg(any())]
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {",
);
}

// HACK(eddyb) "typed alloca" patches.
Expand All @@ -198,8 +228,16 @@ 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`).
// HACK(eddyb) non-array `#[repr(simd)]` workarounds (see `src/abi.rs`).
src = src.replace("if constant_ty.is_simd() {", "if false {");
src = src.replace(
"match (self.val, self.layout.backend_repr) {",
"match (self.val, self.layout.backend_repr) {
// `#[repr(simd)]` types are also immediate.
(OperandValue::Immediate(llval), BackendRepr::SimdVector { element, .. }) => {
(Some(element), bx.extract_element(llval, bx.cx().const_usize(i as u64)))
}",
);
}

fs::write(out_path, src)?;
Expand Down Expand Up @@ -259,6 +297,9 @@ mod win {",
println!("cargo::warning={line}");
}
println!("cargo::warning=");

// HACK(eddyb) allow the warning to be cleared after `lib.rs` is fixed.
println!("cargo:rerun-if-changed=src/lib.rs");
}

// HACK(eddyb) write a file that can be `include!`d from `lib.rs`.
Expand All @@ -276,6 +317,12 @@ mod maybe_pqp_cg_ssa;

println!("cargo::rustc-check-cfg=cfg(rustc_codegen_spirv_disable_pqp_cg_ssa)");

// HACK(eddyb) `if cfg!(llvm_enzyme)` added upstream for autodiff support.
println!("cargo::rustc-check-cfg=cfg(llvm_enzyme)");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, I didn't know you could put those here.


// HACK(eddyb) `cfg_attr(bootstrap, ...` used upstream temporarily.
println!("cargo::rustc-check-cfg=cfg(bootstrap)");

Ok(())
}

Expand Down
126 changes: 110 additions & 16 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use itertools::Itertools;
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_abi::ExternAbi as Abi;
use rustc_abi::{
Align, BackendRepr, FieldIdx, FieldsShape, HasDataLayout as _, LayoutData, Primitive,
ReprFlags, ReprOptions, Scalar, Size, TagEncoding, VariantIdx, Variants,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_hashes::Hash64;
use rustc_index::Idx;
use rustc_middle::query::Providers;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
Expand All @@ -20,12 +26,7 @@ use rustc_middle::{bug, span_bug};
use rustc_span::DUMMY_SP;
use rustc_span::def_id::DefId;
use rustc_span::{Span, Symbol};
use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use rustc_target::abi::{
Align, BackendRepr, FieldsShape, LayoutData, Primitive, ReprFlags, ReprOptions, Scalar, Size,
TagEncoding, VariantIdx, Variants,
};
use rustc_target::spec::abi::Abi;
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::fmt;
Expand Down Expand Up @@ -106,10 +107,12 @@ pub(crate) fn provide(providers: &mut Providers) {
ref variants,
backend_repr,
largest_niche,
uninhabited,
align,
size,
max_repr_align,
unadjusted_abi_align,
randomization_seed,
} = *layout;
LayoutData {
fields: match *fields {
Expand All @@ -125,6 +128,7 @@ pub(crate) fn provide(providers: &mut Providers) {
},
},
variants: match *variants {
Variants::Empty => Variants::Empty,
Variants::Single { index } => Variants::Single { index },
Variants::Multiple {
tag,
Expand All @@ -151,20 +155,108 @@ pub(crate) fn provide(providers: &mut Providers) {
},
backend_repr,
largest_niche,
uninhabited,
align,
size,
max_repr_align,
unadjusted_abi_align,
randomization_seed,
}
}

providers.layout_of = |tcx, key| {
// HACK(eddyb) to special-case any types at all, they must be normalized,
// but when normalization would be needed, `layout_of`'s default provider
// recurses (supposedly for caching reasons), i.e. its calls `layout_of`
// w/ the normalized type in input, which once again reaches this hook,
// without ever needing any explicit normalization here.
let ty = key.value;

// HACK(eddyb) bypassing upstream `#[repr(simd)]` changes (see also
// the later comment above `check_well_formed`, for more details).
let reimplement_old_style_repr_simd = match ty.kind() {
ty::Adt(def, args) if def.repr().simd() && !def.repr().packed() && def.is_struct() => {
Some(def.non_enum_variant()).and_then(|v| {
let (count, e_ty) = v
.fields
.iter()
.map(|f| f.ty(tcx, args))
.dedup_with_count()
.exactly_one()
.ok()?;
let e_len = u64::try_from(count).ok().filter(|&e_len| e_len > 1)?;
Some((def, e_ty, e_len))
})
}
_ => None,
};

// HACK(eddyb) tweaked copy of the old upstream logic for `#[repr(simd)]`:
// https://github.com/rust-lang/rust/blob/1.86.0/compiler/rustc_ty_utils/src/layout.rs#L464-L590
if let Some((adt_def, e_ty, e_len)) = reimplement_old_style_repr_simd {
let cx = rustc_middle::ty::layout::LayoutCx::new(
tcx,
key.typing_env.with_post_analysis_normalized(tcx),
);
let dl = cx.data_layout();

// Compute the ABI of the element type:
let e_ly = cx.layout_of(e_ty)?;
let BackendRepr::Scalar(e_repr) = e_ly.backend_repr else {
// This error isn't caught in typeck, e.g., if
// the element type of the vector is generic.
tcx.dcx().span_fatal(
tcx.def_span(adt_def.did()),
format!(
"SIMD type `{ty}` with a non-primitive-scalar \
(integer/float/pointer) element type `{}`",
e_ly.ty
),
);
};

// Compute the size and alignment of the vector:
let size = e_ly.size.checked_mul(e_len, dl).unwrap();
let align = dl.llvmlike_vector_align(size);
let size = size.align_to(align.abi);

let layout = tcx.mk_layout(LayoutData {
variants: Variants::Single {
index: rustc_abi::FIRST_VARIANT,
},
fields: FieldsShape::Array {
stride: e_ly.size,
count: e_len,
},
backend_repr: BackendRepr::SimdVector {
element: e_repr,
count: e_len,
},
largest_niche: e_ly.largest_niche,
uninhabited: false,
size,
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: e_ly.randomization_seed.wrapping_add(Hash64::new(e_len)),
});

return Ok(TyAndLayout { ty, layout });
}

let TyAndLayout { ty, mut layout } =
(rustc_interface::DEFAULT_QUERY_PROVIDERS.layout_of)(tcx, key)?;

#[allow(clippy::match_like_matches_macro)]
let hide_niche = match ty.kind() {
ty::Bool => true,
ty::Bool => {
// HACK(eddyb) we can't bypass e.g. `Option<bool>` being a byte,
// due to `core` PR https://github.com/rust-lang/rust/pull/138881
// (which adds a new `transmute`, from `ControlFlow<bool>` to `u8`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fix / backout stuff upstream?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's our absurd problem that we want bool to have a layout Option<bool> can't have (cue "qptr will fix this").

let libcore_needs_bool_niche = true;

!libcore_needs_bool_niche
}
_ => false,
};

Expand Down Expand Up @@ -198,7 +290,7 @@ pub(crate) fn provide(providers: &mut Providers) {
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:
&[]
Expand Down Expand Up @@ -462,7 +554,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
// `ScalarPair`.
// 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 {
_ if self.uninhabited => SpirvType::Adt {
def_id: def_id_for_spirv_type_adt(*self),
size: Some(Size::ZERO),
align: Align::from_bytes(0).unwrap(),
Expand Down Expand Up @@ -523,7 +615,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
if let TyKind::Adt(adt, _) = self.ty.kind() {
if let Variants::Single { index } = self.variants {
for i in self.fields.index_by_increasing_offset() {
let field = &adt.variants()[index].fields[i.into()];
let field = &adt.variants()[index].fields[FieldIdx::new(i)];
field_names.push(field.name);
}
}
Expand All @@ -542,7 +634,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
}
.def_with_name(cx, span, TyLayoutNameKey::from(*self))
}
BackendRepr::Vector { element, count } => {
BackendRepr::SimdVector { element, count } => {
let elem_spirv = trans_scalar(cx, span, *self, element, Size::ZERO);
SpirvType::Vector {
element: elem_spirv,
Expand Down Expand Up @@ -652,6 +744,7 @@ fn dig_scalar_pointee<'tcx>(
}

let all_fields = (match &layout.variants {
Variants::Empty => 0..0,
Variants::Multiple { variants, .. } => 0..variants.len(),
Variants::Single { index } => {
let i = index.as_usize();
Expand Down Expand Up @@ -811,7 +904,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -
field_offsets.push(offset);
if let Variants::Single { index } = ty.variants {
if let TyKind::Adt(adt, _) = ty.ty.kind() {
let field = &adt.variants()[index].fields[i.into()];
let field = &adt.variants()[index].fields[FieldIdx::new(i)];
field_names.push(field.name);
} else {
// FIXME(eddyb) this looks like something that should exist in rustc.
Expand Down Expand Up @@ -867,7 +960,7 @@ impl<'tcx> From<TyAndLayout<'tcx>> for TyLayoutNameKey<'tcx> {
ty: layout.ty,
variant: match layout.variants {
Variants::Single { index } => Some(index),
Variants::Multiple { .. } => None,
_ => None,
},
}
}
Expand Down Expand Up @@ -984,9 +1077,10 @@ fn trans_intrinsic_type<'tcx>(
cx: &CodegenCx<'tcx>,
const_: Const<'tcx>,
) -> Result<P, ErrorGuaranteed> {
let (const_val, const_ty) = const_
.try_to_valtree()
.expect("expected monomorphic const in codegen");
let ty::Value {
ty: const_ty,
valtree: const_val,
} = const_.to_value();
assert!(const_ty.is_integral());
const_val
.try_to_scalar_int()
Expand Down
Loading