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 all 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
33 changes: 33 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,39 @@ 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.

// So we remap to deterministic numbers that only depend on the subset of allocations
// that actually appear in the output.
// We use uppercase ALLOC to distinguish from the non-normalized version.
{
let mut seen_allocs = indexmap::IndexSet::new();

// The alloc-id appears in pretty-printed allocations.
let re = Regex::new(r"╾─*a(lloc)?([0-9]+)(\+0x[0-9]+)?─*╼").unwrap();
normalized = re
.replace_all(&normalized, |caps: &Captures<'_>| {
// Renumber the captured index.
let index = caps.get(2).unwrap().as_str().to_string();
let (index, _) = seen_allocs.insert_full(index);
let offset = caps.get(3).map_or("", |c| c.as_str());
// Do not bother keeping it pretty, just make it deterministic.
format!("╾ALLOC{index}{offset}╼")
})
.into_owned();

// The alloc-id appears in a sentence.
let re = Regex::new(r"\balloc([0-9]+)\b").unwrap();
normalized = re
.replace_all(&normalized, |caps: &Captures<'_>| {
let index = caps.get(1).unwrap().as_str().to_string();
let (index, _) = seen_allocs.insert_full(index);
format!("ALLOC{index}")
})
.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 {ALLOC9: &&[(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 │ ╾──╼....
ALLOC9 (static: FOO, size: 8, align: 4) {
ALLOC0╼ 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 │ ....*...╾──╼....
ALLOC0 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾ALLOC2╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ 03 00 00 00 │ ....*...╾──╼....
}

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

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

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

alloc11 (size: 3, align: 1) {
ALLOC5 (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 │ ╾──╼....
ALLOC3 (size: 24, align: 4) {
0x00 │ ╾ALLOC6╼ 03 00 00 00 ╾ALLOC7╼ 03 00 00 00 │ ╾──╼....╾──╼....
0x10 │ ╾ALLOC8╼ 04 00 00 00 │ ╾──╼....
}

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

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

alloc17 (size: 4, align: 1) {
ALLOC8 (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 {ALLOC9: &&[(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 │ ╾──────╼........
ALLOC9 (static: FOO, size: 16, align: 8) {
ALLOC0╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc19 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc6────────╼ │ ....░░░░╾──────╼
ALLOC0 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ │ ....░░░░╾──────╼
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 │ ╾ALLOC2╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ │ ....*...╾──────╼
0x40 │ 03 00 00 00 00 00 00 00 │ ........
}

alloc6 (size: 0, align: 8) {}
ALLOC1 (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 │ ╾──────╼........
ALLOC2 (size: 32, align: 8) {
0x00 │ ╾ALLOC4╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾ALLOC5╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

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

alloc11 (size: 3, align: 1) {
ALLOC5 (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 │ ╾──────╼........
ALLOC3 (size: 48, align: 8) {
0x00 │ ╾ALLOC6╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾ALLOC7╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x20 │ ╾ALLOC8╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
}

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

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

alloc17 (size: 4, align: 1) {
ALLOC8 (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 {ALLOC9: &&[(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 │ ╾──╼....
ALLOC9 (static: FOO, size: 8, align: 4) {
ALLOC0╼ 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 │ ....*...╾──╼....
ALLOC0 (size: 48, align: 4) {
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ 00 00 00 00 │ ....░░░░╾──╼....
0x10 │ 00 00 00 00 __ __ __ __ ╾ALLOC2╼ 02 00 00 00 │ ....░░░░╾──╼....
0x20 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ 03 00 00 00 │ ....*...╾──╼....
}

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

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

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

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

alloc21 (size: 12, align: 4) {
─a18+0x3╼ ╾─alloc19─╼ ╾─a20+0x2╼ │ ╾──╼╾──╼╾──╼
ALLOC3 (size: 12, align: 4) {
ALLOC6+0x3╼ ╾ALLOC7╼ ╾ALLOC8+0x2╼ │ ╾──╼╾──╼╾──╼
}

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

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

alloc20 (size: 4, align: 1) {
ALLOC8 (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 {ALLOC9: &&[(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 │ ╾──────╼........
ALLOC9 (static: FOO, size: 16, align: 8) {
ALLOC0╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc23 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc10───────╼ │ ....░░░░╾──────╼
ALLOC0 (size: 72, align: 8) {
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ │ ....░░░░╾──────╼
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 │ ╾ALLOC2╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x30 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ │ ....*...╾──────╼
0x40 │ 03 00 00 00 00 00 00 00 │ ........
}

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

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

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

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

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

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

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

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