Skip to content

Commit 6ada56d

Browse files
committed
rustup: update to nightly-2024-06-08 (~1.80).
1 parent 3246ebc commit 6ada56d

33 files changed

+201
-182
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
run: cargo run -p example-runner-wgpu-builder --release --no-default-features --features "use-installed-tools"
8181

8282
- name: build example shaders dev
83-
if: ${{ matrix.target != 'aarch64-linux-android' && matrix.target != 'x86_64-apple-darwin' }}
83+
if: ${{ matrix.target != 'aarch64-linux-android' }}
8484
env:
8585
OUT_DIR: "target/tmp"
8686
run: cargo run -p example-runner-wgpu-builder --no-default-features --features "use-installed-tools"

crates/rustc_codegen_spirv/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use std::{env, fs, mem};
1515
/// `cargo publish`. We need to figure out a way to do this properly, but let's hardcode it for now :/
1616
//const REQUIRED_RUST_TOOLCHAIN: &str = include_str!("../../rust-toolchain.toml");
1717
const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain]
18-
channel = "nightly-2024-05-01"
18+
channel = "nightly-2024-06-08"
1919
components = ["rust-src", "rustc-dev", "llvm-tools"]
20-
# commit_hash = f705de59625bb76067a5d102edc1575ff23b8845"#;
20+
# commit_hash = 804421dff5542c9c7da5c60257b5dbc849719505"#;
2121

