Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize alloc-id in tests. #116767

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ dependencies = [
"getopts",
"glob",
"home",
"indexmap 2.0.0",
"lazycell",
"libc",
"miow",
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ colored = "2"
diff = "0.1.10"
unified-diff = "0.2.1"
getopts = "0.2"
indexmap = "2.0.0"
miropt-test-tools = { path = "../miropt-test-tools" }
build_helper = { path = "../build_helper" }
tracing = "0.1"
Expand Down
31 changes: 31 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,37 @@ impl<'test> TestCx<'test> {
V0_BACK_REF_RE.replace_all(&normalized, V0_BACK_REF_PLACEHOLDER).into_owned();
}

// AllocId are numbered globally in a compilation session. This can lead to changes
// depending on the exact compilation flags and host architecture. Meanwhile, we want
// to keep them numbered, to see if the same id appears multiple times.
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +4262 to +4263
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// depending on the exact compilation flags and host architecture. Meanwhile, we want
// to keep them numbered, to see if the same id appears multiple times.
// depending on the exact compilation flags and host architecture. We want
// to normalize those differences away. Meanwhile, we want to keep
// the allocations numbered, to see if the same id appears multiple times.
// So we remap to deterministic numbers that only depend on the subset
// of allocations that actually appears in the output.

{
use std::fmt::Write;

let re = Regex::new(r"(╾a|─a|\balloc)([0-9]+)\b(─|\+0x[0-9]+─)?").unwrap();
let mut seen_allocs = indexmap::IndexSet::new();
normalized = re
.replace_all(&normalized, |caps: &Captures<'_>| {
// Use uppercase to distinguish with the non-normalized version.
let mut ret = caps.get(1).unwrap().as_str().to_uppercase();
// Renumber the captured index.
let index = caps.get(2).unwrap().as_str().to_string();
let (index, _) = seen_allocs.insert_full(index);
write!(&mut ret, "{index}").unwrap();
// If we have a tail finishing with `─`, this means pretty-printing.
Copy link
Member

@RalfJung RalfJung Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be 0 but then a final . That doesn't seem to be handled?
Also the number of can vary, since it might be alloc9 vs alloc10. So you probably want to eat all the trailing ─*╼ and replace them by something deterministic.

And same for the leading ╾─*.

// Complete with filler `─` to preserve the pretty-print.
if let Some(tail) = caps.get(3) {
ret.push_str(tail.as_str());
let orig_len = caps.get(0).unwrap().as_str().len();
let ret_len = ret.len();
for _ in orig_len..ret_len {
ret.push('─');
}
}
ret
})
.into_owned();
}

