Skip to content

Commit f664196

Browse files
committed
Auto merge of rust-lang#2253 - RalfJung:only-bits, r=oli-obk
fix behavior of only-Nbits comments Fixes rust-lang/miri#2206
2 parents 5e584d2 + 7308f8f commit f664196

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

ui_test/src/comments.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub(crate) struct Comments {
1515
/// List of revision names to execute. Can only be speicified once
1616
pub revisions: Option<Vec<String>>,
1717
/// Don't run this test if any of these filters apply
18-
pub ignore: Vec<String>,
18+
pub ignore: Vec<Condition>,
1919
/// Only run this test if all of these filters apply
20-
pub only: Vec<String>,
20+
pub only: Vec<Condition>,
2121
/// Generate one .stderr file per bit width, by prepending with `.64bit` and similar
2222
pub stderr_per_bitwidth: bool,
2323
/// Additional flags to pass to the executable
@@ -31,6 +31,16 @@ pub(crate) struct Comments {
3131
pub error_matches: Vec<ErrorMatch>,
3232
}
3333

34+
35+
/// The conditions used for "ignore" and "only" filters.
36+
#[derive(Debug)]
37+
pub(crate) enum Condition {
38+
/// The given string must appear in the target.
39+
Target(String),
40+
/// Tests that the bitwidth is the given one.
41+
Bitwidth(u8),
42+
}
43+
3444
#[derive(Debug)]
3545
pub(crate) struct ErrorMatch {
3646
pub matched: String,
@@ -42,6 +52,17 @@ pub(crate) struct ErrorMatch {
4252
pub line: usize,
4353
}
4454

55+
impl Condition {
56+
fn parse(c: &str) -> Self {
57+
if let Some(bits) = c.strip_suffix("bit") {
58+
let bits: u8 = bits.parse().expect("ignore/only filter ending in 'bit' must be of the form 'Nbit' for some integer N");
59+
Condition::Bitwidth(bits)
60+
} else {
61+
Condition::Target(c.to_owned())
62+
}
63+
}
64+
}
65+
4566
impl Comments {
4667
pub(crate) fn parse_file(path: &Path) -> Self {
4768
let content = std::fs::read_to_string(path).unwrap();
@@ -75,14 +96,14 @@ impl Comments {
7596
.split_once(|c: char| c == ':' || c.is_whitespace())
7697
.map(|(s, _)| s)
7798
.unwrap_or(s);
78-
this.ignore.push(s.to_owned());
99+
this.ignore.push(Condition::parse(s));
79100
}
80101
if let Some(s) = line.strip_prefix("// only-") {
81102
let s = s
82103
.split_once(|c: char| c == ':' || c.is_whitespace())
83104
.map(|(s, _)| s)
84105
.unwrap_or(s);
85-
this.only.push(s.to_owned());
106+
this.only.push(Condition::parse(s));
86107
}
87108
if line.starts_with("// stderr-per-bitwidth") {
88109
assert!(

ui_test/src/lib.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use comments::ErrorMatch;
1010
use regex::Regex;
1111
use rustc_stderr::{Level, Message};
1212

13-
use crate::comments::Comments;
13+
use crate::comments::{Comments, Condition};
1414

1515
mod comments;
1616
mod rustc_stderr;
@@ -103,7 +103,7 @@ pub fn run_tests(config: Config) {
103103
}
104104
let comments = Comments::parse_file(&path);
105105
// Ignore file if only/ignore rules do (not) apply
106-
if ignore_file(&comments, &target) {
106+
if !test_file_conditions(&comments, &target) {
107107
ignored.fetch_add(1, Ordering::Relaxed);
108108
eprintln!(
109109
"{} ... {}",
@@ -509,42 +509,36 @@ fn check_output(
509509

510510
fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) -> PathBuf {
511511
if comments.stderr_per_bitwidth {
512-
return path.with_extension(format!("{}.{kind}", get_pointer_width(target)));
512+
return path.with_extension(format!("{}bit.{kind}", get_pointer_width(target)));
513513
}
514514
path.with_extension(kind)
515515
}
516516

517-
fn ignore_file(comments: &Comments, target: &str) -> bool {
518-
for s in &comments.ignore {
519-
if target.contains(s) {
520-
return true;
521-
}
522-
if get_pointer_width(target) == s {
523-
return true;
524-
}
517+
fn test_condition(condition: &Condition, target: &str) -> bool {
518+
match condition {
519+
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
520+
Condition::Target(t) => target.contains(t),
525521
}
526-
for s in &comments.only {
527-
if !target.contains(s) {
528-
return true;
529-
}
530-
/* FIXME(https://github.com/rust-lang/miri/issues/2206)
531-
if get_pointer_width(target) != s {
532-
return true;
533-
} */
522+
}
523+
524+
/// Returns whether according to the in-file conditions, this file should be run.
525+
fn test_file_conditions(comments: &Comments, target: &str) -> bool {
526+
if comments.ignore.iter().any(|c| test_condition(c, target)) {
527+
return false;
534528
}
535-
false
529+
comments.only.iter().all(|c| test_condition(c, target))
536530
}
537531

538532
// Taken 1:1 from compiletest-rs
539-
fn get_pointer_width(triple: &str) -> &'static str {
533+
fn get_pointer_width(triple: &str) -> u8 {
540534
if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
541535
|| triple.starts_with("s390x")
542536
{
543-
"64bit"
537+
64
544538
} else if triple.starts_with("avr") {
545-
"16bit"
539+
16
546540
} else {
547-
"32bit"
541+
32
548542
}
549543
}
550544

0 commit comments

Comments
 (0)