Skip to content

Commit

Permalink
rustup: update to nightly-2021-09-29.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 29, 2021
1 parent 35172f7 commit 816c51c
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 79 deletions.
17 changes: 10 additions & 7 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorReported;
use rustc_index::vec::Idx;
use rustc_middle::bug;
use rustc_middle::ty::layout::{FnAbiExt, TyAndLayout};
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{
Const, FloatTy, GeneratorSubsts, IntTy, ParamEnv, PolyFnSig, Ty, TyKind, TypeAndMut, UintTy,
self, Const, FloatTy, GeneratorSubsts, IntTy, ParamEnv, PolyFnSig, Ty, TyKind, TypeAndMut,
UintTy,
};
use rustc_span::def_id::DefId;
use rustc_span::Span;
use rustc_span::DUMMY_SP;
use rustc_target::abi::call::{CastTarget, FnAbi, PassMode, Reg, RegKind};
use rustc_target::abi::{
Abi, Align, FieldsShape, LayoutOf, Primitive, Scalar, Size, VariantIdx, Variants,
};
use rustc_target::abi::{Abi, Align, FieldsShape, Primitive, Scalar, Size, VariantIdx, Variants};
use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::fmt;
Expand Down Expand Up @@ -150,13 +149,17 @@ impl<'tcx> ConvSpirvType<'tcx> for PointeeTy<'tcx> {
fn spirv_type(&self, span: Span, cx: &CodegenCx<'tcx>) -> Word {
match *self {
PointeeTy::Ty(ty) => ty.spirv_type(span, cx),
PointeeTy::Fn(ty) => FnAbi::of_fn_ptr(cx, ty, &[]).spirv_type(span, cx),
PointeeTy::Fn(ty) => cx
.fn_abi_of_fn_ptr(ty, ty::List::empty())
.spirv_type(span, cx),
}
}
fn spirv_type_immediate(&self, span: Span, cx: &CodegenCx<'tcx>) -> Word {
match *self {
PointeeTy::Ty(ty) => ty.spirv_type_immediate(span, cx),
PointeeTy::Fn(ty) => FnAbi::of_fn_ptr(cx, ty, &[]).spirv_type_immediate(span, cx),
PointeeTy::Fn(ty) => cx
.fn_abi_of_fn_ptr(ty, ty::List::empty())
.spirv_type_immediate(span, cx),
}
}
}
Expand Down
21 changes: 0 additions & 21 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,27 +476,13 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
intravisit::walk_variant(self, variant, generics, item_id);
}

fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
self.check_spirv_attributes(macro_def.hir_id(), Target::MacroDef);
intravisit::walk_macro_def(self, macro_def);
}

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
self.check_spirv_attributes(param.hir_id, Target::Param);

intravisit::walk_param(self, param);
}
}

fn check_invalid_macro_level_spirv_attr(tcx: TyCtxt<'_>, sym: &Symbols, attrs: &[Attribute]) {
for attr in attrs {
if attr.has_name(sym.spirv) {
tcx.sess
.span_err(attr.span, "#[spirv(..)] cannot be applied to a macro");
}
}
}

// FIXME(eddyb) DRY this somehow and make it reusable from somewhere in `rustc`.
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let check_spirv_attr_visitor = &mut CheckSpirvAttrVisitor {
Expand All @@ -507,13 +493,6 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
module_def_id,
&mut check_spirv_attr_visitor.as_deep_visitor(),
);
tcx.hir()
.visit_exported_macros_in_krate(check_spirv_attr_visitor);
check_invalid_macro_level_spirv_attr(
tcx,
&check_spirv_attr_visitor.sym,
tcx.hir().krate().non_exported_macro_attrs,
);
if module_def_id.is_top_level_module() {
check_spirv_attr_visitor.check_spirv_attributes(CRATE_HIR_ID, Target::Mod);
}
Expand Down
7 changes: 3 additions & 4 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use rustc_codegen_ssa::MemFlags;
use rustc_middle::bug;
use rustc_middle::ty::Ty;
use rustc_span::Span;
use rustc_target::abi::{Abi, Align, Scalar, Size};
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
use std::convert::TryInto;
use std::iter::{self, empty};
use std::ops::Range;

