Skip to content

Commit 7501f18

Browse files
committed
rustup: update to nightly-2021-08-10.
1 parent 1a3a12f commit 7501f18

19 files changed

+153
-70
lines changed

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,8 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
488488
module_def_id,
489489
&mut check_spirv_attr_visitor.as_deep_visitor(),
490490
);
491-
// FIXME(eddyb) use `tcx.hir().visit_exported_macros_in_krate(...)` after rustup.
492-
for id in tcx.hir().krate().exported_macros {
493-
check_spirv_attr_visitor.visit_macro_def(match tcx.hir().find(id.hir_id()) {
494-
Some(hir::Node::MacroDef(macro_def)) => macro_def,
495-
_ => unreachable!(),
496-
});
497-
}
491+
tcx.hir()
492+
.visit_exported_macros_in_krate(check_spirv_attr_visitor);
498493
check_invalid_macro_level_spirv_attr(
499494
tcx,
500495
&check_spirv_attr_visitor.sym,

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::Builder;
2+
use crate::abi::ConvSpirvType;
23
use crate::builder_spirv::{BuilderCursor, SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
34
use crate::spirv_type::SpirvType;
45
use rspirv::dr::{InsertPoint, Instruction, Operand};
@@ -313,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
313314
} else {
314315
for index in 0..count {
315316
let const_index = self.constant_u32(self.span(), index as u32);
316-
let gep_ptr = self.gep(ptr, &[const_index]);
317+
let gep_ptr = self.gep(pat.ty, ptr, &[const_index]);
317318
self.store(pat, gep_ptr, Align::from_bytes(0).unwrap());
318319
}
319320
}
@@ -339,11 +340,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
339340
self.store(zero, index, zero_align);
340341
self.br(header.llbb());
341342

342-
let current_index = header.load(index, zero_align);
343+
let current_index = header.load(count.ty, index, zero_align);
343344
let cond = header.icmp(IntPredicate::IntULT, current_index, count);
344345
header.cond_br(cond, body.llbb(), exit.llbb());
345346

346-
let gep_ptr = body.gep(ptr, &[current_index]);
347+
let gep_ptr = body.gep(pat.ty, ptr, &[current_index]);
347348
body.store(pat, gep_ptr, zero_align);
348349
let current_index_plus_1 = body.add(current_index, one);
349350
body.store(current_index_plus_1, index, zero_align);
@@ -623,14 +624,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
623624

624625
fn invoke(
625626
&mut self,
627+
llty: Self::Type,
626628
llfn: Self::Value,
627629
args: &[Self::Value],
628630
then: Self::BasicBlock,
629631
_catch: Self::BasicBlock,
630632
funclet: Option<&Self::Funclet>,
631633
) -> Self::Value {
632634
// Exceptions don't exist, jump directly to then block
633-
let result = self.call(llfn, args, funclet);
635+
let result = self.call(llty, llfn, args, funclet);
634636
self.emit().branch(then).unwrap();
635637
result
636638
}
@@ -842,12 +844,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
842844
self.fatal("array alloca not supported yet")
843845
}
844846

