Skip to content
Open
9 changes: 6 additions & 3 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,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-2026-07-03"
channel = "nightly-2026-08-15"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = c397dae808f70caebab1fc4e11b3edf7e59f58c7"#;
# commit_hash = d453bdd8f092d099bc336f0bda4163f809ad18e0"#;

fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
Expand Down Expand Up @@ -153,7 +153,10 @@ fn generate_pqp_cg_ssa() -> Result<(), Box<dyn Error>> {
for line in mem::take(&mut src).lines() {
if line.starts_with("#!") {
src += "// ";
if !line.starts_with("#![doc(") && line != "#![warn(unreachable_pub)]" {
if !line.starts_with("#![doc(")
&& line != "#![warn(unreachable_pub)]"
&& !line.starts_with("#![cfg_attr(bootstrap,")
{
writeln(&mut cg_ssa_lib_rc_attrs, line);
}
} else if line == "#[macro_use]" || line.starts_with("extern crate ") {
Expand Down
19 changes: 14 additions & 5 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,19 @@ pub(crate) fn provide(providers: &mut Providers) {
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
) -> &'tcx FnAbi<'tcx, Ty<'tcx>> {
let readjust_arg_abi = |arg: &ArgAbi<'tcx, Ty<'tcx>>| {
let mut arg = ArgAbi::new(&tcx, arg.layout, |_, _| ArgAttributes::new());
let mut arg = ArgAbi::new(arg.layout, |_, _| ArgAttributes::new());
// FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
// <https://github.com/rust-lang/rust/commit/eaaa03faf77b157907894a4207d8378ecaec7b45>
arg.make_direct_deprecated();
// replaces removed `arg.make_direct_deprecated();`
arg.mode = if let PassMode::Indirect { .. } = arg.mode {
PassMode::Direct(ArgAttributes::new())
} else if arg.layout.is_zst() {
PassMode::Ignore
} else if let PassMode::Ignore | PassMode::Direct(..) | PassMode::Pair(..) = arg.mode {
arg.mode
} else {
panic!("Tried to make {:?} direct", arg.mode)
};

// Avoid pointlessly passing ZSTs, just like the official Rust ABI.
if arg.layout.is_zst() {
Expand Down Expand Up @@ -382,7 +391,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
}
.def_with_name(cx, span, TyLayoutNameKey::from(*self)),
BackendRepr::Scalar(scalar) => trans_scalar(cx, span, *self, scalar, Size::ZERO),
BackendRepr::ScalarPair(a, b) => {
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),
Expand Down Expand Up @@ -444,7 +453,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
let elem_spirv = trans_scalar(cx, span, *self, element, Size::ZERO);
SpirvType::Vector {
element: elem_spirv,
count: count as u32,
count: count.as_u32(),
size: self.size,
align: self.align.abi,
}
Expand Down Expand Up @@ -485,7 +494,7 @@ pub fn scalar_pair_element_backend_type<'tcx>(
index: usize,
) -> Word {
let [a, b] = match ty.backend_repr {
BackendRepr::ScalarPair(a, b) => [a, b],
BackendRepr::ScalarPair { a, b, .. } => [a, b],
other => span_bug!(
span,
"scalar_pair_element_backend_type invalid abi: {:?}",
Expand Down
12 changes: 6 additions & 6 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::symbols::Symbols;
use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass};
use rustc_ast::{LitKind, MetaItemInner, MetaItemLit};
use rustc_hir as hir;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::def_id::LocalModId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Attribute, CRATE_HIR_ID, HirId, MethodKind, Target};
use rustc_middle::hir::nested_filter;
Expand Down Expand Up @@ -433,19 +433,19 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
}

fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let target = Target::from_item(item);
let target = Target::from(item);
self.check_spirv_attributes(item.hir_id(), target);
intravisit::walk_item(self, item);
}

fn visit_generic_param(&mut self, generic_param: &'tcx hir::GenericParam<'tcx>) {
let target = Target::from_generic_param(generic_param);
let target = Target::from(generic_param);
self.check_spirv_attributes(generic_param.hir_id, target);
intravisit::walk_generic_param(self, generic_param);
}

fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
let target = Target::from_trait_item(trait_item);
let target = Target::from(trait_item);
self.check_spirv_attributes(trait_item.hir_id(), target);
intravisit::walk_trait_item(self, trait_item);
}
Expand All @@ -461,7 +461,7 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
}

fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) {
let target = Target::from_foreign_item(f_item);
let target = Target::from(f_item);
self.check_spirv_attributes(f_item.hir_id(), target);
intravisit::walk_foreign_item(self, f_item);
}
Expand Down Expand Up @@ -503,7 +503,7 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
}

// FIXME(eddyb) DRY this somehow and make it reusable from somewhere in `rustc`.
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModId) {
let check_spirv_attr_visitor = &mut CheckSpirvAttrVisitor {
tcx,
sym: Symbols::get(),
Expand Down
7 changes: 4 additions & 3 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn memset_fill_u64(b: u8) -> u64 {

fn memset_fill_u128(b: u8) -> u128 {
let b64 = memset_fill_u64(b) as u128;
b64 | b64 >> 64
b64 | b64 << 64
}

fn memset_dynamic_scalar(
Expand Down Expand Up @@ -484,6 +484,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16 => memset_dynamic_scalar(self, fill_var, 2, false),
32 => memset_dynamic_scalar(self, fill_var, 4, false),
64 => memset_dynamic_scalar(self, fill_var, 8, false),
128 => memset_dynamic_scalar(self, fill_var, 16, false),
_ => self.fatal(format!(
"memset on integer width {width} not implemented yet"
)),
Expand Down Expand Up @@ -1917,14 +1918,14 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {

let val = if place.val.llextra.is_some() {
OperandValue::Ref(place.val)
} else if self.cx.is_backend_immediate(place.layout) {
} else if place.layout.backend_repr.is_scalar_or_simd() {
let llval = self.load(
place.layout.spirv_type(self.span(), self),
place.val.llval,
place.val.align,
);
OperandValue::Immediate(llval)
} else if let BackendRepr::ScalarPair(a, b) = place.layout.backend_repr {
} else if let BackendRepr::ScalarPair { a, b, .. } = place.layout.backend_repr {
let b_offset = a
.primitive()
.size(self)
Expand Down
7 changes: 2 additions & 5 deletions crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
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),
FnDef(def_id, fn_args) => (def_id, fn_args.skip_binder()),
_ => bug!("expected fn item type, found {}", callee_ty),
};

Expand Down Expand Up @@ -360,10 +360,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {

_ => {
// Call the fallback body instead of generating the intrinsic code
return IntrinsicResult::Fallback(Instance::new_raw(
instance.def_id(),
instance.args,
));
return IntrinsicResult::Fallback(Instance::new_raw(def_id, instance.args));
}
};

Expand Down
Loading
Loading