From a21f39522c8d5776f5baa6ead22c1dbb13e56820 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 9 Sep 2024 17:40:25 +1000 Subject: [PATCH 1/5] bootstrap: Print more debug info when `find_initial_libdir` fails --- src/bootstrap/src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 780024e307e..fa295dea1f6 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -347,10 +347,14 @@ pub fn new(mut config: Config) -> Build { }; let Some(initial_libdir) = find_initial_libdir() else { panic!( - "couldn't determine `initial_libdir` \ - from target dir {initial_target_dir:?} \ - and sysroot {initial_sysroot:?}" - ) + "couldn't determine `initial_libdir`: +- config.initial_rustc: {rustc:?} +- initial_target_libdir_str: {initial_target_libdir_str:?} +- initial_target_dir: {initial_target_dir:?} +- initial_sysroot: {initial_sysroot:?} +", + rustc = config.initial_rustc, + ); }; let version = std::fs::read_to_string(src.join("src").join("version")) From 5cf117ed0514af068a6e0e42f732dd93ff5e90dc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 10 Sep 2024 10:54:59 -0400 Subject: [PATCH 2/5] Don't call closure_by_move_body_def_id on FnOnce async closures in MIR validation --- compiler/rustc_interface/src/passes.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 2 +- compiler/rustc_mir_transform/src/validate.rs | 6 +----- .../async-closures/body-check-on-non-fnmut.rs | 20 +++++++++++++++++++ 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index c4a38047b5e..b93bc3ed84f 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -788,7 +788,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { rustc_hir_analysis::check_crate(tcx); sess.time("MIR_coroutine_by_move_body", || { tcx.hir().par_body_owners(|def_id| { - if tcx.needs_coroutine_by_move_body_def_id(def_id) { + if tcx.needs_coroutine_by_move_body_def_id(def_id.to_def_id()) { tcx.ensure_with_value().coroutine_by_move_body_def_id(def_id); } }); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 56fcfe8e798..fe162fe8303 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -3173,7 +3173,7 @@ pub fn impl_polarity(self, def_id: impl IntoQueryParam) -> ty::ImplPolari self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity) } - pub fn needs_coroutine_by_move_body_def_id(self, def_id: LocalDefId) -> bool { + pub fn needs_coroutine_by_move_body_def_id(self, def_id: DefId) -> bool { if let Some(hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure)) = self.coroutine_kind(def_id) && let ty::Coroutine(_, args) = self.type_of(def_id).instantiate_identity().kind() diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 0bbbf047f63..c83b9139801 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -326,7 +326,7 @@ fn mir_promoted( tcx.ensure_with_value().has_ffi_unwind_calls(def); // the `by_move_body` query uses the raw mir, so make sure it is run. - if tcx.needs_coroutine_by_move_body_def_id(def) { + if tcx.needs_coroutine_by_move_body_def_id(def.to_def_id()) { tcx.ensure_with_value().coroutine_by_move_body_def_id(def); } diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 18865c73f75..da36ddd1e9b 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -1,7 +1,6 @@ //! Validates the MIR to ensure that invariants are upheld. use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir as hir; use rustc_hir::LangItem; use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; @@ -716,10 +715,7 @@ fn visit_projection_elem( // first place. let layout = if def_id == self.caller_body.source.def_id() { self.caller_body.coroutine_layout_raw() - } else if let Some(hir::CoroutineKind::Desugared( - _, - hir::CoroutineSource::Closure, - )) = self.tcx.coroutine_kind(def_id) + } else if self.tcx.needs_coroutine_by_move_body_def_id(def_id) && let ty::ClosureKind::FnOnce = args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap() && self.caller_body.source.def_id() diff --git a/tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs b/tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs new file mode 100644 index 00000000000..4382a689e75 --- /dev/null +++ b/tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs @@ -0,0 +1,20 @@ +//@ aux-build:block-on.rs +//@ edition:2021 +//@ build-pass + +#![feature(async_closure)] + +extern crate block_on; + +// Make sure that we don't call `coroutine_by_move_body_def_id` query +// on async closures that are `FnOnce`. See issue: #130167. + +async fn empty() {} + +pub async fn call_once(f: F) { + f().await; +} + +fn main() { + block_on::block_on(call_once(async || empty().await)); +} From af33be54d5cca894b5896530549d5a562354eed0 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 6 Sep 2024 21:00:31 +0300 Subject: [PATCH 3/5] add llvm-bitcode-linker and llvm-tools bins to ci-rustc's sysroot Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index bb07d478f71..e1ab1e7599e 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1760,6 +1760,49 @@ fn run(self, builder: &Builder<'_>) -> Compiler { return target_compiler; } + // We prepend this bin directory to the user PATH when linking Rust binaries. To + // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`. + let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host); + let libdir_bin = libdir.parent().unwrap().join("bin"); + t!(fs::create_dir_all(&libdir_bin)); + + if builder.config.llvm_enabled(target_compiler.host) { + let llvm::LlvmResult { llvm_config, .. } = + builder.ensure(llvm::Llvm { target: target_compiler.host }); + if !builder.config.dry_run() && builder.config.llvm_tools_enabled { + let llvm_bin_dir = + command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout(); + let llvm_bin_dir = Path::new(llvm_bin_dir.trim()); + + // Since we've already built the LLVM tools, install them to the sysroot. + // This is the equivalent of installing the `llvm-tools-preview` component via + // rustup, and lets developers use a locally built toolchain to + // build projects that expect llvm tools to be present in the sysroot + // (e.g. the `bootimage` crate). + for tool in LLVM_TOOLS { + let tool_exe = exe(tool, target_compiler.host); + let src_path = llvm_bin_dir.join(&tool_exe); + // When using `download-ci-llvm`, some of the tools + // may not exist, so skip trying to copy them. + if src_path.exists() { + builder.copy_link(&src_path, &libdir_bin.join(&tool_exe)); + } + } + } + } + + let maybe_install_llvm_bitcode_linker = |compiler| { + if builder.config.llvm_bitcode_linker_enabled { + let src_path = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker { + compiler, + target: target_compiler.host, + extra_features: vec![], + }); + let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); + builder.copy_link(&src_path, &libdir_bin.join(tool_exe)); + } + }; + // If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0. if builder.download_rustc() { builder.ensure(Std::new(target_compiler, target_compiler.host)); @@ -1772,6 +1815,9 @@ fn run(self, builder: &Builder<'_>) -> Compiler { if target_compiler.stage == builder.top_stage { builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage)); } + + maybe_install_llvm_bitcode_linker(target_compiler); + return target_compiler; } @@ -1880,11 +1926,6 @@ fn run(self, builder: &Builder<'_>) -> Compiler { copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler); - // We prepend this bin directory to the user PATH when linking Rust binaries. To - // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`. - let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host); - let libdir_bin = libdir.parent().unwrap().join("bin"); - t!(fs::create_dir_all(&libdir_bin)); if let Some(lld_install) = lld_install { let src_exe = exe("lld", target_compiler.host); let dst_exe = exe("rust-lld", target_compiler.host); @@ -1920,40 +1961,7 @@ fn run(self, builder: &Builder<'_>) -> Compiler { ); } - if builder.config.llvm_enabled(target_compiler.host) { - let llvm::LlvmResult { llvm_config, .. } = - builder.ensure(llvm::Llvm { target: target_compiler.host }); - if !builder.config.dry_run() && builder.config.llvm_tools_enabled { - let llvm_bin_dir = - command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout(); - let llvm_bin_dir = Path::new(llvm_bin_dir.trim()); - - // Since we've already built the LLVM tools, install them to the sysroot. - // This is the equivalent of installing the `llvm-tools-preview` component via - // rustup, and lets developers use a locally built toolchain to - // build projects that expect llvm tools to be present in the sysroot - // (e.g. the `bootimage` crate). - for tool in LLVM_TOOLS { - let tool_exe = exe(tool, target_compiler.host); - let src_path = llvm_bin_dir.join(&tool_exe); - // When using `download-ci-llvm`, some of the tools - // may not exist, so skip trying to copy them. - if src_path.exists() { - builder.copy_link(&src_path, &libdir_bin.join(&tool_exe)); - } - } - } - } - - if builder.config.llvm_bitcode_linker_enabled { - let src_path = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker { - compiler: build_compiler, - target: target_compiler.host, - extra_features: vec![], - }); - let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); - builder.copy_link(&src_path, &libdir_bin.join(tool_exe)); - } + maybe_install_llvm_bitcode_linker(build_compiler); // Ensure that `libLLVM.so` ends up in the newly build compiler directory, // so that it can be found when the newly built `rustc` is run. From f03bfb871bce3d89f948b7138474f91f22fc930a Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 13 Sep 2024 18:54:53 +0300 Subject: [PATCH 4/5] avoid updating LLVM submodule during bootstrap unit tests Signed-off-by: onur-ozkan --- src/bootstrap/src/core/config/config.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 9271e809853..79c2f73161e 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -2739,6 +2739,8 @@ fn parse_download_ci_llvm( return false; } + // Fetching the LLVM submodule is unnecessary for self-tests. + #[cfg(not(feature = "bootstrap-self-test"))] self.update_submodule("src/llvm-project"); // Check for untracked changes in `src/llvm-project`. From c8233a4c6f4f0cd4e39b11170060b1e5e8a54141 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 13 Sep 2024 14:17:32 -0400 Subject: [PATCH 5/5] ProjectionElem and UnOp/BinOp dont need to be PartialOrd/Ord --- compiler/rustc_middle/src/mir/syntax.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 22a4b688c51..f5590aa2762 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1094,7 +1094,7 @@ pub struct Place<'tcx> { pub projection: &'tcx List>, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] pub enum ProjectionElem { Deref, @@ -1468,7 +1468,7 @@ pub enum NullOp<'tcx> { UbChecks, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)] pub enum UnOp { /// The `!` operator for logical inversion @@ -1486,7 +1486,7 @@ pub enum UnOp { PtrMetadata, } -#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] pub enum BinOp { /// The `+` operator (addition)