From f4ae9a4dbb79758a2e3d16ff0854301ce5846ae1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 24 Nov 2018 11:23:49 +0100 Subject: [PATCH] Rustup to rustc 1.32.0-nightly (1f57e4841 2018-11-23) --- Cargo.lock | 1 - Cargo.toml | 1 - src/base.rs | 6 +- src/constant.rs | 10 +++- src/intrinsics.rs | 6 +- src/lib.rs | 139 +++---------------------------------------- src/link.rs | 5 +- src/link_copied.rs | 145 +-------------------------------------------- src/vtable.rs | 10 ++-- 9 files changed, 33 insertions(+), 290 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbfe536eaf70..999353c4cfa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -482,7 +482,6 @@ dependencies = [ "ar 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift 0.23.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-faerie 0.23.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.23.0 (git+https://github.com/CraneStation/cranelift.git)", diff --git a/Cargo.toml b/Cargo.toml index 61cd7707c69a..ee7ea811ad32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ faerie = "0.6.0" ar = "0.6.1" bitflags = "1.0.3" byteorder = "1.2.6" -cc = "1.0.25" libc = "0.2.43" tempfile = "3.0.4" diff --git a/src/base.rs b/src/base.rs index 5607df488382..d7edf23af7fd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -604,9 +604,9 @@ fn trans_stmt<'a, 'tcx: 'a>( use rustc::middle::lang_items::ExchangeMallocFnLangItem; let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap(); - let (size, align) = fx.layout_of(content_ty).size_and_align(); - let llsize = fx.bcx.ins().iconst(usize_type, size.bytes() as i64); - let llalign = fx.bcx.ins().iconst(usize_type, align.abi() as i64); + let layout = fx.layout_of(content_ty); + let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64); + let llalign = fx.bcx.ins().iconst(usize_type, layout.align.abi.bytes() as i64); let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty)); // Allocate space: diff --git a/src/constant.rs b/src/constant.rs index 3a27b1abdbbe..d3c8a3b57048 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -5,7 +5,7 @@ use rustc::mir::interpret::{ }; use rustc::ty::Const; use rustc_mir::interpret::{ - EvalContext, MPlaceTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, Pointer, + EvalContext, MPlaceTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, Pointer, StackPopCleanup, }; use cranelift_module::*; @@ -133,7 +133,13 @@ fn trans_const_place<'a, 'tcx: 'a>( ty::ParamEnv::reveal_all(), TransPlaceInterpreter, ); - let op = ecx.const_to_op(const_)?; + ecx.push_stack_frame(fx.instance, DUMMY_SP, fx.mir, None, StackPopCleanup::None { cleanup: false }).unwrap(); + let op = ecx.eval_operand(&Operand::Constant(Box::new(Constant { + span: DUMMY_SP, + ty: const_.ty, + user_ty: None, + literal: const_, + })), None)?; let ptr = ecx.allocate(op.layout, MemoryKind::Stack)?; ecx.copy_op(op, ptr.into())?; let alloc = ecx.memory().get(ptr.to_ptr()?.alloc_id)?; diff --git a/src/intrinsics.rs b/src/intrinsics.rs index b59e1c6631b4..bb565ea38a51 100644 --- a/src/intrinsics.rs +++ b/src/intrinsics.rs @@ -169,7 +169,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>( ret.write_cvalue(fx, CValue::ByVal(size, usize_layout)); }; min_align_of, () { - let min_align = fx.layout_of(T).align.abi(); + let min_align = fx.layout_of(T).align.abi.bytes(); let min_align = CValue::const_val(fx, usize_layout.ty, min_align as i64); ret.write_cvalue(fx, min_align); }; @@ -179,9 +179,9 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>( _ if !layout.is_unsized() => fx .bcx .ins() - .iconst(fx.pointer_type, layout.align.abi() as i64), + .iconst(fx.pointer_type, layout.align.abi.bytes() as i64), ty::Slice(elem) => { - let align = fx.layout_of(elem).align.abi() as i64; + let align = fx.layout_of(elem).align.abi.bytes() as i64; fx.bcx.ins().iconst(fx.pointer_type, align) } ty::Dynamic(..) => crate::vtable::min_align_of_obj(fx, ptr), diff --git a/src/lib.rs b/src/lib.rs index 9f81cebccafa..e1dcab738bc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ rustc_private, macro_at_most_once_rep, never_type, - extern_crate_item_prelude, decl_macro, )] #![allow(intra_doc_link_resolution_failure)] @@ -10,6 +9,7 @@ extern crate syntax; extern crate rustc; extern crate rustc_allocator; +extern crate rustc_codegen_ssa; extern crate rustc_codegen_utils; extern crate rustc_incremental; extern crate rustc_mir; @@ -25,19 +25,16 @@ use std::sync::mpsc; use syntax::symbol::Symbol; use rustc::dep_graph::DepGraph; -use rustc::middle::cstore::{ - self, CrateSource, LibSource, LinkagePreference, MetadataLoader, NativeLibrary, -}; -use rustc::middle::lang_items::LangItem; -use rustc::middle::weak_lang_items; +use rustc::middle::cstore::MetadataLoader; use rustc::session::{ - config::{self, OutputFilenames, OutputType}, + config::{OutputFilenames, OutputType}, CompileIncomplete, }; use rustc::ty::query::Providers; use rustc_codegen_utils::codegen_backend::CodegenBackend; use rustc_codegen_utils::link::out_filename; -use rustc_codegen_utils::linker::LinkerInfo; +use rustc_codegen_ssa::CrateInfo; +use rustc_codegen_ssa::back::linker::LinkerInfo; use cranelift::codegen::settings; use cranelift_faerie::*; @@ -81,7 +78,7 @@ mod prelude { self, subst::Substs, FnSig, Instance, InstanceDef, ParamEnv, PolyFnSig, Ty, TyCtxt, TypeAndMut, TypeFoldable, }; - pub use rustc_codegen_utils::{CompiledModule, ModuleKind}; + pub use rustc_codegen_ssa::{CompiledModule, ModuleKind}; pub use rustc_data_structures::{ fx::{FxHashMap, FxHashSet}, indexed_vec::Idx, @@ -103,7 +100,7 @@ mod prelude { pub use crate::common::*; pub use crate::trap::*; pub use crate::unimpl::{unimpl, with_unimpl_span}; - pub use crate::{Caches, CodegenResults, CrateInfo}; + pub use crate::{Caches, CodegenResults}; } pub struct Caches<'tcx> { @@ -122,124 +119,6 @@ impl<'tcx> Caches<'tcx> { struct CraneliftCodegenBackend; -pub struct CrateInfo { - panic_runtime: Option, - compiler_builtins: Option, - profiler_runtime: Option, - sanitizer_runtime: Option, - is_no_builtins: FxHashSet, - native_libraries: FxHashMap>>, - crate_name: FxHashMap, - used_libraries: Lrc>, - link_args: Lrc>, - used_crate_source: FxHashMap>, - used_crates_static: Vec<(CrateNum, LibSource)>, - used_crates_dynamic: Vec<(CrateNum, LibSource)>, - wasm_imports: FxHashMap, - lang_item_to_crate: FxHashMap, - missing_lang_items: FxHashMap>, -} - -impl CrateInfo { - pub fn new(tcx: TyCtxt) -> CrateInfo { - let mut info = CrateInfo { - panic_runtime: None, - compiler_builtins: None, - profiler_runtime: None, - sanitizer_runtime: None, - is_no_builtins: Default::default(), - native_libraries: Default::default(), - used_libraries: tcx.native_libraries(LOCAL_CRATE), - link_args: tcx.link_args(LOCAL_CRATE), - crate_name: Default::default(), - used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic), - used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic), - used_crate_source: Default::default(), - wasm_imports: Default::default(), - lang_item_to_crate: Default::default(), - missing_lang_items: Default::default(), - }; - let lang_items = tcx.lang_items(); - - let load_wasm_items = tcx - .sess - .crate_types - .borrow() - .iter() - .any(|c| *c != config::CrateType::Rlib) - && tcx.sess.opts.target_triple.triple() == "wasm32-unknown-unknown"; - - if load_wasm_items { - info.load_wasm_imports(tcx, LOCAL_CRATE); - } - - let crates = tcx.crates(); - - let n_crates = crates.len(); - info.native_libraries.reserve(n_crates); - info.crate_name.reserve(n_crates); - info.used_crate_source.reserve(n_crates); - info.missing_lang_items.reserve(n_crates); - - for &cnum in crates.iter() { - info.native_libraries - .insert(cnum, tcx.native_libraries(cnum)); - info.crate_name - .insert(cnum, tcx.crate_name(cnum).to_string()); - info.used_crate_source - .insert(cnum, tcx.used_crate_source(cnum)); - if tcx.is_panic_runtime(cnum) { - info.panic_runtime = Some(cnum); - } - if tcx.is_compiler_builtins(cnum) { - info.compiler_builtins = Some(cnum); - } - if tcx.is_profiler_runtime(cnum) { - info.profiler_runtime = Some(cnum); - } - if tcx.is_sanitizer_runtime(cnum) { - info.sanitizer_runtime = Some(cnum); - } - if tcx.is_no_builtins(cnum) { - info.is_no_builtins.insert(cnum); - } - if load_wasm_items { - info.load_wasm_imports(tcx, cnum); - } - let missing = tcx.missing_lang_items(cnum); - for &item in missing.iter() { - if let Ok(id) = lang_items.require(item) { - info.lang_item_to_crate.insert(item, id.krate); - } - } - - // No need to look for lang items that are whitelisted and don't - // actually need to exist. - let missing = missing - .iter() - .cloned() - .filter(|&l| !weak_lang_items::whitelisted(tcx, l)) - .collect(); - info.missing_lang_items.insert(cnum, missing); - } - - return info; - } - - fn load_wasm_imports(&mut self, tcx: TyCtxt, cnum: CrateNum) { - self.wasm_imports.extend( - tcx.wasm_import_module_map(cnum) - .iter() - .map(|(&id, module)| { - let instance = Instance::mono(tcx, id); - let import_name = tcx.symbol_name(instance); - - (import_name.to_string(), module.clone()) - }), - ); - } -} - pub struct CodegenResults { artifact: faerie::Artifact, modules: Vec, @@ -283,12 +162,12 @@ impl CodegenBackend for CraneliftCodegenBackend { fn provide(&self, providers: &mut Providers) { rustc_codegen_utils::symbol_names::provide(providers); - rustc_codegen_utils::symbol_export::provide(providers); + rustc_codegen_ssa::back::symbol_export::provide(providers); providers.target_features_whitelist = |_tcx, _cnum| Lrc::new(Default::default()); } fn provide_extern(&self, providers: &mut Providers) { - rustc_codegen_utils::symbol_export::provide_extern(providers); + rustc_codegen_ssa::back::symbol_export::provide_extern(providers); } fn codegen_crate<'a, 'tcx>( diff --git a/src/link.rs b/src/link.rs index 5fccac471238..28cc73797453 100644 --- a/src/link.rs +++ b/src/link.rs @@ -8,8 +8,9 @@ use tempfile::Builder as TempFileBuilder; use rustc::session::config::{self, CrateType, DebugInfo, RUST_CGU_EXT}; use rustc::session::search_paths::PathKind; use rustc::session::Session; -use rustc_codegen_utils::command::Command; -use rustc_codegen_utils::linker::*; +use rustc_codegen_ssa::back::command::Command; +use rustc_codegen_ssa::back::linker::*; +use rustc_codegen_ssa::back::link::*; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel}; diff --git a/src/link_copied.rs b/src/link_copied.rs index 2bec64612aaa..bf5be809a0e5 100644 --- a/src/link_copied.rs +++ b/src/link_copied.rs @@ -1,6 +1,5 @@ //! All functions here are copied from https://github.com/rust-lang/rust/blob/942864a000efd74b73e36bda5606b2cdb55ecf39/src/librustc_codegen_llvm/back/link.rs -use std::env; use std::fmt; use std::fs; use std::io; @@ -8,7 +7,6 @@ use std::iter; use std::path::{Path, PathBuf}; use std::process::{Output, Stdio}; -use cc::windows_registry; use log::info; use rustc::middle::cstore::{NativeLibrary, NativeLibraryKind}; @@ -17,11 +15,11 @@ use rustc::session::config::{self, OutputType, RUST_CGU_EXT}; use rustc::session::search_paths::PathKind; use rustc::session::Session; use rustc::util::common::time; -use rustc_codegen_utils::command::Command; -use rustc_codegen_utils::linker::*; +use rustc_codegen_ssa::back::command::Command; +use rustc_codegen_ssa::back::linker::*; +use rustc_codegen_ssa::back::link::*; use rustc_data_structures::fx::FxHashSet; use rustc_fs_util::fix_windows_verbatim_for_gcc; -use rustc_target::spec::LinkerFlavor; use syntax::attr; use crate::prelude::*; @@ -52,125 +50,6 @@ fn archive_config<'a>(sess: &'a Session, } } -// The third parameter is for env vars, used on windows to set up the -// path for MSVC to find its DLLs, and gcc to find its bundled -// toolchain -pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathBuf, Command) { - let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe"); - - // If our linker looks like a batch script on Windows then to execute this - // we'll need to spawn `cmd` explicitly. This is primarily done to handle - // emscripten where the linker is `emcc.bat` and needs to be spawned as - // `cmd /c emcc.bat ...`. - // - // This worked historically but is needed manually since #42436 (regression - // was tagged as #42791) and some more info can be found on #44443 for - // emscripten itself. - let mut cmd = match linker.to_str() { - Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker), - _ => match flavor { - LinkerFlavor::Lld(f) => Command::lld(linker, f), - LinkerFlavor::Msvc - if sess.opts.cg.linker.is_none() && sess.target.target.options.linker.is_none() => - { - Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker)) - }, - _ => Command::new(linker), - } - }; - - // The compiler's sysroot often has some bundled tools, so add it to the - // PATH for the child. - let mut new_path = sess.host_filesearch(PathKind::All) - .get_tools_search_paths(); - let mut msvc_changed_path = false; - if sess.target.target.options.is_like_msvc { - if let Some(ref tool) = msvc_tool { - cmd.args(tool.args()); - for &(ref k, ref v) in tool.env() { - if k == "PATH" { - new_path.extend(env::split_paths(v)); - msvc_changed_path = true; - } else { - cmd.env(k, v); - } - } - } - } - - if !msvc_changed_path { - if let Some(path) = env::var_os("PATH") { - new_path.extend(env::split_paths(&path)); - } - } - cmd.env("PATH", env::join_paths(new_path).unwrap()); - - (linker.to_path_buf(), cmd) -} - -pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { - fn infer_from( - sess: &Session, - linker: Option, - flavor: Option, - ) -> Option<(PathBuf, LinkerFlavor)> { - match (linker, flavor) { - (Some(linker), Some(flavor)) => Some((linker, flavor)), - // only the linker flavor is known; use the default linker for the selected flavor - (None, Some(flavor)) => Some((PathBuf::from(match flavor { - LinkerFlavor::Em => if cfg!(windows) { "emcc.bat" } else { "emcc" }, - LinkerFlavor::Gcc => "cc", - LinkerFlavor::Ld => "ld", - LinkerFlavor::Msvc => "link.exe", - LinkerFlavor::Lld(_) => "lld", - }), flavor)), - (Some(linker), None) => { - let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| { - sess.fatal("couldn't extract file stem from specified linker"); - }).to_owned(); - - let flavor = if stem == "emcc" { - LinkerFlavor::Em - } else if stem == "gcc" || stem.ends_with("-gcc") { - LinkerFlavor::Gcc - } else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") { - LinkerFlavor::Ld - } else if stem == "link" || stem == "lld-link" { - LinkerFlavor::Msvc - } else if stem == "lld" || stem == "rust-lld" { - LinkerFlavor::Lld(sess.target.target.options.lld_flavor) - } else { - // fall back to the value in the target spec - sess.target.target.linker_flavor - }; - - Some((linker, flavor)) - }, - (None, None) => None, - } - } - - // linker and linker flavor specified via command line have precedence over what the target - // specification specifies - if let Some(ret) = infer_from( - sess, - sess.opts.cg.linker.clone(), - sess.opts.debugging_opts.linker_flavor, - ) { - return ret; - } - - if let Some(ret) = infer_from( - sess, - sess.target.target.options.linker.clone().map(PathBuf::from), - Some(sess.target.target.linker_flavor), - ) { - return ret; - } - - bug!("Not enough information provided to determine how to invoke the linker"); -} - pub fn exec_linker(sess: &Session, cmd: &mut Command, out_filename: &Path, tmpdir: &Path) -> io::Result { @@ -739,24 +618,6 @@ pub fn add_upstream_native_libraries(cmd: &mut dyn Linker, } } -/// Returns a boolean indicating whether the specified crate should be ignored -/// during LTO. -/// -/// Crates ignored during LTO are not lumped together in the "massive object -/// file" that we create and are linked in their normal rlib states. See -/// comments below for what crates do not participate in LTO. -/// -/// It's unusual for a crate to not participate in LTO. Typically only -/// compiler-specific and unstable crates have a reason to not participate in -/// LTO. -fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool { - // If our target enables builtin function lowering in LLVM then the - // crates providing these functions don't participate in LTO (e.g. - // no_builtins or compiler builtins crates). - !sess.target.target.options.no_builtins && - (info.is_no_builtins.contains(&cnum) || info.compiler_builtins == Some(cnum)) -} - fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool { match lib.cfg { Some(ref cfg) => attr::cfg_matches(cfg, &sess.parse_sess, None), diff --git a/src/vtable.rs b/src/vtable.rs index d0ea60666d18..b9045a8eeba3 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -75,10 +75,6 @@ fn build_vtable<'a, 'tcx: 'a>( let tcx = fx.tcx; let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; - let (size, align) = tcx - .layout_of(ParamEnv::reveal_all().and(ty)) - .unwrap() - .size_and_align(); let drop_in_place_fn = fx.get_function_id( crate::rustc_mir::monomorphize::resolve_drop_in_place(tcx, ty), ); @@ -101,8 +97,10 @@ fn build_vtable<'a, 'tcx: 'a>( .take(components.len() * usize_size) .collect::>() .into_boxed_slice(); - write_usize(fx.tcx, &mut data, SIZE_INDEX, size.bytes()); - write_usize(fx.tcx, &mut data, ALIGN_INDEX, align.abi()); + + let layout = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap(); + write_usize(fx.tcx, &mut data, SIZE_INDEX, layout.size.bytes()); + write_usize(fx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes()); data_ctx.define(data); for (i, component) in components.into_iter().enumerate() {