From cf52d51199bbd365800092d46c167019caa15642 Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Tue, 10 Nov 2020 09:16:25 +0100 Subject: [PATCH] Add changes to compile rust-gpu on the latest nightly (#212) * Update DILocation and update trait impls for nightly * rustc_codegen_spirv: Update mir Scalar handling to nightly 2020-11-04 https://github.com/rust-lang/rust/commit/3a7970848cf3b525e94357fc9b01053b1ad15bcd https://github.com/rust-lang/rust/commit/df4d717d0b150375057bd067356a4c7fe3c27551 * More changes to compile on the latest nightly * Remove unused import warnings Co-authored-by: Marijn Suijten --- crates/rustc_codegen_spirv/src/builder/mod.rs | 38 +++++++++---------- .../src/codegen_cx/constant.rs | 36 ++++++++++-------- .../rustc_codegen_spirv/src/codegen_cx/mod.rs | 22 ++++++++--- crates/rustc_codegen_spirv/src/lib.rs | 16 +++----- crates/spirv-builder/src/test/mod.rs | 1 + crates/spirv-tools/src/opt/compiled.rs | 2 +- examples/runners/ash/src/main.rs | 6 +-- rust-toolchain | 2 +- 8 files changed, 68 insertions(+), 55 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/builder/mod.rs b/crates/rustc_codegen_spirv/src/builder/mod.rs index b41fe009b4..e115966fd3 100644 --- a/crates/rustc_codegen_spirv/src/builder/mod.rs +++ b/crates/rustc_codegen_spirv/src/builder/mod.rs @@ -20,7 +20,7 @@ use rustc_codegen_ssa::traits::{ use rustc_errors::DiagnosticBuilder; use rustc_hir::LlvmInlineAsmInner; use rustc_middle::mir::coverage::{ - CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionIndex, Op, + CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, Op, }; use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, TyAndLayout}; use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt}; @@ -214,29 +214,29 @@ impl<'a, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'tcx> { todo!() } - fn add_counter_region( + fn set_function_source_hash(&mut self, _: rustc_middle::ty::Instance<'tcx>, _: u64) -> bool { + todo!() + } + fn add_coverage_counter( &mut self, - _instance: Instance<'tcx>, - _function_source_hash: u64, - _id: CounterValueReference, - _region: CodeRegion, + _: Instance<'tcx>, + _: CounterValueReference, + _: CodeRegion, ) -> bool { todo!() } - - fn add_counter_expression_region( + fn add_coverage_counter_expression( &mut self, - _instance: Instance<'tcx>, - _id: InjectedExpressionIndex, - _lhs: ExpressionOperandId, - _op: Op, - _rhs: ExpressionOperandId, - _region: CodeRegion, + _: Instance<'tcx>, + _: InjectedExpressionId, + _: ExpressionOperandId, + _: Op, + _: ExpressionOperandId, + _: Option, ) -> bool { todo!() } - - fn add_unreachable_region(&mut self, _instance: Instance<'tcx>, _region: CodeRegion) -> bool { + fn add_coverage_unreachable(&mut self, _: Instance<'tcx>, _: CodeRegion) -> bool { todo!() } } @@ -245,17 +245,16 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> { fn dbg_var_addr( &mut self, _dbg_var: Self::DIVariable, - _scope_metadata: Self::DIScope, + _scope_metadata: Self::DILocation, _variable_alloca: Self::Value, _direct_offset: Size, // NB: each offset implies a deref (i.e. they're steps in a pointer chain). _indirect_offsets: &[Size], - _span: Span, ) { todo!() } - fn set_source_location(&mut self, _scope: Self::DIScope, _span: Span) { + fn set_dbg_loc(&mut self, _: Self::DILocation) { todo!() } @@ -375,6 +374,7 @@ impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> { type DIScope = as BackendTypes>::DIScope; type DIVariable = as BackendTypes>::DIVariable; + type DILocation = as BackendTypes>::DILocation; } impl<'a, 'tcx> HasCodegen<'tcx> for Builder<'a, 'tcx> { diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index 06d682e9e4..5f4dc863e9 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -208,10 +208,12 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { ty: Self::Type, ) -> Self::Value { match scalar { - Scalar::Raw { data, size } => match layout.value { - Primitive::Int(int_size, int_signedness) => { - assert_eq!(size as u64, int_size.size().bytes()); - match self.lookup_type(ty) { + Scalar::Int(int) => { + assert_eq!(int.size(), layout.value.size(&self.tcx)); + let data = int.to_bits(int.size()).unwrap(); + + match layout.value { + Primitive::Int(int_size, int_signedness) => match self.lookup_type(ty) { SpirvType::Integer(width, spirv_signedness) => { assert_eq!(width as u64, int_size.size().bits()); if !self.kernel_mode { @@ -231,20 +233,22 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { "scalar_to_backend Primitive::Int not supported on type {}", other.debug(ty, self) )), + }, + Primitive::F32 => { + let res = self.constant_f32(f32::from_bits(data as u32)); + assert_eq!(res.ty, ty); + res + } + Primitive::F64 => { + let res = self.constant_f64(f64::from_bits(data as u64)); + assert_eq!(res.ty, ty); + res + } + Primitive::Pointer => { + bug!("scalar_to_backend Primitive::Ptr is an invalid state") } } - Primitive::F32 => { - let res = self.constant_f32(f32::from_bits(data as u32)); - assert_eq!(res.ty, ty); - res - } - Primitive::F64 => { - let res = self.constant_f64(f64::from_bits(data as u64)); - assert_eq!(res.ty, ty); - res - } - Primitive::Pointer => bug!("scalar_to_backend Primitive::Ptr is an invalid state"), - }, + } Scalar::Ptr(ptr) => { let (base_addr, _base_addr_space) = match self.tcx.global_alloc(ptr.alloc_id) { GlobalAlloc::Memory(alloc) => { diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index 056eeb715a..37b17f7d6f 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -20,9 +20,9 @@ use rustc_hir::GlobalAsm; use rustc_middle::mir::mono::CodegenUnit; use rustc_middle::mir::Body; use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt}; -use rustc_middle::ty::{Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; +use rustc_middle::ty::{Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt, TyS}; use rustc_session::Session; -use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; +use rustc_span::def_id::LOCAL_CRATE; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol}; use rustc_span::SourceFile; @@ -240,6 +240,7 @@ impl<'tcx> BackendTypes for CodegenCx<'tcx> { type Funclet = (); type DIScope = (); + type DILocation = (); type DIVariable = (); } @@ -326,13 +327,26 @@ impl<'tcx> DebugInfoMethods<'tcx> for CodegenCx<'tcx> { // Ignore. } + fn dbg_scope_fn( + &self, + _: rustc_middle::ty::Instance<'tcx>, + _: &FnAbi<'tcx, &'tcx TyS<'tcx>>, + _: Option, + ) -> Self::DIScope { + todo!() + } + + fn dbg_loc(&self, _: Self::DIScope, _: Option, _: Span) -> Self::DILocation { + todo!() + } + fn create_function_debug_context( &self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _llfn: Self::Function, _mir: &Body<'_>, - ) -> Option> { + ) -> Option> { // TODO: This is ignored. Do we want to implement this at some point? None } @@ -341,7 +355,6 @@ impl<'tcx> DebugInfoMethods<'tcx> for CodegenCx<'tcx> { &self, _scope_metadata: Self::DIScope, _file: &SourceFile, - _defining_crate: CrateNum, ) -> Self::DIScope { todo!() } @@ -352,7 +365,6 @@ impl<'tcx> DebugInfoMethods<'tcx> for CodegenCx<'tcx> { fn create_dbg_var( &self, - _dbg_context: &FunctionDebugContext, _variable_name: Symbol, _variable_type: Ty<'tcx>, _scope_metadata: Self::DIScope, diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index 8abce73f7a..f431a80dc8 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -151,23 +151,19 @@ fn is_blocklisted_fn(symbol_name: &str) -> bool { fn target_options() -> Target { Target { llvm_target: "no-llvm".to_string(), - target_endian: "little".to_string(), pointer_width: 32, - target_c_int_width: "32".to_string(), - target_os: "unknown".to_string(), - target_env: String::new(), - target_vendor: "unknown".to_string(), data_layout: "e-m:e-p:32:32:32-i64:64-n8:16:32:64".to_string(), arch: "spirv".to_string(), - linker_flavor: LinkerFlavor::Ld, options: TargetOptions { + allows_weak_linkage: false, + crt_static_allows_dylibs: true, dll_prefix: "".to_string(), dll_suffix: ".spv".to_string(), - panic_strategy: PanicStrategy::Abort, - emit_debug_gdb_scripts: false, - allows_weak_linkage: false, dynamic_linking: true, - crt_static_allows_dylibs: true, + emit_debug_gdb_scripts: false, + linker_flavor: LinkerFlavor::Ld, + panic_strategy: PanicStrategy::Abort, + target_os: "unknown".to_string(), // TODO: Investigate if main_needs_argc_argv is useful (for building exes) main_needs_argc_argv: false, ..Default::default() diff --git a/crates/spirv-builder/src/test/mod.rs b/crates/spirv-builder/src/test/mod.rs index 2b25871631..efda7f293f 100644 --- a/crates/spirv-builder/src/test/mod.rs +++ b/crates/spirv-builder/src/test/mod.rs @@ -52,6 +52,7 @@ static SRC_PREFIX: &str = r#"#![no_std] #![feature(lang_items, register_attr)] #![register_attr(spirv)] use core::panic::PanicInfo; +#[allow(unused_imports)] use spirv_std::*; #[panic_handler] fn panic(_: &PanicInfo) -> ! { diff --git a/crates/spirv-tools/src/opt/compiled.rs b/crates/spirv-tools/src/opt/compiled.rs index a6aadbd1fe..3cae361ef6 100644 --- a/crates/spirv-tools/src/opt/compiled.rs +++ b/crates/spirv-tools/src/opt/compiled.rs @@ -80,7 +80,7 @@ impl Optimizer for CompiledOptimizer { ctx: *mut std::ffi::c_void, ) { unsafe { - let ctx: &mut Ctx<'_> = &mut *(ctx as *mut Ctx); + let ctx: &mut Ctx<'_> = &mut *(ctx as *mut Ctx<'_>); let msg = error::Message::from_parts(level, source, source_pos, msg); diff --git a/examples/runners/ash/src/main.rs b/examples/runners/ash/src/main.rs index cfd45a0ac8..0dd10c7e83 100644 --- a/examples/runners/ash/src/main.rs +++ b/examples/runners/ash/src/main.rs @@ -9,7 +9,7 @@ use ash::extensions::ext::DebugUtils; use ash::extensions::khr::{Surface, Swapchain}; use ash::util::*; use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0}; -use ash::{vk, Device, Entry, Instance}; +use ash::{vk, Device, Instance}; use std::borrow::Cow; use std::default::Default; use std::ffi::{CStr, CString}; @@ -159,7 +159,7 @@ pub struct ExampleBase { #[cfg(target_os = "macos")] pub entry: ash_molten::MoltenEntry, #[cfg(not(target_os = "macos"))] - pub entry: Entry, + pub entry: ash::Entry, pub instance: Instance, pub device: Device, pub surface_loader: Surface, @@ -240,7 +240,7 @@ impl ExampleBase { if #[cfg(target_os = "macos")] { let entry = ash_molten::MoltenEntry::load().unwrap(); } else { - let entry = Entry::new().unwrap(); + let entry = ash::Entry::new().unwrap(); } } diff --git a/rust-toolchain b/rust-toolchain index 148ed93dbc..05ae6e228a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-10-25 +nightly-2020-11-09