845-
fn load(&mut self, ptr: Self::Value, _align: Align) -> Self::Value {
847+
fn load(&mut self, ty: Self::Type, ptr: Self::Value, _align: Align) -> Self::Value {
846848
if let Some(value) = ptr.const_fold_load(self) {
847849
return value;
848850
}
849851
let ty = match self.lookup_type(ptr.ty) {
850-
SpirvType::Pointer { pointee } => pointee,
852+
SpirvType::Pointer { pointee } => {
853+
assert_ty_eq!(self, ty, pointee);
854+
pointee
855+
}
851856
ty => self.fatal(&format!(
852857
"load called on variable that wasn't a pointer: {:?}",
853858
ty
@@ -859,16 +864,25 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
859864
.with_type(ty)
860865
}
861866

862-
fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value {
867+
fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value) -> Self::Value {
863868
// TODO: Implement this
864-
let result = self.load(ptr, Align::from_bytes(0).unwrap());
869+
let result = self.load(ty, ptr, Align::from_bytes(0).unwrap());
865870
self.zombie(result.def(self), "volatile load is not supported yet");
866871
result
867872
}
868873

869-
fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, _size: Size) -> Self::Value {
874+
fn atomic_load(
875+
&mut self,
876+
ty: Self::Type,
877+
ptr: Self::Value,
878+
order: AtomicOrdering,
879+
_size: Size,
880+
) -> Self::Value {
870881
let ty = match self.lookup_type(ptr.ty) {
871-
SpirvType::Pointer { pointee } => pointee,
882+
SpirvType::Pointer { pointee } => {
883+
assert_ty_eq!(self, ty, pointee);
884+
pointee
885+
}
872886
ty => self.fatal(&format!(
873887
"atomic_load called on variable that wasn't a pointer: {:?}",
874888
ty
@@ -903,14 +917,23 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
903917
let val = if let Some(llextra) = place.llextra {
904918
OperandValue::Ref(place.llval, Some(llextra), place.align)
905919
} else if self.cx.is_backend_immediate(place.layout) {
906-
let llval = self.load(place.llval, place.align);
920+
let llval = self.load(
921+
place.layout.spirv_type(self.span(), self),
922+
place.llval,
923+
place.align,
924+
);
907925
OperandValue::Immediate(self.to_immediate(llval, place.layout))
908926
} else if let Abi::ScalarPair(ref a, ref b) = place.layout.abi {
909927
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
910928

929+
let pair_ty = place.layout.spirv_type(self.span(), self);
911930
let mut load = |i, scalar: &Scalar, align| {
912-
let llptr = self.struct_gep(place.llval, i as u64);
913-
let load = self.load(llptr, align);
931+
let llptr = self.struct_gep(pair_ty, place.llval, i as u64);
932+
let load = self.load(
933+
self.scalar_pair_element_backend_type(place.layout, i, false),
934+
llptr,
935+
align,
936+
);
914937
// WARN! This does not go through to_immediate due to only having a Scalar, not a Ty, but it still does
915938
// whatever to_immediate does!
916939
if scalar.is_bool() {
@@ -943,12 +966,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
943966
let zero = self.const_usize(0);
944967
let start = dest.project_index(&mut self, zero).llval;
945968

946-
let align = dest
947-
.align
948-
.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
969+
let elem_layout = dest.layout.field(self.cx(), 0);
970+
let elem_ty = elem_layout.spirv_type(self.span(), &self);
971+
let align = dest.align.restrict_for_offset(elem_layout.size);
949972

950973
for i in 0..count {
951-
let current = self.inbounds_gep(start, &[self.const_usize(i)]);
974+
let current = self.inbounds_gep(elem_ty, start, &[self.const_usize(i)]);
952975
cg_elem.val.store(
953976
&mut self,
954977
PlaceRef::new_sized_aligned(current, cg_elem.layout, align),
@@ -1026,17 +1049,25 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
10261049
.unwrap();
10271050
}
10281051

1029-
fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value {
1030-
self.gep_help(ptr, indices, false)
1052+
fn gep(&mut self, ty: Self::Type, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value {
1053+
self.gep_help(ty, ptr, indices, false)
10311054
}
10321055

1033-
fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value {
1034-
self.gep_help(ptr, indices, true)
1056+
fn inbounds_gep(
1057+
&mut self,
1058+
ty: Self::Type,
1059+
ptr: Self::Value,
1060+
indices: &[Self::Value],
1061+
) -> Self::Value {
1062+
self.gep_help(ty, ptr, indices, true)
10351063
}
10361064

1037-
fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value {
1065+
fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value {
10381066
let pointee = match self.lookup_type(ptr.ty) {
1039-
SpirvType::Pointer { pointee } => pointee,
1067+
SpirvType::Pointer { pointee } => {
1068+
assert_ty_eq!(self, ty, pointee);
1069+
pointee
1070+
}
10401071
other => self.fatal(&format!(
10411072
"struct_gep not on pointer type: {:?}, index {}",
10421073
other, idx
@@ -2087,6 +2118,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
20872118

20882119
fn call(
20892120
&mut self,
2121+
callee_ty: Self::Type,
20902122
callee: Self::Value,
20912123
args: &[Self::Value],
20922124
funclet: Option<&Self::Funclet>,
@@ -2104,15 +2136,21 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
21042136
SpirvType::Function {
21052137
return_type,
21062138
arguments,
2107-
} => (callee.def(self), return_type, arguments),
2139+
} => {
2140+
assert_ty_eq!(self, callee_ty, callee.ty);
2141+
(callee.def(self), return_type, arguments)
2142+
}
21082143

21092144
SpirvType::Pointer { pointee } => match self.lookup_type(pointee) {
21102145
SpirvType::Function {
21112146
return_type,
21122147
arguments,
21132148
} => (
21142149
match callee.kind {
2115-
SpirvValueKind::FnAddr { function } => function,
2150+
SpirvValueKind::FnAddr { function } => {
2151+
assert_ty_eq!(self, callee_ty, pointee);
2152+
function
2153+
}
21162154

21172155
// Truly indirect call.
21182156
_ => {

crates/rustc_codegen_spirv/src/builder/intrinsics.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,17 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
9999
}
100100

101101
sym::volatile_load | sym::unaligned_volatile_load => {
102-
let tp_ty = substs.type_at(0);
103-
let mut ptr = args[0].immediate();
102+
let ptr = args[0].immediate();
104103
if let PassMode::Cast(ty) = fn_abi.ret.mode {
105104
let pointee = ty.spirv_type(self.span(), self);
106105
let pointer = SpirvType::Pointer { pointee }.def(self.span(), self);
107-
ptr = self.pointercast(ptr, pointer);
106+
let ptr = self.pointercast(ptr, pointer);
107+
self.volatile_load(pointee, ptr)
108+
} else {
109+
let layout = self.layout_of(substs.type_at(0));
110+
let load = self.volatile_load(layout.spirv_type(self.span(), self), ptr);
111+
self.to_immediate(load, layout)
108112
}
109-
let load = self.volatile_load(ptr);
110-
self.to_immediate(load, self.layout_of(tp_ty))
111113
}
112114

113115
sym::prefetch_read_data

crates/rustc_codegen_spirv/src/builder/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9595

9696
pub fn gep_help(
9797
&self,
98+
ty: Word,
9899
ptr: SpirvValue,
99100
indices: &[SpirvValue],
100101
is_inbounds: bool,
@@ -105,7 +106,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
105106
// https://github.com/gpuweb/gpuweb/issues/33
106107
let mut result_indices = Vec::with_capacity(indices.len() - 1);
107108
let mut result_pointee_type = match self.lookup_type(ptr.ty) {
108-
SpirvType::Pointer { pointee } => pointee,
109+
SpirvType::Pointer { pointee } => {
110+
assert_ty_eq!(self, ty, pointee);
111+
pointee
112+
}
109113
other_type => self.fatal(&format!(
110114
"GEP first deref not implemented for type {:?}",
111115
other_type

crates/rustc_codegen_spirv/src/builder_spirv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_middle::bug;
1212
use rustc_span::symbol::Symbol;
1313
use rustc_span::{Span, DUMMY_SP};
14+
use std::assert_matches::assert_matches;
1415
use std::cell::{RefCell, RefMut};
1516
use std::rc::Rc;
1617
use std::{fs::File, io::Write, path::Path};

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
262262
}
263263
}
264264
}
265-
Scalar::Ptr(ptr) => {
266-
let (base_addr, _base_addr_space) = match self.tcx.global_alloc(ptr.alloc_id) {
265+
Scalar::Ptr(ptr, _) => {
266+
let (alloc_id, offset) = ptr.into_parts();
267+
let (base_addr, _base_addr_space) = match self.tcx.global_alloc(alloc_id) {
267268
GlobalAlloc::Memory(alloc) => {
268269
let pointee = match self.lookup_type(ty) {
269270
SpirvType::Pointer { pointee } => pointee,
@@ -286,12 +287,12 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
286287
(self.get_static(def_id), AddressSpace::DATA)
287288
}
288289
};
289-
let value = if ptr.offset.bytes() == 0 {
290+
let value = if offset.bytes() == 0 {
290291
base_addr
291292
} else {
292293
self.tcx
293294
.sess
294-
.fatal("Non-constant scalar_to_backend ptr.offset not supported")
295+
.fatal("Non-zero scalar_to_backend ptr.offset not supported")
295296
// let offset = self.constant_u64(ptr.offset.bytes());
296297
// self.gep(base_addr, once(offset))
297298
};
@@ -307,6 +308,13 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
307308
}
308309
}
309310
}
311+
// FIXME(eddyb) this shouldn't exist, and is only used by vtable creation,
312+
// see https://github.com/rust-lang/rust/pull/86475#discussion_r680792727.
313+
fn const_data_from_alloc(&self, _alloc: &Allocation) -> Self::Value {
314+
let undef = self.undef(SpirvType::Void.def(DUMMY_SP, self));
315+
self.zombie_no_span(undef.def_cx(self), "const_data_from_alloc");
316+
undef
317+
}
310318
fn from_const_alloc(
311319
&self,
312320
layout: TyAndLayout<'tcx>,

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'tcx> CodegenCx<'tcx> {
143143
);
144144
}
145145
bx.set_span(span);
146-
bx.call(entry_func, &call_args, None);
146+
bx.call(entry_func.ty, entry_func, &call_args, None);
147147
bx.ret_void();
148148

149149
let stub_fn_id = stub_fn.def_cx(self);
@@ -307,14 +307,13 @@ impl<'tcx> CodegenCx<'tcx> {
307307
let var_ptr_spirv_type;
308308
let (value_ptr, value_len) = match storage_class {
309309
StorageClass::PushConstant | StorageClass::Uniform | StorageClass::StorageBuffer => {
310-
var_ptr_spirv_type = self.type_ptr_to(
311-
SpirvType::InterfaceBlock {
312-
inner_type: value_spirv_type,
313-
}
314-
.def(hir_param.span, self),
315-
);
310+
let var_spirv_type = SpirvType::InterfaceBlock {
311+
inner_type: value_spirv_type,
312+
}
313+
.def(hir_param.span, self);
314+
var_ptr_spirv_type = self.type_ptr_to(var_spirv_type);
316315

317-
let value_ptr = bx.struct_gep(var.with_type(var_ptr_spirv_type), 0);
316+
let value_ptr = bx.struct_gep(var_spirv_type, var.with_type(var_ptr_spirv_type), 0);
318317

319318
let value_len = if is_unsized_with_len {
320319
match self.lookup_type(value_spirv_type) {
@@ -409,7 +408,11 @@ impl<'tcx> CodegenCx<'tcx> {
409408

410409
call_args.push(match entry_arg_abi.mode {
411410
PassMode::Indirect { .. } => value_ptr,
412-
PassMode::Direct(_) => bx.load(value_ptr, entry_arg_abi.layout.align.abi),
411+
PassMode::Direct(_) => bx.load(
412+
entry_arg_abi.layout.spirv_type(hir_param.ty_span, bx),
413+
value_ptr,
414+
entry_arg_abi.layout.align.abi,
415+
),
413416
_ => unreachable!(),
414417
});
415418
assert_eq!(value_len, None);

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'tcx> MiscMethods<'tcx> for CodegenCx<'tcx> {
543543
todo!()
544544
}
545545

546-
fn set_frame_pointer_elimination(&self, _llfn: Self::Function) {
546+
fn set_frame_pointer_type(&self, _llfn: Self::Function) {
547547
todo!()
548548
}
549549

crates/rustc_codegen_spirv/src/codegen_cx/type_.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ impl<'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'tcx> {
4141
ty.spirv_type(DUMMY_SP, self)
4242
}
4343

44-
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type {
44+
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type {
4545
fn_abi.spirv_type(DUMMY_SP, self)
4646
}
4747

48+
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type {
49+
self.type_ptr_to(self.fn_decl_backend_type(fn_abi))
50+
}
51+
4852
fn reg_backend_type(&self, ty: &Reg) -> Self::Type {
4953
ty.spirv_type(DUMMY_SP, self)
5054
}

crates/rustc_codegen_spirv/src/link.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ fn add_upstream_rust_crates(
367367
.iter()
368368
.find(|(ty, _)| *ty == crate_type)
369369
.expect("failed to find crate type in dependency format list");
370-
let deps = &codegen_results.crate_info.used_crates_dynamic;
371-
for &(cnum, _) in deps.iter() {
370+
for &cnum in &codegen_results.crate_info.used_crates {
372371
let src = &codegen_results.crate_info.used_crate_source[&cnum];
373372
match data[cnum.as_usize() - 1] {
374373
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
@@ -391,8 +390,7 @@ fn add_upstream_native_libraries(
391390
.find(|(ty, _)| *ty == crate_type)
392391
.expect("failed to find crate type in dependency format list");
393392

394-
let crates = &codegen_results.crate_info.used_crates_static;
395-
for &(cnum, _) in crates {
393+
for &cnum in &codegen_results.crate_info.used_crates {
396394
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
397395
let name = match lib.name {
398396
Some(l) => l,

0 commit comments

Comments
 (0)