From 813b93efb0bdcb38ec6a90b74e21af43b77179a5 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 7 Apr 2022 11:16:13 -0700 Subject: [PATCH 01/10] rustdoc doctest: include signal number in exit status Related to #95601 --- src/librustdoc/doctest.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 50ae22b99cdf8..eabe0803b4993 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1069,13 +1069,7 @@ impl Tester for Collector { } } TestFailure::ExecutionFailure(out) => { - let reason = if let Some(code) = out.status.code() { - format!("exit code {code}") - } else { - String::from("terminated by signal") - }; - - eprintln!("Test executable failed ({reason})."); + eprintln!("Test executable failed ({reason}).", reason = out.status); // FIXME(#12309): An unfortunate side-effect of capturing the test // executable's output is that the relative ordering between the test's From 898ff01ff9e10fdb3f88cd79efed44b9dbcf5ad1 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 7 Apr 2022 14:25:16 -0700 Subject: [PATCH 02/10] Fix test case --- src/test/rustdoc-ui/failed-doctest-output.stdout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index 6dfe648f8549e..62775b46d47fa 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -17,7 +17,7 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. Couldn't compile the test. ---- $DIR/failed-doctest-output.rs - SomeStruct (line 12) stdout ---- -Test executable failed (exit code 101). +Test executable failed (exit status: 101). stdout: stdout 1 From 482b25b321d06ee2b9e438e458ed41b691553736 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 8 Apr 2022 13:10:52 +1000 Subject: [PATCH 03/10] Change internal naming of macros. When a `macro_rules! foo { ... }` invocation is compiled the name used is `foo`, not `macro_rules!`. This is different to all other macro invocations, and confused me when I was inserted debugging println statements for macro evaluation. This commit changes it to `macro_rules` (or just `macro`), which is what I expected. There are no externally visible changes. --- compiler/rustc_expand/src/mbe/macro_rules.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 31dae6a2fb437..f5c7186bc4b18 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -439,7 +439,8 @@ pub fn compile_declarative_macro( let argument_gram = mbe::macro_parser::compute_locs(&sess.parse_sess, &argument_gram); let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS); - let mut tt_parser = TtParser::new(def.ident); + let mut tt_parser = + TtParser::new(Ident::with_dummy_span(if macro_rules { kw::MacroRules } else { kw::Macro })); let argument_map = match tt_parser.parse_tt(&mut Cow::Borrowed(&parser), &argument_gram) { Success(m) => m, Failure(token, msg) => { From 4ba609601f1a99ddf3cf0cf70f57c4a045f0f23f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 8 Apr 2022 14:16:44 +1000 Subject: [PATCH 04/10] Tweak `NamedMatch` representation. The `Lrc` isn't necessary, neither is the `SmallVec`. Performance is changed negligibly, but the new code is simpler. --- compiler/rustc_expand/src/mbe/macro_parser.rs | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index ce243b4a67272..d26f80e82fcfe 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -81,22 +81,12 @@ use rustc_session::parse::ParseSess; use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; -use smallvec::{smallvec, SmallVec}; - use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use rustc_span::symbol::Ident; use std::borrow::Cow; use std::collections::hash_map::Entry::{Occupied, Vacant}; -// One element is enough to cover 95-99% of vectors for most benchmarks. Also, vectors longer than -// one frequently have many elements, not just two or three. -type NamedMatchVec = SmallVec<[NamedMatch; 1]>; - -// This type is used a lot. Make sure it doesn't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(NamedMatchVec, 48); - /// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from) /// `mbe::TokenTree`, but designed specifically for fast and easy traversal during matching. /// Notable differences to `mbe::TokenTree`: @@ -221,7 +211,7 @@ struct MatcherPos { /// with one element per metavar decl in the matcher. Each element records token trees matched /// against the relevant metavar by the black box parser. An element will be a `MatchedSeq` if /// the corresponding metavar decl is within a sequence. - matches: Lrc, + matches: Lrc>, } // This type is used a lot. Make sure it doesn't unintentionally get bigger. @@ -246,18 +236,12 @@ impl MatcherPos { let mut curr = &mut matches[metavar_idx]; for _ in 0..seq_depth - 1 { match curr { - MatchedSeq(seq) => { - let seq = Lrc::make_mut(seq); - curr = seq.last_mut().unwrap(); - } + MatchedSeq(seq) => curr = seq.last_mut().unwrap(), _ => unreachable!(), } } match curr { - MatchedSeq(seq) => { - let seq = Lrc::make_mut(seq); - seq.push(m); - } + MatchedSeq(seq) => seq.push(m), _ => unreachable!(), } } @@ -350,7 +334,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize { /// ``` #[derive(Debug, Clone)] crate enum NamedMatch { - MatchedSeq(Lrc), + MatchedSeq(Vec), // A metavar match of type `tt`. MatchedTokenTree(rustc_ast::tokenstream::TokenTree), @@ -388,7 +372,7 @@ pub struct TtParser { /// Pre-allocate an empty match array, so it can be cloned cheaply for macros with many rules /// that have no metavars. - empty_matches: Lrc, + empty_matches: Lrc>, } impl TtParser { @@ -398,7 +382,7 @@ impl TtParser { cur_mps: vec![], next_mps: vec![], bb_mps: vec![], - empty_matches: Lrc::new(smallvec![]), + empty_matches: Lrc::new(vec![]), } } @@ -452,11 +436,7 @@ impl TtParser { } => { // Install an empty vec for each metavar within the sequence. for metavar_idx in next_metavar..next_metavar + num_metavar_decls { - mp.push_match( - metavar_idx, - seq_depth, - MatchedSeq(self.empty_matches.clone()), - ); + mp.push_match(metavar_idx, seq_depth, MatchedSeq(vec![])); } if op == KleeneOp::ZeroOrMore || op == KleeneOp::ZeroOrOne { From edd7f2cdab424ff8ed64a84f784a5c1273bcb138 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 8 Apr 2022 14:25:37 +1000 Subject: [PATCH 05/10] Add a useful comment. --- compiler/rustc_expand/src/mbe/macro_parser.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index d26f80e82fcfe..b5f56d7d6dc84 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -211,6 +211,10 @@ struct MatcherPos { /// with one element per metavar decl in the matcher. Each element records token trees matched /// against the relevant metavar by the black box parser. An element will be a `MatchedSeq` if /// the corresponding metavar decl is within a sequence. + /// + /// It is critical to performance that this is an `Lrc`, because it gets cloned frequently when + /// processing sequences. Mostly for sequence-ending possibilities that must be tried but end + /// up failing. matches: Lrc>, } From dae1df68b0d4a0ea9a4b3a2d5e579ad2835605c8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 10 Apr 2022 17:46:30 -0700 Subject: [PATCH 06/10] Fix test case for windows --- .../failed-doctest-output-windows.rs | 28 +++++++++++++ .../failed-doctest-output-windows.stdout | 39 +++++++++++++++++++ src/test/rustdoc-ui/failed-doctest-output.rs | 3 ++ 3 files changed, 70 insertions(+) create mode 100644 src/test/rustdoc-ui/failed-doctest-output-windows.rs create mode 100644 src/test/rustdoc-ui/failed-doctest-output-windows.stdout diff --git a/src/test/rustdoc-ui/failed-doctest-output-windows.rs b/src/test/rustdoc-ui/failed-doctest-output-windows.rs new file mode 100644 index 0000000000000..906e4f3c5cb6b --- /dev/null +++ b/src/test/rustdoc-ui/failed-doctest-output-windows.rs @@ -0,0 +1,28 @@ +// only-windows +// There's a parallel generic version of this test for POSIXy platforms. + +// Issue #51162: A failed doctest was not printing its stdout/stderr +// FIXME: if/when the output of the test harness can be tested on its own, this test should be +// adapted to use that, and that normalize line can go away + +// compile-flags:--test --test-args --test-threads=1 +// rustc-env:RUST_BACKTRACE=0 +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" +// failure-status: 101 + +// doctest fails at runtime +/// ``` +/// println!("stdout 1"); +/// eprintln!("stderr 1"); +/// println!("stdout 2"); +/// eprintln!("stderr 2"); +/// panic!("oh no"); +/// ``` +pub struct SomeStruct; + +// doctest fails at compile time +/// ``` +/// no +/// ``` +pub struct OtherStruct; diff --git a/src/test/rustdoc-ui/failed-doctest-output-windows.stdout b/src/test/rustdoc-ui/failed-doctest-output-windows.stdout new file mode 100644 index 0000000000000..e67ee8ea27d94 --- /dev/null +++ b/src/test/rustdoc-ui/failed-doctest-output-windows.stdout @@ -0,0 +1,39 @@ + +running 2 tests +test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED +test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED + +failures: + +---- $DIR/failed-doctest-output.rs - OtherStruct (line 22) stdout ---- +error[E0425]: cannot find value `no` in this scope + --> $DIR/failed-doctest-output.rs:23:1 + | +LL | no + | ^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. +Couldn't compile the test. +---- $DIR/failed-doctest-output.rs - SomeStruct (line 12) stdout ---- +Test executable failed (exit code: 101). + +stdout: +stdout 1 +stdout 2 + +stderr: +stderr 1 +stderr 2 +thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:7:1 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + + + +failures: + $DIR/failed-doctest-output.rs - OtherStruct (line 22) + $DIR/failed-doctest-output.rs - SomeStruct (line 12) + +test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/src/test/rustdoc-ui/failed-doctest-output.rs b/src/test/rustdoc-ui/failed-doctest-output.rs index 92473b49e1483..42de954d052b3 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.rs +++ b/src/test/rustdoc-ui/failed-doctest-output.rs @@ -1,3 +1,6 @@ +// ignore-windows +// There's a parallel version of this test for Windows. + // Issue #51162: A failed doctest was not printing its stdout/stderr // FIXME: if/when the output of the test harness can be tested on its own, this test should be // adapted to use that, and that normalize line can go away From daa903c46274cc608472b7ec1912e4feca88169c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 11 Apr 2022 09:26:05 -0700 Subject: [PATCH 07/10] Fix line numbers --- .../failed-doctest-output-windows.stdout | 16 ++++++++-------- src/test/rustdoc-ui/failed-doctest-output.stdout | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/test/rustdoc-ui/failed-doctest-output-windows.stdout b/src/test/rustdoc-ui/failed-doctest-output-windows.stdout index e67ee8ea27d94..6c147054da322 100644 --- a/src/test/rustdoc-ui/failed-doctest-output-windows.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output-windows.stdout @@ -1,13 +1,13 @@ running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED +test $DIR/failed-doctest-output-windows.rs - OtherStruct (line 25) ... FAILED +test $DIR/failed-doctest-output-windows.rs - SomeStruct (line 15) ... FAILED failures: ----- $DIR/failed-doctest-output.rs - OtherStruct (line 22) stdout ---- +---- $DIR/failed-doctest-output-windows.rs - OtherStruct (line 25) stdout ---- error[E0425]: cannot find value `no` in this scope - --> $DIR/failed-doctest-output.rs:23:1 + --> $DIR/failed-doctest-output-windows.rs:26:1 | LL | no | ^^ not found in this scope @@ -16,7 +16,7 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. Couldn't compile the test. ----- $DIR/failed-doctest-output.rs - SomeStruct (line 12) stdout ---- +---- $DIR/failed-doctest-output-windows.rs - SomeStruct (line 15) stdout ---- Test executable failed (exit code: 101). stdout: @@ -26,14 +26,14 @@ stdout 2 stderr: stderr 1 stderr 2 -thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:7:1 +thread 'main' panicked at 'oh no', $DIR/failed-doctest-output-windows.rs:7:1 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: - $DIR/failed-doctest-output.rs - OtherStruct (line 22) - $DIR/failed-doctest-output.rs - SomeStruct (line 12) + $DIR/failed-doctest-output-windows.rs - OtherStruct (line 25) + $DIR/failed-doctest-output-windows.rs - SomeStruct (line 15) test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index 62775b46d47fa..630198a561af0 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -1,13 +1,13 @@ running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED +test $DIR/failed-doctest-output.rs - OtherStruct (line 25) ... FAILED +test $DIR/failed-doctest-output.rs - SomeStruct (line 15) ... FAILED failures: ----- $DIR/failed-doctest-output.rs - OtherStruct (line 22) stdout ---- +---- $DIR/failed-doctest-output.rs - OtherStruct (line 25) stdout ---- error[E0425]: cannot find value `no` in this scope - --> $DIR/failed-doctest-output.rs:23:1 + --> $DIR/failed-doctest-output.rs:26:1 | LL | no | ^^ not found in this scope @@ -16,7 +16,7 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. Couldn't compile the test. ----- $DIR/failed-doctest-output.rs - SomeStruct (line 12) stdout ---- +---- $DIR/failed-doctest-output.rs - SomeStruct (line 15) stdout ---- Test executable failed (exit status: 101). stdout: @@ -32,8 +32,8 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: - $DIR/failed-doctest-output.rs - OtherStruct (line 22) - $DIR/failed-doctest-output.rs - SomeStruct (line 12) + $DIR/failed-doctest-output.rs - OtherStruct (line 25) + $DIR/failed-doctest-output.rs - SomeStruct (line 15) test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME From 03bcbbf9280efa27f6cc558b82edff5042b9b584 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Mon, 11 Apr 2022 21:31:42 -0400 Subject: [PATCH 08/10] [bootstrap] Grab the right FileCheck binary for dist when cross-compiling. --- src/bootstrap/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index e4937d7bbccbd..7b496e6c66933 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -865,8 +865,8 @@ impl Build { } } } else { - let base = self.llvm_out(self.config.build).join("build"); - let base = if !self.ninja() && self.config.build.contains("msvc") { + let base = self.llvm_out(target).join("build"); + let base = if !self.ninja() && target.contains("msvc") { if self.config.llvm_optimize { if self.config.llvm_release_debuginfo { base.join("RelWithDebInfo") From 284255add5477af2da9fb53fe60d50fa42c77d32 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 12 Apr 2022 15:00:44 +0200 Subject: [PATCH 09/10] Don't test -Cdefault-linker-libraries=yes when cross compiling. --- src/test/ui/issues/issue-70093.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/issues/issue-70093.rs b/src/test/ui/issues/issue-70093.rs index fbe68fb9379f8..86459dc904a6e 100644 --- a/src/test/ui/issues/issue-70093.rs +++ b/src/test/ui/issues/issue-70093.rs @@ -2,6 +2,7 @@ // compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes // ignore-windows - this will probably only work on unixish systems // ignore-fuchsia - missing __libc_start_main for some reason (#84733) +// ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling #[link(name = "some-random-non-existent-library", kind = "static")] extern "C" {} From 2af843c57da651bd2ce3a8e1e8208deadf08444e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 12 Apr 2022 06:37:00 -0700 Subject: [PATCH 10/10] Update src/test/rustdoc-ui/failed-doctest-output-windows.rs Co-authored-by: Guillaume Gomez --- src/test/rustdoc-ui/failed-doctest-output-windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-ui/failed-doctest-output-windows.rs b/src/test/rustdoc-ui/failed-doctest-output-windows.rs index 906e4f3c5cb6b..4cd9993d8d5b3 100644 --- a/src/test/rustdoc-ui/failed-doctest-output-windows.rs +++ b/src/test/rustdoc-ui/failed-doctest-output-windows.rs @@ -1,5 +1,5 @@ // only-windows -// There's a parallel generic version of this test for POSIXy platforms. +// There's a parallel generic version of this test for non-windows platforms. // Issue #51162: A failed doctest was not printing its stdout/stderr // FIXME: if/when the output of the test harness can be tested on its own, this test should be