rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.61k stars 101 forks source link

Compile rustc using cg_clif #743

Closed bjorn3 closed 3 years ago

bjorn3 commented 5 years ago
$ cd rustc_codegen_cranelift
$ cargo build --release
$ git clone https://github.com/rust-lang/rust.git
$ cd rust
$ git apply ../patches/*
$ git apply - <<EOF
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 475f2e90463..9f722fd7969 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -56,7 +56,7 @@ fn main() {
     let mut dylib_path = bootstrap::util::dylib_path();
     dylib_path.insert(0, PathBuf::from(&libdir));

-    let mut cmd = Command::new(rustc);
+    let mut cmd = Command::new(&rustc);
     cmd.args(&args)
         .env(bootstrap::util::dylib_path_var(),
              env::join_paths(&dylib_path).unwrap());
@@ -81,6 +81,11 @@ fn main() {
         cmd.env("RUST_BACKTRACE", "1");
     }

+    if target.is_some() && (stage == "0" || rustc.to_str().unwrap().contains(".rustup")) {
+        eprintln!("{}: bootstrap", crate_name.unwrap_or("<none>"));
+        cmd.arg("-Zcodegen-backend=$(pwd)/../target/release/librustc_codegen_cranelift.dylib");
+    }
+
     if target.is_some() {
         // 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 6ea32edfb20..28366985c10 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -577,8 +577,6 @@ impl Step for CodegenBackend {
         let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);

         let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "build");
-        cargo.arg("--manifest-path")
-            .arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
         rustc_cargo_env(builder, &mut cargo);

         let features = build_codegen_backend(&builder, &mut cargo, &compiler, target, backend);
@@ -593,7 +591,7 @@ impl Step for CodegenBackend {
         let mut files = files.into_iter()
             .filter(|f| {
                 let filename = f.file_name().unwrap().to_str().unwrap();
-                is_dylib(filename) && filename.contains("rustc_codegen_llvm-")
+                is_dylib(filename) && filename.contains("rustc_codegen_")
             });
         let codegen_backend = match files.next() {
             Some(f) => f,
@@ -618,6 +616,10 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
     let mut features = String::new();

     match &*backend {
+        "cranelift" => {
+            cargo.arg("--manifest-path")
+                .arg(builder.src.join("../Cargo.toml"));
+        }
         "llvm" | "emscripten" => {
             // Build LLVM for our target. This will implicitly build the
             // host LLVM if necessary.
@@ -673,6 +675,8 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
             if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo {
                 cargo.env("LLVM_NDEBUG", "1");
             }
+            cargo.arg("--manifest-path")
+                .arg(builder.src.join("src/rustc_codegen_llvm/Cargo.toml"));
         }
         _ => panic!("unknown backend: {}", backend),
     }
diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml
index e020f2f8da9..9767df6faab 100644
--- a/src/librustc_data_structures/Cargo.toml
+++ b/src/librustc_data_structures/Cargo.toml
@@ -28,4 +28,4 @@ rustc_index = { path = "../librustc_index", package = "rustc_index" }

 [dependencies.parking_lot]
 version = "0.9"
-features = ["nightly"]
+#features = ["nightly"]
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index dd088b68a23..b1b6be041e9 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -773,7 +773,6 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
         println!("commit-date: {}", unw(commit_date_str()));
         println!("host: {}", config::host_triple());
         println!("release: {}", unw(release_str()));
-        get_codegen_sysroot("llvm")().print_version();
     }
 }

@@ -1159,13 +1158,14 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
 /// compilation on fatal errors. This function catches that sentinel and turns
 /// the panic into a `Result` instead.
 pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported> {
-    catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| {
+    /*catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| {
         if value.is::<errors::FatalErrorMarker>() {
             ErrorReported
         } else {
             panic::resume_unwind(value);
         }
-    })
+    })*/
+    Ok(f())
 }

 lazy_static! {
diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs
index b05bad554f4..8e3ea2db6e8 100644
--- a/src/librustc_interface/util.rs
+++ b/src/librustc_interface/util.rs
@@ -149,7 +149,7 @@ impl Write for Sink {

 #[cfg(not(parallel_compiler))]
 pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
-    struct Ptr(*mut ());
+    /*struct Ptr(*mut ());
     unsafe impl Send for Ptr {}
     unsafe impl Sync for Ptr {}

@@ -167,7 +167,8 @@ pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f:
     match thread.unwrap().join() {
         Ok(()) => result.unwrap(),
         Err(p) => panic::resume_unwind(p),
-    }
+    }*/
+    f()
 }

 #[cfg(not(parallel_compiler))]
@@ -272,7 +273,8 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {

     INIT.call_once(|| {
         let codegen_name = sess.opts.debugging_opts.codegen_backend.as_ref()
-            .unwrap_or(&sess.target.target.options.codegen_backend);
+            .map(|s| &**s)
+            .unwrap_or("cranelift");
         let backend = match &codegen_name[..] {
             filename if filename.contains(".") => {
                 load_backend_from_dylib(filename.as_ref())
@@ -459,7 +461,7 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend

     let mut file: Option<PathBuf> = None;

-    let expected_name = format!("rustc_codegen_llvm-{}", backend_name);
+    let expected_name = format!("rustc_codegen_cranelift-{}", backend_name);
     for entry in d.filter_map(|e| e.ok()) {
         let path = entry.path();
         let filename = match path.file_name().and_then(|s| s.to_str()) {
EOF
$ cat > config.toml
[rust]
codegen-backends = ["cranelift"]
deny-warnings = false

[build]
local-rebuild = true
rustc = "$(echo $HOME/.rustup/toolchains/nightly-x86_64-*/bin/rustc)"
$ ./x.py --target <fill_in_your_target>

Currently fails while compiling libcore using the new compiler with:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x000000010bfcfd98 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::interpret::operator::_$LT$impl$u20$rustc_mir..interpret..eval_context..InterpCx$LT$M$GT$$GT$::binary_int_op::h39e964764264c980 + 7336
    frame #1: 0x00007ffeedb595a0
    frame #2: 0x000000010cbc5369 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::interpret::operator::_$LT$impl$u20$rustc_mir..interpret..eval_context..InterpCx$LT$M$GT$$GT$::overflowing_binary_op::h0815cada9026d570 + 12825
    frame #3: 0x000000010bc7bf22 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::interpret::operator::_$LT$impl$u20$rustc_mir..interpret..eval_context..InterpCx$LT$M$GT$$GT$::binop_with_overflow::h6dcfbbcdef4d2605 + 338
    frame #4: 0x000000010c9f4cfa librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::interpret::step::_$LT$impl$u20$rustc_mir..interpret..eval_context..InterpCx$LT$M$GT$$GT$::eval_rvalue_into_place::h022fcd6cee1ec203 + 6714
    frame #5: 0x000000010bb78124 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::const_prop::ConstPropagator::const_prop::_$u7b$$u7b$closure$u7d$$u7d$::hd9f77bd6e9cda066 + 788
    frame #6: 0x000000010b550743 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::const_prop::ConstPropagator::use_ecx::hf516d40ce7ae2798 + 675
    frame #7: 0x000000010c63c453 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::const_prop::ConstPropagator::const_prop::h5a2438af1de70ec0 + 6355
    frame #8: 0x000000010c91d21f librustc_driver-5791a7e91c818ec7.dylib`_$LT$rustc_mir..transform..const_prop..ConstPropagator$u20$as$u20$rustc..mir..visit..MutVisitor$GT$::visit_statement::haf67b3d948fd6e40 + 1247
    frame #9: 0x000000010afee9bf librustc_driver-5791a7e91c818ec7.dylib`rustc::mir::visit::MutVisitor::super_basic_block_data::hdf9aeabca73fc59c + 495
    frame #10: 0x000000010c213acd librustc_driver-5791a7e91c818ec7.dylib`rustc::mir::visit::MutVisitor::visit_basic_block_data::h75a2c2aafc930d58 + 61
    frame #11: 0x000000010b03b532 librustc_driver-5791a7e91c818ec7.dylib`rustc::mir::visit::MutVisitor::super_body::h4c0d6d49440cc7e0 + 786
    frame #12: 0x000000010b18c79a librustc_driver-5791a7e91c818ec7.dylib`rustc::mir::visit::MutVisitor::visit_body::hc510a58cc87353f3 + 10
    frame #13: 0x000000010ce0b17e librustc_driver-5791a7e91c818ec7.dylib`_$LT$rustc_mir..transform..const_prop..ConstProp$u20$as$u20$rustc_mir..transform..MirPass$GT$::run_pass::h947f20b8b28cae6b + 3582
    frame #14: 0x000000010c71ff73 librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::run_passes::_$u7b$$u7b$closure$u7d$$u7d$::h034ea46963d6c7f8 + 467
    frame #15: 0x000000010cca51bc librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::run_passes::h96df8cf6d5cc8e66 + 908
    frame #16: 0x000000010b419d8f librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::run_optimization_passes::h7cef930c71deb22a + 3007
    frame #17: 0x000000010c4f550c librustc_driver-5791a7e91c818ec7.dylib`rustc_mir::transform::optimized_mir::h5218517112155afa + 668
    frame #18: 0x000000010ede9a30 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::_$LT$impl$u20$rustc..ty..query..config..QueryAccessors$u20$for$u20$rustc..ty..query..queries..optimized_mir$GT$::compute::_$u7b$$u7b$closure$u7d$$u7d$::h9aa3fa333b453592 + 384
    frame #19: 0x000000010f13e6d3 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::__query_compute::optimized_mir::h1eeb3b261f804979 + 83
    frame #20: 0x000000010e99def3 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::_$LT$impl$u20$rustc..ty..query..config..QueryAccessors$u20$for$u20$rustc..ty..query..queries..optimized_mir$GT$::compute::h915ac87106bcd204 + 99
    frame #21: 0x000000010ef63cd2 librustc_driver-5791a7e91c818ec7.dylib`rustc::dep_graph::graph::DepGraph::with_task_impl::hecb99bc841482fe2 + 306
    frame #22: 0x000000010f07755f librustc_driver-5791a7e91c818ec7.dylib`rustc::dep_graph::graph::DepGraph::with_task::hc10966ffc80ea705 + 271
    frame #23: 0x000000010ed92eb3 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::force_query_with_job::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h32ca3f250df06d93 + 515
    frame #24: 0x000000010ee4a116 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::start_query::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h486b9a18b0825fd0 + 150
    frame #25: 0x000000010eab5e70 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::_$u7b$$u7b$closure$u7d$$u7d$::hcc742e18f9398fb8 + 144
    frame #26: 0x000000010e509f89 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::set_tlv::ha2dba59ada58c63e + 249
    frame #27: 0x000000010ed1711f librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::h4b72df86eab37212 + 143
    frame #28: 0x000000010e6b6284 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::start_query::_$u7b$$u7b$closure$u7d$$u7d$::h7684079179c8ee45 + 388
    frame #29: 0x000000010e82198f librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_related_context::_$u7b$$u7b$closure$u7d$$u7d$::h10464e6e9ac75a15 + 335
    frame #30: 0x000000010edd42fa librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context::_$u7b$$u7b$closure$u7d$$u7d$::hbe9a7d3406d2aa88 + 298
    frame #31: 0x000000010e86a0df librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context_opt::he9c955e66abaef37 + 367
    frame #32: 0x000000010ee41936 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context::h493650448c91f4de + 86
    frame #33: 0x000000010e990e65 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_related_context::h1929151f6c846510 + 117
    frame #34: 0x000000010ede3460 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::start_query::h195593f17be0202c + 224
    frame #35: 0x000000010ecb2abc librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::force_query_with_job::_$u7b$$u7b$closure$u7d$$u7d$::h102d60e011b4e727 + 268
    frame #36: 0x000000010efa3138 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::with_diagnostics::hf657f0cd7ec450b4 + 248
    frame #37: 0x000000010ea7c246 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::force_query_with_job::h99721e1332d41c7a + 1078
    frame #38: 0x000000010f0f95ff librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::plumbing::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::get_query::hfee388ca31ed1348 + 2751
    frame #39: 0x000000010ea705d9 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::TyCtxtAt::optimized_mir::hb8f2f6c7614eb69e + 169
    frame #40: 0x000000010e73b0bc librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::query::_$LT$impl$u20$rustc..ty..context..TyCtxt$GT$::optimized_mir::hfb4ed97f260bbdc8 + 156
    frame #41: 0x000000010eef46e8 librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::encode_optimized_mir::hb12b094675d182ad + 792
    frame #42: 0x000000010ec26c5b librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::encode_info_for_impl_item::h5eee317b43ff1a70 + 5323
    frame #43: 0x000000010ee9e5ed librustc_driver-5791a7e91c818ec7.dylib`core::ops::function::FnOnce::call_once::hdf473ee76e413793 + 77
    frame #44: 0x000000010ee7895a librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::record::h1bc846c63ee39a62 + 314
    frame #45: 0x000000010ef8fa01 librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::encode_addl_info_for_item::hb2830913baa3783f + 2401
    frame #46: 0x000000010f02b86c librustc_driver-5791a7e91c818ec7.dylib`_$LT$rustc_metadata..encoder..EncodeContext$u20$as$u20$rustc..hir..intravisit..Visitor$GT$::visit_item::h33eacef5c0257d77 + 412
    frame #47: 0x000000010eff04c0 librustc_driver-5791a7e91c818ec7.dylib`_$LT$rustc..hir..itemlikevisit..DeepVisitor$LT$V$GT$$u20$as$u20$rustc..hir..itemlikevisit..ItemLikeVisitor$GT$::visit_item::h6c7aeaecf6f45c40 + 16
    frame #48: 0x000000010f0003b1 librustc_driver-5791a7e91c818ec7.dylib`rustc::hir::Crate::visit_all_item_likes::hd58076888de21f2d + 385
    frame #49: 0x000000010eea85c8 librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::encode_info_for_items::h201ce08a434ae70b + 536
    frame #50: 0x000000010f138965 librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::EncodeContext::encode_crate_root::h71be0a0455709345 + 1973
    frame #51: 0x000000010ed8d0ce librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::encode_metadata::_$u7b$$u7b$closure$u7d$$u7d$::h8523420032380184 + 1038
    frame #52: 0x000000010edb7cd3 librustc_driver-5791a7e91c818ec7.dylib`rustc::dep_graph::graph::DepGraph::with_ignore::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h80606b976a587577 + 115
    frame #53: 0x000000010e75a5a0 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::_$u7b$$u7b$closure$u7d$$u7d$::heffa789c5054df6b + 160
    frame #54: 0x000000010e75c577 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::set_tlv::h980d28b19328d398 + 247
    frame #55: 0x000000010e585f0f librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::h05eb1940e6506ebd + 159
    frame #56: 0x000000010e66987c librustc_driver-5791a7e91c818ec7.dylib`rustc::dep_graph::graph::DepGraph::with_ignore::_$u7b$$u7b$closure$u7d$$u7d$::h3f4c14ba81260de9 + 332
    frame #57: 0x000000010eb902f4 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context::_$u7b$$u7b$closure$u7d$$u7d$::h0d83229c95c3749a + 324
    frame #58: 0x000000010ea91157 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context_opt::hab1d3ae2013efce6 + 423
    frame #59: 0x000000010e9e663d librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_context::h801d3c4987bbf7d3 + 109
    frame #60: 0x000000010f045afd librustc_driver-5791a7e91c818ec7.dylib`rustc::dep_graph::graph::DepGraph::with_ignore::hf13cab4cde210bdb + 109
    frame #61: 0x000000010f186ea5 librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::encoder::encode_metadata::hd01b787502c1d973 + 485
    frame #62: 0x000000010f12360d librustc_driver-5791a7e91c818ec7.dylib`rustc_metadata::cstore_impl::_$LT$impl$u20$rustc..middle..cstore..CrateStore$u20$for$u20$rustc_metadata..cstore..CStore$GT$::encode_metadata::h77bca98dff621b26 + 61
    frame #63: 0x0000000111f807af librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::TyCtxt::encode_metadata::ha030e33d1955fcfe + 175
    frame #64: 0x00000001084217f3 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::encode_and_write_metadata::h00cd2f5b5ec91313 + 515
    frame #65: 0x00000001080767a9 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::start_codegen::_$u7b$$u7b$closure$u7d$$u7d$::h6834a8c1839eed75 + 89
    frame #66: 0x00000001082999ea librustc_driver-5791a7e91c818ec7.dylib`rustc::util::common::time_ext::h21e07834fb303cb7 + 218
    frame #67: 0x0000000108311731 librustc_driver-5791a7e91c818ec7.dylib`rustc::util::common::time::ha6c84b17ce3ba643 + 273
    frame #68: 0x000000010825b497 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::start_codegen::h6745a7e6c32f9265 + 871
    frame #69: 0x0000000107d88859 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::ongoing_codegen::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hf6a4c0b1b84500f7 + 745
    frame #70: 0x0000000108001025 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::BoxedGlobalCtxt::enter::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h93c8a152b3b79a5e + 149
    frame #71: 0x0000000107d2d140 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_global::_$u7b$$u7b$closure$u7d$$u7d$::h6037130dfd231737 + 160
    frame #72: 0x00000001081f9820 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::_$u7b$$u7b$closure$u7d$$u7d$::hd2c5b07655160e9b + 144
    frame #73: 0x00000001080628b9 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::set_tlv::he6588a55cc6ee59e + 249
    frame #74: 0x00000001080bfa2f librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_context::heb9a049a650102a5 + 143
    frame #75: 0x0000000107d66368 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::enter_global::h5a50333276c26acf + 408
    frame #76: 0x0000000107fb5e95 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::BoxedGlobalCtxt::enter::_$u7b$$u7b$closure$u7d$$u7d$::h824d538aa552d51d + 85
    frame #77: 0x0000000107a57135 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::BoxedGlobalCtxt::access::_$u7b$$u7b$closure$u7d$$u7d$::h04a10d84feb3b8ef + 197
    frame #78: 0x0000000107b63d70 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::create_global_ctxt::_$u7b$$u7b$closure$u7d$$u7d$::he8c4b80522b1e3ad + 2720
    frame #79: 0x00000001084729fa librustc_driver-5791a7e91c818ec7.dylib`alloc::boxed::_$LT$impl$u20$core..ops..generator..Generator$u20$for$u20$core..pin..Pin$LT$alloc..boxed..Box$LT$G$GT$$GT$$GT$::resume::h31cf85a80a0b25b4 + 106
    frame #80: 0x0000000108481dc4 librustc_driver-5791a7e91c818ec7.dylib`rustc_data_structures::box_region::PinnedGenerator$LT$I$C$A$C$R$GT$::access::h561917bdc56d7d7e + 132
    frame #81: 0x0000000108057712 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::BoxedGlobalCtxt::access::h75e88e24ca2eb810 + 418
    frame #82: 0x0000000107bc3560 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::passes::BoxedGlobalCtxt::enter::hb20fb9106eeaf309 + 80
    frame #83: 0x00000001082219ef librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::ongoing_codegen::_$u7b$$u7b$closure$u7d$$u7d$::h5a36e77a5957f67c + 639
    frame #84: 0x00000001083f7b6a librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::queries::Query$LT$T$GT$::compute::he747fdbb9674cac7 + 234
    frame #85: 0x0000000108382206 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::ongoing_codegen::hbfbc79c76b042955 + 86
    frame #86: 0x000000010757992c librustc_driver-5791a7e91c818ec7.dylib`rustc_driver::run_compiler::_$u7b$$u7b$closure$u7d$$u7d$::hae40159a6f6b29b6 + 8812
    frame #87: 0x0000000107972765 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::interface::run_compiler_in_existing_thread_pool::h889f2e7df80c2f0d + 1813
    frame #88: 0x00000001078ebf43 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::interface::run_compiler::_$u7b$$u7b$closure$u7d$$u7d$::h2994953efb52cf6e + 147
    frame #89: 0x000000010777763f librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::spawn_thread_pool::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::ha19c9542ba12d219 + 95
    frame #90: 0x00000001077dc5c5 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_thread_locals::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hc28b48421a7f7a96 + 245
    frame #91: 0x00000001077a756a librustc_driver-5791a7e91c818ec7.dylib`std::thread::local::LocalKey$LT$T$GT$::try_with::h636760eb031a5ae7 + 474
    frame #92: 0x00000001077819cb librustc_driver-5791a7e91c818ec7.dylib`std::thread::local::LocalKey$LT$T$GT$::with::h5220682da232a96f + 107
    frame #93: 0x000000010769f199 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_thread_locals::_$u7b$$u7b$closure$u7d$$u7d$::h46b02174573c230a + 265
    frame #94: 0x0000000107728ffa librustc_driver-5791a7e91c818ec7.dylib`std::thread::local::LocalKey$LT$T$GT$::try_with::h00f355cd400b5198 + 474
    frame #95: 0x00000001079b848b librustc_driver-5791a7e91c818ec7.dylib`std::thread::local::LocalKey$LT$T$GT$::with::h572d6d6cfa713135 + 107
    frame #96: 0x00000001079a5395 librustc_driver-5791a7e91c818ec7.dylib`rustc::ty::context::tls::with_thread_locals::h2306c8e6039228b5 + 117
    frame #97: 0x000000010771434f librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::spawn_thread_pool::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::ha52e6acab1058cc0 + 447
    frame #98: 0x0000000107623d9f librustc_driver-5791a7e91c818ec7.dylib`scoped_tls::ScopedKey$LT$T$GT$::set::haef92ef22d99be05 + 239
    frame #99: 0x00000001075a6a49 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::spawn_thread_pool::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h367ac6567fd9c58b + 217
    frame #100: 0x00000001078918df librustc_driver-5791a7e91c818ec7.dylib`scoped_tls::ScopedKey$LT$T$GT$::set::h4f8868bc18c7168e + 239
    frame #101: 0x00000001077df58d librustc_driver-5791a7e91c818ec7.dylib`syntax::with_globals::_$u7b$$u7b$closure$u7d$$u7d$::ha510e7117f02222b + 157
    frame #102: 0x00000001079a0e0f librustc_driver-5791a7e91c818ec7.dylib`scoped_tls::ScopedKey$LT$T$GT$::set::h0acc9da3973500d0 + 239
    frame #103: 0x00000001079b8cab librustc_driver-5791a7e91c818ec7.dylib`syntax::with_globals::h6943f62da2fe1cf3 + 251
    frame #104: 0x00000001075156b8 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::spawn_thread_pool::_$u7b$$u7b$closure$u7d$$u7d$::hfc82785a174f4826 + 168
    frame #105: 0x00000001074cd7dd librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::scoped_thread::h7c257b5ed6f3f8f4 + 141
    frame #106: 0x000000010794c5b3 librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::util::spawn_thread_pool::hf972e343cf523dce + 579
    frame #107: 0x0000000107956f8d librustc_driver-5791a7e91c818ec7.dylib`rustc_interface::interface::run_compiler::h0f62d5709775d36f + 349
    frame #108: 0x000000010790d9a1 librustc_driver-5791a7e91c818ec7.dylib`rustc_driver::run_compiler::h08962bbb02925037 + 5905
    frame #109: 0x000000010772b0cd librustc_driver-5791a7e91c818ec7.dylib`rustc_driver::main::_$u7b$$u7b$closure$u7d$$u7d$::h8a361d146598324b + 349
    frame #110: 0x00000001078a5093 librustc_driver-5791a7e91c818ec7.dylib`rustc_driver::catch_fatal_errors::hc2462c91b0e18741 + 67
    frame #111: 0x0000000107971791 librustc_driver-5791a7e91c818ec7.dylib`rustc_driver::main::h6998d2801938dfbd + 97
    frame #112: 0x000000010206cd3f rustc`rustc_binary::main::hcd0c3f1a87459fb9 + 15
[...]
bjorn3 commented 5 years ago

The problem is UnOp::Neg not being implemented for i128.

bjorn3 commented 5 years ago
thread 'main' panicked at 'not yet implemented', /Users/bjorn/.cargo/registry/src/github.com-1ecc6299db9ec823/c2-chacha-0.2.2/src/guts.rs:260:1

Filled https://github.com/cryptocorrosion/cryptocorrosion/issues/25 for running without SIMD.

bjorn3 commented 5 years ago

Pushed 6129921529e2b4787a0d206244c7a858622b8d6d with some fixes necessary for this.

bjorn3 commented 5 years ago

libcore compiled by patching c2-chacha to not passthrough the simd feature to ppv-lite86.

Now there are two const_err's which don't make sense:

[...]
error: any use of this value will cause an error
   --> src/liballoc/raw_vec.rs:145:18
    |
127 |     pub const NEW: Self = Self::new();
    |     ----------------------------------
...
145 |             cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                  |
    |                  index out of bounds: the len is 2 but the index is 0
    |                  inside call to `raw_vec::RawVec::<u8>::new` at src/liballoc/raw_vec.rs:127:27
    |
    = note: `#[deny(const_err)]` on by default

fatal runtime error: failed to initiate panic, error 5
error: could not compile `alloc`.

Caused by:
  process didn't exit successfully: `/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/bootstrap/debug/rustc --edition=2018 --crate-name alloc src/liballoc/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=2 -C debuginfo=0 --cfg 'feature="compiler-builtins-c"' -C metadata=597966ce1b444f59 -C extra-filename=-597966ce1b444f59 --out-dir /Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps --target x86_64-apple-darwin -L dependency=/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps -L dependency=/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/release/deps --extern compiler_builtins=/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps/libcompiler_builtins-259284571ab1a5fb.rmeta --extern core=/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps/libcore-7f5c6d7d2df26804.rmeta -Zexternal-macro-backtrace -Zosx-rpath-install-name '-Clink-args=-Wl,-rpath,@loader_path/../lib' -Wrust_2018_idioms -Wunused_lifetimes -Cprefer-dynamic -Zbinary-dep-depinfo -L native=/Users/bjorn/Documents/rustc_codegen_cranelift/rust/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/build/compiler_builtins-f2fb94987d72e611/out` (signal: 6, SIGABRT: process abort signal)
warning: build failed, waiting for other jobs to finish...
error: this expression will panic at runtime
   --> src/libpanic_unwind/gcc.rs:156:25
    |
156 |     if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to add with overflow
    |
    = note: `#[deny(const_err)]` on by default

fatal runtime error: failed to initiate panic, error 5
error: could not compile `panic_unwind`.
[...]
bjorn3 commented 5 years ago

Marked as bug because of the impossible const_err's.

bjorn3 commented 4 years ago

I got rustc bootstrapping using cg_clif. Unfortunately the rustc built using cg_clif crashes when you try to use it. So far I have been able to pin point that make_input returns an io::Error. When trying to .to_string() it it turns out that the io::Error has an invalid discriminant.

Rust fork: https://github.com/bjorn3/rust/commit/e5c309197bf97c12c5d0782b9300417a52c80f66 (branch cg_clif_subtree) cg_clif commit: https://github.com/bjorn3/rustc_codegen_cranelift/commit/f7eb36070c602f0dccca26ccec83f1c003cb27dd (branch wip_proc_macro_fixes, clone it to src/rustc_codegen_cranelift in the rust source repo) Cranelift commit: https://github.com/bjorn3/wasmtime/commit/2d60da466dc375b0cb08ad62e49879927f176619 (pr bytecodealliance/wasmtime#1559, clone it to the parent dir of the rust repo, or edit Cargo.toml of the rust repo to point to it in the patch section)

config.toml:

[rust]
codegen-backends = ["cranelift"]
deny-warnings = false
bjorn3 commented 4 years ago

Rust fork: https://github.com/bjorn3/rust/commit/42728c0730229daad922372f76e08f5e40c31aa1 cg_clif commit: https://github.com/bjorn3/rustc_codegen_cranelift/commit/4a48a39b45a0a90974f36790137ab16dc949026b Cranelift commit: https://github.com/bjorn3/wasmtime/commit/abe03816a034b261f4bd199500e4d4bb38ff4b2f (pr bytecodealliance/wasmtime#1559, clone it to the parent dir of the rust repo, or edit Cargo.toml of the rust repo to point to it in the patch section)

Edit has_cpuid in corearch to always return false.

config.toml:

[build]
full-bootstrap = true
[rust]
codegen-backends = ["cranelift"]
deny-warnings = false

Current failure:

``` error: internal compiler error: src/librustc_mir_build/build/matches/test.rs:227:34: expected boolean value but got 1 --> src/libcore/iter/adapters/mod.rs:566:22 | 566 | move |n| if n == 0 { 0 } else { 1 + (n - 1) / (step + 1) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ thread 'rustc' panicked at 'Box', /home/bjorn/Documenten/rust/src/libstd/macros.rs:13:23 stack backtrace: 0: backtrace::backtrace::libunwind::trace 1: backtrace::backtrace::trace_unsynchronized 2: std::sys_common::backtrace::_print_fmt 3: ::fmt 4: core::fmt::write 5: std::io::Write::write_fmt 6: std::sys_common::backtrace::_print 7: std::sys_common::backtrace::print 8: std::panicking::default_hook::{{closure}} 9: std::panicking::default_hook 10: core::ops::function::Fn::call 11: as core::ops::function::Fn>::call at ./src/liballoc/boxed.rs:1092 12: rustc_driver::report_ice at src/librustc_driver/lib.rs:1162 13: ::deref::__static_ref_initialize::{{closure}} at src/librustc_driver/lib.rs:1149 14: std::panicking::rust_panic_with_hook 15: std::panicking::begin_panic at ./src/libstd/panicking.rs:450 16: rustc_errors::HandlerInner::span_bug at ./src/libstd/macros.rs:13 17: rustc_errors::Handler::span_bug at ./src/librustc_errors/lib.rs:622 18: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}} at ./src/librustc_middle/util/bug.rs:32 19: rustc_middle::ty::context::tls::with_opt::{{closure}} at ./src/librustc_middle/ty/context.rs:1848 20: rustc_middle::ty::context::tls::with_context_opt at ./src/librustc_middle/ty/context.rs:1800 21: rustc_middle::ty::context::tls::with_opt at ./src/librustc_middle/ty/context.rs:1848 22: rustc_middle::util::bug::opt_span_bug_fmt at ./src/librustc_middle/util/bug.rs:29 23: rustc_middle::util::bug::span_bug_fmt at ./src/librustc_middle/util/bug.rs:21 24: rustc_mir_build::build::matches::test::::perform_test at src/librustc_mir_build/build/matches/test.rs:227 25: rustc_mir_build::build::matches::::test_candidates at src/librustc_mir_build/build/matches/mod.rs:1502 26: rustc_mir_build::build::matches::::test_candidates_with_or at src/librustc_mir_build/build/matches/mod.rs:1163 27: rustc_mir_build::build::matches::::match_simplified_candidates at src/librustc_mir_build/build/matches/mod.rs:986 28: rustc_mir_build::build::matches::::match_candidates::{{closure}} at src/librustc_mir_build/build/matches/mod.rs:929 29: stacker::maybe_grow at /home/bjorn/.cargo/registry/src/github.com-1ecc6299db9ec823/stacker-0.1.9/src/lib.rs:52 30: rustc_data_structures::stack::ensure_sufficient_stack at ./src/librustc_data_structures/stack.rs:16 31: rustc_mir_build::build::matches::::match_candidates at src/librustc_mir_build/build/matches/mod.rs:912 32: rustc_mir_build::build::matches::::lower_match_tree at src/librustc_mir_build/build/matches/mod.rs:184 33: rustc_mir_build::build::matches::::match_expr at src/librustc_mir_build/build/matches/mod.rs:103 34: rustc_mir_build::build::expr::into::::into_expr at src/librustc_mir_build/build/expr/into.rs:52 35: ::eval_into at src/librustc_mir_build/build/into.rs:42 36: rustc_mir_build::build::into::::into at src/librustc_mir_build/build/into.rs:30 37: rustc_mir_build::build::expr::into::::into_expr::{{closure}} at src/librustc_mir_build/build/expr/into.rs:46 38: rustc_mir_build::build::scope::::in_scope at src/librustc_mir_build/build/scope.rs:455 39: rustc_mir_build::build::expr::into::::into_expr at src/librustc_mir_build/build/expr/into.rs:46 40: ::eval_into at src/librustc_mir_build/build/into.rs:42 41: rustc_mir_build::build::into::::into at src/librustc_mir_build/build/into.rs:30 42: rustc_mir_build::build::expr::into::::into_expr::{{closure}} at src/librustc_mir_build/build/expr/into.rs:46 43: rustc_mir_build::build::scope::::in_scope at src/librustc_mir_build/build/scope.rs:455 44: rustc_mir_build::build::expr::into::::into_expr at src/librustc_mir_build/build/expr/into.rs:46 45: ::eval_into at src/librustc_mir_build/build/into.rs:53 46: rustc_mir_build::build::into::::into at src/librustc_mir_build/build/into.rs:30 47: rustc_mir_build::build::Builder::args_and_body at src/librustc_mir_build/build/mod.rs:949 48: rustc_mir_build::build::construct_fn::{{closure}}::{{closure}}::{{closure}} at src/librustc_mir_build/build/mod.rs:612 49: rustc_mir_build::build::scope::::in_scope at src/librustc_mir_build/build/scope.rs:455 50: rustc_mir_build::build::construct_fn::{{closure}}::{{closure}} at src/librustc_mir_build/build/mod.rs:611 51: rustc_mir_build::build::scope::::in_breakable_scope at src/librustc_mir_build/build/scope.rs:392 52: rustc_mir_build::build::construct_fn::{{closure}} at src/librustc_mir_build/build/mod.rs:606 53: rustc_mir_build::build::scope::::in_scope at src/librustc_mir_build/build/scope.rs:455 54: rustc_mir_build::build::construct_fn at src/librustc_mir_build/build/mod.rs:597 55: rustc_mir_build::build::mir_build::{{closure}} at src/librustc_mir_build/build/mod.rs:154 56: rustc_infer::infer::InferCtxtBuilder::enter::{{closure}} at ./src/librustc_infer/infer/mod.rs:622 57: rustc_middle::ty::context::GlobalCtxt::enter_local::{{closure}}::{{closure}} at ./src/librustc_middle/ty/context.rs:1573 58: rustc_middle::ty::context::tls::enter_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1739 59: rustc_middle::ty::context::tls::set_tlv at ./src/librustc_middle/ty/context.rs:1723 60: rustc_middle::ty::context::tls::enter_context at ./src/librustc_middle/ty/context.rs:1739 61: rustc_middle::ty::context::GlobalCtxt::enter_local::{{closure}} at ./src/librustc_middle/ty/context.rs:1573 62: rustc_middle::ty::context::tls::with_related_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1827 63: rustc_middle::ty::context::tls::with_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1811 64: rustc_middle::ty::context::tls::with_context_opt at ./src/librustc_middle/ty/context.rs:1800 65: rustc_middle::ty::context::tls::with_context at ./src/librustc_middle/ty/context.rs:1811 66: rustc_middle::ty::context::tls::with_related_context at ./src/librustc_middle/ty/context.rs:1824 67: rustc_middle::ty::context::GlobalCtxt::enter_local at ./src/librustc_middle/ty/context.rs:1565 68: rustc_infer::infer::InferCtxtBuilder::enter at ./src/librustc_infer/infer/mod.rs:621 69: rustc_mir_build::build::mir_build at src/librustc_mir_build/build/mod.rs:63 70: rustc_mir_build::build::mir_built at src/librustc_mir_build/build/mod.rs:25 71: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_built>::compute at ./src/librustc_middle/ty/query/plumbing.rs:362 72: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl at ./src/librustc_query_system/dep_graph/graph.rs:303 73: rustc_query_system::dep_graph::graph::DepGraph::with_task at ./src/librustc_query_system/dep_graph/graph.rs:200 74: rustc_query_system::query::plumbing::force_query_with_job::{{closure}}::{{closure}} at ./src/librustc_query_system/query/plumbing.rs:599 75: rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}} at ./src/librustc_middle/ty/query/plumbing.rs:72 76: stacker::maybe_grow at /home/bjorn/.cargo/registry/src/github.com-1ecc6299db9ec823/stacker-0.1.9/src/lib.rs:52 77: rustc_data_structures::stack::ensure_sufficient_stack at ./src/librustc_data_structures/stack.rs:16 78: rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}} at ./src/librustc_middle/ty/query/plumbing.rs:72 79: rustc_middle::ty::context::tls::enter_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1739 80: rustc_middle::ty::context::tls::set_tlv at ./src/librustc_middle/ty/context.rs:1723 81: rustc_middle::ty::context::tls::enter_context at ./src/librustc_middle/ty/context.rs:1739 82: rustc_middle::ty::query::plumbing::::start_query::{{closure}} at ./src/librustc_middle/ty/query/plumbing.rs:71 83: rustc_middle::ty::context::tls::with_related_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1827 84: rustc_middle::ty::context::tls::with_context::{{closure}} at ./src/librustc_middle/ty/context.rs:1811 85: rustc_middle::ty::context::tls::with_context_opt at ./src/librustc_middle/ty/context.rs:1800 86: rustc_middle::ty::context::tls::with_context at ./src/librustc_middle/ty/context.rs:1811 87: rustc_middle::ty::context::tls::with_related_context at ./src/librustc_middle/ty/context.rs:1824 88: rustc_middle::ty::query::plumbing::::start_query at ./src/librustc_middle/ty/query/plumbing.rs:60 89: rustc_query_system::query::plumbing::force_query_with_job::{{closure}} at ./src/librustc_query_system/query/plumbing.rs:589 90: rustc_query_system::query::plumbing::with_diagnostics at ./src/librustc_query_system/query/plumbing.rs:296 91: rustc_query_system::query::plumbing::force_query_with_job at ./src/librustc_query_system/query/plumbing.rs:588 92: rustc_query_system::query::plumbing::try_execute_query at ./src/librustc_query_system/query/plumbing.rs:415 93: rustc_query_system::query::plumbing::get_query_impl::{{closure}} at ./src/librustc_query_system/query/plumbing.rs:639 94: as rustc_query_system::query::caches::QueryCache>::lookup at ./src/librustc_query_system/query/caches.rs:193 95: rustc_query_system::query::plumbing::try_get_cached at ./src/librustc_query_system/query/plumbing.rs:369 96: rustc_query_system::query::plumbing::get_query_impl at ./src/librustc_query_system/query/plumbing.rs:631 97: rustc_query_system::query::plumbing::get_query at ./src/librustc_query_system/query/plumbing.rs:731 98: rustc_middle::ty::query::TyCtxtAt::mir_built at ./src/librustc_middle/ty/query/plumbing.rs:472 99: rustc_middle::ty::query::::mir_built at ./src/librustc_middle/ty/query/plumbing.rs:433 100: rustc_mir::transform::check_unsafety::unsafety_check_result at src/librustc_mir/transform/check_unsafety.rs:543 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports note: rustc 1.46.0-dev running on x86_64-unknown-linux-gnu note: compiler flags: -Z macro-backtrace -Z binary-dep-depinfo -Z force-unstable-if-unmarked -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C link-args=-Wl,-rpath,$ORIGIN/../lib -C prefer-dynamic -C embed-bitcode=yes -C link-arg=-rdynamic -C debug-assertions=n --crate-type lib note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [mir_built] building MIR for ` as iter::traits::iterator::Iterator>::size_hint::first_size::{{closure}}#0` #1 [unsafety_check_result] unsafety-checking ` as iter::traits::iterator::Iterator>::size_hint::first_size::{{closure}}#0` #2 [unsafety_check_result] unsafety-checking ` as iter::traits::iterator::Iterator>::size_hint::first_size` #3 [mir_const] processing MIR for ` as iter::traits::iterator::Iterator>::size_hint::first_size` #4 [mir_validated] processing ` as iter::traits::iterator::Iterator>::size_hint::first_size` #5 [mir_borrowck] borrow-checking ` as iter::traits::iterator::Iterator>::size_hint::first_size` #6 [type_of] computing type of ` as iter::traits::iterator::Iterator>::size_hint::first_size::{{opaque}}#0` #7 [check_mod_item_types] checking item types in module `iter::adapters` #8 [analysis] running analysis passes on this crate end of query stack fatal runtime error: failed to initiate panic, error 5 error: could not compile `core`. ```
bjorn3 commented 4 years ago

The ICE happens at https://github.com/bjorn3/rust/blob/42728c0730229daad922372f76e08f5e40c31aa1/src/librustc_mir_build/build/matches/test.rs#L227. I am probably handling matching on u128 wrong.

bjorn3 commented 4 years ago

Minimal repro for ICE:

fn is_true(a: true) -> u8 {
    if a { 1 } else { 0 }
}
bjorn3 commented 4 years ago

Minimal miscompilation repro:

fn main() {
    let options = [1u128];
    match options[0] {
        1 => (),
        0 => loop {},
        v => panic(v),
    };
}

fn panic(v: u128) -> !{
    panic!("{}", v)
}
clif ir for `main` ``` test compile set is_pic target x86_64-unknown-linux-gnu function u0:2() system_v { ss0 = explicit_slot 16 gv0 = symbol colocated u1:0 sig0 = (i128) system_v sig1 = (i64) -> i32 system_v fn0 = colocated u0:7 sig0 fn1 = u0:13 sig1 jt0 = jump_table [block4, block3] block0: nop jump block1 block1: nop @0001 v0 = iconst.i64 1 @0001 v1 = iconst.i64 0 @0001 v2 = iconcat v0, v1 @0001 v3 = iconst.i64 0 @0001 v4 = imul_imm v3, 16 @0001 v5 = stack_addr.i64 ss0 @0001 v6 = iadd v5, v4 @0001 store v2, v6 @0002 v7 = iconst.i64 0 v12 -> v7 @0003 v8 = imul_imm v7, 16 @0003 v9 = stack_addr.i64 ss0 @0003 v10 = iadd v9, v8 @0003 v11 = load.i128 v10 @0003 jump block6 block6: @0003 br_table.i128 v11, block2, jt0 block2: @0003 nop @0004 v13 = imul_imm.i64 v12, 16 @0004 v14 = stack_addr.i64 ss0 @0004 v15 = iadd v14, v13 @0004 v16 = load.i128 v15 @0006 call fn0(v16) @0006 v17 = global_value.i64 gv0 @0006 v18 = call fn1(v17) @0006 trap unreachable block3: @0006 nop @0008 v19 = iconst.i64 8 @000a return block4: @000a nop @000b jump block5 block5: @000b nop @000b jump block5 } ```
bjorn3 commented 4 years ago

Got to metadata writing with the miscompilation fixed. It panicked in ppv-lite86. Currently recompiling with the simd feature of ppv-lite86 disabled.

bjorn3 commented 4 years ago

It finally works! :tada: :balloon: :rocket: :balloon: :tada:

Rust fork: bjorn3/rust@9a1facc469515a4b51bc463c36e65d001c26baa9 cg_clif commit: 8051242b0574ac57bdefa6b8b3b6dc69743c09c0 Cranelift commit: strike>bjorn3/wasmtime@430ab52a3cf9c941783e7996cb6dd00206e9152a</strike merge bjorn3/wasmtime@8fbde92c387635908955a5a8140a8901861cdade and bjorn3/wasmtime@ed0495c75440a1b593685491da157d79250afa02 (pr bytecodealliance/wasmtime#1559 + pr bytecodealliance/wasmtime#1939 (merged), clone it to the parent dir of the rust repo, or edit Cargo.toml of the rust repo to point to it in the patch section)

Edit has_cpuid in corearch to always return false. Clone https://github.com/cryptocorrosion/cryptocorrosion/ into the cg_clif dir and patch utils-simd/ppv-lite86/src/lib.rs to always user the fallback implementation and never the SIMD implementation.

config.toml:

[build]
full-bootstrap = true
[rust]
codegen-backends = ["cranelift"]
deny-warnings = false
Build completed successfully in 2:57:19
bjorn3 commented 4 years ago

https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/bootstrap.20rustc.20using.20cg_clif/near/202400854

The bootstrap conpiler compiled an optimized compiler with cg_clif support using LLVM. This took 30m. This compiler with cg_clif support compiles a conpiler which is effectively less optimized than an LLVM debug build. This took 4m40s. This unoptimized comiler then took 3h to compile libstd+compiler.

bjorn3 commented 4 years ago

bytecodealliance/wasmtime#1939 got merged. The only Cranelift blocker is now bytecodealliance/wasmtime#1559.

bjorn3 commented 4 years ago

bytecodealliance/wasmtime#1559. has been merged. As of #1068 it is no longer necessary to patch cg_clif or Cranelift.

pepyakin commented 4 years ago

what's left for compiling rustc then?

bjorn3 commented 4 years ago

Edit has_cpuid in corearch to always return false. Clone https://github.com/cryptocorrosion/cryptocorrosion/ into the cg_clif dir and patch utils-simd/ppv-lite86/src/lib.rs to always user the fallback implementation and never the SIMD implementation.

and https://github.com/bjorn3/rust/compare/3b4a3d68b5d3026bab9d41fcc004439207ecff90...9a1facc469515a4b51bc463c36e65d001c26baa9

bjorn3 commented 4 years ago

With #1070 merged, only https://github.com/bjorn3/rust/compare/3b4a3d68b5d3026bab9d41fcc004439207ecff90...9a1facc469515a4b51bc463c36e65d001c26baa9 should be necessary now.

bjorn3 commented 4 years ago

I rebased and cleaned up the rust branch (now called cg_clif_subtree2): https://github.com/bjorn3/rust/commit/faee9abe5113e53946d9b42d00e3194de90c087f It works together with cg_clif commit 4757371aba4e8aaf2cebb4ba32299cf7f9364aaf. No other changes are necessary anymore. There are still a few hacks on the rust side though.

stage std rustc cg_clif
0 46.68s 28m 40s 2m 52s
1 41.43s 4m 25s 51.42s
2 19m 55s 115m 09s 21m 35s
Build completed successfully in 2:36:43
vultix commented 4 years ago

I’m curious - how much longer are those times with llvm?

bjorn3 commented 4 years ago

Stage 0 is using a cg_llvm compiled rustc with cg_llvm as backend. This is representative for all stages when using cg_llvm. Stage 1 is using a cg_llvm compiled rustc with cg_clif as backend. Stage 2 is using a cg_clif compiled rustc with cg_clif as backend.

The difference between stage 0 and stage 1 is the compile time speedup of cg_clif over release mode cg_llvm. The difference between stage 1 and stage 2 is the runtime slowdown of cg_clif over release mode cg_llvm. This difference is much less when using cg_llvm in debug mode. I don't volunteer for testing the difference between cg_clif and debug mode cg_llvm as it would take me ~4-5h, during which I can't use my computer at all. :)

vultix commented 4 years ago

Brilliant - thank you for the explanation! Incredible results.

est31 commented 4 years ago

@bjorn3 in stage 0, are you re-compiling llvm from scratch or do you have it cached? IIRC it's compiled only once for all three stages so to give a fair comparison between cg_llvm and cg_clif, one needs to ensure it's not compiled during the stage 0 build but cached.

bjorn3 commented 4 years ago

I didn't compile LLVM at all. Stage 0 is the compilation of a rustc that only supports cg_clif using the bootstrap compiler.

bjorn3 commented 4 years ago

@vultix On reddit you said 7x faster. This is pretty much comparing apples to oranges. cg_clif compiles code that runs a bit slower than debug mode cg_llvm. The compilation of rustc was however with release mode cg_llvm. This seems to have caused a bit of confusion on reddit.

est31 commented 4 years ago

@bjorn3 amazing!

vultix commented 4 years ago

Ah, my apologies for confusing everyone. That distinction never occurred to me

bjorn3 commented 3 years ago

After #78624 all you need to do is apply

diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml
index 23e689fcae7..5f077b765b6 100644
--- a/compiler/rustc_data_structures/Cargo.toml
+++ b/compiler/rustc_data_structures/Cargo.toml
@@ -32,7 +32,7 @@ tempfile = "3.0.5"

 [dependencies.parking_lot]
 version = "0.11"
-features = ["nightly"]
+#features = ["nightly"]

 [target.'cfg(windows)'.dependencies]
 winapi = { version = "0.3", features = ["fileapi", "psapi"] }

and run

$ cat > config.toml <<EOF
[build]
full-bootstrap = true

[rust]
codegen-backends = ["cranelift"]
EOF
$ ./x.py build --stage 2
bjorn3 commented 3 years ago

Fixed in https://github.com/bjorn3/rustc_codegen_cranelift/pull/1099 and added a test in https://github.com/bjorn3/rustc_codegen_cranelift/commit/54b1d101efec3da791aee1f98fb26230e88b9a05.