From 29eb6860a8104f01ad4bac2b5560d9d66af14a99 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 31 Mar 2021 10:27:01 -0400 Subject: [PATCH 1/5] Give a better error when --theme is not a CSS file Before: ``` error: invalid argument: "bacon.toml" ``` After: ``` error: invalid argument: "bacon.toml" | = help: arguments to --theme must be CSS files ``` --- src/librustdoc/config.rs | 4 +++- src/test/rustdoc-ui/invalid-theme-name.rs | 3 +++ src/test/rustdoc-ui/invalid-theme-name.stderr | 4 ++++ src/tools/compiletest/src/runtest.rs | 3 +-- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/test/rustdoc-ui/invalid-theme-name.rs create mode 100644 src/test/rustdoc-ui/invalid-theme-name.stderr diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ecb6378f31fb4..471ac8f6cad25 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -439,7 +439,9 @@ impl Options { return Err(1); } if theme_file.extension() != Some(OsStr::new("css")) { - diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)).emit(); + diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)) + .help("arguments to --theme must have a .css extension") + .emit(); return Err(1); } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag); diff --git a/src/test/rustdoc-ui/invalid-theme-name.rs b/src/test/rustdoc-ui/invalid-theme-name.rs new file mode 100644 index 0000000000000..c22ebf02718e6 --- /dev/null +++ b/src/test/rustdoc-ui/invalid-theme-name.rs @@ -0,0 +1,3 @@ +// compile-flags:--theme {{src-base}}/invalid-theme-name.rs +// error-pattern: invalid argument +// error-pattern: must have a .css extension diff --git a/src/test/rustdoc-ui/invalid-theme-name.stderr b/src/test/rustdoc-ui/invalid-theme-name.stderr new file mode 100644 index 0000000000000..80204442dbec3 --- /dev/null +++ b/src/test/rustdoc-ui/invalid-theme-name.stderr @@ -0,0 +1,4 @@ +error: invalid argument: "$DIR/invalid-theme-name.rs" + | + = help: arguments to --theme must have a .css extension + diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 7aa3d4ab09e41..91d4e3a26a92d 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1909,8 +1909,7 @@ impl<'test> TestCx<'test> { } else { Command::new(&self.config.rustdoc_path.clone().expect("no rustdoc built yet")) }; - // FIXME Why is -L here? - rustc.arg(input_file); //.arg("-L").arg(&self.config.build_base); + rustc.arg(input_file); // Use a single thread for efficiency and a deterministic error message order rustc.arg("-Zthreads=1"); From 9eabb41ab4299e290f43d614877947d6238c3a96 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 5 Apr 2021 06:02:29 -0400 Subject: [PATCH 2/5] Remove unnecessary exceptions to the platform-specific code check Some of these were just wrong, like src/librustc. Some looked outdated, like std::f64. Not sure what was going on with the others - maybe this check isn't as smart as it needs to be? But it the meantime it seems silly to ignore the check if it will pass anyway. --- src/tools/tidy/src/pal.rs | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 1dba6b73b9361..144529d8641ee 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -40,35 +40,20 @@ const EXCEPTION_PATHS: &[&str] = &[ "library/panic_abort", "library/panic_unwind", "library/unwind", - // black_box implementation is LLVM-version specific and it uses - // target_os to tell targets with different LLVM-versions apart - // (e.g. `wasm32-unknown-emscripten` vs `wasm32-unknown-unknown`): - "library/core/src/hint.rs", "library/std/src/sys/", // Platform-specific code for std lives here. // This has the trailing slash so that sys_common is not excepted. "library/std/src/os", // Platform-specific public interfaces "library/rtstartup", // Not sure what to do about this. magic stuff for mingw - // temporary exceptions - "library/std/src/lib.rs", - "library/std/src/path.rs", - "library/std/src/f32.rs", - "library/std/src/f64.rs", // Integration test for platform-specific run-time feature detection: "library/std/tests/run-time-detect.rs", "library/std/src/net/test.rs", "library/std/src/net/addr", "library/std/src/net/udp", - "library/std/src/sys_common/mod.rs", - "library/std/src/sys_common/net.rs", - "library/std/src/sys_common/backtrace.rs", "library/std/src/sys_common/remutex.rs", "library/std/src/sync/mutex.rs", "library/std/src/sync/rwlock.rs", - // panic_unwind shims - "library/std/src/panicking.rs", "library/term", // Not sure how to make this crate portable, but test crate needs it. "library/test", // Probably should defer to unstable `std::sys` APIs. - "library/std/src/sync/mpsc", // some tests are only run on non-emscripten // std testing crates, okay for now at least "library/core/tests", "library/alloc/tests/lib.rs", @@ -79,13 +64,6 @@ const EXCEPTION_PATHS: &[&str] = &[ // we must use `#[cfg(windows)]` to conditionally compile the // correct `VaList` structure for windows. "library/core/src/ffi.rs", - // non-std crates - "src/test", - "src/tools", - "src/librustc", - "src/librustdoc", - "src/librustc_ast", - "src/bootstrap", ]; pub fn check(path: &Path, bad: &mut bool) { From 1df9d498e19088c6bdd838b22cfd64397e42c43f Mon Sep 17 00:00:00 2001 From: The8472 Date: Mon, 5 Apr 2021 12:15:52 +0200 Subject: [PATCH 3/5] don't try to visit probe file this file is only created for a brief moment during the bins checks in the source directories while other checks may also be visiting that directory. skip processing it to avoid missing file errors --- src/tools/tidy/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index cbcc01dc39a68..fcb27dae9ea90 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -53,6 +53,7 @@ pub mod unstable_book; fn filter_dirs(path: &Path) -> bool { let skip = [ + "tidy-test-file", "compiler/rustc_codegen_cranelift", "src/llvm-project", "library/backtrace", From b1bcff0731f5ce5f9c2de2779b36f94b44946bc6 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 4 Apr 2021 17:44:46 +0100 Subject: [PATCH 4/5] Disallow the use of high byte registes as operands on x86_64 They are still allowed on x86 though. Fixes #83495 --- compiler/rustc_target/src/asm/arm.rs | 2 -- compiler/rustc_target/src/asm/mod.rs | 4 ++-- compiler/rustc_target/src/asm/riscv.rs | 1 - compiler/rustc_target/src/asm/x86.rs | 7 +------ .../unstable-book/src/library-features/asm.md | 4 ++-- src/test/assembly/asm/x86-types.rs | 9 +++++---- src/test/ui/asm/bad-reg.rs | 2 ++ src/test/ui/asm/bad-reg.stderr | 20 ++++++++++++------- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_target/src/asm/arm.rs b/compiler/rustc_target/src/asm/arm.rs index 28000916e0c30..a7a708fe7dec3 100644 --- a/compiler/rustc_target/src/asm/arm.rs +++ b/compiler/rustc_target/src/asm/arm.rs @@ -68,7 +68,6 @@ fn frame_pointer_r11( _arch: InlineAsmArch, has_feature: impl FnMut(&str) -> bool, target: &Target, - _allocating: bool, ) -> Result<(), &'static str> { if !frame_pointer_is_r7(has_feature, target) { Err("the frame pointer (r11) cannot be used as an operand for inline asm") @@ -81,7 +80,6 @@ fn frame_pointer_r7( _arch: InlineAsmArch, has_feature: impl FnMut(&str) -> bool, target: &Target, - _allocating: bool, ) -> Result<(), &'static str> { if frame_pointer_is_r7(has_feature, target) { Err("the frame pointer (r7) cannot be used as an operand for inline asm") diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index a09c87b3ec2b2..e2268a61a4257 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -90,7 +90,7 @@ macro_rules! def_regs { match name { $( $($alias)|* | $reg_name => { - $($filter(_arch, &mut _has_feature, _target, false)?;)? + $($filter(_arch, &mut _has_feature, _target)?;)? Ok(Self::$reg) } )* @@ -114,7 +114,7 @@ macro_rules! def_regs { #[allow(unused_imports)] use super::{InlineAsmReg, InlineAsmRegClass}; $( - if $($filter(_arch, &mut _has_feature, _target, true).is_ok() &&)? true { + if $($filter(_arch, &mut _has_feature, _target).is_ok() &&)? true { if let Some(set) = _map.get_mut(&InlineAsmRegClass::$arch($arch_regclass::$class)) { set.insert(InlineAsmReg::$arch($arch_reg::$reg)); } diff --git a/compiler/rustc_target/src/asm/riscv.rs b/compiler/rustc_target/src/asm/riscv.rs index ced7483b00571..185d6ac8246c9 100644 --- a/compiler/rustc_target/src/asm/riscv.rs +++ b/compiler/rustc_target/src/asm/riscv.rs @@ -52,7 +52,6 @@ fn not_e( _arch: InlineAsmArch, mut has_feature: impl FnMut(&str) -> bool, _target: &Target, - _allocating: bool, ) -> Result<(), &'static str> { if has_feature("e") { Err("register can't be used with the `e` target feature") diff --git a/compiler/rustc_target/src/asm/x86.rs b/compiler/rustc_target/src/asm/x86.rs index 0f62c19e1a3cd..90660dad4c2a1 100644 --- a/compiler/rustc_target/src/asm/x86.rs +++ b/compiler/rustc_target/src/asm/x86.rs @@ -133,7 +133,6 @@ fn x86_64_only( arch: InlineAsmArch, _has_feature: impl FnMut(&str) -> bool, _target: &Target, - _allocating: bool, ) -> Result<(), &'static str> { match arch { InlineAsmArch::X86 => Err("register is only available on x86_64"), @@ -146,13 +145,9 @@ fn high_byte( arch: InlineAsmArch, _has_feature: impl FnMut(&str) -> bool, _target: &Target, - allocating: bool, ) -> Result<(), &'static str> { match arch { - InlineAsmArch::X86_64 if allocating => { - // The error message isn't actually used... - Err("high byte registers are not allocated by reg_byte") - } + InlineAsmArch::X86_64 => Err("high byte registers cannot be used as an operand on x86_64"), _ => Ok(()), } } diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index c0e23b834d150..6c61f4f0d20f1 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -495,7 +495,7 @@ Here is the list of currently supported register classes: | x86 | `reg` | `ax`, `bx`, `cx`, `dx`, `si`, `di`, `r[8-15]` (x86-64 only) | `r` | | x86 | `reg_abcd` | `ax`, `bx`, `cx`, `dx` | `Q` | | x86-32 | `reg_byte` | `al`, `bl`, `cl`, `dl`, `ah`, `bh`, `ch`, `dh` | `q` | -| x86-64 | `reg_byte` | `al`, `bl`, `cl`, `dl`, `sil`, `dil`, `r[8-15]b`, `ah`\*, `bh`\*, `ch`\*, `dh`\* | `q` | +| x86-64 | `reg_byte`\* | `al`, `bl`, `cl`, `dl`, `sil`, `dil`, `r[8-15]b` | `q` | | x86 | `xmm_reg` | `xmm[0-7]` (x86) `xmm[0-15]` (x86-64) | `x` | | x86 | `ymm_reg` | `ymm[0-7]` (x86) `ymm[0-15]` (x86-64) | `x` | | x86 | `zmm_reg` | `zmm[0-7]` (x86) `zmm[0-31]` (x86-64) | `v` | @@ -526,7 +526,7 @@ Here is the list of currently supported register classes: > **Note**: On x86 we treat `reg_byte` differently from `reg` because the compiler can allocate `al` and `ah` separately whereas `reg` reserves the whole register. > -> Note #2: On x86-64 the high byte registers (e.g. `ah`) are only available when used as an explicit register. Specifying the `reg_byte` register class for an operand will always allocate a low byte register. +> Note #2: On x86-64 the high byte registers (e.g. `ah`) are not available in the `reg_byte` register class. > > Note #3: NVPTX doesn't have a fixed register set, so named registers are not supported. > diff --git a/src/test/assembly/asm/x86-types.rs b/src/test/assembly/asm/x86-types.rs index e0190d3bdaed1..b65b727d2255c 100644 --- a/src/test/assembly/asm/x86-types.rs +++ b/src/test/assembly/asm/x86-types.rs @@ -748,10 +748,11 @@ check_reg!(eax_f64 f64 "eax" "mov"); // CHECK: #NO_APP check_reg!(eax_ptr ptr "eax" "mov"); -// CHECK-LABEL: ah_byte: -// CHECK: #APP -// CHECK: mov ah, ah -// CHECK: #NO_APP +// i686-LABEL: ah_byte: +// i686: #APP +// i686: mov ah, ah +// i686: #NO_APP +#[cfg(i686)] check_reg!(ah_byte i8 "ah" "mov"); // CHECK-LABEL: xmm0_i32: diff --git a/src/test/ui/asm/bad-reg.rs b/src/test/ui/asm/bad-reg.rs index 016ea9329c4d0..da302b248760f 100644 --- a/src/test/ui/asm/bad-reg.rs +++ b/src/test/ui/asm/bad-reg.rs @@ -37,6 +37,8 @@ fn main() { //~^ ERROR invalid register `mm0`: MMX registers are not currently supported as operands asm!("", in("k0") foo); //~^ ERROR invalid register `k0`: the k0 AVX mask register cannot be used as an operand + asm!("", in("ah") foo); + //~^ ERROR invalid register `ah`: high byte registers cannot be used as an operand // Explicit register conflicts // (except in/lateout which don't conflict) diff --git a/src/test/ui/asm/bad-reg.stderr b/src/test/ui/asm/bad-reg.stderr index c6b7d310dfa6c..2bfb4854c3442 100644 --- a/src/test/ui/asm/bad-reg.stderr +++ b/src/test/ui/asm/bad-reg.stderr @@ -94,8 +94,14 @@ error: invalid register `k0`: the k0 AVX mask register cannot be used as an oper LL | asm!("", in("k0") foo); | ^^^^^^^^^^^^ +error: invalid register `ah`: high byte registers cannot be used as an operand on x86_64 + --> $DIR/bad-reg.rs:40:18 + | +LL | asm!("", in("ah") foo); + | ^^^^^^^^^^^^ + error: register `al` conflicts with register `ax` - --> $DIR/bad-reg.rs:44:33 + --> $DIR/bad-reg.rs:46:33 | LL | asm!("", in("eax") foo, in("al") bar); | ------------- ^^^^^^^^^^^^ register `al` @@ -103,7 +109,7 @@ LL | asm!("", in("eax") foo, in("al") bar); | register `ax` error: register `ax` conflicts with register `ax` - --> $DIR/bad-reg.rs:46:33 + --> $DIR/bad-reg.rs:48:33 | LL | asm!("", in("rax") foo, out("rax") bar); | ------------- ^^^^^^^^^^^^^^ register `ax` @@ -111,13 +117,13 @@ LL | asm!("", in("rax") foo, out("rax") bar); | register `ax` | help: use `lateout` instead of `out` to avoid conflict - --> $DIR/bad-reg.rs:46:18 + --> $DIR/bad-reg.rs:48:18 | LL | asm!("", in("rax") foo, out("rax") bar); | ^^^^^^^^^^^^^ error: register `ymm0` conflicts with register `xmm0` - --> $DIR/bad-reg.rs:49:34 + --> $DIR/bad-reg.rs:51:34 | LL | asm!("", in("xmm0") foo, in("ymm0") bar); | -------------- ^^^^^^^^^^^^^^ register `ymm0` @@ -125,7 +131,7 @@ LL | asm!("", in("xmm0") foo, in("ymm0") bar); | register `xmm0` error: register `ymm0` conflicts with register `xmm0` - --> $DIR/bad-reg.rs:51:34 + --> $DIR/bad-reg.rs:53:34 | LL | asm!("", in("xmm0") foo, out("ymm0") bar); | -------------- ^^^^^^^^^^^^^^^ register `ymm0` @@ -133,10 +139,10 @@ LL | asm!("", in("xmm0") foo, out("ymm0") bar); | register `xmm0` | help: use `lateout` instead of `out` to avoid conflict - --> $DIR/bad-reg.rs:51:18 + --> $DIR/bad-reg.rs:53:18 | LL | asm!("", in("xmm0") foo, out("ymm0") bar); | ^^^^^^^^^^^^^^ -error: aborting due to 18 previous errors +error: aborting due to 19 previous errors From 580a740bdd35706e487abd5beb76bd28f2be4012 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 22 Mar 2021 02:31:47 -0400 Subject: [PATCH 5/5] Add `download-rustc = "if-unchanged"` This allows keeping the setting to a fixed value without having to toggle it when you want to work on the compiler instead of on tools. --- config.toml.example | 4 +++- src/bootstrap/bootstrap.py | 8 +++++++- src/bootstrap/config.rs | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config.toml.example b/config.toml.example index ee06e1bd0ba1b..539ff06c5adc9 100644 --- a/config.toml.example +++ b/config.toml.example @@ -372,7 +372,9 @@ changelog-seen = 2 # Whether to download the stage 1 and 2 compilers from CI. # This is mostly useful for tools; if you have changes to `compiler/` they will be ignored. # -# FIXME: currently, this also uses the downloaded compiler for stage0, but that causes unnecessary rebuilds. +# You can set this to "if-unchanged" to only download if `compiler/` has not been modified. +# +# FIXME(#82739): currently, this also uses the downloaded compiler for stage0, but that causes unnecessary rebuilds. #download-rustc = false # Number of codegen units to use for each compiler invocation. A value of 0 diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 3e7d1d54f1284..59f22f3310caa 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -638,8 +638,10 @@ def fix_bin_or_dylib(self, fname, rpath_libz=False): # Return the stage1 compiler to download, if any. def maybe_download_rustc(self): # If `download-rustc` is not set, default to rebuilding. - if self.get_toml("download-rustc", section="rust") != "true": + download_rustc = self.get_toml("download-rustc", section="rust") + if download_rustc is None or download_rustc == "false": return None + assert download_rustc == "true" or download_rustc == "if-unchanged", download_rustc # Handle running from a directory other than the top level rev_parse = ["git", "rev-parse", "--show-toplevel"] @@ -654,6 +656,8 @@ def maybe_download_rustc(self): # Warn if there were changes to the compiler since the ancestor commit. status = subprocess.call(["git", "diff-index", "--quiet", commit, "--", compiler]) if status != 0: + if download_rustc == "if-unchanged": + return None print("warning: `download-rustc` is enabled, but there are changes to compiler/") return commit @@ -1158,6 +1162,8 @@ def bootstrap(help_triggered): env["RUSTC_BOOTSTRAP"] = '1' if toml_path: env["BOOTSTRAP_CONFIG"] = toml_path + if build.rustc_commit is not None: + env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1' run(args, env=env, verbose=build.verbose) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b9b090bb2d2de..43ae146e86661 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -510,7 +510,8 @@ struct Rust { new_symbol_mangling: Option, profile_generate: Option, profile_use: Option, - download_rustc: Option, + // ignored; this is set from an env var set by bootstrap.py + download_rustc: Option, } /// TOML representation of how each build target is configured. @@ -897,7 +898,7 @@ impl Config { config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config); config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use); config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate); - config.download_rustc = rust.download_rustc.unwrap_or(false); + config.download_rustc = env::var("BOOTSTRAP_DOWNLOAD_RUSTC").as_deref() == Ok("1"); } else { config.rust_profile_use = flags.rust_profile_use; config.rust_profile_generate = flags.rust_profile_generate;