macro_rules! simple_op {
(
Expand Down Expand Up @@ -794,7 +793,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {

// silly clippy, we can't rename this!
#[allow(clippy::wrong_self_convention)]
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &Scalar) -> Self::Value {
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value {
if scalar.is_bool() {
let bool = SpirvType::Bool.def(self.span(), self);
return self.trunc(val, bool);
Expand Down Expand Up @@ -982,7 +981,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
self
}

fn range_metadata(&mut self, _load: Self::Value, _range: Range<u128>) {
fn range_metadata(&mut self, _load: Self::Value, _range: WrappingRange) {
// ignore
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use rustc_codegen_ssa::mir::operand::OperandRef;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallMethods};
use rustc_middle::bug;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{FnDef, Instance, ParamEnv, Ty, TyKind};
use rustc_span::source_map::Span;
use rustc_span::sym;
use rustc_target::abi::call::{FnAbi, PassMode};
use rustc_target::abi::LayoutOf;

fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_>) -> Option<(u64, bool)> {
match ty.kind() {
Expand Down
31 changes: 24 additions & 7 deletions crates/rustc_codegen_spirv/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ use rustc_errors::DiagnosticBuilder;
use rustc_middle::mir::coverage::{
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, Op,
};
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, TyAndLayout};
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
};
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::source_map::Span;
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout};
use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout};
use rustc_target::spec::{HasTargetSpec, Target};
use std::ops::Deref;

Expand Down Expand Up @@ -389,11 +392,25 @@ impl<'a, 'tcx> HasDataLayout for Builder<'a, 'tcx> {
}
}

impl<'a, 'tcx> LayoutOf for Builder<'a, 'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = TyAndLayout<'tcx>;
impl<'tcx> LayoutOfHelpers<'tcx> for Builder<'_, 'tcx> {
type LayoutOfResult = TyAndLayout<'tcx>;

#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
self.cx.handle_layout_err(err, span, ty)
}
}

impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, 'tcx> {
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;

fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.cx.layout_of(ty)
#[inline]
fn handle_fn_abi_err(
&self,
err: FnAbiError<'tcx>,
span: Span,
fn_abi_request: FnAbiRequest<'tcx>,
) -> ! {
self.cx.handle_fn_abi_err(err, span, fn_abi_request)
}
}
13 changes: 7 additions & 6 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use rspirv::spirv::Word;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, MiscMethods, StaticMethods};
use rustc_middle::bug;
use rustc_middle::mir::interpret::{alloc_range, Allocation, GlobalAlloc, ScalarMaybeUninit};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_mir::interpret::Scalar;
use rustc_middle::mir::interpret::{
alloc_range, Allocation, GlobalAlloc, Scalar, ScalarMaybeUninit,
};
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{self, AddressSpace, HasDataLayout, Integer, LayoutOf, Primitive, Size};
use rustc_target::abi::{self, AddressSpace, HasDataLayout, Integer, Primitive, Size};

