From 4de5d372aab05f2c893ef83d08884e1ccfa72475 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 22 Nov 2023 09:22:39 +1100 Subject: [PATCH 01/36] Avoid need for `{D,Subd}iagnosticMessage` imports. The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8c7bae0c8866d..dcf7a4124c279 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,7 @@ use rustc_codegen_ssa::target_features::supported_target_features; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::IntoDynSyncSend; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods}; -use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, SubdiagnosticMessage}; +use rustc_errors::{ErrorGuaranteed, Handler}; use rustc_fluent_macro::fluent_messages; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; From 8e13be084a316883b4aadabbc9ff08aaaf676aa6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 22 Nov 2023 09:53:07 +1100 Subject: [PATCH 02/36] Use `rustc_fluent_macro::fluent_messages!` directly. Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter. --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dcf7a4124c279..d54057615d2d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,7 +102,6 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::IntoDynSyncSend; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods}; use rustc_errors::{ErrorGuaranteed, Handler}; -use rustc_fluent_macro::fluent_messages; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::util::Providers; @@ -116,7 +115,7 @@ use tempfile::TempDir; use crate::back::lto::ModuleBuffer; use crate::gcc_util::target_cpu; -fluent_messages! { "../messages.ftl" } +rustc_fluent_macro::fluent_messages! { "../messages.ftl" } pub struct PrintOnPanic String>(pub F); From f9a228df48f24f6596aeac5373efe9ee78e7f037 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 4 Dec 2023 08:43:18 +1100 Subject: [PATCH 03/36] Rename some arguments. `sess` is a terribly misleading name for a `Handler`! This confused me for a bit. --- src/errors.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 4bf3b71f503d6..5fc4b12d7e699 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -111,8 +111,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = sess.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); + fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.set_span(span); }; From 2baa073fb1dc1a3556d174b58e5bc94b28682119 Mon Sep 17 00:00:00 2001 From: quininer Date: Mon, 13 Nov 2023 20:48:23 +0800 Subject: [PATCH 04/36] Add emulated TLS support Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. --- src/context.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/context.rs b/src/context.rs index a043660ea632b..893cad0516182 100644 --- a/src/context.rs +++ b/src/context.rs @@ -569,5 +569,6 @@ fn to_gcc_tls_mode(tls_model: TlsModel) -> gccjit::TlsModel { TlsModel::LocalDynamic => gccjit::TlsModel::LocalDynamic, TlsModel::InitialExec => gccjit::TlsModel::InitialExec, TlsModel::LocalExec => gccjit::TlsModel::LocalExec, + TlsModel::Emulated => gccjit::TlsModel::GlobalDynamic, } } From 19e11760ab8c2694875f4fdbeb4063706ceae009 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 7 Dec 2023 14:59:37 +0100 Subject: [PATCH 05/36] Update rustc_codegen_gcc libc --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c18633692783..ddfce5d59bde8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,9 +120,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" From 3cfff05ac7c880e24c4e89f4e9518e8715d2ef29 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 7 Dec 2023 15:25:46 +0100 Subject: [PATCH 06/36] Allow internal_features in rustc_codegen_gcc examples --- example/std_example.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/example/std_example.rs b/example/std_example.rs index 0f6325c8980e7..ad69409eb6590 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -1,3 +1,4 @@ +#![allow(internal_features)] #![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted)] #[cfg(feature="master")] From cb32ffd8da5831c7052362fa58d27b36558b3b78 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 25 Nov 2023 18:41:53 +0100 Subject: [PATCH 07/36] ctfe interpreter: extend provenance so that it can track whether a pointer is immutable --- src/common.rs | 3 ++- src/consts.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common.rs b/src/common.rs index 93fe27e547aef..b7ddc410315c3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -199,7 +199,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } } Scalar::Ptr(ptr, _size) => { - let (alloc_id, offset) = ptr.into_parts(); + let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative + let alloc_id = prov.alloc_id(); let base_addr = match self.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { diff --git a/src/consts.rs b/src/consts.rs index d8a1fd315c0a5..f06416b9bb5fe 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -285,7 +285,8 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl let pointer_size = dl.pointer_size.bytes() as usize; let mut next_offset = 0; - for &(offset, alloc_id) in alloc.provenance().ptrs().iter() { + for &(offset, prov) in alloc.provenance().ptrs().iter() { + let alloc_id = prov.alloc_id(); let offset = offset.bytes(); assert_eq!(offset as usize as u64, offset); let offset = offset as usize; @@ -313,7 +314,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl llvals.push(cx.scalar_to_backend( InterpScalar::from_pointer( - interpret::Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), + interpret::Pointer::new(prov, Size::from_bytes(ptr_offset)), &cx.tcx, ), abi::Scalar::Initialized { value: Primitive::Pointer(address_space), valid_range: WrappingRange::full(dl.pointer_size) }, From 92de9d4210a7e81fd8db558c54367026a68bec62 Mon Sep 17 00:00:00 2001 From: r0cky Date: Mon, 11 Dec 2023 23:12:49 +0800 Subject: [PATCH 08/36] Remove dead codes --- src/common.rs | 11 ----------- src/context.rs | 6 ------ 2 files changed, 17 deletions(-) diff --git a/src/common.rs b/src/common.rs index b7ddc410315c3..c6edd52d1e416 100644 --- a/src/common.rs +++ b/src/common.rs @@ -377,9 +377,6 @@ pub trait TypeReflection<'gcc, 'tcx> { fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool; fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool; - fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool; - fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool; - fn is_vector(&self) -> bool; } @@ -464,14 +461,6 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> { self.unqualified() == cx.u128_type.unqualified() } - fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.context.new_type::() - } - - fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool { - self.unqualified() == cx.context.new_type::() - } - fn is_vector(&self) -> bool { let mut typ = self.clone(); loop { diff --git a/src/context.rs b/src/context.rs index 893cad0516182..ab9c703db37da 100644 --- a/src/context.rs +++ b/src/context.rs @@ -22,12 +22,6 @@ use rustc_target::spec::{HasTargetSpec, Target, TlsModel}; use crate::callee::get_fn; use crate::common::SignType; -#[derive(Clone)] -pub struct FuncSig<'gcc> { - pub params: Vec>, - pub return_type: Type<'gcc>, -} - pub struct CodegenCx<'gcc, 'tcx> { pub check_overflow: bool, pub codegen_unit: &'tcx CodegenUnit<'tcx>, From a72e20d77378420af6c02daebb9c6b1f3fe9757a Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 11 Dec 2023 18:48:49 +0100 Subject: [PATCH 09/36] Fix rustc codegen gcc tests --- example/mini_core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 3432852034325..db94bc1c86af9 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -4,7 +4,7 @@ thread_local )] #![no_core] -#![allow(dead_code, internal_features)] +#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)] #[no_mangle] unsafe extern "C" fn _Unwind_Resume() { From e1f039f5628f665dead2c9a13b4c32ffe92336ac Mon Sep 17 00:00:00 2001 From: Lukasz Anforowicz Date: Wed, 13 Dec 2023 21:14:18 +0000 Subject: [PATCH 10/36] Add unstable `-Zdefault-hidden-visibility` cmdline flag for `rustc`. The new flag has been described in the Major Change Proposal at https://github.com/rust-lang/compiler-team/issues/656 --- src/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index c8c098e2973f0..7c7044830f3d4 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -90,7 +90,7 @@ fn create_wrapper_function( .collect(); let func = context.new_function(None, FunctionType::Exported, output.unwrap_or(void), &args, from_name, false); - if tcx.sess.target.options.default_hidden_visibility { + if tcx.sess.default_hidden_visibility() { #[cfg(feature="master")] func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden)); } From b1affb9321442f378ee06fbaf0ebdc3317e5c9fe Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 12 Dec 2023 21:47:20 +0100 Subject: [PATCH 11/36] Move rustc_codegen_ssa target features to rustc_target --- src/gcc_util.rs | 8 +++----- src/lib.rs | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/gcc_util.rs b/src/gcc_util.rs index 1248fdcd2599c..2aa84f26797c3 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -2,12 +2,10 @@ use gccjit::Context; use smallvec::{smallvec, SmallVec}; -use rustc_codegen_ssa::target_features::{ - supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES, -}; use rustc_data_structures::fx::FxHashMap; use rustc_middle::bug; use rustc_session::Session; +use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES; use crate::errors::{PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature, UnknownCTargetFeaturePrefix}; @@ -44,7 +42,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> // Given a map from target_features to whether they are enabled or disabled, // ensure only valid combinations are allowed. pub fn check_tied_features(sess: &Session, features: &FxHashMap<&str, bool>) -> Option<&'static [&'static str]> { - for tied in tied_target_features(sess) { + for tied in sess.target.tied_target_features() { // Tied features must be set to the same value, or not set at all let mut tied_iter = tied.iter(); let enabled = features.get(tied_iter.next().unwrap()); diff --git a/src/lib.rs b/src/lib.rs index d54057615d2d8..0ececc5dda0a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,6 @@ use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen}; use rustc_codegen_ssa::base::codegen_crate; use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn}; use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule}; -use rustc_codegen_ssa::target_features::supported_target_features; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::IntoDynSyncSend; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods}; @@ -397,7 +396,9 @@ fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { } pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &LockedTargetInfo) -> Vec { - supported_target_features(sess) + sess + .target + .supported_target_features() .iter() .filter_map( |&(feature, gate)| { From 590e0d9573bcde7637b9c0a00c96a6e18d887b70 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 17 Dec 2023 21:48:57 +1100 Subject: [PATCH 12/36] Rename `Handler` as `DiagCtxt`. --- src/back/lto.rs | 6 +++--- src/back/write.rs | 6 +++--- src/errors.rs | 5 +++-- src/lib.rs | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/back/lto.rs b/src/back/lto.rs index 529454b119e86..289b93fab876a 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -30,7 +30,7 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput}; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind}; use rustc_data_structures::memmap::Mmap; -use rustc_errors::{FatalError, Handler}; +use rustc_errors::{FatalError, DiagCtxt}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; @@ -61,7 +61,7 @@ struct LtoData { tmp_path: TempDir, } -fn prepare_lto(cgcx: &CodegenContext, diag_handler: &Handler) -> Result { +fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt) -> Result { let export_threshold = match cgcx.lto { // We're just doing LTO for our one crate Lto::ThinLocal => SymbolExportLevel::Rust, @@ -192,7 +192,7 @@ pub(crate) fn run_fat( ) } -fn fat_lto(cgcx: &CodegenContext, _diag_handler: &Handler, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, +fn fat_lto(cgcx: &CodegenContext, _diag_handler: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, //symbols_below_threshold: &[*const libc::c_char], ) -> Result, FatalError> { let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module"); diff --git a/src/back/write.rs b/src/back/write.rs index 04772d7707abd..c2438d7ca36fd 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -4,7 +4,7 @@ use gccjit::OutputKind; use rustc_codegen_ssa::{CompiledModule, ModuleCodegen}; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig}; -use rustc_errors::Handler; +use rustc_errors::DiagCtxt; use rustc_fs_util::link_or_copy; use rustc_session::config::OutputType; use rustc_span::fatal_error::FatalError; @@ -13,7 +13,7 @@ use rustc_target::spec::SplitDebuginfo; use crate::{GccCodegenBackend, GccContext}; use crate::errors::CopyBitcode; -pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &Handler, module: ModuleCodegen, config: &ModuleConfig) -> Result { +pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name); { let context = &module.module_llvm.context; @@ -148,7 +148,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_hand )) } -pub(crate) fn link(_cgcx: &CodegenContext, _diag_handler: &Handler, mut _modules: Vec>) -> Result, FatalError> { +pub(crate) fn link(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, mut _modules: Vec>) -> Result, FatalError> { unimplemented!(); } diff --git a/src/errors.rs b/src/errors.rs index 5fc4b12d7e699..0261d5cd59044 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,6 @@ use rustc_errors::{ - DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, IntoDiagnosticArg, + DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, + IntoDiagnosticArg, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -111,7 +112,7 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.set_span(span); diff --git a/src/lib.rs b/src/lib.rs index 0ececc5dda0a9..cbe03f4051ed3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,7 +100,7 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::IntoDynSyncSend; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods}; -use rustc_errors::{ErrorGuaranteed, Handler}; +use rustc_errors::{ErrorGuaranteed, DiagCtxt}; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::util::Providers; @@ -330,7 +330,7 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!() } - unsafe fn optimize(_cgcx: &CodegenContext, _diag_handler: &Handler, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { + unsafe fn optimize(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level)); Ok(()) } @@ -344,7 +344,7 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &Handler, module: ModuleCodegen, config: &ModuleConfig) -> Result { + unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { back::write::codegen(cgcx, diag_handler, module, config) } @@ -356,7 +356,7 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - fn run_link(cgcx: &CodegenContext, diag_handler: &Handler, modules: Vec>) -> Result, FatalError> { + fn run_link(cgcx: &CodegenContext, diag_handler: &DiagCtxt, modules: Vec>) -> Result, FatalError> { back::write::link(cgcx, diag_handler, modules) } } From a5c63ae13b8e5f37bb5e58ce44fd6d3a6fb503e1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 08:43:59 +1100 Subject: [PATCH 13/36] Rename `CodegenContext::create_diag_handler` as `CodegenContext::create_dcx`. --- src/back/lto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/back/lto.rs b/src/back/lto.rs index 289b93fab876a..ee8da7c6cb736 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -183,7 +183,7 @@ pub(crate) fn run_fat( modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, ) -> Result, FatalError> { - let diag_handler = cgcx.create_diag_handler(); + let diag_handler = cgcx.create_dcx(); let lto_data = prepare_lto(cgcx, &diag_handler)?; /*let symbols_below_threshold = lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::>();*/ From 5ea71c1150a7ef7a35be240c0e0d40525a94afe0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 10:15:45 +1100 Subject: [PATCH 14/36] Rename many `DiagCtxt` arguments. --- src/back/lto.rs | 20 ++++++++++---------- src/back/write.rs | 8 ++++---- src/errors.rs | 4 ++-- src/lib.rs | 10 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/back/lto.rs b/src/back/lto.rs index ee8da7c6cb736..c21b768682399 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -61,7 +61,7 @@ struct LtoData { tmp_path: TempDir, } -fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt) -> Result { +fn prepare_lto(cgcx: &CodegenContext, dcx: &DiagCtxt) -> Result { let export_threshold = match cgcx.lto { // We're just doing LTO for our one crate Lto::ThinLocal => SymbolExportLevel::Rust, @@ -106,18 +106,18 @@ fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt // Make sure we actually can run LTO for crate_type in cgcx.crate_types.iter() { if !crate_type_allows_lto(*crate_type) { - diag_handler.emit_err(LtoDisallowed); + dcx.emit_err(LtoDisallowed); return Err(FatalError); } else if *crate_type == CrateType::Dylib { if !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(LtoDylib); + dcx.emit_err(LtoDylib); return Err(FatalError); } } } if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(DynamicLinkingWithLTO); + dcx.emit_err(DynamicLinkingWithLTO); return Err(FatalError); } @@ -154,7 +154,7 @@ fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt upstream_modules.push((module, CString::new(name).unwrap())); } Err(e) => { - diag_handler.emit_err(e); + dcx.emit_err(e); return Err(FatalError); } } @@ -183,16 +183,16 @@ pub(crate) fn run_fat( modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, ) -> Result, FatalError> { - let diag_handler = cgcx.create_dcx(); - let lto_data = prepare_lto(cgcx, &diag_handler)?; + let dcx = cgcx.create_dcx(); + let lto_data = prepare_lto(cgcx, &dcx)?; /*let symbols_below_threshold = lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::>();*/ - fat_lto(cgcx, &diag_handler, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path, + fat_lto(cgcx, &dcx, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path, //&symbols_below_threshold, ) } -fn fat_lto(cgcx: &CodegenContext, _diag_handler: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, +fn fat_lto(cgcx: &CodegenContext, _dcx: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, //symbols_below_threshold: &[*const libc::c_char], ) -> Result, FatalError> { let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module"); @@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext, _diag_handler: &DiagCtxt, m let (buffer, name) = serialized_modules.remove(0); info!("no in-memory regular modules to choose from, parsing {:?}", name); ModuleCodegen { - module_llvm: GccContext::parse(cgcx, &name, buffer.data(), diag_handler)?, + module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?, name: name.into_string().unwrap(), kind: ModuleKind::Regular, }*/ diff --git a/src/back/write.rs b/src/back/write.rs index c2438d7ca36fd..2f8a54f529cc5 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -13,7 +13,7 @@ use rustc_target::spec::SplitDebuginfo; use crate::{GccCodegenBackend, GccContext}; use crate::errors::CopyBitcode; -pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { +pub(crate) unsafe fn codegen(cgcx: &CodegenContext, dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name); { let context = &module.module_llvm.context; @@ -127,12 +127,12 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_hand EmitObj::Bitcode => { debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out); if let Err(err) = link_or_copy(&bc_out, &obj_out) { - diag_handler.emit_err(CopyBitcode { err }); + dcx.emit_err(CopyBitcode { err }); } if !config.emit_bc { debug!("removing_bitcode {:?}", bc_out); - ensure_removed(diag_handler, &bc_out); + ensure_removed(dcx, &bc_out); } } @@ -148,7 +148,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_hand )) } -pub(crate) fn link(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, mut _modules: Vec>) -> Result, FatalError> { +pub(crate) fn link(_cgcx: &CodegenContext, _dcx: &DiagCtxt, mut _modules: Vec>) -> Result, FatalError> { unimplemented!(); } diff --git a/src/errors.rs b/src/errors.rs index 0261d5cd59044..766d90cf72407 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -112,8 +112,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); + fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.set_span(span); }; diff --git a/src/lib.rs b/src/lib.rs index cbe03f4051ed3..1f3f909d8b4f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -330,7 +330,7 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!() } - unsafe fn optimize(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { + unsafe fn optimize(_cgcx: &CodegenContext, _dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level)); Ok(()) } @@ -344,8 +344,8 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { - back::write::codegen(cgcx, diag_handler, module, config) + unsafe fn codegen(cgcx: &CodegenContext, dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { + back::write::codegen(cgcx, dcx, module, config) } fn prepare_thin(_module: ModuleCodegen) -> (String, Self::ThinBuffer) { @@ -356,8 +356,8 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - fn run_link(cgcx: &CodegenContext, diag_handler: &DiagCtxt, modules: Vec>) -> Result, FatalError> { - back::write::link(cgcx, diag_handler, modules) + fn run_link(cgcx: &CodegenContext, dcx: &DiagCtxt, modules: Vec>) -> Result, FatalError> { + back::write::link(cgcx, dcx, modules) } } From 472ea06999ce6ecfb78554a74b14dec9dae97f38 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 14:12:39 +1100 Subject: [PATCH 15/36] Add `level` arg to `into_diagnostic`. And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions. --- src/errors.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 766d90cf72407..1b1ed0b411c71 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,6 @@ use rustc_errors::{ - DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, - IntoDiagnosticArg, + DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, + IntoDiagnosticArg, Level, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -111,9 +111,13 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { #[help(codegen_gcc_missing_features)] pub(crate) struct MissingFeatures; -impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); +impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { + let mut diag = DiagnosticBuilder::new( + dcx, + level, + fluent::codegen_gcc_target_feature_disable_or_enable + ); if let Some(span) = self.span { diag.set_span(span); }; From 02ed79063171e4214d4139e651b477487c517108 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 22:21:37 +1100 Subject: [PATCH 16/36] Remove `Session` methods that duplicate `DiagCtxt` methods. Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access. --- src/asm.rs | 2 +- src/attributes.rs | 2 +- src/consts.rs | 2 +- src/context.rs | 6 +++--- src/gcc_util.rs | 6 +++--- src/intrinsic/mod.rs | 2 +- src/intrinsic/simd.rs | 4 ++-- src/lib.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/asm.rs b/src/asm.rs index f3a9ca77a67b1..ddd67a994c942 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -109,7 +109,7 @@ enum ConstraintOrRegister { impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, span: &[Span], instance: Instance<'_>, _dest_catch_funclet: Option<(Self::BasicBlock, Self::BasicBlock, Option<&Self::Funclet>)>) { if options.contains(InlineAsmOptions::MAY_UNWIND) { - self.sess() + self.sess().dcx() .create_err(UnwindingInlineAsm { span: span[0] }) .emit(); return; diff --git a/src/attributes.rs b/src/attributes.rs index 6159971cfaa8d..9f361d3688695 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -80,7 +80,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>( let span = cx.tcx .get_attr(instance.def_id(), sym::target_feature) .map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span); - cx.tcx.sess.create_err(TiedTargetFeatures { + cx.tcx.dcx().create_err(TiedTargetFeatures { features: features.join(", "), span, }) diff --git a/src/consts.rs b/src/consts.rs index f06416b9bb5fe..70d8db02247ce 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -24,7 +24,7 @@ fn set_global_alignment<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, gv: LValue<'gcc> match Align::from_bits(min) { Ok(min) => align = align.max(min), Err(err) => { - cx.sess().emit_err(InvalidMinimumAlignment { err: err.to_string() }); + cx.sess().dcx().emit_err(InvalidMinimumAlignment { err: err.to_string() }); } } } diff --git a/src/context.rs b/src/context.rs index ab9c703db37da..053f759329fb1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -500,9 +500,9 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { - self.sess().emit_fatal(respan(span, err.into_diagnostic())) + self.tcx.dcx().emit_fatal(respan(span, err.into_diagnostic())) } else { - self.tcx.sess.emit_fatal(ssa_errors::FailedToGetLayout { span, ty, err }) + self.tcx.dcx().emit_fatal(ssa_errors::FailedToGetLayout { span, ty, err }) } } } @@ -518,7 +518,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> { fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { - self.sess().emit_fatal(respan(span, err)) + self.tcx.dcx().emit_fatal(respan(span, err)) } else { match fn_abi_request { FnAbiRequest::OfFnPtr { sig, extra_args } => { diff --git a/src/gcc_util.rs b/src/gcc_util.rs index 2aa84f26797c3..df917d527ced8 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -52,7 +52,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec c, Some(_) => { if diagnostics { - sess.emit_warning(UnknownCTargetFeaturePrefix { feature: s }); + sess.dcx().emit_warning(UnknownCTargetFeaturePrefix { feature: s }); } return None; } @@ -79,7 +79,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec Vec IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { _ => bug!(), }, None => { - tcx.sess.emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty }); + tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty }); return; } } diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index 85d3e7234a0e6..9fa978cd2ef7a 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -34,7 +34,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // macros for error handling: macro_rules! return_error { ($err:expr) => {{ - bx.sess().emit_err($err); + bx.tcx.dcx().emit_err($err); return Err(()); }}; } @@ -390,7 +390,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( ) -> Result, ()> { macro_rules! return_error { ($err:expr) => {{ - bx.sess().emit_err($err); + bx.tcx.dcx().emit_err($err); return Err(()); }}; } diff --git a/src/lib.rs b/src/lib.rs index 1f3f909d8b4f0..f69f850c1d4a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,7 +191,7 @@ impl CodegenBackend for GccCodegenBackend { #[cfg(feature="master")] gccjit::set_global_personality_function_name(b"rust_eh_personality\0"); if sess.lto() == Lto::Thin { - sess.emit_warning(LTONotSupported {}); + sess.dcx().emit_warning(LTONotSupported {}); } #[cfg(not(feature="master"))] From 69b5a9f2eb8b7d16091b76a2a5b84cd4889eefe2 Mon Sep 17 00:00:00 2001 From: Bernd Schmidt Date: Thu, 30 Nov 2023 14:54:27 +0100 Subject: [PATCH 17/36] Change `rustc_codegen_ssa`'s `atomic_cmpxchg` interface to return a pair of values --- src/builder.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index b8a8c144dc90b..42e61b3ccb5ad 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1296,7 +1296,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { } // Atomic Operations - fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> RValue<'gcc> { + fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> (RValue<'gcc>, RValue<'gcc>) { let expected = self.current_func().new_local(None, cmp.get_type(), "expected"); self.llbb().add_assignment(None, expected, cmp); // NOTE: gcc doesn't support a failure memory model that is stronger than the success @@ -1310,20 +1310,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { }; let success = self.compare_exchange(dst, expected, src, order, failure_order, weak); - let pair_type = self.cx.type_struct(&[src.get_type(), self.bool_type], false); - let result = self.current_func().new_local(None, pair_type, "atomic_cmpxchg_result"); - let align = Align::from_bits(64).expect("align"); // TODO(antoyo): use good align. + // NOTE: since success contains the call to the intrinsic, it must be added to the basic block before + // expected so that we store expected after the call. + let success_var = self.current_func().new_local(None, self.bool_type, "success"); + self.llbb().add_assignment(None, success_var, success); - let value_type = result.to_rvalue().get_type(); - if let Some(struct_type) = value_type.is_struct() { - self.store(success, result.access_field(None, struct_type.get_field(1)).get_address(None), align); - // NOTE: since success contains the call to the intrinsic, it must be stored before - // expected so that we store expected after the call. - self.store(expected.to_rvalue(), result.access_field(None, struct_type.get_field(0)).get_address(None), align); - } - // TODO(antoyo): handle when value is not a struct. - - result.to_rvalue() + (expected.to_rvalue(), success_var.to_rvalue()) } fn atomic_rmw(&mut self, op: AtomicRmwBinOp, dst: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering) -> RValue<'gcc> { From eca05c6cb06ca059bf13bd7f2b53066d217edaa2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Dec 2023 01:52:10 +0000 Subject: [PATCH 18/36] Remove movability from TyKind::Coroutine --- src/type_of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type_of.rs b/src/type_of.rs index 479a814788a54..e5c0b2de4ca46 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -98,7 +98,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } - if let (&ty::Coroutine(_, _, _), &Variants::Single { index }) = + if let (&ty::Coroutine(_, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); From a56eff2b4152a9846027f03c6bab35a653f958c4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 24 Dec 2023 09:08:41 +1100 Subject: [PATCH 19/36] Rename some `Diagnostic` setters. `Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods. --- src/errors.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 1b1ed0b411c71..e9283b1989453 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -119,12 +119,12 @@ impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnabl fluent::codegen_gcc_target_feature_disable_or_enable ); if let Some(span) = self.span { - diag.set_span(span); + diag.span(span); }; if let Some(missing_features) = self.missing_features { diag.subdiagnostic(missing_features); } - diag.set_arg("features", self.features.join(", ")); + diag.arg("features", self.features.join(", ")); diag } } From f93e985664ad56be1286b9cbe3a14cfe499be239 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 3 Jan 2024 18:00:37 +0900 Subject: [PATCH 20/36] Support reg_addr register class in s390x inline assembly --- src/asm.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/asm.rs b/src/asm.rs index ddd67a994c942..78e8e32b97299 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -634,6 +634,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister { } InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r", InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r", + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a", InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f", InlineAsmRegClass::Err => unreachable!(), } @@ -704,7 +705,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") }, - InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(), + InlineAsmRegClass::S390x( + S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr + ) => cx.type_i32(), InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(), InlineAsmRegClass::Err => unreachable!(), } From 47b06069b3e63df4d850479084d5543b24a92302 Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Fri, 22 Dec 2023 15:12:01 +0300 Subject: [PATCH 21/36] Update test for `E0796` and `static_mut_ref` lint --- example/mini_core_hello_world.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 40a1ad22c0e13..9827e299f2a31 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -98,6 +98,9 @@ fn start( } static mut NUM: u8 = 6 * 7; + +// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint +#[allow(static_mut_ref)] static NUM_REF: &'static u8 = unsafe { &NUM }; macro_rules! assert { From 558d051b1d956dc9db8fd7c437f2a624fd86e751 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 4 Jan 2024 11:28:14 +1100 Subject: [PATCH 22/36] Rename `{create,emit}_warning` as `{create,emit}_warn`. For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form. --- src/gcc_util.rs | 4 ++-- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gcc_util.rs b/src/gcc_util.rs index df917d527ced8..4babe5bfb813f 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -52,7 +52,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec c, Some(_) => { if diagnostics { - sess.dcx().emit_warning(UnknownCTargetFeaturePrefix { feature: s }); + sess.dcx().emit_warn(UnknownCTargetFeaturePrefix { feature: s }); } return None; } @@ -79,7 +79,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec Date: Wed, 3 Jan 2024 20:24:24 +0800 Subject: [PATCH 23/36] add avx512fp16 to x86 target features --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 03f8f43ff1643..f8f054db65ede 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -408,7 +408,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Locke .filter(|_feature| { target_info.cpu_supports(_feature) /* - adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma, + adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512fp16, avx512ifma, avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq, bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, gfni, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm, sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves From b2a7afd898b06b8d575563caebb43b32b3a149ec Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Tue, 23 Jan 2024 12:02:31 -0500 Subject: [PATCH 24/36] Further Implement `is_val_statically_known` --- src/context.rs | 7 ++++--- src/intrinsic/mod.rs | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/context.rs b/src/context.rs index 053f759329fb1..5760d96165ddf 100644 --- a/src/context.rs +++ b/src/context.rs @@ -196,15 +196,16 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { let mut functions = FxHashMap::default(); let builtins = [ - "__builtin_unreachable", "abort", "__builtin_expect", "__builtin_add_overflow", "__builtin_mul_overflow", - "__builtin_saddll_overflow", /*"__builtin_sadd_overflow",*/ "__builtin_smulll_overflow", /*"__builtin_smul_overflow",*/ + "__builtin_unreachable", "abort", "__builtin_expect", /*"__builtin_expect_with_probability",*/ + "__builtin_constant_p", "__builtin_add_overflow", "__builtin_mul_overflow", "__builtin_saddll_overflow", + /*"__builtin_sadd_overflow",*/ "__builtin_smulll_overflow", /*"__builtin_smul_overflow",*/ "__builtin_ssubll_overflow", /*"__builtin_ssub_overflow",*/ "__builtin_sub_overflow", "__builtin_uaddll_overflow", "__builtin_uadd_overflow", "__builtin_umulll_overflow", "__builtin_umul_overflow", "__builtin_usubll_overflow", "__builtin_usub_overflow", "sqrtf", "sqrt", "__builtin_powif", "__builtin_powi", "sinf", "sin", "cosf", "cos", "powf", "pow", "expf", "exp", "exp2f", "exp2", "logf", "log", "log10f", "log10", "log2f", "log2", "fmaf", "fma", "fabsf", "fabs", "fminf", "fmin", "fmaxf", "fmax", "copysignf", "copysign", "floorf", "floor", "ceilf", "ceil", "truncf", "trunc", "rintf", "rint", "nearbyintf", "nearbyint", "roundf", "round", - "__builtin_expect_with_probability", + ]; for builtin in builtins.iter() { diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 85b891fce3e42..eac8cb437794b 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -123,6 +123,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { sym::unlikely => { self.expect(args[0].immediate(), false) } + sym::is_val_statically_known => { + let a = args[0].immediate(); + let builtin = self.context.get_builtin_function("__builtin_constant_p"); + let res = self.context.new_call(None, builtin, &[a]); + self.icmp(IntPredicate::IntEQ, res, self.const_i32(0)) + } kw::Try => { try_intrinsic( self, From 215284a490a382cf9c1e2bde12484d7daa72e9aa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 26 Sep 2023 09:39:41 +0200 Subject: [PATCH 25/36] remove StructuralEq trait --- example/mini_core.rs | 3 --- tests/run/static.rs | 3 --- 2 files changed, 6 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index db94bc1c86af9..230009741dc41 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -100,9 +100,6 @@ unsafe impl Freeze for &mut T {} #[lang = "structural_peq"] pub trait StructuralPartialEq {} -#[lang = "structural_teq"] -pub trait StructuralEq {} - #[lang = "not"] pub trait Not { type Output; diff --git a/tests/run/static.rs b/tests/run/static.rs index 0b933754c2937..e7c46ae3fcc81 100644 --- a/tests/run/static.rs +++ b/tests/run/static.rs @@ -61,9 +61,6 @@ mod libc { #[lang = "structural_peq"] pub trait StructuralPartialEq {} -#[lang = "structural_teq"] -pub trait StructuralEq {} - #[lang = "drop_in_place"] #[allow(unconditional_recursion)] pub unsafe fn drop_in_place(to_drop: *mut T) { From b9d44eef7ad1fc21d3c6fed7f0ca5401ae59f5f8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 15:27:16 +1100 Subject: [PATCH 26/36] Remove the lifetime from `DiagnosticArgValue`. Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere. --- src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors.rs b/src/errors.rs index e9283b1989453..cc0fbe46dcc11 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -35,7 +35,7 @@ pub(crate) enum PossibleFeature<'a> { struct ExitCode(Option); impl IntoDiagnosticArg for ExitCode { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { let ExitCode(exit_code) = self; match exit_code { Some(t) => t.into_diagnostic_arg(), From 04e4c5ddbc7ab8e60a9481698d97e805b81fa59a Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 30 Jan 2024 20:55:56 +0000 Subject: [PATCH 27/36] Remove `ffi_returns_twice` feature --- src/attributes.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/attributes.rs b/src/attributes.rs index 9f361d3688695..142f86b003ddb 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -62,9 +62,6 @@ pub fn from_fn_attrs<'gcc, 'tcx>( if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) { func.add_attribute(FnAttribute::Cold); } - if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_RETURNS_TWICE) { - func.add_attribute(FnAttribute::ReturnsTwice); - } if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_PURE) { func.add_attribute(FnAttribute::Pure); } From 007cea323884bc8f61effcbf625bcb1d7368a7ec Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 6 Feb 2024 09:51:39 +1100 Subject: [PATCH 28/36] Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f8f054db65ede..863b6333bcc29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,8 +27,6 @@ #![recursion_limit="256"] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] -#![deny(rustc::untranslatable_diagnostic)] -#![deny(rustc::diagnostic_outside_of_impl)] extern crate rustc_apfloat; extern crate rustc_ast; From 31f7f03c2a08396f518d7732a5dc86f9c13de106 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Jan 2024 18:01:56 +0000 Subject: [PATCH 29/36] Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs --- src/type_of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type_of.rs b/src/type_of.rs index e5c0b2de4ca46..25149b8020162 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -87,7 +87,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | - ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str + ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str if !cx.sess().fewer_names() => { let mut name = with_no_trimmed_paths!(layout.ty.to_string()); From 64dfa4f455ed72e1c17a82fa67a577b869ed5992 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 31 Jan 2024 20:39:59 +0000 Subject: [PATCH 30/36] Teach llvm backend how to fall back to default bodies --- src/intrinsic/mod.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index eac8cb437794b..f162ef831b768 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -90,7 +90,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, name: Symbol) -> } impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { - fn codegen_intrinsic_call(&mut self, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, args: &[OperandRef<'tcx, RValue<'gcc>>], llresult: RValue<'gcc>, span: Span) { + fn codegen_intrinsic_call(&mut self, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, args: &[OperandRef<'tcx, RValue<'gcc>>], llresult: RValue<'gcc>, span: Span) -> Result<(), Instance<'tcx>> { let tcx = self.tcx; let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); @@ -137,7 +137,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { args[2].immediate(), llresult, ); - return; + return Ok(()); } sym::breakpoint => { unimplemented!(); @@ -166,12 +166,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { sym::volatile_store => { let dst = args[0].deref(self.cx()); args[1].val.volatile_store(self, dst); - return; + return Ok(()); } sym::unaligned_volatile_store => { let dst = args[0].deref(self.cx()); args[1].val.unaligned_volatile_store(self, dst); - return; + return Ok(()); } sym::prefetch_read_data | sym::prefetch_write_data @@ -269,7 +269,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { }, None => { tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty }); - return; + return Ok(()); } } } @@ -339,7 +339,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { extended_asm.set_volatile_flag(true); // We have copied the value to `result` already. - return; + return Ok(()); } sym::ptr_mask => { @@ -357,11 +357,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { _ if name_str.starts_with("simd_") => { match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) { Ok(llval) => llval, - Err(()) => return, + Err(()) => return Ok(()), } } - _ => bug!("unknown intrinsic '{}'", name), + // Fall back to default body + _ => return Err(Instance::new(instance.def_id(), instance.args)), }; if !fn_abi.ret.is_ignore() { @@ -376,6 +377,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { .store(self, result); } } + Ok(()) } fn abort(&mut self) { From ec5328b3d9aa08986abd3237b40c0bf74b08bc2b Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 14 Feb 2024 14:17:27 +0000 Subject: [PATCH 31/36] errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood --- src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors.rs b/src/errors.rs index cc0fbe46dcc11..79eb4406b8a33 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -122,7 +122,7 @@ impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnabl diag.span(span); }; if let Some(missing_features) = self.missing_features { - diag.subdiagnostic(missing_features); + diag.subdiagnostic(dcx, missing_features); } diag.arg("features", self.features.join(", ")); diag From 7b1ac28f1c235ec5cd25bb0cd42014fdc95a5b46 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 17 Feb 2024 10:51:35 +1100 Subject: [PATCH 32/36] Make `CodegenBackend::join_codegen` infallible. Because they all are, in practice. --- src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 863b6333bcc29..09ce059476ec7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,13 +217,11 @@ impl CodegenBackend for GccCodegenBackend { Box::new(res) } - fn join_codegen(&self, ongoing_codegen: Box, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxIndexMap), ErrorGuaranteed> { - let (codegen_results, work_products) = ongoing_codegen + fn join_codegen(&self, ongoing_codegen: Box, sess: &Session, _outputs: &OutputFilenames) -> (CodegenResults, FxIndexMap) { + ongoing_codegen .downcast::>() .expect("Expected GccCodegenBackend's OngoingCodegen, found Box") - .join(sess); - - Ok((codegen_results, work_products)) + .join(sess) } fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorGuaranteed> { From b959fc1d0ae090301fa204f37bec8891957243b3 Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Sat, 17 Feb 2024 22:01:56 +0300 Subject: [PATCH 33/36] Improve wording of static_mut_ref Rename `static_mut_ref` lint to `static_mut_refs`. --- example/mini_core_hello_world.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 9827e299f2a31..add77880716c8 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -99,8 +99,8 @@ fn start( static mut NUM: u8 = 6 * 7; -// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint -#[allow(static_mut_ref)] +// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint +#[allow(static_mut_refs)] static NUM_REF: &'static u8 = unsafe { &NUM }; macro_rules! assert { From 6bbbf59951a6ef9f54f5f0e2849bba2ac53928a5 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 20 Feb 2024 10:23:05 -0500 Subject: [PATCH 34/36] Update to nightly-2024-02-20 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 1962c217258a4..cd278090924d1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-11-17" +channel = "nightly-2024-02-20" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From c3d5b7fe3ba0c2b04fcd4a7d2ebdb1ab9e357b6e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 20 Feb 2024 10:35:56 -0500 Subject: [PATCH 35/36] Fix patches --- .../0022-core-Disable-not-compiling-tests.patch | 4 +--- .../0001-Disable-libstd-and-libtest-dylib.patch | 16 ---------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/patches/0022-core-Disable-not-compiling-tests.patch b/patches/0022-core-Disable-not-compiling-tests.patch index 4db56fa3bd2c7..a7d523f940826 100644 --- a/patches/0022-core-Disable-not-compiling-tests.patch +++ b/patches/0022-core-Disable-not-compiling-tests.patch @@ -39,6 +39,4 @@ index 42a26ae..5ac1042 100644 +#![cfg(test)] #![feature(alloc_layout_extra)] #![feature(array_chunks)] - #![feature(array_methods)] --- -2.21.0 (Apple Git-122) + #![feature(array_windows)] diff --git a/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch b/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch index 74d9c208a05ac..c220f53040f05 100644 --- a/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch +++ b/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch @@ -21,19 +21,3 @@ index 5b21355..cb0c49b 100644 [dependencies] alloc = { path = "../alloc", public = true } -diff --git a/library/test/Cargo.toml b/library/test/Cargo.toml -index 91a1abd..a58c160 100644 ---- a/library/test/Cargo.toml -+++ b/library/test/Cargo.toml -@@ -4,7 +4,7 @@ version = "0.0.0" - edition = "2021" - - [lib] --crate-type = ["dylib", "rlib"] -+crate-type = ["rlib"] - - [dependencies] - getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] } --- -2.42.0 - From e7b7c98e1c9628570bed2915e683ab298c59a0d6 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 20 Feb 2024 11:08:45 -0500 Subject: [PATCH 36/36] Fix tests --- build_system/src/prepare.rs | 17 +------- .../0002-rand-Disable-failing-test.patch | 32 --------------- tests/failing-lto-tests.txt | 16 +++++++- tests/failing-ui-tests.txt | 39 +++++++++++++++++++ tests/failing-ui-tests12.txt | 4 ++ 5 files changed, 59 insertions(+), 49 deletions(-) delete mode 100644 patches/crate_patches/0002-rand-Disable-failing-test.patch diff --git a/build_system/src/prepare.rs b/build_system/src/prepare.rs index 1a3eb7d2e57b4..66f440f53553a 100644 --- a/build_system/src/prepare.rs +++ b/build_system/src/prepare.rs @@ -159,21 +159,6 @@ where let repo_path = Path::new(crate::BUILD_DIR).join(&clone_result.repo_name); run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?; run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?; - let filter = format!("-{}-", clone_result.repo_name); - walk_dir( - "patches/crate_patches", - |_| Ok(()), - |file_path| { - let patch = file_path.as_os_str().to_str().unwrap(); - if patch.contains(&filter) && patch.ends_with(".patch") { - run_command_with_output( - &[&"git", &"am", &file_path.canonicalize().unwrap()], - Some(&repo_path), - )?; - } - Ok(()) - }, - )?; if let Some(extra) = extra { extra(&repo_path)?; } @@ -238,7 +223,7 @@ pub fn run() -> Result<(), String> { let to_clone = &[ ( "https://github.com/rust-random/rand.git", - "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", + "1f4507a8e1cf8050e4ceef95eeda8f64645b6719", None, ), ( diff --git a/patches/crate_patches/0002-rand-Disable-failing-test.patch b/patches/crate_patches/0002-rand-Disable-failing-test.patch deleted file mode 100644 index 449ca5f6e29cd..0000000000000 --- a/patches/crate_patches/0002-rand-Disable-failing-test.patch +++ /dev/null @@ -1,32 +0,0 @@ -From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sat, 15 Aug 2020 20:04:38 +0200 -Subject: [PATCH] [rand] Disable failing test - ---- - src/distributions/uniform.rs | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs -index 480b859..c80bb6f 100644 ---- a/src/distributions/uniform.rs -+++ b/src/distributions/uniform.rs -@@ -1085,7 +1085,7 @@ mod tests { - _ => panic!("`UniformDurationMode` was not serialized/deserialized correctly") - } - } -- -+ - #[test] - #[cfg(feature = "serde1")] - fn test_uniform_serialization() { -@@ -1314,6 +1314,7 @@ mod tests { - not(target_arch = "wasm32"), - not(target_arch = "asmjs") - ))] -+ #[ignore] // FIXME - fn test_float_assertions() { - use super::SampleUniform; - use std::panic::catch_unwind; --- -2.20.1 diff --git a/tests/failing-lto-tests.txt b/tests/failing-lto-tests.txt index 2e0b6134070b9..8de45ae0f28b1 100644 --- a/tests/failing-lto-tests.txt +++ b/tests/failing-lto-tests.txt @@ -1,6 +1,6 @@ tests/ui/lint/unsafe_code/forge_unsafe_block.rs tests/ui/lint/unused-qualification-in-derive-expansion.rs -tests/ui/macro-quote-test.rs +tests/ui/macros/macro-quote-test.rs tests/ui/macros/proc_macro.rs tests/ui/panic-runtime/lto-unwind.rs tests/ui/resolve/derive-macro-1.rs @@ -21,3 +21,17 @@ tests/ui/fmt/format-args-capture-issue-106408.rs tests/ui/fmt/indoc-issue-106408.rs tests/ui/hygiene/issue-77523-def-site-async-await.rs tests/ui/inherent-impls-overlap-check/no-overlap.rs +tests/ui/annotate-snippet/multispan.rs +tests/ui/enum-discriminant/issue-46519.rs +tests/ui/issues/issue-45731.rs +tests/ui/lint/test-allow-dead-extern-static-no-warning.rs +tests/ui/macros/macro-comma-behavior-rpass.rs +tests/ui/macros/rfc-2011-nicer-assert-messages/assert-with-custom-errors-does-not-create-unnecessary-code.rs +tests/ui/macros/rfc-2011-nicer-assert-messages/feature-gate-generic_assert.rs +tests/ui/macros/stringify.rs +tests/ui/panics/test-panic.rs +tests/ui/panics/test-should-fail-bad-message.rs +tests/ui/panics/test-should-panic-bad-message.rs +tests/ui/panics/test-should-panic-no-message.rs +tests/ui/reexport-test-harness-main.rs +tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test.rs diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index 6e020e9b354da..e504021bf2ad2 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -69,3 +69,42 @@ tests/ui/async-await/deep-futures-are-freeze.rs tests/ui/closures/capture-unsized-by-ref.rs tests/ui/coroutine/resume-after-return.rs tests/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs +tests/ui/limits/issue-17913.rs +tests/ui/limits/issue-55878.rs +tests/ui/linkage-attr/common-linkage-non-zero-init.rs +tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs +tests/ui/numbers-arithmetic/divide-by-zero.rs +tests/ui/numbers-arithmetic/mod-zero.rs +tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs +tests/ui/numbers-arithmetic/overflowing-neg.rs +tests/ui/optimization-remark.rs +tests/ui/panic-handler/panic-handler-std.rs +tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs +tests/ui/panic-runtime/need-unwind-got-abort.rs +tests/ui/panics/issue-47429-short-backtraces.rs +tests/ui/panics/panic-in-cleanup.rs +tests/ui/panics/panic-in-ffi.rs +tests/ui/panics/runtime-switch.rs +tests/ui/panics/short-ice-remove-middle-frames-2.rs +tests/ui/panics/short-ice-remove-middle-frames.rs +tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs +tests/ui/simd/masked-load-store.rs +tests/ui/simd/repr_packed.rs +tests/ui/type_length_limit.rs +tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs +tests/ui/async-await/issues/issue-65419/issue-65419-coroutine-resume-after-completion.rs +tests/ui/c-variadic/issue-86053-1.rs +tests/ui/const-ptr/out_of_bounds_read.rs +tests/ui/consts/const_unsafe_unreachable_ub.rs +tests/ui/consts/miri_unleashed/drop.rs +tests/ui/consts/timeout.rs +tests/ui/consts/try-operator.rs +tests/ui/coroutine/coroutine-resume-after-panic.rs +tests/ui/coroutine/unwind-abort-mix.rs +tests/ui/duplicate/dupe-symbols-7.rs +tests/ui/duplicate/dupe-symbols-8.rs +tests/ui/hygiene/panic-location.rs +tests/ui/invalid/issue-114435-layout-type-err.rs +tests/ui/invalid-compile-flags/invalid-llvm-passes.rs +tests/ui/lto/issue-105637.rs +tests/ui/lto/lto-duplicate-symbols.rs diff --git a/tests/failing-ui-tests12.txt b/tests/failing-ui-tests12.txt index 64f89b03eecc8..1d9bdaa552c6b 100644 --- a/tests/failing-ui-tests12.txt +++ b/tests/failing-ui-tests12.txt @@ -42,3 +42,7 @@ tests/ui/codegen/issue-79865-llvm-miscompile.rs tests/ui/std-backtrace.rs tests/ui/mir/alignment/packed.rs tests/ui/intrinsics/intrinsics-integer.rs +tests/ui/asm/x86_64/evex512-implicit-feature.rs +tests/ui/packed/dyn-trait.rs +tests/ui/packed/issue-118537-field-offset-ice.rs +tests/ui/stable-mir-print/basic_function.rs