2222
fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
2323
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
@@ -189,8 +189,8 @@ mod win {",
189189
);
190190
} else if relative_path == Path::new("src/mir/place.rs") {
191191
src = src.replace(
192-
"alloca(layout.size,",
193-
"typed_alloca(bx.cx().backend_type(layout),",
192+
"PlaceValue::alloca(bx, layout.size, layout.align.abi)",
193+
"PlaceValue::new_sized(bx.typed_alloca(bx.cx().backend_type(layout), layout.align.abi), layout.align.abi)",
194194
);
195195
} else if relative_path == Path::new("src/mir/operand.rs") {
196196
src = src.replace("alloca(field.size,", "typed_alloca(llfield_ty,");

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_errors::ErrorGuaranteed;
1010
use rustc_index::Idx;
11+
use rustc_middle::mir::interpret::ErrorHandled;
1112
use rustc_middle::query::Providers;
1213
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
13-
use rustc_middle::ty::GenericArgsRef;
1414
use rustc_middle::ty::{
15-
self, Const, CoroutineArgs, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind, UintTy,
15+
self, Const, CoroutineArgs, CoroutineArgsExt as _, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty,
16+
TyCtxt, TyKind, UintTy,
1617
};
18+
use rustc_middle::ty::{GenericArgsRef, ScalarInt};
1719
use rustc_middle::{bug, span_bug};
1820
use rustc_span::def_id::DefId;
1921
use rustc_span::DUMMY_SP;
@@ -27,8 +29,6 @@ use std::cell::RefCell;
2729
use std::collections::hash_map::Entry;
2830
use std::fmt;
2931

30-
use num_traits::cast::FromPrimitive;
31-
3232
pub(crate) fn provide(providers: &mut Providers) {
3333
// This is a lil weird: so, we obviously don't support C ABIs at all. However, libcore does declare some extern
3434
// C functions:
@@ -501,13 +501,12 @@ fn trans_scalar<'tcx>(
501501
}
502502

503503
match scalar.primitive() {
504-
Primitive::Int(width, signedness) => {
505-
SpirvType::Integer(width.size().bits() as u32, signedness).def(span, cx)
504+
Primitive::Int(int_kind, signedness) => {
505+
SpirvType::Integer(int_kind.size().bits() as u32, signedness).def(span, cx)
506+
}
507+
Primitive::Float(float_kind) => {
508+
SpirvType::Float(float_kind.size().bits() as u32).def(span, cx)
506509
}
507-
Primitive::F16 => SpirvType::Float(16).def(span, cx),
508-
Primitive::F32 => SpirvType::Float(32).def(span, cx),
509-
Primitive::F64 => SpirvType::Float(64).def(span, cx),
510-
Primitive::F128 => SpirvType::Float(128).def(span, cx),
511510
Primitive::Pointer(_) => {
512511
let pointee_ty = dig_scalar_pointee(cx, ty, offset);
513512
// Pointers can be recursive. So, record what we're currently translating, and if we're already translating
@@ -862,41 +861,51 @@ fn trans_intrinsic_type<'tcx>(
862861
// let image_format: spirv::ImageFormat =
863862
// type_from_variant_discriminant(cx, args.const_at(6));
864863

865-
trait FromU128Const: Sized {
866-
fn from_u128_const(n: u128) -> Option<Self>;
864+
trait FromScalarInt: Sized {
865+
fn from_scalar_int(n: ScalarInt) -> Option<Self>;
867866
}
868867

869-
impl FromU128Const for u32 {
870-
fn from_u128_const(n: u128) -> Option<Self> {
871-
u32::from_u128(n)
868+
impl FromScalarInt for u32 {
869+
fn from_scalar_int(n: ScalarInt) -> Option<Self> {
870+
n.try_to_u32().ok()
872871
}
873872
}
874873

875-
impl FromU128Const for Dim {
876-
fn from_u128_const(n: u128) -> Option<Self> {
877-
Dim::from_u32(u32::from_u128(n)?)
874+
impl FromScalarInt for Dim {
875+
fn from_scalar_int(n: ScalarInt) -> Option<Self> {
876+
Dim::from_u32(u32::from_scalar_int(n)?)
878877
}
879878
}
880879

881-
impl FromU128Const for ImageFormat {
882-
fn from_u128_const(n: u128) -> Option<Self> {
883-
ImageFormat::from_u32(u32::from_u128(n)?)
880+
impl FromScalarInt for ImageFormat {
881+
fn from_scalar_int(n: ScalarInt) -> Option<Self> {
882+
ImageFormat::from_u32(u32::from_scalar_int(n)?)
884883
}
885884
}
886885

887-
fn const_int_value<'tcx, P: FromU128Const>(
886+
fn const_int_value<'tcx, P: FromScalarInt>(
888887
cx: &CodegenCx<'tcx>,
889888
const_: Const<'tcx>,
890889
) -> Result<P, ErrorGuaranteed> {
891-
assert!(const_.ty().is_integral());
892-
let value = const_.eval_bits(cx.tcx, ParamEnv::reveal_all());
893-
match P::from_u128_const(value) {
894-
Some(v) => Ok(v),
895-
None => Err(cx
896-
.tcx
897-
.dcx()
898-
.err(format!("Invalid value for Image const generic: {value}"))),
899-
}
890+
const_
891+
.eval(cx.tcx, ParamEnv::reveal_all(), DUMMY_SP)
892+
.map_err(|e| match e {
893+
ErrorHandled::Reported(reported_error_info, _) => {
894+
Some(reported_error_info.into())
895+
}
896+
ErrorHandled::TooGeneric(_) => None,
897+
})
898+
.and_then(|(const_ty, const_val)| {
899+
assert!(const_ty.is_integral());
900+
P::from_scalar_int(const_val.try_to_scalar_int().ok_or(None)?).ok_or(None)
901+
})
902+
.map_err(|already_reported| {
903+
already_reported.unwrap_or_else(|| {
904+
cx.tcx
905+
.dcx()
906+
.err(format!("invalid value for Image const generic: {const_}"))
907+
})
908+
})
900909
}
901910

902911
let dim = const_int_value(cx, args.const_at(1))?;

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
977977
cx,
978978
cursor,
979979
current_fn,
980-
basic_block: llbb,
981980
current_span: Default::default(),
982981
}
983982
}
@@ -987,7 +986,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
987986
}
988987

989988
fn llbb(&self) -> Self::BasicBlock {
990-
self.basic_block
989+
// FIXME(eddyb) `llbb` should be removed from `rustc_codegen_ssa::traits`.
990+
unreachable!("dead code within `rustc_codegen_ssa`")
991991
}
992992

993993
fn set_span(&mut self, span: Span) {
@@ -2797,7 +2797,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
27972797
///
27982798
/// E.g. for `format_args!("{a} {b:x}")` they'll be:
27992799
/// * `&a` with `typeof a` and ' ',
2800-
/// *`&b` with `typeof b` and 'x'
2800+
/// * `&b` with `typeof b` and 'x'
28012801
ref_arg_ids_with_ty_and_spec: SmallVec<[(Word, Ty<'tcx>, char); 2]>,
28022802
}
28032803
struct FormatArgsNotRecognized(String);
@@ -2810,24 +2810,23 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
28102810
SpirvConst::Scalar(x) => Some(u32::try_from(x).ok()? as usize),
28112811
_ => None,
28122812
};
2813-
let const_slice_as_elem_ids = |slice_ptr_and_len_ids: &[Word]| {
2814-
if let [ptr_id, len_id] = slice_ptr_and_len_ids[..] {
2815-
if let SpirvConst::PtrTo { pointee } =
2816-
self.builder.lookup_const_by_id(ptr_id)?
2813+
let const_slice_as_elem_ids = |ptr_id: Word, len: usize| {
2814+
if let SpirvConst::PtrTo { pointee } =
2815+
self.builder.lookup_const_by_id(ptr_id)?
2816+
{
2817+
if let SpirvConst::Composite(elems) =
2818+
self.builder.lookup_const_by_id(pointee)?
28172819
{
2818-
if let SpirvConst::Composite(elems) =
2819-
self.builder.lookup_const_by_id(pointee)?
2820-
{
2821-
if elems.len() == const_u32_as_usize(len_id)? {
2822-
return Some(elems);
2823-
}
2820+
if elems.len() == len {
2821+
return Some(elems);
28242822
}
28252823
}
28262824
}
28272825
None
28282826
};
2829-
let const_str_as_utf8 = |str_ptr_and_len_ids: &[Word]| {
2830-
let piece_str_bytes = const_slice_as_elem_ids(str_ptr_and_len_ids)?
2827+
let const_str_as_utf8 = |&[str_ptr_id, str_len_id]: &[Word; 2]| {
2828+
let str_len = const_u32_as_usize(str_len_id)?;
2829+
let piece_str_bytes = const_slice_as_elem_ids(str_ptr_id, str_len)?
28312830
.iter()
28322831
.map(|&id| u8::try_from(const_u32_as_usize(id)?).ok())
28332832
.collect::<Option<Vec<u8>>>()?;
@@ -3001,42 +3000,36 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
30013000
"fmt::Arguments::new call: ran out of instructions".into(),
30023001
)
30033002
})?;
3004-
let ((pieces_slice_ptr_id, pieces_len_id), (rt_args_slice_ptr_id, rt_args_count)) =
3003+
let ((pieces_slice_ptr_id, pieces_len), (rt_args_slice_ptr_id, rt_args_count)) =
30053004
match fmt_args_new_call_insts[..] {
30063005
[
30073006
Inst::Call(call_ret_id, callee_id, ref call_args),
30083007
Inst::Store(st_dst_id, st_val_id),
30093008
Inst::Load(ld_val_id, ld_src_id),
3010-
] if self.fmt_args_new_fn_ids.borrow().contains(&callee_id)
3011-
&& call_ret_id == st_val_id
3009+
] if call_ret_id == st_val_id
30123010
&& st_dst_id == ld_src_id
30133011
&& ld_val_id == format_args_id =>
30143012
{
30153013
require_local_var(st_dst_id, "fmt::Arguments::new destination")?;
30163014

3015+
let Some(&(pieces_len, rt_args_count)) =
3016+
self.fmt_args_new_fn_ids.borrow().get(&callee_id)
3017+
else {
3018+
return Err(FormatArgsNotRecognized(
3019+
"fmt::Arguments::new callee not registered".into(),
3020+
));
3021+
};
3022+
30173023
match call_args[..] {
30183024
// `<core::fmt::Arguments>::new_v1`
3019-
[
3020-
pieces_slice_ptr_id,
3021-
pieces_len_id,
3022-
rt_args_slice_ptr_id,
3023-
rt_args_len_id,
3024-
] => (
3025-
(pieces_slice_ptr_id, pieces_len_id),
3026-
(
3027-
Some(rt_args_slice_ptr_id),
3028-
const_u32_as_usize(rt_args_len_id).ok_or_else(|| {
3029-
FormatArgsNotRecognized(
3030-
"fmt::Arguments::new: args.len() not constant"
3031-
.into(),
3032-
)
3033-
})?,
3034-
),
3025+
[pieces_slice_ptr_id, rt_args_slice_ptr_id] => (
3026+
(pieces_slice_ptr_id, pieces_len),
3027+
(Some(rt_args_slice_ptr_id), rt_args_count),
30353028
),
30363029

30373030
// `<core::fmt::Arguments>::new_const`
3038-
[pieces_slice_ptr_id, pieces_len_id] => {
3039-
((pieces_slice_ptr_id, pieces_len_id), (None, 0))
3031+
[pieces_slice_ptr_id] if rt_args_count == 0 => {
3032+
((pieces_slice_ptr_id, pieces_len), (None, rt_args_count))
30403033
}
30413034

30423035
_ => {
@@ -3068,21 +3061,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
30683061
// arguments (from e.g. new `assert!`s being added to `core`),
30693062
// we have to confirm their many instructions for removal.
30703063
if rt_args_count > 0 {
3071-
let rt_args_slice_ptr_id = rt_args_slice_ptr_id.unwrap();
3072-
let rt_args_array_ptr_id = match try_rev_take(1).ok_or_else(|| {
3073-
FormatArgsNotRecognized(
3074-
"&[fmt::rt::Argument] bitcast: ran out of instructions".into(),
3075-
)
3076-
})?[..]
3077-
{
3078-
[Inst::Bitcast(out_id, in_id)] if out_id == rt_args_slice_ptr_id => in_id,
3079-
_ => {
3080-
return Err(FormatArgsNotRecognized(
3081-
"&[fmt::rt::Argument] bitcast".into(),
3082-
));
3083-
}
3084-
};
3085-
require_local_var(rt_args_array_ptr_id, "[fmt::rt::Argument; N]")?;
3064+
let rt_args_array_ptr_id = rt_args_slice_ptr_id.unwrap();
30863065

30873066
// Each runtime argument has 4 instructions to call one of
30883067
// the `fmt::rt::Argument::new_*` functions (and temporarily
@@ -3162,13 +3141,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
31623141
_ => pieces_slice_ptr_id,
31633142
};
31643143
decoded_format_args.const_pieces =
3165-
const_slice_as_elem_ids(&[pieces_slice_ptr_id, pieces_len_id]).and_then(
3144+
const_slice_as_elem_ids(pieces_slice_ptr_id, pieces_len).and_then(
31663145
|piece_ids| {
31673146
piece_ids
31683147
.iter()
31693148
.map(|&piece_id| {
31703149
match self.builder.lookup_const_by_id(piece_id)? {
3171-
SpirvConst::Composite(piece) => const_str_as_utf8(piece),
3150+
SpirvConst::Composite(piece) => {
3151+
const_str_as_utf8(piece.try_into().ok()?)
3152+
}
31723153
_ => None,
31733154
}
31743155
})
@@ -3198,7 +3179,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
31983179
.map(|s| Cow::Owned(s.replace('%', "%%")))
31993180
.interleave(ref_arg_ids_with_ty_and_spec.iter().map(
32003181
|&(ref_id, ty, spec)| {
3201-
use rustc_target::abi::{Integer::*, Primitive::*};
3182+
use rustc_target::abi::{
3183+
Float::*, Integer::*, Primitive::*,
3184+
};
32023185

32033186
let layout = self.layout_of(ty);
32043187

@@ -3212,7 +3195,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
32123195
(' ' | '?', Some(Int(I32, false))) => "%u",
32133196
('x', Some(Int(I32, false))) => "%x",
32143197
(' ' | '?', Some(Int(I32, true))) => "%i",
3215-
(' ' | '?', Some(F32)) => "%f",
3198+
(' ' | '?', Some(Float(F32))) => "%f",
32163199

32173200
_ => "",
32183201
};

crates/rustc_codegen_spirv/src/builder/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub struct Builder<'a, 'tcx> {
4242
cx: &'a CodegenCx<'tcx>,
4343
cursor: BuilderCursor,
4444
current_fn: <Self as BackendTypes>::Function,
45-
basic_block: <Self as BackendTypes>::BasicBlock,
4645
current_span: Option<Span>,
4746
}
4847

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::bug;
1111
use rustc_middle::mir::interpret::{alloc_range, ConstAllocation, GlobalAlloc, Scalar};
1212
use rustc_middle::ty::layout::LayoutOf;
1313
use rustc_span::{Span, DUMMY_SP};
14-
use rustc_target::abi::{self, AddressSpace, HasDataLayout, Integer, Primitive, Size};
14+
use rustc_target::abi::{self, AddressSpace, Float, HasDataLayout, Integer, Primitive, Size};
1515

1616
impl<'tcx> CodegenCx<'tcx> {
1717
pub fn def_constant(&self, ty: Word, val: SpirvConst<'_, 'tcx>) -> SpirvValue {
@@ -398,8 +398,8 @@ impl<'tcx> CodegenCx<'tcx> {
398398
let size = ty_concrete.sizeof(self).unwrap();
399399
let primitive = match ty_concrete {
400400
SpirvType::Bool => Primitive::Int(Integer::fit_unsigned(0), false),
401-
SpirvType::Integer(int_size, int_signedness) => {
402-
let integer = match int_size {
401+
SpirvType::Integer(int_size, int_signedness) => Primitive::Int(
402+
match int_size {
403403
8 => Integer::I8,
404404
16 => Integer::I16,
405405
32 => Integer::I32,
@@ -410,18 +410,20 @@ impl<'tcx> CodegenCx<'tcx> {
410410
.dcx()
411411
.fatal(format!("invalid size for integer: {other}"));
412412
}
413-
};
414-
Primitive::Int(integer, int_signedness)
415-
}
416-
SpirvType::Float(float_size) => match float_size {
417-
32 => Primitive::F32,
418-
64 => Primitive::F64,
413+
},
414+
int_signedness,
415+
),
416+
SpirvType::Float(float_size) => Primitive::Float(match float_size {
417+
16 => Float::F16,
418+
32 => Float::F32,
419+
64 => Float::F64,
420+
128 => Float::F128,
419421
other => {
420422
self.tcx
421423
.dcx()
422424
.fatal(format!("invalid size for float: {other}"));
423425
}
424-
},
426+
}),
425427
SpirvType::Pointer { .. } => Primitive::Pointer(AddressSpace::DATA),
426428
unsupported_spirv_type => bug!(
427429
"invalid spirv type internal to create_alloc_const2: {:?}",

0 commit comments

Comments
 (0)