// Custom normalization rules
for rule in custom_rules {
let re = Regex::new(&rule.0).expect("bad regex in custom normalization rule");
Expand Down
8 changes: 4 additions & 4 deletions tests/mir-opt/building/custom/consts.statics.built.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ fn statics() -> () {
let mut _2: *mut i32;

bb0: {
_1 = const {alloc1: &i32};
_2 = const {alloc2: *mut i32};
_1 = const {ALLOC0: &i32};
_2 = const {ALLOC1: *mut i32};
return;
}
}

alloc2 (static: T, size: 4, align: 4) {
ALLOC1 (static: T, size: 4, align: 4) {
0a 0a 0a 0a │ ....
}

alloc1 (static: S, size: 4, align: 4) {
ALLOC0 (static: S, size: 4, align: 4) {
05 05 05 05 │ ....
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn main() -> () {
}
}

alloc1 (size: 3, align: 1) {
ALLOC0 (size: 3, align: 1) {
66 6f 6f │ foo
}
36 changes: 18 additions & 18 deletions tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&str])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,43 +17,43 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 8, align: 4) {
╾─alloc19─╼ 03 00 00 00 │ ╾──╼....
ALLOC0 (static: FOO, size: 8, align: 4) {
╾─ALLOC1──╼ 03 00 00 00 │ ╾──╼....
}

alloc19 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc6──╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc10─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc15─╼ 03 00 00 00 │ ....*...╾──╼....
ALLOC1 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾─ALLOC2──╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾─ALLOC3──╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾─ALLOC4──╼ 03 00 00 00 │ ....*...╾──╼....
}

alloc6 (size: 0, align: 4) {}
ALLOC2 (size: 0, align: 4) {}

alloc10 (size: 16, align: 4) {
╾─alloc9──╼ 03 00 00 00 ╾─alloc11─╼ 03 00 00 00 │ ╾──╼....╾──╼....
ALLOC3 (size: 16, align: 4) {
╾─ALLOC5──╼ 03 00 00 00 ╾─ALLOC6──╼ 03 00 00 00 │ ╾──╼....╾──╼....
}

alloc9 (size: 3, align: 1) {
ALLOC5 (size: 3, align: 1) {
66 6f 6f │ foo
}

alloc11 (size: 3, align: 1) {
ALLOC6 (size: 3, align: 1) {
62 61 72 │ bar
}

alloc15 (size: 24, align: 4) {
0x00 │ ╾─alloc14─╼ 03 00 00 00 ╾─alloc16─╼ 03 00 00 00 │ ╾──╼....╾──╼....
0x10 │ ╾─alloc17─╼ 04 00 00 00 │ ╾──╼....
ALLOC4 (size: 24, align: 4) {
0x00 │ ╾─ALLOC7──╼ 03 00 00 00 ╾─ALLOC8──╼ 03 00 00 00 │ ╾──╼....╾──╼....
0x10 │ ╾─ALLOC9──╼ 04 00 00 00 │ ╾──╼....
}

alloc14 (size: 3, align: 1) {
ALLOC7 (size: 3, align: 1) {
6d 65 68 │ meh
}

alloc16 (size: 3, align: 1) {
ALLOC8 (size: 3, align: 1) {
6d 6f 70 │ mop
}

alloc17 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
6d c3 b6 70 │ m..p
}
40 changes: 20 additions & 20 deletions tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&str])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,47 +17,47 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 16, align: 8) {
╾───────alloc19───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC0 (static: FOO, size: 16, align: 8) {
╾───────ALLOC1────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc19 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc6────────╼ │ ....░░░░╾──────╼
ALLOC1 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────ALLOC2────────╼ │ ....░░░░╾──────╼
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
0x20 │ ╾───────alloc10───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc15───────╼ │ ....*...╾──────╼
0x20 │ ╾───────ALLOC3────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────ALLOC4────────╼ │ ....*...╾──────╼
0x40 │ 03 00 00 00 00 00 00 00 │ ........
}

alloc6 (size: 0, align: 8) {}
ALLOC2 (size: 0, align: 8) {}

alloc10 (size: 32, align: 8) {
0x00 │ ╾───────alloc9────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────alloc11───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC3 (size: 32, align: 8) {
0x00 │ ╾───────ALLOC5────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────ALLOC6────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc9 (size: 3, align: 1) {
ALLOC5 (size: 3, align: 1) {
66 6f 6f │ foo
}

alloc11 (size: 3, align: 1) {
ALLOC6 (size: 3, align: 1) {
62 61 72 │ bar
}

alloc15 (size: 48, align: 8) {
0x00 │ ╾───────alloc14───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────alloc16───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x20 │ ╾───────alloc17───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC4 (size: 48, align: 8) {
0x00 │ ╾───────ALLOC7────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────ALLOC8────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x20 │ ╾───────ALLOC9────────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc14 (size: 3, align: 1) {
ALLOC7 (size: 3, align: 1) {
6d 65 68 │ meh
}

alloc16 (size: 3, align: 1) {
ALLOC8 (size: 3, align: 1) {
6d 6f 70 │ mop
}

alloc17 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
6d c3 b6 70 │ m..p
}
34 changes: 17 additions & 17 deletions tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&u8])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,42 +17,42 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 8, align: 4) {
╾─alloc23─╼ 03 00 00 00 │ ╾──╼....
ALLOC0 (static: FOO, size: 8, align: 4) {
╾─ALLOC1──╼ 03 00 00 00 │ ╾──╼....
}

alloc23 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc10─╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc15─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc21─╼ 03 00 00 00 │ ....*...╾──╼....
ALLOC1 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾─ALLOC2──╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾─ALLOC3──╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾─ALLOC4──╼ 03 00 00 00 │ ....*...╾──╼....
}

alloc10 (size: 0, align: 4) {}
ALLOC2 (size: 0, align: 4) {}

alloc15 (size: 8, align: 4) {
╾─alloc13─╼ ╾─alloc14─╼ │ ╾──╼╾──╼
ALLOC3 (size: 8, align: 4) {
╾─ALLOC5──╼ ╾─ALLOC6──╼ │ ╾──╼╾──╼
}

alloc13 (size: 1, align: 1) {
ALLOC5 (size: 1, align: 1) {
05 │ .
}

alloc14 (size: 1, align: 1) {
ALLOC6 (size: 1, align: 1) {
06 │ .
}

alloc21 (size: 12, align: 4) {
╾─a18+0x3─╼ ╾─alloc19─╼ ╾─a20+0x2─╼ │ ╾──╼╾──╼╾──╼
ALLOC4 (size: 12, align: 4) {
╾─A7+0x3─╼ ╾─ALLOC8──╼ ╾─A9+0x2─╼ │ ╾──╼╾──╼╾──╼
}

alloc18 (size: 4, align: 1) {
ALLOC7 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}

alloc19 (size: 1, align: 1) {
ALLOC8 (size: 1, align: 1) {
2a │ *
}

alloc20 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}
36 changes: 18 additions & 18 deletions tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&u8])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,45 +17,45 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 16, align: 8) {
╾───────alloc23───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC0 (static: FOO, size: 16, align: 8) {
╾───────ALLOC1────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc23 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc10───────╼ │ ....░░░░╾──────╼
ALLOC1 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────ALLOC2────────╼ │ ....░░░░╾──────╼
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
0x20 │ ╾───────alloc15───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc21───────╼ │ ....*...╾──────╼
0x20 │ ╾───────ALLOC3────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────ALLOC4────────╼ │ ....*...╾──────╼
0x40 │ 03 00 00 00 00 00 00 00 │ ........
}

alloc10 (size: 0, align: 8) {}
ALLOC2 (size: 0, align: 8) {}

alloc15 (size: 16, align: 8) {
╾───────alloc13───────╼ ╾───────alloc14───────╼ │ ╾──────╼╾──────╼
ALLOC3 (size: 16, align: 8) {
╾───────ALLOC5───────╼ ╾───────ALLOC6────────╼ │ ╾──────╼╾──────╼
}

alloc13 (size: 1, align: 1) {
ALLOC5 (size: 1, align: 1) {
05 │ .
}

alloc14 (size: 1, align: 1) {
ALLOC6 (size: 1, align: 1) {
06 │ .
}

alloc21 (size: 24, align: 8) {
0x00 │ ╾─────alloc18+0x3─────╼ ╾───────alloc19───────╼ │ ╾──────╼╾──────╼
0x10 │ ╾─────alloc20+0x2─────╼ │ ╾──────╼
ALLOC4 (size: 24, align: 8) {
0x00 │ ╾─────ALLOC7+0x3─────╼ ╾───────ALLOC8────────╼ │ ╾──────╼╾──────╼
0x10 │ ╾─────ALLOC9+0x2─────╼ │ ╾──────╼
}

alloc18 (size: 4, align: 1) {
ALLOC7 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}

alloc19 (size: 1, align: 1) {
ALLOC8 (size: 1, align: 1) {
2a │ *
}

alloc20 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}
Loading