Skip to content

Commit

Permalink
Auto merge of #95987 - m-ou-se:rollup-sdevd9b, r=m-ou-se
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #95783 (rustdoc doctest: include signal number in exit status)
 - #95794 (`parse_tt`: a few more tweaks)
 - #95963 ([bootstrap] Grab the right FileCheck binary for dist when cross-compiling.)
 - #95975 (Don't test -Cdefault-linker-libraries=yes when cross compiling.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 12, 2022
2 parents de56c29 + 550a510 commit 52ca603
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 45 deletions.
38 changes: 11 additions & 27 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -221,7 +211,11 @@ 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<NamedMatchVec>,
///
/// 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<Vec<NamedMatch>>,
}

// This type is used a lot. Make sure it doesn't unintentionally get bigger.
Expand All @@ -246,18 +240,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!(),
}
}
Expand Down Expand Up @@ -350,7 +338,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
/// ```
#[derive(Debug, Clone)]
crate enum NamedMatch {
MatchedSeq(Lrc<NamedMatchVec>),
MatchedSeq(Vec<NamedMatch>),

// A metavar match of type `tt`.
MatchedTokenTree(rustc_ast::tokenstream::TokenTree),
Expand Down Expand Up @@ -388,7 +376,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<NamedMatchVec>,
empty_matches: Lrc<Vec<NamedMatch>>,
}

impl TtParser {
Expand All @@ -398,7 +386,7 @@ impl TtParser {
cur_mps: vec![],
next_mps: vec![],
bb_mps: vec![],
empty_matches: Lrc::new(smallvec![]),
empty_matches: Lrc::new(vec![]),
}
}

Expand Down Expand Up @@ -452,11 +440,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 {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 1 addition & 7 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/test/rustdoc-ui/failed-doctest-output-windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// only-windows
// 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
// 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;
39 changes: 39 additions & 0 deletions src/test/rustdoc-ui/failed-doctest-output-windows.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

running 2 tests
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-windows.rs - OtherStruct (line 25) stdout ----
error[E0425]: cannot find value `no` in this scope
--> $DIR/failed-doctest-output-windows.rs:26: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-windows.rs - SomeStruct (line 15) 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-windows.rs:7:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
$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

3 changes: 3 additions & 0 deletions src/test/rustdoc-ui/failed-doctest-output.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/test/rustdoc-ui/failed-doctest-output.stdout
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,8 +16,8 @@ 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).
---- $DIR/failed-doctest-output.rs - SomeStruct (line 15) stdout ----
Test executable failed (exit status: 101).

stdout:
stdout 1
Expand All @@ -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

1 change: 1 addition & 0 deletions src/test/ui/issues/issue-70093.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}
Expand Down

0 comments on commit 52ca603

Please sign in to comment.