Skip to content

Commit 60291af

Browse files
eddybLegNeato
authored andcommitted
rustup: update to nightly-2024-04-01.
1 parent bbb61f5 commit 60291af

21 files changed

+162
-121
lines changed

crates/rustc_codegen_spirv/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use std::process::{Command, ExitCode};
1010
/// `cargo publish`. We need to figure out a way to do this properly, but let's hardcode it for now :/
1111
//const REQUIRED_RUST_TOOLCHAIN: &str = include_str!("../../rust-toolchain.toml");
1212
const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain]
13-
channel = "nightly-2024-03-21"
13+
channel = "nightly-2024-04-01"
1414
components = ["rust-src", "rustc-dev", "llvm-tools"]
15-
# commit_hash = 1388d7a069d872bcfe5e5dd97ef61fa0a586fac0"#;
15+
# commit_hash = 805813650248c1a2f6f271460d728d1bb852d2a7"#;
1616

1717
fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
1818
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use rustc_middle::query::Providers;
1212
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
1313
use rustc_middle::ty::GenericArgsRef;
1414
use rustc_middle::ty::{
15-
self, Const, CoroutineArgs, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind,
16-
TypeAndMut, UintTy,
15+
self, Const, CoroutineArgs, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind, UintTy,
1716
};
1817
use rustc_middle::{bug, span_bug};
1918
use rustc_span::def_id::DefId;
@@ -547,7 +546,7 @@ fn dig_scalar_pointee<'tcx>(
547546
if let FieldsShape::Primitive = layout.fields {
548547
assert_eq!(offset, Size::ZERO);
549548
let pointee = match *layout.ty.kind() {
550-
TyKind::Ref(_, pointee_ty, _) | TyKind::RawPtr(TypeAndMut { ty: pointee_ty, .. }) => {
549+
TyKind::Ref(_, pointee_ty, _) | TyKind::RawPtr(pointee_ty, _) => {
551550
PointeeTy::Ty(cx.layout_of(pointee_ty))
552551
}
553552
TyKind::FnPtr(sig) => PointeeTy::Fn(sig),

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_data_structures::fx::FxHashSet;
2121
use rustc_middle::bug;
2222
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2323
use rustc_middle::ty::layout::LayoutOf;
24-
use rustc_middle::ty::Ty;
24+
use rustc_middle::ty::{self, Ty};
2525
use rustc_span::Span;
2626
use rustc_target::abi::call::FnAbi;
2727
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
@@ -1175,9 +1175,10 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
11751175
then: Self::BasicBlock,
11761176
_catch: Self::BasicBlock,
11771177
funclet: Option<&Self::Funclet>,
1178+
instance: Option<ty::Instance<'tcx>>,
11781179
) -> Self::Value {
11791180
// Exceptions don't exist, jump directly to then block
1180-
let result = self.call(llty, fn_attrs, fn_abi, llfn, args, funclet);
1181+
let result = self.call(llty, fn_attrs, fn_abi, llfn, args, funclet, instance);
11811182
self.emit().branch(then).unwrap();
11821183
result
11831184
}
@@ -2616,6 +2617,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
26162617
callee: Self::Value,
26172618
args: &[Self::Value],
26182619
funclet: Option<&Self::Funclet>,
2620+
instance: Option<ty::Instance<'tcx>>,
26192621
) -> Self::Value {
26202622
if funclet.is_some() {
26212623
self.fatal("TODO: Funclets are not supported");
@@ -2674,17 +2676,19 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
26742676
.collect();
26752677
let args = &args[..];
26762678

2677-
let libm_intrinsic = self.libm_intrinsics.borrow().get(&callee_val).copied();
2678-
let buffer_load_intrinsic = self
2679-
.buffer_load_intrinsic_fn_id
2680-
.borrow()
2681-
.get(&callee_val)
2682-
.copied();
2683-
let buffer_store_intrinsic = self
2684-
.buffer_store_intrinsic_fn_id
2685-
.borrow()
2686-
.get(&callee_val)
2687-
.copied();
2679+
// FIXME(eddyb) should the maps exist at all, now that the `DefId` is known
2680+
// at `call` time, and presumably its high-level details can be looked up?
2681+
let instance_def_id = instance.map(|instance| instance.def_id());
2682+
2683+
let libm_intrinsic =
2684+
instance_def_id.and_then(|def_id| self.libm_intrinsics.borrow().get(&def_id).copied());
2685+
let buffer_load_intrinsic = instance_def_id
2686+
.and_then(|def_id| self.buffer_load_intrinsics.borrow().get(&def_id).copied());
2687+
let buffer_store_intrinsic = instance_def_id
2688+
.and_then(|def_id| self.buffer_store_intrinsics.borrow().get(&def_id).copied());
2689+
let is_panic_entry_point = instance_def_id
2690+
.is_some_and(|def_id| self.panic_entry_points.borrow().contains(&def_id));
2691+
26882692
if let Some(libm_intrinsic) = libm_intrinsic {
26892693
let result = self.call_libm_intrinsic(libm_intrinsic, result_type, args);
26902694
if result_type != result.ty {
@@ -2696,7 +2700,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
26962700
);
26972701
}
26982702
result
2699-
} else if self.panic_entry_point_ids.borrow().contains(&callee_val) {
2703+
} else if is_panic_entry_point {
27002704
// HACK(eddyb) Rust 2021 `panic!` always uses `format_args!`, even
27012705
// in the simple case that used to pass a `&str` constant, which
27022706
// would not remain reachable in the SPIR-V - but `format_args!` is

crates/rustc_codegen_spirv/src/builder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_codegen_ssa::traits::{
2121
DebugInfoBuilderMethods, HasCodegen, StaticBuilderMethods, TypeMembershipMethods,
2222
};
2323
use rustc_errors::{Diag, DiagMessage};
24-
use rustc_middle::mir::Coverage;
24+
use rustc_middle::mir::coverage::CoverageKind;
2525
use rustc_middle::span_bug;
2626
use rustc_middle::ty::layout::{
2727
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
@@ -147,7 +147,7 @@ impl<'a, 'tcx> Deref for Builder<'a, 'tcx> {
147147
}
148148

149149
impl<'a, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'tcx> {
150-
fn add_coverage(&mut self, _instance: Instance<'tcx>, _coverage: &Coverage) {}
150+
fn add_coverage(&mut self, _instance: Instance<'tcx>, _kind: &CoverageKind) {}
151151
}
152152

153153
impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ impl<'tcx> CodegenCx<'tcx> {
5959
// MiscMethods::get_fn_addr -> get_fn_ext -> declare_fn_ext
6060
// PreDefineMethods::predefine_fn -> declare_fn_ext
6161
fn declare_fn_ext(&self, instance: Instance<'tcx>, linkage: Option<LinkageType>) -> SpirvValue {
62-
let control = attrs_to_spirv(self.tcx.codegen_fn_attrs(instance.def_id()));
62+
let def_id = instance.def_id();
63+
64+
let control = attrs_to_spirv(self.tcx.codegen_fn_attrs(def_id));
6365
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
64-
let span = self.tcx.def_span(instance.def_id());
66+
let span = self.tcx.def_span(def_id);
6567
let function_type = fn_abi.spirv_type(span, self);
6668
let (return_type, argument_types) = match self.lookup_type(function_type) {
6769
SpirvType::Function {
@@ -99,7 +101,7 @@ impl<'tcx> CodegenCx<'tcx> {
99101
// which prevents us from attaching `OpLine`s to `OpFunction` definitions,
100102
// but we can use our custom `SrcLocDecoration` instead.
101103
let src_loc_inst = SrcLocDecoration::from_rustc_span(
102-
self.tcx.def_ident_span(instance.def_id()).unwrap_or(span),
104+
self.tcx.def_ident_span(def_id).unwrap_or(span),
103105
&self.builder,
104106
)
105107
.map(|src_loc| src_loc.encode_to_inst(fn_id));
@@ -128,12 +130,12 @@ impl<'tcx> CodegenCx<'tcx> {
128130

129131
let attrs = AggregatedSpirvAttributes::parse(
130132
self,
131-
match self.tcx.def_kind(instance.def_id()) {
133+
match self.tcx.def_kind(def_id) {
132134
// This was made to ICE cross-crate at some point, but then got
133135
// reverted in https://github.com/rust-lang/rust/pull/111381.
134136
// FIXME(eddyb) remove this workaround once we rustup past that.
135137
DefKind::Closure => &[],
136-
_ => self.tcx.get_attrs_unchecked(instance.def_id()),
138+
_ => self.tcx.get_attrs_unchecked(def_id),
137139
},
138140
);
139141
if let Some(entry) = attrs.entry.map(|attr| attr.value) {
@@ -143,28 +145,29 @@ impl<'tcx> CodegenCx<'tcx> {
143145
.map_or_else(|| instance.to_string(), ToString::to_string);
144146
self.entry_stub(&instance, fn_abi, declared, entry_name, entry);
145147
}
148+
149+
// FIXME(eddyb) should the maps exist at all, now that the `DefId` is known
150+
// at `call` time, and presumably its high-level details can be looked up?
146151
if attrs.buffer_load_intrinsic.is_some() {
147152
let mode = &fn_abi.ret.mode;
148-
self.buffer_load_intrinsic_fn_id
153+
self.buffer_load_intrinsics
149154
.borrow_mut()
150-
.insert(fn_id, mode);
155+
.insert(def_id, mode);
151156
}
152157
if attrs.buffer_store_intrinsic.is_some() {
153158
let mode = &fn_abi.args.last().unwrap().mode;
154-
self.buffer_store_intrinsic_fn_id
159+
self.buffer_store_intrinsics
155160
.borrow_mut()
156-
.insert(fn_id, mode);
161+
.insert(def_id, mode);
157162
}
158163

159-
let instance_def_id = instance.def_id();
160-
161-
if self.tcx.crate_name(instance_def_id.krate) == self.sym.libm {
162-
let item_name = self.tcx.item_name(instance_def_id);
164+
if self.tcx.crate_name(def_id.krate) == self.sym.libm {
165+
let item_name = self.tcx.item_name(def_id);
163166
let intrinsic = self.sym.libm_intrinsics.get(&item_name);
164-
if self.tcx.visibility(instance.def_id()) == ty::Visibility::Public {
167+
if self.tcx.visibility(def_id) == ty::Visibility::Public {
165168
match intrinsic {
166169
Some(&intrinsic) => {
167-
self.libm_intrinsics.borrow_mut().insert(fn_id, intrinsic);
170+
self.libm_intrinsics.borrow_mut().insert(def_id, intrinsic);
168171
}
169172
None => {
170173
self.tcx.dcx().err(format!(
@@ -179,9 +182,9 @@ impl<'tcx> CodegenCx<'tcx> {
179182
self.tcx.lang_items().panic_fn(),
180183
self.tcx.lang_items().panic_fmt(),
181184
]
182-
.contains(&Some(instance_def_id))
185+
.contains(&Some(def_id))
183186
{
184-
self.panic_entry_point_ids.borrow_mut().insert(fn_id);
187+
self.panic_entry_points.borrow_mut().insert(def_id);
185188
}
186189

187190
// HACK(eddyb) there is no good way to identify these definitions

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl<'tcx> CodegenCx<'tcx> {
199199
entry_func,
200200
&call_args,
201201
None,
202+
None,
202203
);
203204
bx.ret_void();
204205

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_codegen_ssa::traits::{
1919
AsmMethods, BackendTypes, DebugInfoMethods, GlobalAsmOperandRef, MiscMethods,
2020
};
2121
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
22+
use rustc_hir::def_id::DefId;
2223
use rustc_middle::mir;
2324
use rustc_middle::mir::mono::CodegenUnit;
2425
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt};
@@ -57,11 +58,14 @@ pub struct CodegenCx<'tcx> {
5758
/// Cache of all the builtin symbols we need
5859
pub sym: Rc<Symbols>,
5960
pub instruction_table: InstructionTable,
60-
pub libm_intrinsics: RefCell<FxHashMap<Word, super::builder::libm_intrinsics::LibmIntrinsic>>,
61+
62+
// FIXME(eddyb) should the maps exist at all, now that the `DefId` is known
63+
// at `call` time, and presumably its high-level details can be looked up?
64+
pub libm_intrinsics: RefCell<FxHashMap<DefId, super::builder::libm_intrinsics::LibmIntrinsic>>,
6165

6266
/// All `panic!(...)`s and builtin panics (from MIR `Assert`s) call into one
6367
/// of these lang items, which we always replace with an "abort".
64-
pub panic_entry_point_ids: RefCell<FxHashSet<Word>>,
68+
pub panic_entry_points: RefCell<FxHashSet<DefId>>,
6569

6670
/// `core::fmt::Arguments::new_{v1,const}` instances (for Rust 2021 panics).
6771
pub fmt_args_new_fn_ids: RefCell<FxHashSet<Word>>,
@@ -72,18 +76,15 @@ pub struct CodegenCx<'tcx> {
7276
pub fmt_rt_arg_new_fn_ids_to_ty_and_spec: RefCell<FxHashMap<Word, (Ty<'tcx>, char)>>,
7377

7478
/// Intrinsic for loading a `<T>` from a `&[u32]`. The `PassMode` is the mode of the `<T>`.
75-
pub buffer_load_intrinsic_fn_id: RefCell<FxHashMap<Word, &'tcx PassMode>>,
79+
pub buffer_load_intrinsics: RefCell<FxHashMap<DefId, &'tcx PassMode>>,
7680
/// Intrinsic for storing a `<T>` into a `&[u32]`. The `PassMode` is the mode of the `<T>`.
77-
pub buffer_store_intrinsic_fn_id: RefCell<FxHashMap<Word, &'tcx PassMode>>,
81+
pub buffer_store_intrinsics: RefCell<FxHashMap<DefId, &'tcx PassMode>>,
7882

7983
/// Some runtimes (e.g. intel-compute-runtime) disallow atomics on i8 and i16, even though it's allowed by the spec.
8084
/// This enables/disables them.
8185
pub i8_i16_atomics_allowed: bool,
8286

8387
pub codegen_args: CodegenArgs,
84-
85-
/// Information about the SPIR-V target.
86-
pub target: SpirvTarget,
8788
}
8889

8990
impl<'tcx> CodegenCx<'tcx> {
@@ -190,15 +191,14 @@ impl<'tcx> CodegenCx<'tcx> {
190191
vtables: Default::default(),
191192
ext_inst: Default::default(),
192193
zombie_decorations: Default::default(),
193-
target,
194194
sym,
195195
instruction_table: InstructionTable::new(),
196196
libm_intrinsics: Default::default(),
197-
panic_entry_point_ids: Default::default(),
197+
panic_entry_points: Default::default(),
198198
fmt_args_new_fn_ids: Default::default(),
199199
fmt_rt_arg_new_fn_ids_to_ty_and_spec: Default::default(),
200-
buffer_load_intrinsic_fn_id: Default::default(),
201-
buffer_store_intrinsic_fn_id: Default::default(),
200+
buffer_load_intrinsics: Default::default(),
201+
buffer_store_intrinsics: Default::default(),
202202
i8_i16_atomics_allowed: false,
203203
codegen_args,
204204
}
@@ -296,7 +296,6 @@ pub enum SpirvMetadata {
296296
}
297297

298298
pub struct CodegenArgs {
299-
pub module_output_type: ModuleOutputType,
300299
pub disassemble: bool,
301300
pub disassemble_fn: Option<String>,
302301
pub disassemble_entry: Option<String>,
@@ -554,8 +553,6 @@ impl CodegenArgs {
554553
std::process::exit(1);
555554
}
556555

557-
let module_output_type =
558-
matches.opt_get_default("module-output", ModuleOutputType::Single)?;
559556
let disassemble = matches.opt_present("disassemble");
560557
let disassemble_fn = matches.opt_str("disassemble-fn");
561558
let disassemble_entry = matches.opt_str("disassemble-entry");
@@ -617,9 +614,9 @@ impl CodegenArgs {
617614
.collect(),
618615

619616
abort_strategy: matches.opt_str("abort-strategy"),
617+
module_output_type: matches.opt_get_default("module-output", Default::default())?,
620618

621619
// FIXME(eddyb) deduplicate between `CodegenArgs` and `linker::Options`.
622-
emit_multiple_modules: module_output_type == ModuleOutputType::Multiple,
623620
spirv_metadata,
624621
keep_link_exports: false,
625622

@@ -639,7 +636,6 @@ impl CodegenArgs {
639636
};
640637

641638
Ok(Self {
642-
module_output_type,
643639
disassemble,
644640
disassemble_fn,
645641
disassemble_entry,
@@ -781,8 +777,9 @@ impl CodegenArgs {
781777
}
782778
}
783779

784-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
780+
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
785781
pub enum ModuleOutputType {
782+
#[default]
786783
Single,
787784
Multiple,
788785
}

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod zombies;
1818

1919
use std::borrow::Cow;
2020

21-
use crate::codegen_cx::SpirvMetadata;
21+
use crate::codegen_cx::{ModuleOutputType, SpirvMetadata};
2222
use crate::custom_decorations::{CustomDecoration, SrcLocDecoration, ZombieDecoration};
2323
use crate::custom_insts;
2424
use either::Either;
@@ -45,8 +45,8 @@ pub struct Options {
4545
pub spirt_passes: Vec<String>,
4646

4747
pub abort_strategy: Option<String>,
48+
pub module_output_type: ModuleOutputType,
4849

49-
pub emit_multiple_modules: bool,
5050
pub spirv_metadata: SpirvMetadata,
5151

5252
/// Whether to preserve `LinkageAttributes "..." Export` decorations,
@@ -620,7 +620,7 @@ pub fn link(
620620
simple_passes::sort_globals(&mut output);
621621
}
622622

623-
let mut output = if opts.emit_multiple_modules {
623+
let mut output = if opts.module_output_type == ModuleOutputType::Multiple {
624624
let mut file_stem_to_entry_name_and_module = BTreeMap::new();
625625
for (i, entry) in output.entry_points.iter().enumerate() {
626626
let mut module = output.clone();
@@ -695,7 +695,7 @@ pub fn link(
695695
)
696696
.unwrap();
697697
}
698-
// Run DCE again, even if emit_multiple_modules==false - the first DCE ran before
698+
// Run DCE again, even if module_output_type == ModuleOutputType::Multiple - the first DCE ran before
699699
// structurization and mem2reg (for perf reasons), and mem2reg may remove references to
700700
// invalid types, so we need to DCE again.
701701
if opts.dce {

crates/rustc_codegen_spirv/src/spirv_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::sync::{LazyLock, Mutex};
2222
/// the `result_id` of the type declaration instruction, merely the contents.
2323
//
2424
// FIXME(eddyb) should `SpirvType`s be behind `&'tcx` from `tcx.arena.dropless`?
25-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
25+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
2626
pub enum SpirvType<'tcx> {
2727
Void,
2828
Bool,

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub struct Symbols {
1919
pub discriminant: Symbol,
2020
pub rust_gpu: Symbol,
2121
pub spirv: Symbol,
22-
pub spirv_std: Symbol,
2322
pub libm: Symbol,
24-
pub num_traits: Symbol,
2523
pub entry_point_name: Symbol,
2624
pub spv_intel_shader_integer_functions2: Symbol,
2725
pub spv_khr_vulkan_memory_model: Symbol,
@@ -383,9 +381,7 @@ impl Symbols {
383381
discriminant: Symbol::intern("discriminant"),
384382
rust_gpu: Symbol::intern("rust_gpu"),
385383
spirv: Symbol::intern("spirv"),
386-
spirv_std: Symbol::intern("spirv_std"),
387384
libm: Symbol::intern("libm"),
388-
num_traits: Symbol::intern("num_traits"),
389385
entry_point_name: Symbol::intern("entry_point_name"),
390386
spv_intel_shader_integer_functions2: Symbol::intern(
391387
"SPV_INTEL_shader_integer_functions2",

0 commit comments

Comments
 (0)