Skip to content

Commit

Permalink
Update to nightly-2023-08-29
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Aug 31, 2023
1 parent e87c324 commit fca717d
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 112 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ spirt = "0.3.0"
lazy_static = "1.4.0"
itertools = "0.10.5"

# `termcolor` is needed because we cannot construct an Emitter after it was added in
# https://github.com/rust-lang/rust/pull/114104. This can be removed when
# https://github.com/rust-lang/rust/pull/115393 lands.
# We need to construct an emitter as yet another workaround,
# see https://github.com/rust-lang/rust/pull/102992.
termcolor = "1.2"

[dev-dependencies]
pipe = "0.4"
pretty_assertions = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::process::{Command, ExitCode};
/// `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-2023-07-08"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
# commit_hash = cb80ff132a0e9aa71529b701427e4e6c243b58df"#;
channel = "nightly-2023-08-29"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 4e78abb437a0478d1f42115198ee45888e5330fd"#;

fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));
Expand Down
46 changes: 25 additions & 21 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use rustc_errors::ErrorGuaranteed;
use rustc_index::Idx;
use rustc_middle::query::{ExternProviders, Providers};
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{
self, Const, FloatTy, GeneratorSubsts, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind,
self, Const, FloatTy, GeneratorArgs, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind,
TypeAndMut, UintTy,
};
use rustc_middle::{bug, span_bug};
Expand Down Expand Up @@ -104,6 +104,8 @@ pub(crate) fn provide(providers: &mut Providers) {
largest_niche,
align,
size,
max_repr_align,
unadjusted_abi_align,
} = *layout;
LayoutS {
fields: match *fields {
Expand Down Expand Up @@ -147,6 +149,8 @@ pub(crate) fn provide(providers: &mut Providers) {
largest_niche,
align,
size,
max_repr_align,
unadjusted_abi_align,
}
}
providers.layout_of = |tcx, key| {
Expand Down Expand Up @@ -343,7 +347,7 @@ impl<'tcx> ConvSpirvType<'tcx> for FnAbi<'tcx, Ty<'tcx>> {

impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
fn spirv_type(&self, mut span: Span, cx: &CodegenCx<'tcx>) -> Word {
if let TyKind::Adt(adt, substs) = *self.ty.kind() {
if let TyKind::Adt(adt, args) = *self.ty.kind() {
if span == DUMMY_SP {
span = cx.tcx.def_span(adt.did());
}
Expand All @@ -352,7 +356,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {

if let Some(intrinsic_type_attr) = attrs.intrinsic_type.map(|attr| attr.value) {
if let Ok(spirv_type) =
trans_intrinsic_type(cx, span, *self, substs, intrinsic_type_attr)
trans_intrinsic_type(cx, span, *self, args, intrinsic_type_attr)
{
return spirv_type;
}
Expand Down Expand Up @@ -782,7 +786,7 @@ impl fmt::Display for TyLayoutNameKey<'_> {
}
}
if let (TyKind::Generator(_, _, _), Some(index)) = (self.ty.kind(), self.variant) {
write!(f, "::{}", GeneratorSubsts::variant_name(index))?;
write!(f, "::{}", GeneratorArgs::variant_name(index))?;
}
Ok(())
}
Expand All @@ -792,7 +796,7 @@ fn trans_intrinsic_type<'tcx>(
cx: &CodegenCx<'tcx>,
span: Span,
ty: TyAndLayout<'tcx>,
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
intrinsic_type_attr: IntrinsicType,
) -> Result<Word, ErrorGuaranteed> {
match intrinsic_type_attr {
Expand All @@ -817,7 +821,7 @@ fn trans_intrinsic_type<'tcx>(
// <_>::from_u64(value).unwrap()
// }

let sampled_type = match substs.type_at(0).kind() {
let sampled_type = match args.type_at(0).kind() {
TyKind::Int(int) => match int {
IntTy::Isize => {
SpirvType::Integer(cx.tcx.data_layout.pointer_size.bits() as u32, true)
Expand Down Expand Up @@ -850,13 +854,13 @@ fn trans_intrinsic_type<'tcx>(
}
};

// let dim: spirv::Dim = type_from_variant_discriminant(cx, substs.const_at(1));
// let depth: u32 = type_from_variant_discriminant(cx, substs.const_at(2));
// let arrayed: u32 = type_from_variant_discriminant(cx, substs.const_at(3));
// let multisampled: u32 = type_from_variant_discriminant(cx, substs.const_at(4));
// let sampled: u32 = type_from_variant_discriminant(cx, substs.const_at(5));
// let dim: spirv::Dim = type_from_variant_discriminant(cx, args.const_at(1));
// let depth: u32 = type_from_variant_discriminant(cx, args.const_at(2));
// let arrayed: u32 = type_from_variant_discriminant(cx, args.const_at(3));
// let multisampled: u32 = type_from_variant_discriminant(cx, args.const_at(4));
// let sampled: u32 = type_from_variant_discriminant(cx, args.const_at(5));
// let image_format: spirv::ImageFormat =
// type_from_variant_discriminant(cx, substs.const_at(6));
// type_from_variant_discriminant(cx, args.const_at(6));

fn const_int_value<'tcx, P: FromPrimitive>(
cx: &CodegenCx<'tcx>,
Expand All @@ -873,12 +877,12 @@ fn trans_intrinsic_type<'tcx>(
}
}

let dim = const_int_value(cx, substs.const_at(1))?;
let depth = const_int_value(cx, substs.const_at(2))?;
let arrayed = const_int_value(cx, substs.const_at(3))?;
let multisampled = const_int_value(cx, substs.const_at(4))?;
let sampled = const_int_value(cx, substs.const_at(5))?;
let image_format = const_int_value(cx, substs.const_at(6))?;
let dim = const_int_value(cx, args.const_at(1))?;
let depth = const_int_value(cx, args.const_at(2))?;
let arrayed = const_int_value(cx, args.const_at(3))?;
let multisampled = const_int_value(cx, args.const_at(4))?;
let sampled = const_int_value(cx, args.const_at(5))?;
let image_format = const_int_value(cx, args.const_at(6))?;

let ty = SpirvType::Image {
sampled_type,
Expand Down Expand Up @@ -913,7 +917,7 @@ fn trans_intrinsic_type<'tcx>(

// We use a generic to indicate the underlying image type of the sampled image.
// The spirv type of it will be generated by querying the type of the first generic.
if let Some(image_ty) = substs.types().next() {
if let Some(image_ty) = args.types().next() {
// TODO: enforce that the generic param is an image type?
let image_type = cx.layout_of(image_ty).spirv_type(span, cx);
Ok(SpirvType::SampledImage { image_type }.def(span, cx))
Expand All @@ -934,7 +938,7 @@ fn trans_intrinsic_type<'tcx>(

// We use a generic to indicate the underlying element type.
// The spirv type of it will be generated by querying the type of the first generic.
if let Some(elem_ty) = substs.types().next() {
if let Some(elem_ty) = args.types().next() {
let element = cx.layout_of(elem_ty).spirv_type(span, cx);
Ok(SpirvType::RuntimeArray { element }.def(span, cx))
} else {
Expand Down
10 changes: 5 additions & 5 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::Attribute;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{HirId, MethodKind, Target, CRATE_HIR_ID};
use rustc_middle::hir::nested_filter;
Expand Down Expand Up @@ -484,7 +484,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: LocalDefId) {
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
let check_spirv_attr_visitor = &mut CheckSpirvAttrVisitor {
tcx,
sym: Symbols::get(),
Expand All @@ -498,10 +498,10 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {

pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
check_mod_attrs: |tcx, def_id| {
check_mod_attrs: |tcx, module_def_id| {
// Run both the default checks, and our `#[spirv(...)]` ones.
(rustc_interface::DEFAULT_QUERY_PROVIDERS.check_mod_attrs)(tcx, def_id);
check_mod_attrs(tcx, def_id);
(rustc_interface::DEFAULT_QUERY_PROVIDERS.check_mod_attrs)(tcx, module_def_id);
check_mod_attrs(tcx, module_def_id);
},
..*providers
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::Builder;
use crate::builder_spirv::{SpirvValue, SpirvValueExt, SpirvValueKind};
use crate::spirv_type::SpirvType;
use rspirv::spirv::Word;
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
use rustc_codegen_ssa::traits::BuilderMethods;
use rustc_errors::ErrorGuaranteed;
use rustc_span::DUMMY_SP;
use rustc_target::abi::call::PassMode;
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
) {
let callee_ty = instance.ty(self.tcx, ParamEnv::reveal_all());

let (def_id, substs) = match *callee_ty.kind() {
FnDef(def_id, substs) => (def_id, substs),
let (def_id, fn_args) = match *callee_ty.kind() {
FnDef(def_id, fn_args) => (def_id, fn_args),
_ => bug!("expected fn item type, found {}", callee_ty),
};

Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {

sym::volatile_load | sym::unaligned_volatile_load => {
let ptr = args[0].immediate();
let layout = self.layout_of(substs.type_at(0));
let layout = self.layout_of(fn_args.type_at(0));
let load = self.volatile_load(layout.spirv_type(self.span(), self), ptr);
self.to_immediate(load, layout)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
/// `leftover_operands` is used for `IndexComposite` patterns, if any exist.
/// If the pattern isn't constraining enough to determine an unique type,
/// `Err(Ambiguous)` is returned instead.
fn subst_ty_pat(
fn arg_ty_pat(
cx: &CodegenCx<'_>,
pat: &TyPat<'_>,
ty_vars: &[Option<Word>],
Expand All @@ -673,23 +673,23 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
},

TyPat::Pointer(_, pat) => SpirvType::Pointer {
pointee: subst_ty_pat(cx, pat, ty_vars, leftover_operands)?,
pointee: arg_ty_pat(cx, pat, ty_vars, leftover_operands)?,
}
.def(DUMMY_SP, cx),

TyPat::Vector4(pat) => SpirvType::Vector {
element: subst_ty_pat(cx, pat, ty_vars, leftover_operands)?,
element: arg_ty_pat(cx, pat, ty_vars, leftover_operands)?,
count: 4,
}
.def(DUMMY_SP, cx),

TyPat::SampledImage(pat) => SpirvType::SampledImage {
image_type: subst_ty_pat(cx, pat, ty_vars, leftover_operands)?,
image_type: arg_ty_pat(cx, pat, ty_vars, leftover_operands)?,
}
.def(DUMMY_SP, cx),

TyPat::IndexComposite(pat) => {
let mut ty = subst_ty_pat(cx, pat, ty_vars, leftover_operands)?;
let mut ty =arg_ty_pat(cx, pat, ty_vars, leftover_operands)?;
for index in leftover_operands {
let index_to_usize = || match *index {
// FIXME(eddyb) support more than just literals,
Expand Down Expand Up @@ -780,7 +780,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
_ => return None,
}

match subst_ty_pat(
match arg_ty_pat(
self,
sig.output_type.unwrap(),
&combined_ty_vars,
Expand Down
14 changes: 1 addition & 13 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::abi::ConvSpirvType;
use crate::builder_spirv::{SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
use crate::spirv_type::SpirvType;
use rspirv::spirv::Word;
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, MiscMethods, StaticMethods};
use rustc_codegen_ssa::traits::{ConstMethods, MiscMethods, StaticMethods};
use rustc_middle::bug;
use rustc_middle::mir::interpret::{alloc_range, ConstAllocation, GlobalAlloc, Scalar};
use rustc_middle::ty::layout::LayoutOf;
Expand Down Expand Up @@ -361,18 +361,6 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
self.def_constant(void_type, SpirvConst::ConstDataFromAlloc(alloc))
}

// FIXME(eddyb) is this just redundant with `const_bitcast`?!
fn const_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value {
if val.ty == ty {
val
} else {
// FIXME(eddyb) implement via `OpSpecConstantOp`.
// FIXME(eddyb) this zombies the original value without creating a new one.
let result = val.def_cx(self).with_type(ty);
self.zombie_no_span(result.def_cx(self), "const_ptrcast");
result
}
}
fn const_bitcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value {
// HACK(eddyb) special-case `const_data_from_alloc` + `static_addr_of`
// as the old `from_const_alloc` (now `OperandRef::from_const_alloc`).
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::spirv_type::SpirvType;
use itertools::Itertools;
use rspirv::spirv::{FunctionControl, LinkageType, StorageClass, Word};
use rustc_attr::InlineAttr;
use rustc_codegen_ssa::traits::{BaseTypeMethods, PreDefineMethods, StaticMethods};
use rustc_codegen_ssa::traits::{PreDefineMethods, StaticMethods};
use rustc_hir::def::DefKind;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
Expand Down Expand Up @@ -37,8 +37,8 @@ fn attrs_to_spirv(attrs: &CodegenFnAttrs) -> FunctionControl {
impl<'tcx> CodegenCx<'tcx> {
/// Returns a function if it already exists, or declares a header if it doesn't.
pub fn get_fn_ext(&self, instance: Instance<'tcx>) -> SpirvValue {
assert!(!instance.substs.has_infer());
assert!(!instance.substs.has_escaping_bound_vars());
assert!(!instance.args.has_infer());
assert!(!instance.args.has_escaping_bound_vars());

if let Some(&func) = self.instances.borrow().get(&instance) {
return func;
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'tcx> CodegenCx<'tcx> {
})
});
if let Some(spec) = spec {
if let Some((ty,)) = instance.substs.types().collect_tuple() {
if let Some((ty,)) = instance.args.types().collect_tuple() {
self.fmt_rt_arg_new_fn_ids_to_ty_and_spec
.borrow_mut()
.insert(fn_id, (ty, spec));
Expand Down
10 changes: 9 additions & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_span::{SourceFile, Span, DUMMY_SP};
use rustc_target::abi::call::{FnAbi, PassMode};
use rustc_target::abi::{HasDataLayout, TargetDataLayout};
use rustc_target::abi::{AddressSpace, HasDataLayout, TargetDataLayout};
use rustc_target::spec::{HasTargetSpec, Target};
use std::cell::RefCell;
use std::collections::BTreeSet;
Expand Down Expand Up @@ -162,6 +162,14 @@ impl<'tcx> CodegenCx<'tcx> {
self.lookup_type(ty).debug(ty, self)
}

pub fn type_ptr_to(&self, ty: Word) -> Word {
SpirvType::Pointer { pointee: ty }.def(DUMMY_SP, self)
}

pub fn type_ptr_to_ext(&self, ty: Word, _address_space: AddressSpace) -> Word {
SpirvType::Pointer { pointee: ty }.def(DUMMY_SP, self)
}

/// Zombie system:
///
/// If something unrepresentable is encountered, we don't want to fail
Expand Down
10 changes: 5 additions & 5 deletions crates/rustc_codegen_spirv/src/codegen_cx/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
align,
size,
field_types: els,
field_offsets: &field_offsets,
field_offsets: &field_offsets.as_slice(),
field_names: None,
}
.def(DUMMY_SP, self)
Expand Down Expand Up @@ -230,11 +230,11 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
=> TypeKind::Token,
}
}
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type {
SpirvType::Pointer { pointee: ty }.def(DUMMY_SP, self)
fn type_ptr(&self) -> Self::Type {
self.type_ptr_to(SpirvType::Void.def(DUMMY_SP, self))
}
fn type_ptr_to_ext(&self, ty: Self::Type, _address_space: AddressSpace) -> Self::Type {
SpirvType::Pointer { pointee: ty }.def(DUMMY_SP, self)
fn type_ptr_ext(&self, address_space: AddressSpace) -> Self::Type {
self.type_ptr_to_ext(SpirvType::Void.def(DUMMY_SP, self), address_space)
}
fn element_type(&self, ty: Self::Type) -> Self::Type {
match self.lookup_type(ty) {
Expand Down
Loading

0 comments on commit fca717d

Please sign in to comment.