Skip to content

rustup to nightly-2025-04-28 #246

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
606 changes: 346 additions & 260 deletions Cargo.lock

Large diffs are not rendered by default.

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
7 changes: 5 additions & 2 deletions crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ rustix = { version = "0.38.42", features = ["all-apis"] }

# HACK(eddyb) deps of `rustc_codegen_ssa`, for `pqp_cg_ssa` (see `build.rs`),
# that cannot be handled with just `extern crate` pulling out of the sysroot.
object = { version = "0.36.2", default-features = false, features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"] }
thorin-dwp = "0.8"
object = { version = "0.36.2", default-features = false, features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"] }
thorin-dwp = "0.9"

# Normal dependencies.
ar = "0.9.0"
Expand All @@ -64,6 +64,9 @@ tracing-tree = "0.3.0"
[dev-dependencies]
pretty_assertions = "1.0"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)', 'cfg(llvm_enzyme)'] }

# HACK(eddyb) can't re-introduce deps of `rustc_codegen_ssa`, for `pqp_cg_ssa`
# (see `build.rs`).
# tempfile = "3.4"
Expand Down
68 changes: 57 additions & 11 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-11-22"
channel = "nightly-2025-04-28"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = b19329a37cedf2027517ae22c87cf201f93d776e"#;
# commit_hash = cb31a009e3e735ab08613cec2d8a5a754e65596f"#;

fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
Expand Down Expand Up @@ -206,24 +206,70 @@ mod win {",
// HACK(eddyb) very basic extraction of deps from original `Cargo.toml`.
let mut all_extern_crates = cg_ssa_lib_rs_extern_crates;
let cg_ssa_cargo_toml = fs::read_to_string(out_pqp_cg_ssa_dir.join("Cargo.toml"))?;
let mut toml_directive = None;

let mut current_section: Option<&str> = None;

for line in cg_ssa_cargo_toml.lines() {
let line = line.trim();
if line.starts_with('#') || line.is_empty() {
continue;
}
if line.starts_with('[') {
toml_directive = Some(line);
} else if toml_directive == Some("[dependencies]") {
if let Some((name, _)) = line.split_once(" = ") {

if line.starts_with('[') && line.ends_with(']') {
if line == "[dependencies]" {
current_section = Some("[dependencies]");
} else if line.starts_with("[dependencies.") {
// This is a [dependencies.foo] section header.
// Extract 'foo' from '[dependencies.foo]'
if let Some(name_in_header) = line
.strip_prefix("[dependencies.")
.and_then(|s| s.strip_suffix(']'))
{
let name = name_in_header.trim().trim_matches('"');

// HACK(eddyb) ignore a weird edge case.
if name == "thorin-dwp" {
continue;
}
if !name.is_empty() {
let crate_identifier = name.replace('-', "_");
let extern_crate = format!("extern crate {};", crate_identifier);

if !all_extern_crates.contains(&extern_crate) {
writeln(&mut all_extern_crates, "#[allow(unused_extern_crates)]");
writeln(&mut all_extern_crates, &extern_crate);
}
}

// Set section to None so we don't process lines *within* this table
// (like version="...") as dependency names.
current_section = None;
} else {
// Malformed line like "[dependencies.foo", treat as unknown section
current_section = Some(line);
}
} else {
// It's some other section ([build-dependencies], [workspace], etc.)
current_section = Some(line);
}
} else if current_section == Some("[dependencies]") {
// Look for lines like `name = ...`
if let Some((name_in_line, _)) = line.split_once('=') {
let name = name_in_line.trim().trim_matches('"');

// HACK(eddyb) ignore a weird edge case.
if name == "thorin-dwp" {
continue;
}
let extern_crate = format!("extern crate {};", name.replace('-', "_"));
if !all_extern_crates.contains(&extern_crate) {
writeln(&mut all_extern_crates, "#[allow(unused_extern_crates)]");
writeln(&mut all_extern_crates, &extern_crate);

if !name.is_empty() {
let crate_identifier = name.replace('-', "_");
let extern_crate = format!("extern crate {};", crate_identifier);

if !all_extern_crates.contains(&extern_crate) {
writeln(&mut all_extern_crates, "#[allow(unused_extern_crates)]");
writeln(&mut all_extern_crates, &extern_crate);
}
}
}
}
Expand Down
41 changes: 26 additions & 15 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use itertools::Itertools;
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_abi::ExternAbi;
use rustc_abi::{
Align, BackendRepr, FieldsShape, LayoutData, Primitive, ReprFlags, ReprOptions, Scalar, Size,
TagEncoding, VariantIdx, Variants,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_index::Idx;
Expand All @@ -20,12 +25,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 All @@ -46,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 Abi::C { .. } = inner.abi {
inner.abi = Abi::Unadjusted;
if let ExternAbi::C { .. } = inner.abi {
inner.abi = ExternAbi::Unadjusted;
}
inner
})
Expand Down Expand Up @@ -110,6 +110,8 @@ pub(crate) fn provide(providers: &mut Providers) {
size,
max_repr_align,
unadjusted_abi_align,
uninhabited,
randomization_seed,
} = *layout;
LayoutData {
fields: match *fields {
Expand All @@ -125,6 +127,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 Down Expand Up @@ -155,6 +158,8 @@ pub(crate) fn provide(providers: &mut Providers) {
size,
max_repr_align,
unadjusted_abi_align,
uninhabited,
randomization_seed,
}
}

Expand Down Expand Up @@ -198,6 +203,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 +468,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 {
x @ _ if x.is_unsized() => 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 +529,9 @@ 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_index = rustc_abi::FieldIdx::from_usize(i);
let field: &rustc_middle::ty::FieldDef =
&adt.variants()[index].fields[field_index];
field_names.push(field.name);
}
}
Expand All @@ -542,7 +550,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 @@ -653,6 +661,7 @@ fn dig_scalar_pointee<'tcx>(

let all_fields = (match &layout.variants {
Variants::Multiple { variants, .. } => 0..variants.len(),
Variants::Empty => 0..0,
Variants::Single { index } => {
let i = index.as_usize();
i..i + 1
Expand Down Expand Up @@ -811,7 +820,8 @@ 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_index = rustc_abi::FieldIdx::from_usize(i);
let field: &rustc_middle::ty::FieldDef = &adt.variants()[index].fields[field_index];
field_names.push(field.name);
} else {
// FIXME(eddyb) this looks like something that should exist in rustc.
Expand Down Expand Up @@ -868,6 +878,7 @@ impl<'tcx> From<TyAndLayout<'tcx>> for TyLayoutNameKey<'tcx> {
variant: match layout.variants {
Variants::Single { index } => Some(index),
Variants::Multiple { .. } => None,
Variants::Empty => None,
},
}
}
Expand Down Expand Up @@ -984,11 +995,11 @@ 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 const_val = const_.to_value();
let const_ty = const_val.ty;
assert!(const_ty.is_integral());
const_val
.valtree
.try_to_scalar_int()
.and_then(P::from_scalar_int)
.ok_or_else(|| {
Expand Down
25 changes: 12 additions & 13 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::codegen_cx::CodegenCx;
use crate::symbols::Symbols;
use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass};
use rustc_ast::Attribute;

use rustc_hir as hir;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::intravisit::{self, Visitor};
Expand Down Expand Up @@ -148,7 +148,7 @@ impl AggregatedSpirvAttributes {
///
/// Any errors for malformed/duplicate attributes will have been reported
/// prior to codegen, by the `attr` check pass.
pub fn parse<'tcx>(cx: &CodegenCx<'tcx>, attrs: &'tcx [Attribute]) -> Self {
pub fn parse<'tcx>(cx: &CodegenCx<'tcx>, attrs: &'tcx [rustc_hir::Attribute]) -> Self {
let mut aggregated_attrs = Self::default();

// NOTE(eddyb) `span_delayed_bug` ensures that if attribute checking fails
Expand Down Expand Up @@ -254,8 +254,8 @@ fn target_from_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) -> Targ
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Fn(..) => {
let parent_owner_id = tcx.hir().get_parent_item(impl_item.hir_id());
let containing_item = tcx.hir().expect_item(parent_owner_id.def_id);
let parent_owner_id = tcx.hir_get_parent_item(impl_item.hir_id());
let containing_item = tcx.hir_expect_item(parent_owner_id.def_id);
let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => of_trait.is_some(),
_ => unreachable!("parent of an ImplItem must be an Impl"),
Expand All @@ -281,7 +281,7 @@ impl CheckSpirvAttrVisitor<'_> {

let parse_attrs = |attrs| crate::symbols::parse_attrs_for_checking(&self.sym, attrs);

let attrs = self.tcx.hir().attrs(hir_id);
let attrs = self.tcx.hir_attrs(hir_id);
for parse_attr_result in parse_attrs(attrs) {
let (span, parsed_attr) = match parse_attr_result {
Ok(span_and_parsed_attr) => span_and_parsed_attr,
Expand Down Expand Up @@ -327,10 +327,9 @@ impl CheckSpirvAttrVisitor<'_> {
| SpirvAttribute::SpecConstant(_) => match target {
Target::Param => {
let parent_hir_id = self.tcx.parent_hir_id(hir_id);
let parent_is_entry_point =
parse_attrs(self.tcx.hir().attrs(parent_hir_id))
.filter_map(|r| r.ok())
.any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_)));
let parent_is_entry_point = parse_attrs(self.tcx.hir_attrs(parent_hir_id))
.filter_map(|r| r.ok())
.any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_)));
if !parent_is_entry_point {
self.tcx.dcx().span_err(
span,
Expand Down Expand Up @@ -418,8 +417,8 @@ impl CheckSpirvAttrVisitor<'_> {
impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
type NestedFilter = nested_filter::OnlyBodies;

fn nested_visit_map(&mut self) -> Self::Map {
self.tcx.hir()
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx
}

fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
Expand Down Expand Up @@ -498,8 +497,8 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
tcx,
sym: Symbols::get(),
};
tcx.hir()
.visit_item_likes_in_module(module_def_id, check_spirv_attr_visitor);
tcx.hir_visit_item_likes_in_module(module_def_id, check_spirv_attr_visitor);

if module_def_id.is_top_level_module() {
check_spirv_attr_visitor.check_spirv_attributes(CRATE_HIR_ID, Target::Mod);
}
Expand Down
Loading
Loading