diff options
| author | antoyo <antoyo@users.noreply.github.com> | 2022-08-27 12:09:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-27 12:09:37 -0400 |
| commit | b4626b3ca07c4fcdce1d96840567005e294e5ecc (patch) | |
| tree | 3fb39322d5717e88333d80eb6ca4dd996f1688a0 /src | |
| parent | b4eb2c30a262763d59711d285979facc95e1ba56 (diff) | |
| parent | 61a7b96c800c7f0a338b3f8f4b5b1e89f82b1668 (diff) | |
| download | rust-b4626b3ca07c4fcdce1d96840567005e294e5ecc.tar.gz rust-b4626b3ca07c4fcdce1d96840567005e294e5ecc.zip | |
Merge pull request #209 from rust-lang/2022-08-26_sync_from_rust
2022/08/26 sync from rust
Diffstat (limited to 'src')
| -rw-r--r-- | src/abi.rs | 2 | ||||
| -rw-r--r-- | src/allocator.rs | 2 | ||||
| -rw-r--r-- | src/archive.rs | 103 | ||||
| -rw-r--r-- | src/base.rs | 2 | ||||
| -rw-r--r-- | src/builder.rs | 21 | ||||
| -rw-r--r-- | src/callee.rs | 2 | ||||
| -rw-r--r-- | src/common.rs | 30 | ||||
| -rw-r--r-- | src/context.rs | 4 | ||||
| -rw-r--r-- | src/intrinsic/mod.rs | 10 | ||||
| -rw-r--r-- | src/intrinsic/simd.rs | 3 | ||||
| -rw-r--r-- | src/lib.rs | 20 | ||||
| -rw-r--r-- | src/mono_item.rs | 2 | ||||
| -rw-r--r-- | src/type_.rs | 13 | ||||
| -rw-r--r-- | src/type_of.rs | 2 |
14 files changed, 111 insertions, 105 deletions
diff --git a/src/abi.rs b/src/abi.rs index 2c796d0f69e..0ed3e1fbe93 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -1,6 +1,6 @@ use gccjit::{ToLValue, ToRValue, Type}; use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods}; -use rustc_data_structures::stable_set::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_middle::bug; use rustc_middle::ty::Ty; use rustc_target::abi::call::{CastTarget, FnAbi, PassMode, Reg, RegKind}; diff --git a/src/allocator.rs b/src/allocator.rs index 60985003a9e..11482c69d59 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -127,7 +127,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam let name = OomStrategy::SYMBOL.to_string(); let global = context.new_global(None, GlobalKind::Exported, i8, name); - let value = tcx.sess.opts.debugging_opts.oom.should_panic(); + let value = tcx.sess.opts.unstable_opts.oom.should_panic(); let value = context.new_rvalue_from_int(i8, value as i32); global.global_set_initializer_rvalue(value); } diff --git a/src/archive.rs b/src/archive.rs index fac532f3e9c..f863abdcc97 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,15 +1,13 @@ use std::fs::File; use std::path::{Path, PathBuf}; -use rustc_codegen_ssa::back::archive::ArchiveBuilder; +use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder}; use rustc_session::Session; -use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_session::cstore::DllImport; struct ArchiveConfig<'a> { sess: &'a Session, - dst: PathBuf, use_native_ar: bool, use_gnu_style_archive: bool, } @@ -23,66 +21,44 @@ enum ArchiveEntry { File(PathBuf), } -pub struct ArArchiveBuilder<'a> { - config: ArchiveConfig<'a>, - src_archives: Vec<(PathBuf, ar::Archive<File>)>, - // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at - // the end of an archive for linkers to not get confused. - entries: Vec<(String, ArchiveEntry)>, -} +pub struct ArArchiveBuilderBuilder; -impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { - fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self { +impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder { + fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> { let config = ArchiveConfig { sess, - dst: output.to_path_buf(), use_native_ar: false, // FIXME test for linux and System V derivatives instead use_gnu_style_archive: sess.target.options.archive_format == "gnu", }; - let (src_archives, entries) = if let Some(input) = input { - let mut archive = ar::Archive::new(File::open(input).unwrap()); - let mut entries = Vec::new(); - - let mut i = 0; - while let Some(entry) = archive.next_entry() { - let entry = entry.unwrap(); - entries.push(( - String::from_utf8(entry.header().identifier().to_vec()).unwrap(), - ArchiveEntry::FromArchive { - archive_index: 0, - entry_index: i, - }, - )); - i += 1; - } - - (vec![(input.to_owned(), archive)], entries) - } else { - (vec![], Vec::new()) - }; - - ArArchiveBuilder { + Box::new(ArArchiveBuilder { config, - src_archives, - entries, - } + src_archives: vec![], + entries: vec![], + }) } - fn src_files(&mut self) -> Vec<String> { - self.entries.iter().map(|(name, _)| name.clone()).collect() + fn create_dll_import_lib( + &self, + _sess: &Session, + _lib_name: &str, + _dll_imports: &[DllImport], + _tmpdir: &Path, + ) -> PathBuf { + unimplemented!(); } +} - fn remove_file(&mut self, name: &str) { - let index = self - .entries - .iter() - .position(|(entry_name, _)| entry_name == name) - .expect("Tried to remove file not existing in src archive"); - self.entries.remove(index); - } +pub struct ArArchiveBuilder<'a> { + config: ArchiveConfig<'a>, + src_archives: Vec<(PathBuf, ar::Archive<File>)>, + // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at + // the end of an archive for linkers to not get confused. + entries: Vec<(String, ArchiveEntry)>, +} +impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { fn add_file(&mut self, file: &Path) { self.entries.push(( file.file_name().unwrap().to_str().unwrap().to_string(), @@ -90,10 +66,11 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { )); } - fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()> - where - F: FnMut(&str) -> bool + 'static, - { + fn add_archive( + &mut self, + archive_path: &Path, + mut skip: Box<dyn FnMut(&str) -> bool + 'static>, + ) -> std::io::Result<()> { let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?); let archive_index = self.src_archives.len(); @@ -113,7 +90,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { Ok(()) } - fn build(mut self) { + fn build(mut self: Box<Self>, output: &Path) -> bool { use std::process::Command; fn add_file_using_ar(archive: &Path, file: &Path) { @@ -133,19 +110,21 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } let mut builder = if self.config.use_native_ar { - BuilderKind::NativeAr(&self.config.dst) + BuilderKind::NativeAr(output) } else if self.config.use_gnu_style_archive { BuilderKind::Gnu(ar::GnuBuilder::new( - File::create(&self.config.dst).unwrap(), + File::create(output).unwrap(), self.entries .iter() .map(|(name, _)| name.as_bytes().to_vec()) .collect(), )) } else { - BuilderKind::Bsd(ar::Builder::new(File::create(&self.config.dst).unwrap())) + BuilderKind::Bsd(ar::Builder::new(File::create(output).unwrap())) }; + let any_members = !self.entries.is_empty(); + // Add all files for (entry_name, entry) in self.entries.into_iter() { match entry { @@ -198,17 +177,13 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { std::mem::drop(builder); // Run ranlib to be able to link the archive - let status = std::process::Command::new("ranlib") - .arg(self.config.dst) - .status() - .expect("Couldn't run ranlib"); + let status = + std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib"); if !status.success() { self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code())); } - } - fn inject_dll_import_lib(&mut self, _lib_name: &str, _dll_imports: &[DllImport], _tmpdir: &MaybeTempDir) { - unimplemented!(); + any_members } } diff --git a/src/base.rs b/src/base.rs index 42194b526e6..8cc9581e842 100644 --- a/src/base.rs +++ b/src/base.rs @@ -121,7 +121,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_ // NOTE: Rust relies on LLVM not doing TBAA (https://github.com/rust-lang/unsafe-code-guidelines/issues/292). context.add_command_line_option("-fno-strict-aliasing"); - if tcx.sess.opts.debugging_opts.function_sections.unwrap_or(tcx.sess.target.function_sections) { + if tcx.sess.opts.unstable_opts.function_sections.unwrap_or(tcx.sess.target.function_sections) { context.add_command_line_option("-ffunction-sections"); context.add_command_line_option("-fdata-sections"); } diff --git a/src/builder.rs b/src/builder.rs index bcbaad39044..41df7e647b5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -30,7 +30,7 @@ use rustc_codegen_ssa::traits::{ OverflowOp, StaticBuilderMethods, }; -use rustc_data_structures::stable_set::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_span::Span; @@ -820,16 +820,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { // TODO(antoyo) } - fn type_metadata(&mut self, _function: RValue<'gcc>, _typeid: String) { - // Unsupported. - } - - fn typeid_metadata(&mut self, _typeid: String) -> RValue<'gcc> { - // Unsupported. - self.context.new_rvalue_from_int(self.int_type, 0) - } - - fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> { self.store_with_flags(val, ptr, align, MemFlags::empty()) } @@ -1195,6 +1185,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> 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 + // memory model. + let order = + if failure_order as i32 > order as i32 { + failure_order + } + else { + order + }; 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); diff --git a/src/callee.rs b/src/callee.rs index d7bbf1d34ef..be7d48b2279 100644 --- a/src/callee.rs +++ b/src/callee.rs @@ -2,7 +2,7 @@ use gccjit::{FnAttribute, Visibility}; use gccjit::{FunctionType, RValue}; use rustc_codegen_ssa::traits::BaseTypeMethods; -use rustc_middle::ty::{self, Instance, TypeFoldable}; +use rustc_middle::ty::{self, Instance, TypeVisitable}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; use crate::abi::FnAbiGccExt; diff --git a/src/common.rs b/src/common.rs index 9c55692dea1..1d44dc48668 100644 --- a/src/common.rs +++ b/src/common.rs @@ -9,10 +9,8 @@ use rustc_codegen_ssa::traits::{ StaticMethods, }; use rustc_middle::mir::Mutability; -use rustc_middle::ty::ScalarInt; use rustc_middle::ty::layout::{TyAndLayout, LayoutOf}; use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar}; -use rustc_span::Symbol; use rustc_target::abi::{self, HasDataLayout, Pointer, Size}; use crate::consts::const_alloc_to_gcc; @@ -125,12 +123,15 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.context.new_rvalue_from_double(typ, val) } - fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) { - let s_str = s.as_str(); - let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| { - self.global_string(s_str) - }); - let len = s_str.len(); + fn const_str(&self, s: &str) -> (RValue<'gcc>, RValue<'gcc>) { + let str_global = *self + .const_str_cache + .borrow_mut() + .raw_entry_mut() + .from_key(s) + .or_insert_with(|| (s.to_owned(), self.global_string(s))) + .1; + let len = s.len(); let cs = self.const_ptrcast(str_global.get_address(None), self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self)), ); @@ -157,13 +158,13 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { None } + fn zst_to_backend(&self, _ty: Type<'gcc>) -> RValue<'gcc> { + self.const_undef(self.type_ix(0)) + } + fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> { let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() }; match cv { - Scalar::Int(ScalarInt::ZST) => { - assert_eq!(0, layout.size(self).bytes()); - self.const_undef(self.type_ix(0)) - } Scalar::Int(int) => { let data = int.assert_bits(layout.size(self)); @@ -210,6 +211,11 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { GlobalAlloc::Function(fn_instance) => { self.get_fn_addr(fn_instance) }, + GlobalAlloc::VTable(ty, trait_ref) => { + let alloc = self.tcx.global_alloc(self.tcx.vtable_allocation((ty, trait_ref))).unwrap_memory(); + let init = const_alloc_to_gcc(self, alloc); + self.static_addr_of(init, alloc.inner().align, None) + } GlobalAlloc::Static(def_id) => { assert!(self.tcx.is_static(def_id)); self.get_static(def_id).get_address(None) diff --git a/src/context.rs b/src/context.rs index 9879e31c2ea..2699559dc2a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -13,7 +13,7 @@ use rustc_middle::mir::mono::CodegenUnit; use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers}; use rustc_session::Session; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, Target, TlsModel}; @@ -99,7 +99,7 @@ pub struct CodegenCx<'gcc, 'tcx> { pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>, /// Cache of constant strings, - pub const_str_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>, + pub const_str_cache: RefCell<FxHashMap<String, LValue<'gcc>>>, /// Cache of globals. pub globals: RefCell<FxHashMap<String, RValue<'gcc>>>, diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 1315edf0891..e3461b97973 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -356,6 +356,16 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { self.context.new_rvalue_from_int(self.int_type, 0) } + fn type_checked_load( + &mut self, + _llvtable: Self::Value, + _vtable_byte_offset: u64, + _typeid: Self::Value, + ) -> Self::Value { + // Unsupported. + self.context.new_rvalue_from_int(self.int_type, 0) + } + fn va_start(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> { unimplemented!(); } diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index 9c2a1401a15..dbf6ee6d285 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -395,9 +395,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>, args: &[OperandRef<'tcx, RValue<'gcc>>], ) -> Result<RValue<'gcc>, ()> { macro_rules! emit_error { - ($msg: tt) => { - emit_error!($msg, ) - }; ($msg: tt, $($fmt: tt)*) => { span_invalid_monomorphization_error( bx.sess(), span, diff --git a/src/lib.rs b/src/lib.rs index b3cbf344ad1..e43ee5cf21d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,14 @@ * TODO(antoyo): remove the patches. */ -#![feature(rustc_private, decl_macro, associated_type_bounds, never_type, trusted_len)] +#![feature( + rustc_private, + decl_macro, + associated_type_bounds, + never_type, + trusted_len, + hash_raw_entry +)] #![allow(broken_intra_doc_links)] #![recursion_limit="256"] #![warn(rust_2018_idioms)] @@ -128,15 +135,16 @@ impl CodegenBackend for GccCodegenBackend { fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorGuaranteed> { use rustc_codegen_ssa::back::link::link_binary; - link_binary::<crate::archive::ArArchiveBuilder<'_>>( + link_binary( sess, + &crate::archive::ArArchiveBuilderBuilder, &codegen_results, outputs, ) } - fn target_features(&self, sess: &Session) -> Vec<Symbol> { - target_features(sess) + fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> { + target_features(sess, allow_unstable) } } @@ -293,12 +301,12 @@ pub fn target_cpu(sess: &Session) -> &str { } } -pub fn target_features(sess: &Session) -> Vec<Symbol> { +pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> { supported_target_features(sess) .iter() .filter_map( |&(feature, gate)| { - if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None } + if sess.is_nightly_build() || allow_unstable || gate.is_none() { Some(feature) } else { None } }, ) .filter(|_feature| { diff --git a/src/mono_item.rs b/src/mono_item.rs index d0d6b9b5bfe..ce439d339b6 100644 --- a/src/mono_item.rs +++ b/src/mono_item.rs @@ -4,7 +4,7 @@ use rustc_codegen_ssa::traits::PreDefineMethods; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::mono::{Linkage, Visibility}; -use rustc_middle::ty::{self, Instance, TypeFoldable}; +use rustc_middle::ty::{self, Instance, TypeVisitable}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf}; use crate::attributes; diff --git a/src/type_.rs b/src/type_.rs index b85aad7c00b..c97e9586005 100644 --- a/src/type_.rs +++ b/src/type_.rs @@ -1,7 +1,7 @@ use std::convert::TryInto; use gccjit::{RValue, Struct, Type}; -use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods}; +use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods}; use rustc_codegen_ssa::common::TypeKind; use rustc_middle::{bug, ty}; use rustc_middle::ty::layout::TyAndLayout; @@ -290,3 +290,14 @@ pub fn struct_fields<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout (result, packed) } + +impl<'gcc, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'gcc, 'tcx> { + fn set_type_metadata(&self, _function: RValue<'gcc>, _typeid: String) { + // Unsupported. + } + + fn typeid_metadata(&self, _typeid: String) -> RValue<'gcc> { + // Unsupported. + self.context.new_rvalue_from_int(self.int_type, 0) + } +} diff --git a/src/type_of.rs b/src/type_of.rs index c7aa4239c7f..29d394dbba4 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -3,7 +3,7 @@ use std::fmt::Write; use gccjit::{Struct, Type}; use crate::rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods}; use rustc_middle::bug; -use rustc_middle::ty::{self, Ty, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TypeVisitable}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_target::abi::{self, Abi, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants}; |
