Skip to content

Commit 3dba041

Browse files
committed
Don't use parse_cfg_name_directive for normalize directives
This is a little more verbose, but also more explicit, and avoids invoking the full condition engine when only the pointer-width conditions are used.
1 parent d997bc9 commit 3dba041

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/tools/compiletest/src/header.rs

+43-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use tracing::*;
1212
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
1414
use crate::header::auxiliary::{AuxProps, parse_and_update_aux};
15-
use crate::header::cfg::{MatchOutcome, parse_cfg_name_directive};
1615
use crate::header::needs::CachedNeedsConditions;
1716
use crate::util::static_regex;
1817

@@ -472,11 +471,24 @@ impl TestProps {
472471

473472
config.set_name_directive(ln, IGNORE_PASS, &mut self.ignore_pass);
474473

475-
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
476-
self.normalize_stdout.push(rule);
477-
}
478-
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
479-
self.normalize_stderr.push(rule);
474+
if let Some(NormalizeRule { kind, regex, replacement }) =
475+
config.parse_custom_normalization(ln)
476+
{
477+
let rule_tuple = (regex, replacement);
478+
match kind {
479+
NormalizeKind::Stdout => self.normalize_stdout.push(rule_tuple),
480+
NormalizeKind::Stderr => self.normalize_stderr.push(rule_tuple),
481+
NormalizeKind::Stderr32bit => {
482+
if config.target_cfg().pointer_width == 32 {
483+
self.normalize_stderr.push(rule_tuple);
484+
}
485+
}
486+
NormalizeKind::Stderr64bit => {
487+
if config.target_cfg().pointer_width == 64 {
488+
self.normalize_stderr.push(rule_tuple);
489+
}
490+
}
491+
}
480492
}
481493

482494
if let Some(code) = config
@@ -966,20 +978,24 @@ impl Config {
966978
}
967979
}
968980

969-
fn parse_custom_normalization(&self, line: &str, prefix: &str) -> Option<(String, String)> {
970-
let parsed = parse_cfg_name_directive(self, line, prefix);
971-
if parsed.outcome != MatchOutcome::Match {
972-
return None;
973-
}
974-
let name = parsed.name.expect("successful match always has a name");
981+
fn parse_custom_normalization(&self, line: &str) -> Option<NormalizeRule> {
982+
let directive_name = line.split_once(':')?.0;
983+
984+
let kind = match directive_name {
985+
"normalize-stdout-test" => NormalizeKind::Stdout,
986+
"normalize-stderr-test" => NormalizeKind::Stderr,
987+
"normalize-stderr-32bit" => NormalizeKind::Stderr32bit,
988+
"normalize-stderr-64bit" => NormalizeKind::Stderr64bit,
989+
_ => return None,
990+
};
975991

976992
let Some((regex, replacement)) = parse_normalize_rule(line) else {
977993
panic!(
978994
"couldn't parse custom normalization rule: `{line}`\n\
979-
help: expected syntax is: `{prefix}-{name}: \"REGEX\" -> \"REPLACEMENT\"`"
995+
help: expected syntax is: `{directive_name}: \"REGEX\" -> \"REPLACEMENT\"`"
980996
);
981997
};
982-
Some((regex, replacement))
998+
Some(NormalizeRule { kind, regex, replacement })
983999
}
9841000

9851001
fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
@@ -1105,6 +1121,19 @@ fn expand_variables(mut value: String, config: &Config) -> String {
11051121
value
11061122
}
11071123

1124+
struct NormalizeRule {
1125+
kind: NormalizeKind,
1126+
regex: String,
1127+
replacement: String,
1128+
}
1129+
1130+
enum NormalizeKind {
1131+
Stdout,
1132+
Stderr,
1133+
Stderr32bit,
1134+
Stderr64bit,
1135+
}
1136+
11081137
/// Parses the regex and replacement values of a `//@ normalize-*` header,
11091138
/// in the format:
11101139
/// ```text

src/tools/compiletest/src/header/cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub(super) fn handle_only(config: &Config, line: &str) -> IgnoreDecision {
4040
}
4141

4242
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
43-
/// or `normalize-stderr-32bit`.
44-
pub(super) fn parse_cfg_name_directive<'a>(
43+
/// or `only-windows`.
44+
fn parse_cfg_name_directive<'a>(
4545
config: &Config,
4646
line: &'a str,
4747
prefix: &str,

0 commit comments

Comments
 (0)