Rollup merge of #131392 - jieyouxu:remove-legacy-directive-check, r=Urgau

Drop compiletest legacy directive check

Sufficient time has passed (> 6 months) since we migrated from `//` to `//`@`,` so let's drop the
legacy directive check as it causes friction due to false positives.

As a side-effect, dropping the legacy directive check simplifies the directive scanning logic.

The legacy directive check was originally added to help people be aware of the migration.

Blocker for #131382 cc `@ehuss.`

Can be reviewed by any compiler/bootstrap reviewer.
This commit is contained in:
Matthias Krüger 2024-10-08 16:05:36 +02:00 committed by GitHub
commit 46f821a016
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 97 deletions

View file

@ -5,9 +5,7 @@ use std::io::BufReader;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::sync::OnceLock;
use regex::Regex;
use tracing::*; use tracing::*;
use crate::common::{Config, Debugger, FailMode, Mode, PassMode}; use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
@ -797,7 +795,6 @@ struct HeaderLine<'ln> {
pub(crate) struct CheckDirectiveResult<'ln> { pub(crate) struct CheckDirectiveResult<'ln> {
is_known_directive: bool, is_known_directive: bool,
directive_name: &'ln str,
trailing_directive: Option<&'ln str>, trailing_directive: Option<&'ln str>,
} }
@ -832,11 +829,7 @@ pub(crate) fn check_directive<'a>(
} }
.then_some(trailing); .then_some(trailing);
CheckDirectiveResult { CheckDirectiveResult { is_known_directive: is_known(&directive_name), trailing_directive }
is_known_directive: is_known(&directive_name),
directive_name: directive_ln,
trailing_directive,
}
} }
fn iter_header( fn iter_header(
@ -851,16 +844,17 @@ fn iter_header(
return; return;
} }
// Coverage tests in coverage-run mode always have these extra directives, // Coverage tests in coverage-run mode always have these extra directives, without needing to
// without needing to specify them manually in every test file. // specify them manually in every test file. (Some of the comments below have been copied over
// (Some of the comments below have been copied over from the old // from the old `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
// `tests/run-make/coverage-reports/Makefile`, which no longer exists.) //
// FIXME(jieyouxu): I feel like there's a better way to do this, leaving for later.
if mode == Mode::CoverageRun { if mode == Mode::CoverageRun {
let extra_directives: &[&str] = &[ let extra_directives: &[&str] = &[
"needs-profiler-support", "needs-profiler-support",
// FIXME(pietroalbini): this test currently does not work on cross-compiled // FIXME(pietroalbini): this test currently does not work on cross-compiled targets
// targets because remote-test is not capable of sending back the *.profraw // because remote-test is not capable of sending back the *.profraw files generated by
// files generated by the LLVM instrumentation. // the LLVM instrumentation.
"ignore-cross-compile", "ignore-cross-compile",
]; ];
// Process the extra implied directives, with a dummy line number of 0. // Process the extra implied directives, with a dummy line number of 0.
@ -869,17 +863,13 @@ fn iter_header(
} }
} }
// NOTE(jieyouxu): once we get rid of `Makefile`s we can unconditionally check for `//@`.
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" }; let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" };
let mut rdr = BufReader::with_capacity(1024, rdr); let mut rdr = BufReader::with_capacity(1024, rdr);
let mut ln = String::new(); let mut ln = String::new();
let mut line_number = 0; let mut line_number = 0;
// Match on error annotations like `//~ERROR`.
static REVISION_MAGIC_COMMENT_RE: OnceLock<Regex> = OnceLock::new();
let revision_magic_comment_re =
REVISION_MAGIC_COMMENT_RE.get_or_init(|| Regex::new("//(\\[.*\\])?~.*").unwrap());
loop { loop {
line_number += 1; line_number += 1;
ln.clear(); ln.clear();
@ -892,85 +882,62 @@ fn iter_header(
// with a warm page cache. Maybe with a cold one. // with a warm page cache. Maybe with a cold one.
let original_line = &ln; let original_line = &ln;
let ln = ln.trim(); let ln = ln.trim();
// Assume that any directives will be found before the first module or function. This
// doesn't seem to be an optimization with a warm page cache. Maybe with a cold one.
// FIXME(jieyouxu): this will cause `//@` directives in the rest of the test file to
// not be checked.
if ln.starts_with("fn") || ln.starts_with("mod") { if ln.starts_with("fn") || ln.starts_with("mod") {
return; return;
}
// First try to accept `ui_test` style comments (`//@`) let Some((header_revision, non_revisioned_directive_line)) = line_directive(comment, ln)
} else if let Some((header_revision, non_revisioned_directive_line)) = else {
line_directive(comment, ln) continue;
{ };
// Perform unknown directive check on Rust files.
if testfile.extension().map(|e| e == "rs").unwrap_or(false) {
let directive_ln = non_revisioned_directive_line.trim();
let CheckDirectiveResult { is_known_directive, trailing_directive, .. } = // Perform unknown directive check on Rust files.
check_directive(directive_ln, mode, ln); if testfile.extension().map(|e| e == "rs").unwrap_or(false) {
let directive_ln = non_revisioned_directive_line.trim();
if !is_known_directive { let CheckDirectiveResult { is_known_directive, trailing_directive } =
*poisoned = true; check_directive(directive_ln, mode, ln);
eprintln!( if !is_known_directive {
"error: detected unknown compiletest test directive `{}` in {}:{}",
directive_ln,
testfile.display(),
line_number,
);
return;
}
if let Some(trailing_directive) = &trailing_directive {
*poisoned = true;
eprintln!(
"error: detected trailing compiletest test directive `{}` in {}:{}\n \
help: put the trailing directive in it's own line: `//@ {}`",
trailing_directive,
testfile.display(),
line_number,
trailing_directive,
);
return;
}
}
it(HeaderLine {
line_number,
original_line,
header_revision,
directive: non_revisioned_directive_line,
});
// Then we try to check for legacy-style candidates, which are not the magic ~ERROR family
// error annotations.
} else if !revision_magic_comment_re.is_match(ln) {
let Some((_, rest)) = line_directive("//", ln) else {
continue;
};
if rest.trim_start().starts_with(':') {
// This is likely a markdown link:
// `[link_name]: https://example.org`
continue;
}
let rest = rest.trim_start();
let CheckDirectiveResult { is_known_directive, directive_name, .. } =
check_directive(rest, mode, ln);
if is_known_directive {
*poisoned = true; *poisoned = true;
eprintln!( eprintln!(
"error: detected legacy-style directive {} in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead: {:#?}", "error: detected unknown compiletest test directive `{}` in {}:{}",
directive_name, directive_ln,
testfile.display(), testfile.display(),
line_number, line_number,
line_directive("//", ln),
); );
return;
}
if let Some(trailing_directive) = &trailing_directive {
*poisoned = true;
eprintln!(
"error: detected trailing compiletest test directive `{}` in {}:{}\n \
help: put the trailing directive in it's own line: `//@ {}`",
trailing_directive,
testfile.display(),
line_number,
trailing_directive,
);
return; return;
} }
} }
it(HeaderLine {
line_number,
original_line,
header_revision,
directive: non_revisioned_directive_line,
});
} }
} }

View file

@ -618,17 +618,6 @@ fn test_unknown_directive_check() {
assert!(poisoned); assert!(poisoned);
} }
#[test]
fn test_known_legacy_directive_check() {
let mut poisoned = false;
run_path(
&mut poisoned,
Path::new("a.rs"),
include_bytes!("./test-auxillary/known_legacy_directive.rs"),
);
assert!(poisoned);
}
#[test] #[test]
fn test_known_directive_check_no_error() { fn test_known_directive_check_no_error() {
let mut poisoned = false; let mut poisoned = false;