From 6ceb1637b2500f384015578a5a6f556bcc992052 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 15 Jun 2018 19:02:41 +0200 Subject: [PATCH 01/19] Move some functions out of rustc_codegen_llvm and fix metadata_only backend --- src/bootstrap/bin/rustc.rs | 4 + src/bootstrap/compile.rs | 16 ++- src/librustc_codegen_llvm/base.rs | 7 +- src/librustc_codegen_llvm/common.rs | 104 ++++++++++++++- src/librustc_codegen_llvm/lib.rs | 4 +- src/librustc_codegen_llvm/llvm_util.rs | 118 +----------------- src/librustc_codegen_llvm/mono_item.rs | 2 +- src/librustc_codegen_utils/codegen_backend.rs | 16 ++- src/librustc_codegen_utils/lib.rs | 2 + .../llvm_target_features.rs | 117 +++++++++++++++++ .../time_graph.rs | 0 src/librustc_driver/lib.rs | 14 ++- 12 files changed, 265 insertions(+), 139 deletions(-) create mode 100644 src/librustc_codegen_utils/llvm_target_features.rs rename src/{librustc_codegen_llvm => librustc_codegen_utils}/time_graph.rs (100%) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 4607ca5cf9f4..d38ffe431e04 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -114,6 +114,10 @@ fn main() { cmd.env("RUSTC_BREAK_ON_ICE", "1"); + if args.iter().find(|s| **s == OsString::from("___")).is_some() { + cmd.arg("-Zcodegen-backend=metadata_only"); + } + if let Some(target) = target { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option. diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 298bd58c6cdf..e23566d52f0b 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -182,11 +182,13 @@ pub fn std_cargo(builder: &Builder, // missing // We also only build the runtimes when --enable-sanitizers (or its // config.toml equivalent) is used - let llvm_config = builder.ensure(native::Llvm { - target: builder.config.build, - emscripten: false, - }); - cargo.env("LLVM_CONFIG", llvm_config); + if !builder.config.rust_codegen_backends.is_empty() { + let llvm_config = builder.ensure(native::Llvm { + target: builder.config.build, + emscripten: false, + }); + cargo.env("LLVM_CONFIG", llvm_config); + } } cargo.arg("--features").arg(features) @@ -675,7 +677,9 @@ impl Step for CodegenBackend { .arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml")); rustc_cargo_env(builder, &mut cargo); - features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); + if !backend.is_empty() { + features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); + } let tmp_stamp = builder.cargo_out(compiler, Mode::Codegen, target) .join(".tmp.stamp"); diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index a4709739a23d..53c70eb42ce5 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -56,6 +56,7 @@ use builder::{Builder, MemFlags}; use callee; use common::{C_bool, C_bytes_in_context, C_i32, C_usize}; use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode}; +use rustc_mir::monomorphize::item::DefPathBasedNames; use common::{self, C_struct_in_context, C_array, val_ty}; use consts; use context::{self, CodegenCx}; @@ -67,7 +68,7 @@ use monomorphize::Instance; use monomorphize::partitioning::{self, PartitioningStrategy, CodegenUnit, CodegenUnitExt}; use rustc_codegen_utils::symbol_names_test; use time_graph; -use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt, DefPathBasedNames}; +use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt}; use type_::Type; use type_of::LayoutLlvmExt; use rustc::util::nodemap::{FxHashMap, FxHashSet, DefIdSet}; @@ -92,8 +93,6 @@ use syntax::ast; use mir::operand::OperandValue; -pub use rustc_codegen_utils::check_for_rustc_errors_attr; - pub struct StatRecorder<'a, 'tcx: 'a> { cx: &'a CodegenCx<'a, 'tcx>, name: Option, @@ -715,7 +714,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, rx: mpsc::Receiver>) -> OngoingCodegen { - check_for_rustc_errors_attr(tcx); + ::rustc_codegen_utils::check_for_rustc_errors_attr(tcx); if let Some(true) = tcx.sess.opts.debugging_opts.thinlto { if unsafe { !llvm::LLVMRustThinLTOAvailable() } { diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 7e55642814bb..099d717e3c00 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -12,9 +12,7 @@ //! Code that is useful in various codegen modules. -use llvm; -use llvm::{ValueRef, ContextRef, TypeKind}; -use llvm::{True, False, Bool, OperandBundleDef}; +use llvm::{self, ValueRef, ContextRef, TypeKind, True, False, Bool, OperandBundleDef}; use rustc::hir::def_id::DefId; use rustc::middle::lang_items::LangItem; use abi; @@ -29,6 +27,8 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::layout::{HasDataLayout, LayoutOf}; use rustc::hir; +use meth; + use libc::{c_uint, c_char}; use std::iter; @@ -448,3 +448,101 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, _ => bug!("unexpected type {:?} to ty_fn_sig", ty) } } + +pub fn size_and_align_of_dst<'a, 'tcx>(bx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) + -> (ValueRef, ValueRef) { + debug!("calculate size of DST: {}; with lost info: {:?}", + t, Value(info)); + if bx.cx.type_is_sized(t) { + let (size, align) = bx.cx.size_and_align_of(t); + debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}", + t, Value(info), size, align); + let size = C_usize(bx.cx, size.bytes()); + let align = C_usize(bx.cx, align.abi()); + return (size, align); + } + assert!(!info.is_null()); + match t.sty { + ty::TyDynamic(..) => { + // load size/align from vtable + (meth::SIZE.get_usize(bx, info), meth::ALIGN.get_usize(bx, info)) + } + ty::TySlice(_) | ty::TyStr => { + let unit = t.sequence_element_type(bx.tcx()); + // The info in this case is the length of the str, so the size is that + // times the unit size. + let (size, align) = bx.cx.size_and_align_of(unit); + (bx.mul(info, C_usize(bx.cx, size.bytes())), + C_usize(bx.cx, align.abi())) + } + _ => { + let cx = bx.cx; + // First get the size of all statically known fields. + // Don't use size_of because it also rounds up to alignment, which we + // want to avoid, as the unsized field's alignment could be smaller. + assert!(!t.is_simd()); + let layout = cx.layout_of(t); + debug!("DST {} layout: {:?}", t, layout); + + let i = layout.fields.count() - 1; + let sized_size = layout.fields.offset(i).bytes(); + let sized_align = layout.align.abi(); + debug!("DST {} statically sized prefix size: {} align: {}", + t, sized_size, sized_align); + let sized_size = C_usize(cx, sized_size); + let sized_align = C_usize(cx, sized_align); + + // Recurse to get the size of the dynamically sized field (must be + // the last field). + let field_ty = layout.field(cx, i).ty; + let (unsized_size, mut unsized_align) = size_and_align_of_dst(bx, field_ty, info); + + // FIXME (#26403, #27023): We should be adding padding + // to `sized_size` (to accommodate the `unsized_align` + // required of the unsized field that follows) before + // summing it with `sized_size`. (Note that since #26403 + // is unfixed, we do not yet add the necessary padding + // here. But this is where the add would go.) + + // Return the sum of sizes and max of aligns. + let size = bx.add(sized_size, unsized_size); + + // Packed types ignore the alignment of their fields. + if let ty::TyAdt(def, _) = t.sty { + if def.repr.packed() { + unsized_align = sized_align; + } + } + + // Choose max of two known alignments (combined value must + // be aligned according to more restrictive of the two). + let align = match (const_to_opt_u128(sized_align, false), + const_to_opt_u128(unsized_align, false)) { + (Some(sized_align), Some(unsized_align)) => { + // If both alignments are constant, (the sized_align should always be), then + // pick the correct alignment statically. + C_usize(cx, ::std::cmp::max(sized_align, unsized_align) as u64) + } + _ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align), + sized_align, + unsized_align) + }; + + // Issue #27023: must add any necessary padding to `size` + // (to make it a multiple of `align`) before returning it. + // + // Namely, the returned size should be, in C notation: + // + // `size + ((size & (align-1)) ? align : 0)` + // + // emulated via the semi-standard fast bit trick: + // + // `(size + (align-1)) & -align` + + let addend = bx.sub(align, C_usize(bx.cx, 1)); + let size = bx.and(bx.add(size, addend), bx.neg(align)); + + (size, align) + } + } +} diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index b11b0c7abe87..eee4e5f8f7a0 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -79,6 +79,7 @@ use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use rustc_mir::monomorphize; use rustc_codegen_utils::codegen_backend::CodegenBackend; +use rustc_codegen_utils::time_graph; mod diagnostics; @@ -114,7 +115,6 @@ mod llvm_util; mod metadata; mod meth; mod mir; -mod time_graph; mod mono_item; mod type_; mod type_of; @@ -368,7 +368,7 @@ struct CodegenResults { crate_info: CrateInfo, } -// Misc info we load from metadata to persist beyond the tcx +/// Misc info we load from metadata to persist beyond the tcx struct CrateInfo { panic_runtime: Option, compiler_builtins: Option, diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index 87ee9ef5adb2..b63b43c9c73a 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -20,6 +20,8 @@ use syntax::feature_gate::UnstableFeatures; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Once; +pub use rustc_codegen_utils::llvm_target_features::*; + static POISONED: AtomicBool = AtomicBool::new(false); static INIT: Once = Once::new(); @@ -79,108 +81,6 @@ unsafe fn configure_llvm(sess: &Session) { llvm_args.as_ptr()); } -// WARNING: the features after applying `to_llvm_feature` must be known -// to LLVM or the feature detection code will walk past the end of the feature -// array, leading to crashes. - -const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ - ("mclass", Some("arm_target_feature")), - ("neon", Some("arm_target_feature")), - ("v7", Some("arm_target_feature")), - ("vfp2", Some("arm_target_feature")), - ("vfp3", Some("arm_target_feature")), - ("vfp4", Some("arm_target_feature")), -]; - -const AARCH64_WHITELIST: &[(&str, Option<&str>)] = &[ - ("fp", Some("aarch64_target_feature")), - ("neon", Some("aarch64_target_feature")), - ("sve", Some("aarch64_target_feature")), - ("crc", Some("aarch64_target_feature")), - ("crypto", Some("aarch64_target_feature")), - ("ras", Some("aarch64_target_feature")), - ("lse", Some("aarch64_target_feature")), - ("rdm", Some("aarch64_target_feature")), - ("fp16", Some("aarch64_target_feature")), - ("rcpc", Some("aarch64_target_feature")), - ("dotprod", Some("aarch64_target_feature")), - ("v8.1a", Some("aarch64_target_feature")), - ("v8.2a", Some("aarch64_target_feature")), - ("v8.3a", Some("aarch64_target_feature")), -]; - -const X86_WHITELIST: &[(&str, Option<&str>)] = &[ - ("aes", None), - ("avx", None), - ("avx2", None), - ("avx512bw", Some("avx512_target_feature")), - ("avx512cd", Some("avx512_target_feature")), - ("avx512dq", Some("avx512_target_feature")), - ("avx512er", Some("avx512_target_feature")), - ("avx512f", Some("avx512_target_feature")), - ("avx512ifma", Some("avx512_target_feature")), - ("avx512pf", Some("avx512_target_feature")), - ("avx512vbmi", Some("avx512_target_feature")), - ("avx512vl", Some("avx512_target_feature")), - ("avx512vpopcntdq", Some("avx512_target_feature")), - ("bmi1", None), - ("bmi2", None), - ("fma", None), - ("fxsr", None), - ("lzcnt", None), - ("mmx", Some("mmx_target_feature")), - ("pclmulqdq", None), - ("popcnt", None), - ("rdrand", None), - ("rdseed", None), - ("sha", None), - ("sse", None), - ("sse2", None), - ("sse3", None), - ("sse4.1", None), - ("sse4.2", None), - ("sse4a", Some("sse4a_target_feature")), - ("ssse3", None), - ("tbm", Some("tbm_target_feature")), - ("xsave", None), - ("xsavec", None), - ("xsaveopt", None), - ("xsaves", None), -]; - -const HEXAGON_WHITELIST: &[(&str, Option<&str>)] = &[ - ("hvx", Some("hexagon_target_feature")), - ("hvx-double", Some("hexagon_target_feature")), -]; - -const POWERPC_WHITELIST: &[(&str, Option<&str>)] = &[ - ("altivec", Some("powerpc_target_feature")), - ("power8-altivec", Some("powerpc_target_feature")), - ("power9-altivec", Some("powerpc_target_feature")), - ("power8-vector", Some("powerpc_target_feature")), - ("power9-vector", Some("powerpc_target_feature")), - ("vsx", Some("powerpc_target_feature")), -]; - -const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[ - ("fp64", Some("mips_target_feature")), - ("msa", Some("mips_target_feature")), -]; - -/// When rustdoc is running, provide a list of all known features so that all their respective -/// primtives may be documented. -/// -/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this -/// iterator! -pub fn all_known_features() -> impl Iterator)> { - ARM_WHITELIST.iter().cloned() - .chain(AARCH64_WHITELIST.iter().cloned()) - .chain(X86_WHITELIST.iter().cloned()) - .chain(HEXAGON_WHITELIST.iter().cloned()) - .chain(POWERPC_WHITELIST.iter().cloned()) - .chain(MIPS_WHITELIST.iter().cloned()) -} - pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str { let arch = if sess.target.target.arch == "x86_64" { "x86" @@ -216,20 +116,6 @@ pub fn target_features(sess: &Session) -> Vec { .map(|feature| Symbol::intern(feature)).collect() } -pub fn target_feature_whitelist(sess: &Session) - -> &'static [(&'static str, Option<&'static str>)] -{ - match &*sess.target.target.arch { - "arm" => ARM_WHITELIST, - "aarch64" => AARCH64_WHITELIST, - "x86" | "x86_64" => X86_WHITELIST, - "hexagon" => HEXAGON_WHITELIST, - "mips" | "mips64" => MIPS_WHITELIST, - "powerpc" | "powerpc64" => POWERPC_WHITELIST, - _ => &[], - } -} - pub fn print_version() { // Can be called without initializing LLVM unsafe { diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index c4a23ac653ca..61f4bc3e6bc8 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -33,7 +33,7 @@ use std::fmt; pub use rustc::mir::mono::MonoItem; -pub use rustc_mir::monomorphize::item::*; +use rustc_mir::monomorphize::item::*; pub use rustc_mir::monomorphize::item::MonoItemExt as BaseMonoItemExt; pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> { diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 8ba6f30cf16e..8b52d61fd9e5 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -26,7 +26,7 @@ use std::io::prelude::*; use std::io::{self, Cursor}; use std::fs::File; use std::path::Path; -use std::sync::mpsc; +use std::sync::{mpsc, Arc}; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::sync::Lrc; @@ -44,7 +44,6 @@ use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::MetadataLoader; use rustc::dep_graph::DepGraph; use rustc_target::spec::Target; -use rustc_data_structures::fx::FxHashMap; use rustc_mir::monomorphize::collector; use link::{build_link_meta, out_filename}; @@ -203,10 +202,17 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { ::symbol_names::provide(providers); providers.target_features_whitelist = |_tcx, _cnum| { - Lrc::new(FxHashMap()) // Just a dummy + Lrc::new(::llvm_target_features::all_known_features() + .map(|(a, b)| (a.to_string(), b.map(|s| s.to_string()))) + .collect()) }; + providers.is_reachable_non_generic = |_tcx, _defid| true; + providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); + providers.wasm_custom_sections = |_tcx, _crate| Lrc::new(Vec::new()); + } + fn provide_extern(&self, providers: &mut Providers) { + providers.is_reachable_non_generic = |_tcx, _defid| true; } - fn provide_extern(&self, _providers: &mut Providers) {} fn codegen_crate<'a, 'tcx>( &self, @@ -225,7 +231,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { collector::MonoItemCollectionMode::Eager ).0.iter() ); - ::rustc::middle::dependency_format::calculate(tcx); + //::rustc::middle::dependency_format::calculate(tcx); let _ = tcx.link_args(LOCAL_CRATE); let _ = tcx.native_libraries(LOCAL_CRATE); for mono_item in diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index d09e8f4845e5..058e4b7841f5 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -47,6 +47,8 @@ pub mod link; pub mod codegen_backend; pub mod symbol_names; pub mod symbol_names_test; +pub mod time_graph; +pub mod llvm_target_features; /// check for the #[rustc_error] annotation, which forces an /// error in codegen. This is used to write compile-fail tests diff --git a/src/librustc_codegen_utils/llvm_target_features.rs b/src/librustc_codegen_utils/llvm_target_features.rs new file mode 100644 index 000000000000..82cd397be232 --- /dev/null +++ b/src/librustc_codegen_utils/llvm_target_features.rs @@ -0,0 +1,117 @@ +use rustc::session::Session; + +// WARNING: the features after applying `to_llvm_feature` must be known +// to LLVM or the feature detection code will walk past the end of the feature +// array, leading to crashes. + +const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ + ("mclass", Some("arm_target_feature")), + ("neon", Some("arm_target_feature")), + ("v7", Some("arm_target_feature")), + ("vfp2", Some("arm_target_feature")), + ("vfp3", Some("arm_target_feature")), + ("vfp4", Some("arm_target_feature")), +]; + +const AARCH64_WHITELIST: &[(&str, Option<&str>)] = &[ + ("fp", Some("aarch64_target_feature")), + ("neon", Some("aarch64_target_feature")), + ("sve", Some("aarch64_target_feature")), + ("crc", Some("aarch64_target_feature")), + ("crypto", Some("aarch64_target_feature")), + ("ras", Some("aarch64_target_feature")), + ("lse", Some("aarch64_target_feature")), + ("rdm", Some("aarch64_target_feature")), + ("fp16", Some("aarch64_target_feature")), + ("rcpc", Some("aarch64_target_feature")), + ("dotprod", Some("aarch64_target_feature")), + ("v8.1a", Some("aarch64_target_feature")), + ("v8.2a", Some("aarch64_target_feature")), + ("v8.3a", Some("aarch64_target_feature")), +]; + +const X86_WHITELIST: &[(&str, Option<&str>)] = &[ + ("aes", None), + ("avx", None), + ("avx2", None), + ("avx512bw", Some("avx512_target_feature")), + ("avx512cd", Some("avx512_target_feature")), + ("avx512dq", Some("avx512_target_feature")), + ("avx512er", Some("avx512_target_feature")), + ("avx512f", Some("avx512_target_feature")), + ("avx512ifma", Some("avx512_target_feature")), + ("avx512pf", Some("avx512_target_feature")), + ("avx512vbmi", Some("avx512_target_feature")), + ("avx512vl", Some("avx512_target_feature")), + ("avx512vpopcntdq", Some("avx512_target_feature")), + ("bmi1", None), + ("bmi2", None), + ("fma", None), + ("fxsr", None), + ("lzcnt", None), + ("mmx", Some("mmx_target_feature")), + ("pclmulqdq", None), + ("popcnt", None), + ("rdrand", None), + ("rdseed", None), + ("sha", None), + ("sse", None), + ("sse2", None), + ("sse3", None), + ("sse4.1", None), + ("sse4.2", None), + ("sse4a", Some("sse4a_target_feature")), + ("ssse3", None), + ("tbm", Some("tbm_target_feature")), + ("xsave", None), + ("xsavec", None), + ("xsaveopt", None), + ("xsaves", None), +]; + +const HEXAGON_WHITELIST: &[(&str, Option<&str>)] = &[ + ("hvx", Some("hexagon_target_feature")), + ("hvx-double", Some("hexagon_target_feature")), +]; + +const POWERPC_WHITELIST: &[(&str, Option<&str>)] = &[ + ("altivec", Some("powerpc_target_feature")), + ("power8-altivec", Some("powerpc_target_feature")), + ("power9-altivec", Some("powerpc_target_feature")), + ("power8-vector", Some("powerpc_target_feature")), + ("power9-vector", Some("powerpc_target_feature")), + ("vsx", Some("powerpc_target_feature")), +]; + +const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[ + ("fp64", Some("mips_target_feature")), + ("msa", Some("mips_target_feature")), +]; + +/// When rustdoc is running, provide a list of all known features so that all their respective +/// primtives may be documented. +/// +/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this +/// iterator! +pub fn all_known_features() -> impl Iterator)> { + ARM_WHITELIST.iter().cloned() + .chain(AARCH64_WHITELIST.iter().cloned()) + .chain(X86_WHITELIST.iter().cloned()) + .chain(HEXAGON_WHITELIST.iter().cloned()) + .chain(POWERPC_WHITELIST.iter().cloned()) + .chain(MIPS_WHITELIST.iter().cloned()) +} + +pub fn target_feature_whitelist(sess: &Session) + -> &'static [(&'static str, Option<&'static str>)] +{ + match &*sess.target.target.arch { + "arm" => ARM_WHITELIST, + "aarch64" => AARCH64_WHITELIST, + "x86" | "x86_64" => X86_WHITELIST, + "hexagon" => HEXAGON_WHITELIST, + "mips" | "mips64" => MIPS_WHITELIST, + "powerpc" | "powerpc64" => POWERPC_WHITELIST, + _ => &[], + } +} diff --git a/src/librustc_codegen_llvm/time_graph.rs b/src/librustc_codegen_utils/time_graph.rs similarity index 100% rename from src/librustc_codegen_llvm/time_graph.rs rename to src/librustc_codegen_utils/time_graph.rs diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 84f7b35d21f3..321d398b5210 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -375,10 +375,20 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box { match file { Some(ref s) => return load_backend_from_dylib(s), None => { - let err = format!("failed to load default codegen backend for `{}`, \ + if !::rustc::session::config::nightly_options::is_nightly_build() { + let err = format!("failed to load default codegen backend for `{}`, \ no appropriate codegen dylib found in `{}`", backend_name, sysroot.display()); - early_error(ErrorOutputType::default(), &err); + early_error(ErrorOutputType::default(), &err); + } else { + let warn = format!("no codegen-backend `{}`, \ + no appropriate dylib in `{}`. \ + Falling back to metadata_only codegen backend. \ + **This is suitable for dev purposes only**", + backend_name, sysroot.display()); + early_warn(ErrorOutputType::default(), &warn); + return rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::new; + } } } From 95ed511514ea46ae50ce06e9e19c5460a786838a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 16 Jun 2018 11:45:59 +0200 Subject: [PATCH 02/19] Mostly fix compiling without LLVM (with metadata_only backend) --- config.toml.example | 4 - src/Cargo.lock | 2 - src/bootstrap/bin/rustc.rs | 4 - src/bootstrap/builder.rs | 2 +- src/bootstrap/config.rs | 4 - src/bootstrap/test.rs | 4 +- src/bootstrap/tool.rs | 2 +- src/librustc_codegen_utils/Cargo.toml | 2 - src/librustc_codegen_utils/codegen_backend.rs | 105 ++---------------- src/librustc_codegen_utils/lib.rs | 4 - src/tools/tidy/src/deps.rs | 1 - 11 files changed, 15 insertions(+), 119 deletions(-) diff --git a/config.toml.example b/config.toml.example index 0578f929224d..7bf52a369e37 100644 --- a/config.toml.example +++ b/config.toml.example @@ -14,10 +14,6 @@ # ============================================================================= [llvm] -# Indicates whether rustc will support compilation with LLVM -# note: rustc does not compile without LLVM at the moment -#enabled = true - # Indicates whether the LLVM build is a Release or Debug build #optimize = true diff --git a/src/Cargo.lock b/src/Cargo.lock index 7297d8a8299a..e3610c1d679b 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2031,8 +2031,6 @@ dependencies = [ name = "rustc_codegen_utils" version = "0.0.0" dependencies = [ - "ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index d38ffe431e04..4607ca5cf9f4 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -114,10 +114,6 @@ fn main() { cmd.env("RUSTC_BREAK_ON_ICE", "1"); - if args.iter().find(|s| **s == OsString::from("___")).is_some() { - cmd.arg("-Zcodegen-backend=metadata_only"); - } - if let Some(target) = target { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option. diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index fad0a553802a..d2f9b2653d50 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -893,7 +893,7 @@ impl<'a> Builder<'a> { // // If LLVM support is disabled we need to use the snapshot compiler to compile // build scripts, as the new compiler doesn't support executables. - if mode == Mode::Std || !self.config.llvm_enabled { + if mode == Mode::Std || self.config.rust_codegen_backends.is_empty() { cargo .env("RUSTC_SNAPSHOT", &self.initial_rustc) .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b3ed10257bda..2e629456b7ef 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -74,7 +74,6 @@ pub struct Config { pub backtrace_on_ice: bool, // llvm codegen options - pub llvm_enabled: bool, pub llvm_assertions: bool, pub llvm_optimize: bool, pub llvm_release_debuginfo: bool, @@ -239,7 +238,6 @@ struct Install { #[derive(Deserialize, Default)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct Llvm { - enabled: Option, ccache: Option, ninja: Option, assertions: Option, @@ -341,7 +339,6 @@ impl Config { pub fn default_opts() -> Config { let mut config = Config::default(); - config.llvm_enabled = true; config.llvm_optimize = true; config.llvm_version_check = true; config.use_jemalloc = true; @@ -496,7 +493,6 @@ impl Config { Some(StringOrBool::Bool(false)) | None => {} } set(&mut config.ninja, llvm.ninja); - set(&mut config.llvm_enabled, llvm.enabled); llvm_assertions = llvm.assertions; set(&mut config.llvm_optimize, llvm.optimize); set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 6254f9816566..917b85690dea 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1096,7 +1096,7 @@ impl Step for Compiletest { cmd.arg("--quiet"); } - if builder.config.llvm_enabled { + if !builder.config.rust_codegen_backends.is_empty() { let llvm_config = builder.ensure(native::Llvm { target: builder.config.build, emscripten: false, @@ -1129,7 +1129,7 @@ impl Step for Compiletest { } } } - if suite == "run-make-fulldeps" && !builder.config.llvm_enabled { + if suite == "run-make-fulldeps" && builder.config.rust_codegen_backends.is_empty() { builder.info(&format!( "Ignoring run-make test suite as they generally don't work without LLVM" )); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index b3d7b9a91ecf..640dd9ecdd99 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -672,7 +672,7 @@ impl<'a> Builder<'a> { } fn llvm_bin_path(&self) -> Option { - if self.config.llvm_enabled && !self.config.dry_run { + if !self.config.rust_codegen_backends.is_empty() && !self.config.dry_run { let llvm_config = self.ensure(native::Llvm { target: self.config.build, emscripten: false, diff --git a/src/librustc_codegen_utils/Cargo.toml b/src/librustc_codegen_utils/Cargo.toml index 690fb260390e..77a29ac89f5c 100644 --- a/src/librustc_codegen_utils/Cargo.toml +++ b/src/librustc_codegen_utils/Cargo.toml @@ -10,8 +10,6 @@ crate-type = ["dylib"] test = false [dependencies] -ar = "0.3.0" -flate2 = "1.0" log = "0.4" syntax = { path = "../libsyntax" } diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 8b52d61fd9e5..25d01ace4cae 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -22,17 +22,13 @@ #![feature(box_syntax)] use std::any::Any; -use std::io::prelude::*; -use std::io::{self, Cursor}; +use std::io::{self, Write}; use std::fs::File; use std::path::Path; use std::sync::{mpsc, Arc}; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::sync::Lrc; -use ar::{Archive, Builder, Header}; -use flate2::Compression; -use flate2::write::DeflateEncoder; use syntax::symbol::Symbol; use rustc::hir::def_id::LOCAL_CRATE; @@ -80,96 +76,27 @@ pub trait CodegenBackend { ) -> Result<(), CompileIncomplete>; } -pub struct DummyCodegenBackend; - -impl CodegenBackend for DummyCodegenBackend { - fn metadata_loader(&self) -> Box { - box DummyMetadataLoader(()) - } - - fn provide(&self, _providers: &mut Providers) { - bug!("DummyCodegenBackend::provide"); - } - - fn provide_extern(&self, _providers: &mut Providers) { - bug!("DummyCodegenBackend::provide_extern"); - } - - fn codegen_crate<'a, 'tcx>( - &self, - _tcx: TyCtxt<'a, 'tcx, 'tcx>, - _rx: mpsc::Receiver> - ) -> Box { - bug!("DummyCodegenBackend::codegen_backend"); - } - - fn join_codegen_and_link( - &self, - _ongoing_codegen: Box, - _sess: &Session, - _dep_graph: &DepGraph, - _outputs: &OutputFilenames, - ) -> Result<(), CompileIncomplete> { - bug!("DummyCodegenBackend::join_codegen_and_link"); - } -} - -pub struct DummyMetadataLoader(()); - -impl MetadataLoader for DummyMetadataLoader { - fn get_rlib_metadata( - &self, - _target: &Target, - _filename: &Path - ) -> Result { - bug!("DummyMetadataLoader::get_rlib_metadata"); - } - - fn get_dylib_metadata( - &self, - _target: &Target, - _filename: &Path - ) -> Result { - bug!("DummyMetadataLoader::get_dylib_metadata"); - } -} - pub struct NoLlvmMetadataLoader; impl MetadataLoader for NoLlvmMetadataLoader { fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result { - let file = File::open(filename) + let mut file = File::open(filename) .map_err(|e| format!("metadata file open err: {:?}", e))?; - let mut archive = Archive::new(file); - while let Some(entry_result) = archive.next_entry() { - let mut entry = entry_result - .map_err(|e| format!("metadata section read err: {:?}", e))?; - if entry.header().identifier() == "rust.metadata.bin" { - let mut buf = Vec::new(); - io::copy(&mut entry, &mut buf).unwrap(); - let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); - return Ok(rustc_erase_owner!(buf.map_owner_box())); - } - } - - Err("Couldn't find metadata section".to_string()) + let mut buf = Vec::new(); + io::copy(&mut file, &mut buf).unwrap(); + let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); + return Ok(rustc_erase_owner!(buf.map_owner_box())); } - fn get_dylib_metadata( - &self, - _target: &Target, - _filename: &Path, - ) -> Result { - // FIXME: Support reading dylibs from llvm enabled rustc - self.get_rlib_metadata(_target, _filename) + fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result { + self.get_rlib_metadata(target, filename) } } pub struct MetadataOnlyCodegenBackend(()); pub struct OngoingCodegen { metadata: EncodedMetadata, - metadata_version: Vec, crate_name: Symbol, } @@ -257,7 +184,6 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { box OngoingCodegen { metadata: metadata, - metadata_version: tcx.metadata_encoding_version().to_vec(), crate_name: tcx.crate_name(LOCAL_CRATE), } } @@ -277,18 +203,9 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { } let output_name = out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str()); - let mut compressed = ongoing_codegen.metadata_version.clone(); - let metadata = if crate_type == CrateType::CrateTypeDylib { - DeflateEncoder::new(&mut compressed, Compression::fast()) - .write_all(&ongoing_codegen.metadata.raw_data) - .unwrap(); - &compressed - } else { - &ongoing_codegen.metadata.raw_data - }; - let mut builder = Builder::new(File::create(&output_name).unwrap()); - let header = Header::new("rust.metadata.bin".to_string(), metadata.len() as u64); - builder.append(&header, Cursor::new(metadata)).unwrap(); + let metadata = &ongoing_codegen.metadata.raw_data; + let mut file = File::create(&output_name).unwrap(); + file.write_all(metadata).unwrap(); } sess.abort_if_errors(); diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 058e4b7841f5..c168f26cd170 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -25,8 +25,6 @@ #![recursion_limit="256"] -extern crate ar; -extern crate flate2; #[macro_use] extern crate log; @@ -39,8 +37,6 @@ extern crate syntax; extern crate syntax_pos; #[macro_use] extern crate rustc_data_structures; -pub extern crate rustc as __rustc; - use rustc::ty::TyCtxt; pub mod link; diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index dedf42fecbbd..942d27202ecd 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -59,7 +59,6 @@ static WHITELIST_CRATES: &'static [CrateVersion] = &[ /// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible. static WHITELIST: &'static [Crate] = &[ Crate("aho-corasick"), - Crate("ar"), Crate("arrayvec"), Crate("atty"), Crate("backtrace"), From edd6ed571f9886d4b01fe87812442d5e81d1c895 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 16 Jun 2018 12:07:54 +0200 Subject: [PATCH 03/19] Fix some errors --- src/librustc_codegen_llvm/glue.rs | 122 ------------------ src/librustc_codegen_llvm/intrinsic.rs | 5 +- src/librustc_codegen_llvm/lib.rs | 1 - src/librustc_codegen_llvm/mir/place.rs | 7 +- src/librustc_codegen_llvm/mono_item.rs | 1 - src/librustc_codegen_llvm/type_of.rs | 2 +- .../llvm_target_features.rs | 10 ++ 7 files changed, 17 insertions(+), 131 deletions(-) delete mode 100644 src/librustc_codegen_llvm/glue.rs diff --git a/src/librustc_codegen_llvm/glue.rs b/src/librustc_codegen_llvm/glue.rs deleted file mode 100644 index c7275d094018..000000000000 --- a/src/librustc_codegen_llvm/glue.rs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! -// -// Code relating to drop glue. - -use std; - -use builder::Builder; -use common::*; -use llvm::{ValueRef}; -use llvm; -use meth; -use rustc::ty::layout::LayoutOf; -use rustc::ty::{self, Ty}; -use value::Value; - -pub fn size_and_align_of_dst<'a, 'tcx>(bx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) - -> (ValueRef, ValueRef) { - debug!("calculate size of DST: {}; with lost info: {:?}", - t, Value(info)); - if bx.cx.type_is_sized(t) { - let (size, align) = bx.cx.size_and_align_of(t); - debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}", - t, Value(info), size, align); - let size = C_usize(bx.cx, size.bytes()); - let align = C_usize(bx.cx, align.abi()); - return (size, align); - } - assert!(!info.is_null()); - match t.sty { - ty::TyDynamic(..) => { - // load size/align from vtable - (meth::SIZE.get_usize(bx, info), meth::ALIGN.get_usize(bx, info)) - } - ty::TySlice(_) | ty::TyStr => { - let unit = t.sequence_element_type(bx.tcx()); - // The info in this case is the length of the str, so the size is that - // times the unit size. - let (size, align) = bx.cx.size_and_align_of(unit); - (bx.mul(info, C_usize(bx.cx, size.bytes())), - C_usize(bx.cx, align.abi())) - } - _ => { - let cx = bx.cx; - // First get the size of all statically known fields. - // Don't use size_of because it also rounds up to alignment, which we - // want to avoid, as the unsized field's alignment could be smaller. - assert!(!t.is_simd()); - let layout = cx.layout_of(t); - debug!("DST {} layout: {:?}", t, layout); - - let i = layout.fields.count() - 1; - let sized_size = layout.fields.offset(i).bytes(); - let sized_align = layout.align.abi(); - debug!("DST {} statically sized prefix size: {} align: {}", - t, sized_size, sized_align); - let sized_size = C_usize(cx, sized_size); - let sized_align = C_usize(cx, sized_align); - - // Recurse to get the size of the dynamically sized field (must be - // the last field). - let field_ty = layout.field(cx, i).ty; - let (unsized_size, mut unsized_align) = size_and_align_of_dst(bx, field_ty, info); - - // FIXME (#26403, #27023): We should be adding padding - // to `sized_size` (to accommodate the `unsized_align` - // required of the unsized field that follows) before - // summing it with `sized_size`. (Note that since #26403 - // is unfixed, we do not yet add the necessary padding - // here. But this is where the add would go.) - - // Return the sum of sizes and max of aligns. - let size = bx.add(sized_size, unsized_size); - - // Packed types ignore the alignment of their fields. - if let ty::TyAdt(def, _) = t.sty { - if def.repr.packed() { - unsized_align = sized_align; - } - } - - // Choose max of two known alignments (combined value must - // be aligned according to more restrictive of the two). - let align = match (const_to_opt_u128(sized_align, false), - const_to_opt_u128(unsized_align, false)) { - (Some(sized_align), Some(unsized_align)) => { - // If both alignments are constant, (the sized_align should always be), then - // pick the correct alignment statically. - C_usize(cx, std::cmp::max(sized_align, unsized_align) as u64) - } - _ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align), - sized_align, - unsized_align) - }; - - // Issue #27023: must add any necessary padding to `size` - // (to make it a multiple of `align`) before returning it. - // - // Namely, the returned size should be, in C notation: - // - // `size + ((size & (align-1)) ? align : 0)` - // - // emulated via the semi-standard fast bit trick: - // - // `(size + (align-1)) & -align` - - let addend = bx.sub(align, C_usize(bx.cx, 1)); - let size = bx.and(bx.add(size, addend), bx.neg(align)); - - (size, align) - } - } -} diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 6bb5456f9034..d7a068265a9e 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -19,7 +19,6 @@ use mir::operand::{OperandRef, OperandValue}; use base::*; use common::*; use declare; -use glue; use type_::Type; use type_of::LayoutLlvmExt; use rustc::ty::{self, Ty}; @@ -146,7 +145,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let tp_ty = substs.type_at(0); if let OperandValue::Pair(_, meta) = args[0].val { let (llsize, _) = - glue::size_and_align_of_dst(bx, tp_ty, meta); + size_and_align_of_dst(bx, tp_ty, meta); llsize } else { C_usize(cx, cx.size_of(tp_ty).bytes()) @@ -160,7 +159,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let tp_ty = substs.type_at(0); if let OperandValue::Pair(_, meta) = args[0].val { let (_, llalign) = - glue::size_and_align_of_dst(bx, tp_ty, meta); + size_and_align_of_dst(bx, tp_ty, meta); llalign } else { C_usize(cx, cx.align_of(tp_ty).abi()) diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index eee4e5f8f7a0..fd2d1f538876 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -109,7 +109,6 @@ mod consts; mod context; mod debuginfo; mod declare; -mod glue; mod intrinsic; mod llvm_util; mod metadata; diff --git a/src/librustc_codegen_llvm/mir/place.rs b/src/librustc_codegen_llvm/mir/place.rs index 2a1e3980adbc..93c31286932e 100644 --- a/src/librustc_codegen_llvm/mir/place.rs +++ b/src/librustc_codegen_llvm/mir/place.rs @@ -16,12 +16,13 @@ use rustc::mir::tcx::PlaceTy; use rustc_data_structures::indexed_vec::Idx; use base; use builder::Builder; -use common::{CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big}; +use common::{ + CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big,size_and_align_of_dst +}; use consts; use type_of::LayoutLlvmExt; use type_::Type; use value::Value; -use glue; use std::ptr; @@ -222,7 +223,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> { let unaligned_offset = C_usize(cx, offset.bytes()); // Get the alignment of the field - let (_, unsized_align) = glue::size_and_align_of_dst(bx, field.ty, meta); + let (_, unsized_align) = size_and_align_of_dst(bx, field.ty, meta); // Bump the unaligned offset up to the appropriate alignment using the // following expression: diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index 61f4bc3e6bc8..2f7b27b85afe 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -33,7 +33,6 @@ use std::fmt; pub use rustc::mir::mono::MonoItem; -use rustc_mir::monomorphize::item::*; pub use rustc_mir::monomorphize::item::MonoItemExt as BaseMonoItemExt; pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> { diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 88b75ff9c094..bfabf65dfd85 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -16,7 +16,7 @@ use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout}; use rustc_target::spec::PanicStrategy; use rustc_target::abi::FloatTy; -use mono_item::DefPathBasedNames; +use rustc_mir::monomorphize::item::DefPathBasedNames; use type_::Type; use std::fmt::Write; diff --git a/src/librustc_codegen_utils/llvm_target_features.rs b/src/librustc_codegen_utils/llvm_target_features.rs index 82cd397be232..8e11363cead8 100644 --- a/src/librustc_codegen_utils/llvm_target_features.rs +++ b/src/librustc_codegen_utils/llvm_target_features.rs @@ -1,3 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use rustc::session::Session; // WARNING: the features after applying `to_llvm_feature` must be known From f44ec6439b31caa92ee394f65aae7d4a1a5341dd Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 16 Jun 2018 16:46:03 +0200 Subject: [PATCH 04/19] Undo unnecessary change --- src/librustc_codegen_llvm/base.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 53c70eb42ce5..f9d843194337 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -93,6 +93,8 @@ use syntax::ast; use mir::operand::OperandValue; +use rustc_codegen_utils::check_for_rustc_errors_attr; + pub struct StatRecorder<'a, 'tcx: 'a> { cx: &'a CodegenCx<'a, 'tcx>, name: Option, @@ -714,7 +716,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, rx: mpsc::Receiver>) -> OngoingCodegen { - ::rustc_codegen_utils::check_for_rustc_errors_attr(tcx); + check_for_rustc_errors_attr(tcx); if let Some(true) = tcx.sess.opts.debugging_opts.thinlto { if unsafe { !llvm::LLVMRustThinLTOAvailable() } { From d7bc2937464b760d69ae8fc1146b660dc867e802 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 16 Jun 2018 18:46:54 +0200 Subject: [PATCH 05/19] Solve review comment --- src/bootstrap/compile.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index e23566d52f0b..524df9587dad 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -645,14 +645,13 @@ impl Step for CodegenBackend { fn make_run(run: RunConfig) { let backend = run.builder.config.rust_codegen_backends.get(0); - let backend = backend.cloned().unwrap_or_else(|| { - INTERNER.intern_str("llvm") - }); - run.builder.ensure(CodegenBackend { - compiler: run.builder.compiler(run.builder.top_stage, run.host), - target: run.target, - backend, - }); + if let Some(backend) = backend.cloned() { + run.builder.ensure(CodegenBackend { + compiler: run.builder.compiler(run.builder.top_stage, run.host), + target: run.target, + backend, + }); + } } fn run(self, builder: &Builder) { @@ -677,9 +676,7 @@ impl Step for CodegenBackend { .arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml")); rustc_cargo_env(builder, &mut cargo); - if !backend.is_empty() { - features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); - } + features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); let tmp_stamp = builder.cargo_out(compiler, Mode::Codegen, target) .join(".tmp.stamp"); From 097de536e43e0040e5966ee8e4c75e84c973b2e0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 18 Jun 2018 18:13:00 +0200 Subject: [PATCH 06/19] Fix metadata_only metadata encoding --- src/librustc_codegen_utils/Cargo.toml | 1 + src/librustc_codegen_utils/codegen_backend.rs | 14 +++++++++++++- src/librustc_codegen_utils/lib.rs | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustc_codegen_utils/Cargo.toml b/src/librustc_codegen_utils/Cargo.toml index 77a29ac89f5c..30f533285ddf 100644 --- a/src/librustc_codegen_utils/Cargo.toml +++ b/src/librustc_codegen_utils/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["dylib"] test = false [dependencies] +flate2 = "1.0" log = "0.4" syntax = { path = "../libsyntax" } diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 25d01ace4cae..c8cb92b7782f 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -29,6 +29,8 @@ use std::sync::{mpsc, Arc}; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::sync::Lrc; +use flate2::Compression; +use flate2::write::DeflateEncoder; use syntax::symbol::Symbol; use rustc::hir::def_id::LOCAL_CRATE; @@ -97,6 +99,7 @@ impl MetadataLoader for NoLlvmMetadataLoader { pub struct MetadataOnlyCodegenBackend(()); pub struct OngoingCodegen { metadata: EncodedMetadata, + metadata_version: Vec, crate_name: Symbol, } @@ -184,6 +187,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { box OngoingCodegen { metadata: metadata, + metadata_version: tcx.metadata_encoding_version().to_vec(), crate_name: tcx.crate_name(LOCAL_CRATE), } } @@ -203,7 +207,15 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { } let output_name = out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str()); - let metadata = &ongoing_codegen.metadata.raw_data; + let mut compressed = ongoing_codegen.metadata_version.clone(); + let metadata = if crate_type == CrateType::CrateTypeDylib { + DeflateEncoder::new(&mut compressed, Compression::fast()) + .write_all(&ongoing_codegen.metadata.raw_data) + .unwrap(); + &compressed + } else { + &ongoing_codegen.metadata.raw_data + }; let mut file = File::create(&output_name).unwrap(); file.write_all(metadata).unwrap(); } diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index c168f26cd170..0298162bbb51 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -25,6 +25,7 @@ #![recursion_limit="256"] +extern crate flate2; #[macro_use] extern crate log; From e65db8161d39e1f27a1c525027c92f8f0aa7f97c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 19 Jun 2018 10:52:13 +0200 Subject: [PATCH 07/19] Fix test --- src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile | 2 +- .../run-make-fulldeps/hotplug_codegen_backend/some_crate.rs | 5 ++--- .../run-make-fulldeps/hotplug_codegen_backend/the_backend.rs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile b/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile index 2ddf3aa5439f..e203ec2737fc 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile @@ -4,6 +4,6 @@ all: /bin/echo || exit 0 # This test requires /bin/echo to exist $(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \ -o $(TMPDIR)/the_backend.dylib - $(RUSTC) some_crate.rs --crate-name some_crate --crate-type bin -o $(TMPDIR)/some_crate \ + $(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \ -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options grep -x "This has been \"compiled\" successfully." $(TMPDIR)/some_crate diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs index 26ffce01b2e2..bfa8b6b3ef69 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs @@ -8,6 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { - ::std::process::exit(1); -} +#![feature(no_core)] +#![no_core] diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs index 439bc017fee6..a3cd033f8638 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs @@ -63,7 +63,7 @@ impl CodegenBackend for TheBackend { let crate_name = ongoing_codegen.downcast::() .expect("in join_codegen_and_link: ongoing_codegen is not a Symbol"); for &crate_type in sess.opts.crate_types.iter() { - if crate_type != CrateType::CrateTypeExecutable { + if crate_type != CrateType::CrateTypeRlib { sess.fatal(&format!("Crate type is {:?}", crate_type)); } let output_name = From cd4989ee94b86914469d917ba848a2cb3a51a72e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 20 Jun 2018 09:35:01 +0200 Subject: [PATCH 08/19] Leave fixme comment --- src/librustc_codegen_utils/codegen_backend.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index c8cb92b7782f..8043559b3109 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -161,7 +161,8 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { collector::MonoItemCollectionMode::Eager ).0.iter() ); - //::rustc::middle::dependency_format::calculate(tcx); + // FIXME: Fix this + // ::rustc::middle::dependency_format::calculate(tcx); let _ = tcx.link_args(LOCAL_CRATE); let _ = tcx.native_libraries(LOCAL_CRATE); for mono_item in From b95ef9577632520d44ac10270632de729ac4bc1c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 21 Jun 2018 13:12:56 +0200 Subject: [PATCH 09/19] Add comment about disabling LLVM by setting codegen-backends empty --- config.toml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml.example b/config.toml.example index 7bf52a369e37..568790ab4dd6 100644 --- a/config.toml.example +++ b/config.toml.example @@ -330,8 +330,8 @@ # This is an array of the codegen backends that will be compiled for the rustc # that's being compiled. The default is to only build the LLVM codegen backend, # but you can also optionally enable the "emscripten" backend for asm.js or -# make this an empty array (but that probably won't get too far in the -# bootstrap) +# make this an empty array (that will disable LLVM, but bootstrap will fail at +# the time the final rustc binary is built for stage 1) #codegen-backends = ["llvm"] # This is the name of the directory in which codegen backends will get installed From b723bc1fa92647f1d91eabf5b86df22eacd16838 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 22 Jun 2018 14:32:49 +0200 Subject: [PATCH 10/19] Change comment on setting codegen-backend empty --- config.toml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml.example b/config.toml.example index 568790ab4dd6..e120b9b62b48 100644 --- a/config.toml.example +++ b/config.toml.example @@ -330,8 +330,8 @@ # This is an array of the codegen backends that will be compiled for the rustc # that's being compiled. The default is to only build the LLVM codegen backend, # but you can also optionally enable the "emscripten" backend for asm.js or -# make this an empty array (that will disable LLVM, but bootstrap will fail at -# the time the final rustc binary is built for stage 1) +# make this an empty array (which will disable LLVM, but that probably won't +# get too far in the bootstrap #codegen-backends = ["llvm"] # This is the name of the directory in which codegen backends will get installed From c61531dc55296f7c4b58e52b1d3b53dbaa0713cc Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 22 Jun 2018 14:35:53 +0200 Subject: [PATCH 11/19] Remove unused rustc_driver dependency on ar --- src/librustc_driver/Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 5b75912c18f5..7a020f331e50 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -37,5 +37,3 @@ serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } syntax_ext = { path = "../libsyntax_ext" } syntax_pos = { path = "../libsyntax_pos" } - -ar = "0.3.0" From c5a6b51e442287d31b12591225d2e81a4345074d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 22 Jun 2018 19:28:06 +0200 Subject: [PATCH 12/19] Update Cargo.lock and move size_and_align_of_dst back --- src/librustc_codegen_llvm/common.rs | 104 +-------------------- src/librustc_codegen_llvm/glue.rs | 122 +++++++++++++++++++++++++ src/librustc_codegen_llvm/intrinsic.rs | 5 +- src/librustc_codegen_llvm/lib.rs | 1 + src/librustc_codegen_llvm/mir/place.rs | 7 +- 5 files changed, 132 insertions(+), 107 deletions(-) create mode 100644 src/librustc_codegen_llvm/glue.rs diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 099d717e3c00..7e55642814bb 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -12,7 +12,9 @@ //! Code that is useful in various codegen modules. -use llvm::{self, ValueRef, ContextRef, TypeKind, True, False, Bool, OperandBundleDef}; +use llvm; +use llvm::{ValueRef, ContextRef, TypeKind}; +use llvm::{True, False, Bool, OperandBundleDef}; use rustc::hir::def_id::DefId; use rustc::middle::lang_items::LangItem; use abi; @@ -27,8 +29,6 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::layout::{HasDataLayout, LayoutOf}; use rustc::hir; -use meth; - use libc::{c_uint, c_char}; use std::iter; @@ -448,101 +448,3 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, _ => bug!("unexpected type {:?} to ty_fn_sig", ty) } } - -pub fn size_and_align_of_dst<'a, 'tcx>(bx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) - -> (ValueRef, ValueRef) { - debug!("calculate size of DST: {}; with lost info: {:?}", - t, Value(info)); - if bx.cx.type_is_sized(t) { - let (size, align) = bx.cx.size_and_align_of(t); - debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}", - t, Value(info), size, align); - let size = C_usize(bx.cx, size.bytes()); - let align = C_usize(bx.cx, align.abi()); - return (size, align); - } - assert!(!info.is_null()); - match t.sty { - ty::TyDynamic(..) => { - // load size/align from vtable - (meth::SIZE.get_usize(bx, info), meth::ALIGN.get_usize(bx, info)) - } - ty::TySlice(_) | ty::TyStr => { - let unit = t.sequence_element_type(bx.tcx()); - // The info in this case is the length of the str, so the size is that - // times the unit size. - let (size, align) = bx.cx.size_and_align_of(unit); - (bx.mul(info, C_usize(bx.cx, size.bytes())), - C_usize(bx.cx, align.abi())) - } - _ => { - let cx = bx.cx; - // First get the size of all statically known fields. - // Don't use size_of because it also rounds up to alignment, which we - // want to avoid, as the unsized field's alignment could be smaller. - assert!(!t.is_simd()); - let layout = cx.layout_of(t); - debug!("DST {} layout: {:?}", t, layout); - - let i = layout.fields.count() - 1; - let sized_size = layout.fields.offset(i).bytes(); - let sized_align = layout.align.abi(); - debug!("DST {} statically sized prefix size: {} align: {}", - t, sized_size, sized_align); - let sized_size = C_usize(cx, sized_size); - let sized_align = C_usize(cx, sized_align); - - // Recurse to get the size of the dynamically sized field (must be - // the last field). - let field_ty = layout.field(cx, i).ty; - let (unsized_size, mut unsized_align) = size_and_align_of_dst(bx, field_ty, info); - - // FIXME (#26403, #27023): We should be adding padding - // to `sized_size` (to accommodate the `unsized_align` - // required of the unsized field that follows) before - // summing it with `sized_size`. (Note that since #26403 - // is unfixed, we do not yet add the necessary padding - // here. But this is where the add would go.) - - // Return the sum of sizes and max of aligns. - let size = bx.add(sized_size, unsized_size); - - // Packed types ignore the alignment of their fields. - if let ty::TyAdt(def, _) = t.sty { - if def.repr.packed() { - unsized_align = sized_align; - } - } - - // Choose max of two known alignments (combined value must - // be aligned according to more restrictive of the two). - let align = match (const_to_opt_u128(sized_align, false), - const_to_opt_u128(unsized_align, false)) { - (Some(sized_align), Some(unsized_align)) => { - // If both alignments are constant, (the sized_align should always be), then - // pick the correct alignment statically. - C_usize(cx, ::std::cmp::max(sized_align, unsized_align) as u64) - } - _ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align), - sized_align, - unsized_align) - }; - - // Issue #27023: must add any necessary padding to `size` - // (to make it a multiple of `align`) before returning it. - // - // Namely, the returned size should be, in C notation: - // - // `size + ((size & (align-1)) ? align : 0)` - // - // emulated via the semi-standard fast bit trick: - // - // `(size + (align-1)) & -align` - - let addend = bx.sub(align, C_usize(bx.cx, 1)); - let size = bx.and(bx.add(size, addend), bx.neg(align)); - - (size, align) - } - } -} diff --git a/src/librustc_codegen_llvm/glue.rs b/src/librustc_codegen_llvm/glue.rs new file mode 100644 index 000000000000..c7275d094018 --- /dev/null +++ b/src/librustc_codegen_llvm/glue.rs @@ -0,0 +1,122 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! +// +// Code relating to drop glue. + +use std; + +use builder::Builder; +use common::*; +use llvm::{ValueRef}; +use llvm; +use meth; +use rustc::ty::layout::LayoutOf; +use rustc::ty::{self, Ty}; +use value::Value; + +pub fn size_and_align_of_dst<'a, 'tcx>(bx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) + -> (ValueRef, ValueRef) { + debug!("calculate size of DST: {}; with lost info: {:?}", + t, Value(info)); + if bx.cx.type_is_sized(t) { + let (size, align) = bx.cx.size_and_align_of(t); + debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}", + t, Value(info), size, align); + let size = C_usize(bx.cx, size.bytes()); + let align = C_usize(bx.cx, align.abi()); + return (size, align); + } + assert!(!info.is_null()); + match t.sty { + ty::TyDynamic(..) => { + // load size/align from vtable + (meth::SIZE.get_usize(bx, info), meth::ALIGN.get_usize(bx, info)) + } + ty::TySlice(_) | ty::TyStr => { + let unit = t.sequence_element_type(bx.tcx()); + // The info in this case is the length of the str, so the size is that + // times the unit size. + let (size, align) = bx.cx.size_and_align_of(unit); + (bx.mul(info, C_usize(bx.cx, size.bytes())), + C_usize(bx.cx, align.abi())) + } + _ => { + let cx = bx.cx; + // First get the size of all statically known fields. + // Don't use size_of because it also rounds up to alignment, which we + // want to avoid, as the unsized field's alignment could be smaller. + assert!(!t.is_simd()); + let layout = cx.layout_of(t); + debug!("DST {} layout: {:?}", t, layout); + + let i = layout.fields.count() - 1; + let sized_size = layout.fields.offset(i).bytes(); + let sized_align = layout.align.abi(); + debug!("DST {} statically sized prefix size: {} align: {}", + t, sized_size, sized_align); + let sized_size = C_usize(cx, sized_size); + let sized_align = C_usize(cx, sized_align); + + // Recurse to get the size of the dynamically sized field (must be + // the last field). + let field_ty = layout.field(cx, i).ty; + let (unsized_size, mut unsized_align) = size_and_align_of_dst(bx, field_ty, info); + + // FIXME (#26403, #27023): We should be adding padding + // to `sized_size` (to accommodate the `unsized_align` + // required of the unsized field that follows) before + // summing it with `sized_size`. (Note that since #26403 + // is unfixed, we do not yet add the necessary padding + // here. But this is where the add would go.) + + // Return the sum of sizes and max of aligns. + let size = bx.add(sized_size, unsized_size); + + // Packed types ignore the alignment of their fields. + if let ty::TyAdt(def, _) = t.sty { + if def.repr.packed() { + unsized_align = sized_align; + } + } + + // Choose max of two known alignments (combined value must + // be aligned according to more restrictive of the two). + let align = match (const_to_opt_u128(sized_align, false), + const_to_opt_u128(unsized_align, false)) { + (Some(sized_align), Some(unsized_align)) => { + // If both alignments are constant, (the sized_align should always be), then + // pick the correct alignment statically. + C_usize(cx, std::cmp::max(sized_align, unsized_align) as u64) + } + _ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align), + sized_align, + unsized_align) + }; + + // Issue #27023: must add any necessary padding to `size` + // (to make it a multiple of `align`) before returning it. + // + // Namely, the returned size should be, in C notation: + // + // `size + ((size & (align-1)) ? align : 0)` + // + // emulated via the semi-standard fast bit trick: + // + // `(size + (align-1)) & -align` + + let addend = bx.sub(align, C_usize(bx.cx, 1)); + let size = bx.and(bx.add(size, addend), bx.neg(align)); + + (size, align) + } + } +} diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index d7a068265a9e..6bb5456f9034 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -19,6 +19,7 @@ use mir::operand::{OperandRef, OperandValue}; use base::*; use common::*; use declare; +use glue; use type_::Type; use type_of::LayoutLlvmExt; use rustc::ty::{self, Ty}; @@ -145,7 +146,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let tp_ty = substs.type_at(0); if let OperandValue::Pair(_, meta) = args[0].val { let (llsize, _) = - size_and_align_of_dst(bx, tp_ty, meta); + glue::size_and_align_of_dst(bx, tp_ty, meta); llsize } else { C_usize(cx, cx.size_of(tp_ty).bytes()) @@ -159,7 +160,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let tp_ty = substs.type_at(0); if let OperandValue::Pair(_, meta) = args[0].val { let (_, llalign) = - size_and_align_of_dst(bx, tp_ty, meta); + glue::size_and_align_of_dst(bx, tp_ty, meta); llalign } else { C_usize(cx, cx.align_of(tp_ty).abi()) diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index fd2d1f538876..eee4e5f8f7a0 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -109,6 +109,7 @@ mod consts; mod context; mod debuginfo; mod declare; +mod glue; mod intrinsic; mod llvm_util; mod metadata; diff --git a/src/librustc_codegen_llvm/mir/place.rs b/src/librustc_codegen_llvm/mir/place.rs index 93c31286932e..2a1e3980adbc 100644 --- a/src/librustc_codegen_llvm/mir/place.rs +++ b/src/librustc_codegen_llvm/mir/place.rs @@ -16,13 +16,12 @@ use rustc::mir::tcx::PlaceTy; use rustc_data_structures::indexed_vec::Idx; use base; use builder::Builder; -use common::{ - CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big,size_and_align_of_dst -}; +use common::{CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big}; use consts; use type_of::LayoutLlvmExt; use type_::Type; use value::Value; +use glue; use std::ptr; @@ -223,7 +222,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> { let unaligned_offset = C_usize(cx, offset.bytes()); // Get the alignment of the field - let (_, unsized_align) = size_and_align_of_dst(bx, field.ty, meta); + let (_, unsized_align) = glue::size_and_align_of_dst(bx, field.ty, meta); // Bump the unaligned offset up to the appropriate alignment using the // following expression: From c504d26c1cd4f4dbf9304415b12960c604f01ebf Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 23 Jun 2018 13:52:52 +0200 Subject: [PATCH 13/19] Move time_graph.rs to rustc/util --- src/librustc/lib.rs | 1 + src/{librustc_codegen_utils => librustc/util}/time_graph.rs | 0 src/librustc_codegen_llvm/lib.rs | 2 +- src/librustc_codegen_utils/lib.rs | 1 - 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{librustc_codegen_utils => librustc/util}/time_graph.rs (100%) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d8efb582eaa8..8050522d0664 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -162,6 +162,7 @@ pub mod util { pub mod ppaux; pub mod nodemap; pub mod fs; + pub mod time_graph; } // A private module so that macro-expanded idents like diff --git a/src/librustc_codegen_utils/time_graph.rs b/src/librustc/util/time_graph.rs similarity index 100% rename from src/librustc_codegen_utils/time_graph.rs rename to src/librustc/util/time_graph.rs diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index eee4e5f8f7a0..93d9ce1e98a4 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -76,10 +76,10 @@ use rustc::middle::lang_items::LangItem; use rustc::session::{Session, CompileIncomplete}; use rustc::session::config::{OutputFilenames, OutputType, PrintRequest}; use rustc::ty::{self, TyCtxt}; +use rustc::util::time_graph; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use rustc_mir::monomorphize; use rustc_codegen_utils::codegen_backend::CodegenBackend; -use rustc_codegen_utils::time_graph; mod diagnostics; diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 0298162bbb51..4ac0e3591b3c 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -44,7 +44,6 @@ pub mod link; pub mod codegen_backend; pub mod symbol_names; pub mod symbol_names_test; -pub mod time_graph; pub mod llvm_target_features; /// check for the #[rustc_error] annotation, which forces an From 679743646e7008c2c0c6972cf766914387c4bb52 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 23 Jun 2018 17:01:40 +0200 Subject: [PATCH 14/19] Add missing ) to comment --- config.toml.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.toml.example b/config.toml.example index e120b9b62b48..0de2cce5679d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -331,7 +331,7 @@ # that's being compiled. The default is to only build the LLVM codegen backend, # but you can also optionally enable the "emscripten" backend for asm.js or # make this an empty array (which will disable LLVM, but that probably won't -# get too far in the bootstrap +# get too far in the bootstrap) #codegen-backends = ["llvm"] # This is the name of the directory in which codegen backends will get installed From c7c534fa0ed1e34c26122de5258b057d15a4ec68 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 23 Jun 2018 17:22:35 +0200 Subject: [PATCH 15/19] Move llvm_target_features back to llvm_util --- src/librustc_codegen_llvm/llvm_util.rs | 118 +++++++++++++++- src/librustc_codegen_utils/codegen_backend.rs | 5 +- src/librustc_codegen_utils/lib.rs | 1 - .../llvm_target_features.rs | 127 ------------------ 4 files changed, 118 insertions(+), 133 deletions(-) delete mode 100644 src/librustc_codegen_utils/llvm_target_features.rs diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index b63b43c9c73a..87ee9ef5adb2 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -20,8 +20,6 @@ use syntax::feature_gate::UnstableFeatures; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Once; -pub use rustc_codegen_utils::llvm_target_features::*; - static POISONED: AtomicBool = AtomicBool::new(false); static INIT: Once = Once::new(); @@ -81,6 +79,108 @@ unsafe fn configure_llvm(sess: &Session) { llvm_args.as_ptr()); } +// WARNING: the features after applying `to_llvm_feature` must be known +// to LLVM or the feature detection code will walk past the end of the feature +// array, leading to crashes. + +const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ + ("mclass", Some("arm_target_feature")), + ("neon", Some("arm_target_feature")), + ("v7", Some("arm_target_feature")), + ("vfp2", Some("arm_target_feature")), + ("vfp3", Some("arm_target_feature")), + ("vfp4", Some("arm_target_feature")), +]; + +const AARCH64_WHITELIST: &[(&str, Option<&str>)] = &[ + ("fp", Some("aarch64_target_feature")), + ("neon", Some("aarch64_target_feature")), + ("sve", Some("aarch64_target_feature")), + ("crc", Some("aarch64_target_feature")), + ("crypto", Some("aarch64_target_feature")), + ("ras", Some("aarch64_target_feature")), + ("lse", Some("aarch64_target_feature")), + ("rdm", Some("aarch64_target_feature")), + ("fp16", Some("aarch64_target_feature")), + ("rcpc", Some("aarch64_target_feature")), + ("dotprod", Some("aarch64_target_feature")), + ("v8.1a", Some("aarch64_target_feature")), + ("v8.2a", Some("aarch64_target_feature")), + ("v8.3a", Some("aarch64_target_feature")), +]; + +const X86_WHITELIST: &[(&str, Option<&str>)] = &[ + ("aes", None), + ("avx", None), + ("avx2", None), + ("avx512bw", Some("avx512_target_feature")), + ("avx512cd", Some("avx512_target_feature")), + ("avx512dq", Some("avx512_target_feature")), + ("avx512er", Some("avx512_target_feature")), + ("avx512f", Some("avx512_target_feature")), + ("avx512ifma", Some("avx512_target_feature")), + ("avx512pf", Some("avx512_target_feature")), + ("avx512vbmi", Some("avx512_target_feature")), + ("avx512vl", Some("avx512_target_feature")), + ("avx512vpopcntdq", Some("avx512_target_feature")), + ("bmi1", None), + ("bmi2", None), + ("fma", None), + ("fxsr", None), + ("lzcnt", None), + ("mmx", Some("mmx_target_feature")), + ("pclmulqdq", None), + ("popcnt", None), + ("rdrand", None), + ("rdseed", None), + ("sha", None), + ("sse", None), + ("sse2", None), + ("sse3", None), + ("sse4.1", None), + ("sse4.2", None), + ("sse4a", Some("sse4a_target_feature")), + ("ssse3", None), + ("tbm", Some("tbm_target_feature")), + ("xsave", None), + ("xsavec", None), + ("xsaveopt", None), + ("xsaves", None), +]; + +const HEXAGON_WHITELIST: &[(&str, Option<&str>)] = &[ + ("hvx", Some("hexagon_target_feature")), + ("hvx-double", Some("hexagon_target_feature")), +]; + +const POWERPC_WHITELIST: &[(&str, Option<&str>)] = &[ + ("altivec", Some("powerpc_target_feature")), + ("power8-altivec", Some("powerpc_target_feature")), + ("power9-altivec", Some("powerpc_target_feature")), + ("power8-vector", Some("powerpc_target_feature")), + ("power9-vector", Some("powerpc_target_feature")), + ("vsx", Some("powerpc_target_feature")), +]; + +const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[ + ("fp64", Some("mips_target_feature")), + ("msa", Some("mips_target_feature")), +]; + +/// When rustdoc is running, provide a list of all known features so that all their respective +/// primtives may be documented. +/// +/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this +/// iterator! +pub fn all_known_features() -> impl Iterator)> { + ARM_WHITELIST.iter().cloned() + .chain(AARCH64_WHITELIST.iter().cloned()) + .chain(X86_WHITELIST.iter().cloned()) + .chain(HEXAGON_WHITELIST.iter().cloned()) + .chain(POWERPC_WHITELIST.iter().cloned()) + .chain(MIPS_WHITELIST.iter().cloned()) +} + pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str { let arch = if sess.target.target.arch == "x86_64" { "x86" @@ -116,6 +216,20 @@ pub fn target_features(sess: &Session) -> Vec { .map(|feature| Symbol::intern(feature)).collect() } +pub fn target_feature_whitelist(sess: &Session) + -> &'static [(&'static str, Option<&'static str>)] +{ + match &*sess.target.target.arch { + "arm" => ARM_WHITELIST, + "aarch64" => AARCH64_WHITELIST, + "x86" | "x86_64" => X86_WHITELIST, + "hexagon" => HEXAGON_WHITELIST, + "mips" | "mips64" => MIPS_WHITELIST, + "powerpc" | "powerpc64" => POWERPC_WHITELIST, + _ => &[], + } +} + pub fn print_version() { // Can be called without initializing LLVM unsafe { diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 8043559b3109..3cbf176d98bc 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -42,6 +42,7 @@ use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::MetadataLoader; use rustc::dep_graph::DepGraph; use rustc_target::spec::Target; +use rustc_data_structures::fx::FxHashMap; use rustc_mir::monomorphize::collector; use link::{build_link_meta, out_filename}; @@ -132,9 +133,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { ::symbol_names::provide(providers); providers.target_features_whitelist = |_tcx, _cnum| { - Lrc::new(::llvm_target_features::all_known_features() - .map(|(a, b)| (a.to_string(), b.map(|s| s.to_string()))) - .collect()) + Lrc::new(FxHashMap()) // Just a dummy }; providers.is_reachable_non_generic = |_tcx, _defid| true; providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 4ac0e3591b3c..f59cf5832fcb 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -44,7 +44,6 @@ pub mod link; pub mod codegen_backend; pub mod symbol_names; pub mod symbol_names_test; -pub mod llvm_target_features; /// check for the #[rustc_error] annotation, which forces an /// error in codegen. This is used to write compile-fail tests diff --git a/src/librustc_codegen_utils/llvm_target_features.rs b/src/librustc_codegen_utils/llvm_target_features.rs deleted file mode 100644 index 8e11363cead8..000000000000 --- a/src/librustc_codegen_utils/llvm_target_features.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rustc::session::Session; - -// WARNING: the features after applying `to_llvm_feature` must be known -// to LLVM or the feature detection code will walk past the end of the feature -// array, leading to crashes. - -const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ - ("mclass", Some("arm_target_feature")), - ("neon", Some("arm_target_feature")), - ("v7", Some("arm_target_feature")), - ("vfp2", Some("arm_target_feature")), - ("vfp3", Some("arm_target_feature")), - ("vfp4", Some("arm_target_feature")), -]; - -const AARCH64_WHITELIST: &[(&str, Option<&str>)] = &[ - ("fp", Some("aarch64_target_feature")), - ("neon", Some("aarch64_target_feature")), - ("sve", Some("aarch64_target_feature")), - ("crc", Some("aarch64_target_feature")), - ("crypto", Some("aarch64_target_feature")), - ("ras", Some("aarch64_target_feature")), - ("lse", Some("aarch64_target_feature")), - ("rdm", Some("aarch64_target_feature")), - ("fp16", Some("aarch64_target_feature")), - ("rcpc", Some("aarch64_target_feature")), - ("dotprod", Some("aarch64_target_feature")), - ("v8.1a", Some("aarch64_target_feature")), - ("v8.2a", Some("aarch64_target_feature")), - ("v8.3a", Some("aarch64_target_feature")), -]; - -const X86_WHITELIST: &[(&str, Option<&str>)] = &[ - ("aes", None), - ("avx", None), - ("avx2", None), - ("avx512bw", Some("avx512_target_feature")), - ("avx512cd", Some("avx512_target_feature")), - ("avx512dq", Some("avx512_target_feature")), - ("avx512er", Some("avx512_target_feature")), - ("avx512f", Some("avx512_target_feature")), - ("avx512ifma", Some("avx512_target_feature")), - ("avx512pf", Some("avx512_target_feature")), - ("avx512vbmi", Some("avx512_target_feature")), - ("avx512vl", Some("avx512_target_feature")), - ("avx512vpopcntdq", Some("avx512_target_feature")), - ("bmi1", None), - ("bmi2", None), - ("fma", None), - ("fxsr", None), - ("lzcnt", None), - ("mmx", Some("mmx_target_feature")), - ("pclmulqdq", None), - ("popcnt", None), - ("rdrand", None), - ("rdseed", None), - ("sha", None), - ("sse", None), - ("sse2", None), - ("sse3", None), - ("sse4.1", None), - ("sse4.2", None), - ("sse4a", Some("sse4a_target_feature")), - ("ssse3", None), - ("tbm", Some("tbm_target_feature")), - ("xsave", None), - ("xsavec", None), - ("xsaveopt", None), - ("xsaves", None), -]; - -const HEXAGON_WHITELIST: &[(&str, Option<&str>)] = &[ - ("hvx", Some("hexagon_target_feature")), - ("hvx-double", Some("hexagon_target_feature")), -]; - -const POWERPC_WHITELIST: &[(&str, Option<&str>)] = &[ - ("altivec", Some("powerpc_target_feature")), - ("power8-altivec", Some("powerpc_target_feature")), - ("power9-altivec", Some("powerpc_target_feature")), - ("power8-vector", Some("powerpc_target_feature")), - ("power9-vector", Some("powerpc_target_feature")), - ("vsx", Some("powerpc_target_feature")), -]; - -const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[ - ("fp64", Some("mips_target_feature")), - ("msa", Some("mips_target_feature")), -]; - -/// When rustdoc is running, provide a list of all known features so that all their respective -/// primtives may be documented. -/// -/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this -/// iterator! -pub fn all_known_features() -> impl Iterator)> { - ARM_WHITELIST.iter().cloned() - .chain(AARCH64_WHITELIST.iter().cloned()) - .chain(X86_WHITELIST.iter().cloned()) - .chain(HEXAGON_WHITELIST.iter().cloned()) - .chain(POWERPC_WHITELIST.iter().cloned()) - .chain(MIPS_WHITELIST.iter().cloned()) -} - -pub fn target_feature_whitelist(sess: &Session) - -> &'static [(&'static str, Option<&'static str>)] -{ - match &*sess.target.target.arch { - "arm" => ARM_WHITELIST, - "aarch64" => AARCH64_WHITELIST, - "x86" | "x86_64" => X86_WHITELIST, - "hexagon" => HEXAGON_WHITELIST, - "mips" | "mips64" => MIPS_WHITELIST, - "powerpc" | "powerpc64" => POWERPC_WHITELIST, - _ => &[], - } -} From a5330415aa4b85ede7ca6a32fdad1c27ca5056a5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 23 Jun 2018 17:23:04 +0200 Subject: [PATCH 16/19] Only use coresimd when codegen_backend is LLVM --- src/bootstrap/bin/rustc.rs | 7 +++++++ src/bootstrap/builder.rs | 4 ++++ src/libcore/lib.rs | 7 ++++--- src/librustc/session/config.rs | 12 ++++++++++++ src/libstd/lib.rs | 8 ++++---- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 4607ca5cf9f4..98fec4c4861f 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -107,6 +107,13 @@ fn main() { env::join_paths(&dylib_path).unwrap()); let mut maybe_crate = None; + // Don't use metadata only backend for snapshot compiler, because it may be broken + if env::var("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND").is_ok() && stage != "0" { + //cmd.arg("-Zcodegen-backend=metadata_only"); + } else { + cmd.arg("--cfg").arg("codegen_backend=\"llvm\""); + } + // Print backtrace in case of ICE if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() { cmd.env("RUST_BACKTRACE", "1"); diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index d2f9b2653d50..7e4a12f7310f 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -747,6 +747,10 @@ impl<'a> Builder<'a> { stage = compiler.stage; } + if self.config.rust_codegen_backends.is_empty() { + cargo.env("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND", "1"); + } + let mut extra_args = env::var(&format!("RUSTFLAGS_STAGE_{}", stage)).unwrap_or_default(); if stage != 0 { let s = env::var("RUSTFLAGS_STAGE_NOT_0").unwrap_or_default(); diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index bbe6ae8619fe..0971f50913cb 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -241,12 +241,13 @@ macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*) #[path = "../stdsimd/coresimd/mod.rs"] #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)] #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(not(stage0))] // allow changes to how stdsimd works in stage0 +// allow changes to how stdsimd works in stage0 and don't use whithout LLVM +#[cfg(all(not(stage0), codegen_backend="llvm"))] mod coresimd; #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(not(stage0))] +#[cfg(all(not(stage0), codegen_backend="llvm"))] pub use coresimd::simd; #[stable(feature = "simd_arch", since = "1.27.0")] -#[cfg(not(stage0))] +#[cfg(all(not(stage0), codegen_backend="llvm"))] pub use coresimd::arch; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 95c68214ec7c..05e08cb7973a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1418,6 +1418,18 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { if sess.opts.crate_types.contains(&CrateTypeProcMacro) { ret.insert((Symbol::intern("proc_macro"), None)); } + /*if nightly_options::is_nightly_build() { + let backend_name = sess.opts + .debugging_opts + .codegen_backend + .as_ref() + .map(|s| s as &str) + .unwrap_or("llvm"); + ret.insert(( + Symbol::intern("codegen_backend"), + Some(Symbol::intern(backend_name)), + )); + }*/ return ret; } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d73cb1f8349a..d79f851a3d76 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -523,22 +523,22 @@ pub mod rt; #[path = "../stdsimd/stdsimd/mod.rs"] #[allow(missing_debug_implementations, missing_docs, dead_code)] #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(all(not(stage0), not(test)))] +#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] mod stdsimd; // A "fake" module needed by the `stdsimd` module to compile, not actually // exported though. -#[cfg(not(stage0))] +#[cfg(all(not(stage0), codegen_backend="llvm"))] mod coresimd { pub use core::arch; pub use core::simd; } #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(all(not(stage0), not(test)))] +#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] pub use stdsimd::simd; #[stable(feature = "simd_arch", since = "1.27.0")] -#[cfg(all(not(stage0), not(test)))] +#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] pub use stdsimd::arch; // Include a number of private modules that exist solely to provide From 163cb572a491cb3eb7f2c792415c93840cb7e9c0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 24 Jun 2018 13:32:33 +0200 Subject: [PATCH 17/19] Hopefully fix it --- src/bootstrap/bin/rustc.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 98fec4c4861f..04882426fd8e 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -108,9 +108,7 @@ fn main() { let mut maybe_crate = None; // Don't use metadata only backend for snapshot compiler, because it may be broken - if env::var("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND").is_ok() && stage != "0" { - //cmd.arg("-Zcodegen-backend=metadata_only"); - } else { + if env::var("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND").is_err() { cmd.arg("--cfg").arg("codegen_backend=\"llvm\""); } From ff12beb8756f028d44f898a91960ed70102a4792 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 30 Jun 2018 10:45:14 +0200 Subject: [PATCH 18/19] Revert changes to bootstrap, rustc_driver and fix {core,std}simd --- config.toml.example | 8 ++++++-- src/bootstrap/bin/rustc.rs | 5 ----- src/bootstrap/builder.rs | 6 +----- src/bootstrap/compile.rs | 27 +++++++++++++-------------- src/bootstrap/config.rs | 4 ++++ src/bootstrap/test.rs | 4 ++-- src/bootstrap/tool.rs | 2 +- src/libcore/lib.rs | 7 +++---- src/librustc/session/config.rs | 12 ------------ src/librustc_driver/lib.rs | 14 ++------------ src/libstd/lib.rs | 8 ++++---- 11 files changed, 36 insertions(+), 61 deletions(-) diff --git a/config.toml.example b/config.toml.example index 0de2cce5679d..0578f929224d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -14,6 +14,10 @@ # ============================================================================= [llvm] +# Indicates whether rustc will support compilation with LLVM +# note: rustc does not compile without LLVM at the moment +#enabled = true + # Indicates whether the LLVM build is a Release or Debug build #optimize = true @@ -330,8 +334,8 @@ # This is an array of the codegen backends that will be compiled for the rustc # that's being compiled. The default is to only build the LLVM codegen backend, # but you can also optionally enable the "emscripten" backend for asm.js or -# make this an empty array (which will disable LLVM, but that probably won't -# get too far in the bootstrap) +# make this an empty array (but that probably won't get too far in the +# bootstrap) #codegen-backends = ["llvm"] # This is the name of the directory in which codegen backends will get installed diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 04882426fd8e..4607ca5cf9f4 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -107,11 +107,6 @@ fn main() { env::join_paths(&dylib_path).unwrap()); let mut maybe_crate = None; - // Don't use metadata only backend for snapshot compiler, because it may be broken - if env::var("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND").is_err() { - cmd.arg("--cfg").arg("codegen_backend=\"llvm\""); - } - // Print backtrace in case of ICE if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() { cmd.env("RUST_BACKTRACE", "1"); diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7e4a12f7310f..fad0a553802a 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -747,10 +747,6 @@ impl<'a> Builder<'a> { stage = compiler.stage; } - if self.config.rust_codegen_backends.is_empty() { - cargo.env("RUSTC_SHOULD_USE_METADATA_ONLY_BACKEND", "1"); - } - let mut extra_args = env::var(&format!("RUSTFLAGS_STAGE_{}", stage)).unwrap_or_default(); if stage != 0 { let s = env::var("RUSTFLAGS_STAGE_NOT_0").unwrap_or_default(); @@ -897,7 +893,7 @@ impl<'a> Builder<'a> { // // If LLVM support is disabled we need to use the snapshot compiler to compile // build scripts, as the new compiler doesn't support executables. - if mode == Mode::Std || self.config.rust_codegen_backends.is_empty() { + if mode == Mode::Std || !self.config.llvm_enabled { cargo .env("RUSTC_SNAPSHOT", &self.initial_rustc) .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 524df9587dad..298bd58c6cdf 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -182,13 +182,11 @@ pub fn std_cargo(builder: &Builder, // missing // We also only build the runtimes when --enable-sanitizers (or its // config.toml equivalent) is used - if !builder.config.rust_codegen_backends.is_empty() { - let llvm_config = builder.ensure(native::Llvm { - target: builder.config.build, - emscripten: false, - }); - cargo.env("LLVM_CONFIG", llvm_config); - } + let llvm_config = builder.ensure(native::Llvm { + target: builder.config.build, + emscripten: false, + }); + cargo.env("LLVM_CONFIG", llvm_config); } cargo.arg("--features").arg(features) @@ -645,13 +643,14 @@ impl Step for CodegenBackend { fn make_run(run: RunConfig) { let backend = run.builder.config.rust_codegen_backends.get(0); - if let Some(backend) = backend.cloned() { - run.builder.ensure(CodegenBackend { - compiler: run.builder.compiler(run.builder.top_stage, run.host), - target: run.target, - backend, - }); - } + let backend = backend.cloned().unwrap_or_else(|| { + INTERNER.intern_str("llvm") + }); + run.builder.ensure(CodegenBackend { + compiler: run.builder.compiler(run.builder.top_stage, run.host), + target: run.target, + backend, + }); } fn run(self, builder: &Builder) { diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 2e629456b7ef..b3ed10257bda 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -74,6 +74,7 @@ pub struct Config { pub backtrace_on_ice: bool, // llvm codegen options + pub llvm_enabled: bool, pub llvm_assertions: bool, pub llvm_optimize: bool, pub llvm_release_debuginfo: bool, @@ -238,6 +239,7 @@ struct Install { #[derive(Deserialize, Default)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct Llvm { + enabled: Option, ccache: Option, ninja: Option, assertions: Option, @@ -339,6 +341,7 @@ impl Config { pub fn default_opts() -> Config { let mut config = Config::default(); + config.llvm_enabled = true; config.llvm_optimize = true; config.llvm_version_check = true; config.use_jemalloc = true; @@ -493,6 +496,7 @@ impl Config { Some(StringOrBool::Bool(false)) | None => {} } set(&mut config.ninja, llvm.ninja); + set(&mut config.llvm_enabled, llvm.enabled); llvm_assertions = llvm.assertions; set(&mut config.llvm_optimize, llvm.optimize); set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 917b85690dea..6254f9816566 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1096,7 +1096,7 @@ impl Step for Compiletest { cmd.arg("--quiet"); } - if !builder.config.rust_codegen_backends.is_empty() { + if builder.config.llvm_enabled { let llvm_config = builder.ensure(native::Llvm { target: builder.config.build, emscripten: false, @@ -1129,7 +1129,7 @@ impl Step for Compiletest { } } } - if suite == "run-make-fulldeps" && builder.config.rust_codegen_backends.is_empty() { + if suite == "run-make-fulldeps" && !builder.config.llvm_enabled { builder.info(&format!( "Ignoring run-make test suite as they generally don't work without LLVM" )); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 640dd9ecdd99..b3d7b9a91ecf 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -672,7 +672,7 @@ impl<'a> Builder<'a> { } fn llvm_bin_path(&self) -> Option { - if !self.config.rust_codegen_backends.is_empty() && !self.config.dry_run { + if self.config.llvm_enabled && !self.config.dry_run { let llvm_config = self.ensure(native::Llvm { target: self.config.build, emscripten: false, diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 0971f50913cb..bbe6ae8619fe 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -241,13 +241,12 @@ macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*) #[path = "../stdsimd/coresimd/mod.rs"] #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)] #[unstable(feature = "stdsimd", issue = "48556")] -// allow changes to how stdsimd works in stage0 and don't use whithout LLVM -#[cfg(all(not(stage0), codegen_backend="llvm"))] +#[cfg(not(stage0))] // allow changes to how stdsimd works in stage0 mod coresimd; #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(all(not(stage0), codegen_backend="llvm"))] +#[cfg(not(stage0))] pub use coresimd::simd; #[stable(feature = "simd_arch", since = "1.27.0")] -#[cfg(all(not(stage0), codegen_backend="llvm"))] +#[cfg(not(stage0))] pub use coresimd::arch; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 05e08cb7973a..95c68214ec7c 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1418,18 +1418,6 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { if sess.opts.crate_types.contains(&CrateTypeProcMacro) { ret.insert((Symbol::intern("proc_macro"), None)); } - /*if nightly_options::is_nightly_build() { - let backend_name = sess.opts - .debugging_opts - .codegen_backend - .as_ref() - .map(|s| s as &str) - .unwrap_or("llvm"); - ret.insert(( - Symbol::intern("codegen_backend"), - Some(Symbol::intern(backend_name)), - )); - }*/ return ret; } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 321d398b5210..84f7b35d21f3 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -375,20 +375,10 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box { match file { Some(ref s) => return load_backend_from_dylib(s), None => { - if !::rustc::session::config::nightly_options::is_nightly_build() { - let err = format!("failed to load default codegen backend for `{}`, \ + let err = format!("failed to load default codegen backend for `{}`, \ no appropriate codegen dylib found in `{}`", backend_name, sysroot.display()); - early_error(ErrorOutputType::default(), &err); - } else { - let warn = format!("no codegen-backend `{}`, \ - no appropriate dylib in `{}`. \ - Falling back to metadata_only codegen backend. \ - **This is suitable for dev purposes only**", - backend_name, sysroot.display()); - early_warn(ErrorOutputType::default(), &warn); - return rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::new; - } + early_error(ErrorOutputType::default(), &err); } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d79f851a3d76..d73cb1f8349a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -523,22 +523,22 @@ pub mod rt; #[path = "../stdsimd/stdsimd/mod.rs"] #[allow(missing_debug_implementations, missing_docs, dead_code)] #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] +#[cfg(all(not(stage0), not(test)))] mod stdsimd; // A "fake" module needed by the `stdsimd` module to compile, not actually // exported though. -#[cfg(all(not(stage0), codegen_backend="llvm"))] +#[cfg(not(stage0))] mod coresimd { pub use core::arch; pub use core::simd; } #[unstable(feature = "stdsimd", issue = "48556")] -#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] +#[cfg(all(not(stage0), not(test)))] pub use stdsimd::simd; #[stable(feature = "simd_arch", since = "1.27.0")] -#[cfg(all(not(stage0), not(test), codegen_backend="llvm"))] +#[cfg(all(not(stage0), not(test)))] pub use stdsimd::arch; // Include a number of private modules that exist solely to provide From 23c0b3b75c865f18e452e42680247502961778b9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 7 Jul 2018 11:05:21 +0200 Subject: [PATCH 19/19] Update Cargo.lock --- src/Cargo.lock | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index e3610c1d679b..d91a165e5373 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -57,11 +57,6 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ar" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "arena" version = "0.0.0" @@ -2031,6 +2026,7 @@ dependencies = [ name = "rustc_codegen_utils" version = "0.0.0" dependencies = [ + "flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", @@ -2070,7 +2066,6 @@ dependencies = [ name = "rustc_driver" version = "0.0.0" dependencies = [ - "ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "arena 0.0.0", "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "graphviz 0.0.0", @@ -3075,7 +3070,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aho-corasick 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0ba20154ea1f47ce2793322f049c5646cc6d0fa9759d5f333f286e507bf8080" "checksum ammonia 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd4c682378117e4186a492b2252b9537990e1617f44aed9788b9a1149de45477" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35c7a5669cb64f085739387e1308b74e6d44022464b7f1b63bbd4ceb6379ec31" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum assert_cli 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98589b0e465a6c510d95fceebd365bb79bedece7f6e18a480897f2015f85ec51" "checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"