impl<'tcx> CodegenCx<'tcx> {
pub fn constant_u8(&self, span: Span, val: u8) -> SpirvValue {
Expand Down Expand Up @@ -207,7 +208,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
fn scalar_to_backend(
&self,
scalar: Scalar,
layout: &abi::Scalar,
layout: abi::Scalar,
ty: Self::Type,
) -> Self::Value {
match scalar {
Expand Down Expand Up @@ -426,7 +427,7 @@ impl<'tcx> CodegenCx<'tcx> {
// tldr, the pointer here is only needed for the offset
let value = match alloc.read_scalar(self, alloc_range(*offset, size)).unwrap() {
ScalarMaybeUninit::Scalar(scalar) => {
self.scalar_to_backend(scalar, &self.primitive_to_scalar(primitive), ty)
self.scalar_to_backend(scalar, self.primitive_to_scalar(primitive), ty)
}
ScalarMaybeUninit::Uninit => self.undef(ty),
};
Expand Down
9 changes: 4 additions & 5 deletions crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use rustc_codegen_ssa::traits::{BaseTypeMethods, PreDefineMethods, StaticMethods
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
use rustc_middle::ty::layout::FnAbiExt;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
use rustc_middle::ty::{self, Instance, ParamEnv, TypeFoldable};
use rustc_span::def_id::DefId;
use rustc_span::Span;
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Align, LayoutOf};
use rustc_target::abi::Align;

fn attrs_to_spirv(attrs: &CodegenFnAttrs) -> FunctionControl {
let mut control = FunctionControl::NONE;
Expand Down Expand Up @@ -58,7 +57,7 @@ impl<'tcx> CodegenCx<'tcx> {
// PreDefineMethods::predefine_fn -> declare_fn_ext
fn declare_fn_ext(&self, instance: Instance<'tcx>, linkage: Option<LinkageType>) -> SpirvValue {
let control = attrs_to_spirv(self.tcx.codegen_fn_attrs(instance.def_id()));
let fn_abi = FnAbi::of_instance(self, instance, &[]);
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
let span = self.tcx.def_span(instance.def_id());
let function_type = fn_abi.spirv_type(span, self);
let (return_type, argument_types) = match self.lookup_type(function_type) {
Expand Down Expand Up @@ -116,7 +115,7 @@ impl<'tcx> CodegenCx<'tcx> {
.as_ref()
.map(ToString::to_string)
.unwrap_or_else(|| instance.to_string());
self.entry_stub(&instance, &fn_abi, declared, entry_name, entry);
self.entry_stub(&instance, fn_abi, declared, entry_name, entry);
}
if attrs.unroll_loops.is_some() {
self.unroll_loops_decorations.borrow_mut().insert(fn_id);
Expand Down
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use rspirv::spirv::{
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{Instance, Ty, TyKind};
use rustc_span::Span;
use rustc_target::abi::{
call::{ArgAbi, ArgAttribute, ArgAttributes, FnAbi, PassMode},
LayoutOf, Size,
Size,
};

impl<'tcx> CodegenCx<'tcx> {
Expand Down
70 changes: 52 additions & 18 deletions crates/rustc_codegen_spirv/src/codegen_cx/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,65 @@ use crate::spirv_type::SpirvType;
use rspirv::spirv::Word;
use rustc_codegen_ssa::common::TypeKind;
use rustc_codegen_ssa::traits::{BaseTypeMethods, LayoutTypeMethods};
use rustc_middle::bug;
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
use rustc_middle::ty::{ParamEnv, Ty};
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::Ty;
use rustc_middle::{bug, span_bug};
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
use rustc_target::abi::{Abi, AddressSpace, FieldsShape, LayoutOf};
use rustc_target::abi::{Abi, AddressSpace, FieldsShape};

impl<'tcx> LayoutOf for CodegenCx<'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = TyAndLayout<'tcx>;
impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'tcx> {
type LayoutOfResult = TyAndLayout<'tcx>;

fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.spanned_layout_of(ty, DUMMY_SP)
#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
if let LayoutError::SizeOverflow(_) = err {
self.tcx.sess.span_fatal(span, &err.to_string())
} else {
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
}
}
}

fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyAndLayout {
self.tcx
.layout_of(ParamEnv::reveal_all().and(ty))
.unwrap_or_else(|e| {
if let LayoutError::SizeOverflow(_) = e {
self.tcx.sess.span_fatal(span, &e.to_string())
} else {
bug!("failed to get layout for `{}`: {}", ty, e)
impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'tcx> {
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;

#[inline]
fn handle_fn_abi_err(
&self,
err: FnAbiError<'tcx>,
span: Span,
fn_abi_request: FnAbiRequest<'tcx>,
) -> ! {
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
self.tcx.sess.span_fatal(span, &err.to_string())
} else {
match fn_abi_request {
FnAbiRequest::OfFnPtr { sig, extra_args } => {
span_bug!(
span,
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
sig,
extra_args,
err
);
}
})
FnAbiRequest::OfInstance {
instance,
extra_args,
} => {
span_bug!(
span,
"`fn_abi_of_instance({}, {:?})` failed: {}",
instance,
extra_args,
err
);
}
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ extern crate rustc_hir;
extern crate rustc_index;
extern crate rustc_interface;
extern crate rustc_middle;
extern crate rustc_mir;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
Expand Down Expand Up @@ -171,9 +170,9 @@ use rustc_errors::{ErrorReported, FatalError, Handler};
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
use rustc_middle::mir::pretty::write_mir_pretty;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, query, DefIdTree, Instance, InstanceDef, TyCtxt};
use rustc_mir::util::write_mir_pretty;
use rustc_session::config::{self, OptLevel, OutputFilenames, OutputType};
use rustc_session::Session;
use rustc_span::symbol::{sym, Symbol};
Expand Down Expand Up @@ -500,6 +499,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
&self,
_: TyCtxt<'tcx>,
_: &mut Self::Module,
_: &str,
_: AllocatorKind,
_: bool,
) {
Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
),
register_attr(spirv)
)]
#![feature(const_generics)]
#![feature(adt_const_params)]
// BEGIN - Embark standard lints v0.4
// do not change or add/remove here, but one can add exceptions after this section
// for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
Expand Down Expand Up @@ -88,7 +88,7 @@
// We deblierately provide an unimplemented version of our API on CPU
// platforms so that code completion still works.
clippy::unimplemented,
// The part of `const-generics` we're using (C-like enums) is not incomplete.
// The part of `adt_const_params` we're using (C-like enums) is not incomplete.
incomplete_features,
)]

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".

[toolchain]
channel = "nightly-2021-08-27"
channel = "nightly-2021-09-29"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
Loading

0 comments on commit 816c51c

Please sign in to comment.