Skip to content

Commit 09df610

Browse files
committed
Auto merge of #116767 - cjgillot:alloc-normalize, r=oli-obk
Normalize alloc-id in tests. AllocIds are globally numbered in a rustc invocation. This makes them very sensitive to changes unrelated to what is being tested. This commit normalizes them by renumbering, in order of appearance in the output. The renumbering allows to keep the identity, that a simple `allocN` wouldn't. This is useful when we have memory dumps. cc `@saethlin` r? `@oli-obk`
2 parents 94ba57c + 1f90d85 commit 09df610

File tree

106 files changed

+361
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+361
-326
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ dependencies = [
697697
"getopts",
698698
"glob",
699699
"home",
700+
"indexmap 2.0.0",
700701
"lazycell",
701702
"libc",
702703
"miow",

Diff for: src/tools/compiletest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ colored = "2"
1111
diff = "0.1.10"
1212
unified-diff = "0.2.1"
1313
getopts = "0.2"
14+
indexmap = "2.0.0"
1415
miropt-test-tools = { path = "../miropt-test-tools" }
1516
build_helper = { path = "../build_helper" }
1617
tracing = "0.1"

Diff for: src/tools/compiletest/src/runtest.rs

+33
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,39 @@ impl<'test> TestCx<'test> {
42584258
V0_BACK_REF_RE.replace_all(&normalized, V0_BACK_REF_PLACEHOLDER).into_owned();
42594259
}
42604260

4261+
// AllocId are numbered globally in a compilation session. This can lead to changes
4262+
// depending on the exact compilation flags and host architecture. Meanwhile, we want
4263+
// to keep them numbered, to see if the same id appears multiple times.
4264+
// So we remap to deterministic numbers that only depend on the subset of allocations
4265+
// that actually appear in the output.
4266+
// We use uppercase ALLOC to distinguish from the non-normalized version.
4267+
{
4268+
let mut seen_allocs = indexmap::IndexSet::new();
4269+
4270+
// The alloc-id appears in pretty-printed allocations.
4271+
let re = Regex::new(r"╾─*a(lloc)?([0-9]+)(\+0x[0-9]+)?─*╼").unwrap();
4272+
normalized = re
4273+
.replace_all(&normalized, |caps: &Captures<'_>| {
4274+
// Renumber the captured index.
4275+
let index = caps.get(2).unwrap().as_str().to_string();
4276+
let (index, _) = seen_allocs.insert_full(index);
4277+
let offset = caps.get(3).map_or("", |c| c.as_str());
4278+
// Do not bother keeping it pretty, just make it deterministic.
4279+
format!("╾ALLOC{index}{offset}╼")
4280+
})
4281+
.into_owned();
4282+
4283+
// The alloc-id appears in a sentence.
4284+
let re = Regex::new(r"\balloc([0-9]+)\b").unwrap();
4285+
normalized = re
4286+
.replace_all(&normalized, |caps: &Captures<'_>| {
4287+
let index = caps.get(1).unwrap().as_str().to_string();
4288+
let (index, _) = seen_allocs.insert_full(index);
4289+
format!("ALLOC{index}")
4290+
})
4291+
.into_owned();
4292+
}
4293+
42614294
// Custom normalization rules
42624295
for rule in custom_rules {
42634296
let re = Regex::new(&rule.0).expect("bad regex in custom normalization rule");

Diff for: tests/mir-opt/building/custom/consts.statics.built.after.mir

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ fn statics() -> () {
66
let mut _2: *mut i32;
77

88
bb0: {
9-
_1 = const {alloc1: &i32};
10-
_2 = const {alloc2: *mut i32};
9+
_1 = const {ALLOC0: &i32};
10+
_2 = const {ALLOC1: *mut i32};
1111
return;
1212
}
1313
}
1414

15-
alloc2 (static: T, size: 4, align: 4) {
15+
ALLOC1 (static: T, size: 4, align: 4) {
1616
0a 0a 0a 0a │ ....
1717
}
1818

19-
alloc1 (static: S, size: 4, align: 4) {
19+
ALLOC0 (static: S, size: 4, align: 4) {
2020
05 05 05 05 │ ....
2121
}

Diff for: tests/mir-opt/byte_slice.main.SimplifyCfg-elaborate-drops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ fn main() -> () {
2323
}
2424
}
2525

26-
alloc1 (size: 3, align: 1) {
26+
ALLOC0 (size: 3, align: 1) {
2727
66 6f 6f │ foo
2828
}

Diff for: tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() -> () {
88
bb0: {
99
StorageLive(_1);
1010
StorageLive(_2);
11-
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
11+
_2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
1212
_1 = (*_2);
1313
StorageDead(_2);
1414
StorageDead(_1);
@@ -17,43 +17,43 @@ fn main() -> () {
1717
}
1818
}
1919

20-
alloc1 (static: FOO, size: 8, align: 4) {
21-
─alloc19─╼ 03 00 00 00 │ ╾──╼....
20+
ALLOC9 (static: FOO, size: 8, align: 4) {
21+
ALLOC0╼ 03 00 00 00 │ ╾──╼....
2222
}
2323

24-
alloc19 (size: 48, align: 4) {
25-
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc6──╼ 00 00 00 00 │ ....░░░░╾──╼....
26-
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc10─╼ 02 00 00 00 │ ....░░░░╾──╼....
27-
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc15─╼ 03 00 00 00 │ ....*...╾──╼....
24+
ALLOC0 (size: 48, align: 4) {
25+
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ 00 00 00 00 │ ....░░░░╾──╼....
26+
0x10 │ 00 00 00 00 __ __ __ __ ╾ALLOC2╼ 02 00 00 00 │ ....░░░░╾──╼....
27+
0x20 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ 03 00 00 00 │ ....*...╾──╼....
2828
}
2929

30-
alloc6 (size: 0, align: 4) {}
30+
ALLOC1 (size: 0, align: 4) {}
3131

32-
alloc10 (size: 16, align: 4) {
33-
─alloc9──╼ 03 00 00 00 ╾─alloc11─╼ 03 00 00 00 │ ╾──╼....╾──╼....
32+
ALLOC2 (size: 16, align: 4) {
33+
ALLOC4╼ 03 00 00 00 ╾ALLOC5╼ 03 00 00 00 │ ╾──╼....╾──╼....
3434
}
3535

36-
alloc9 (size: 3, align: 1) {
36+
ALLOC4 (size: 3, align: 1) {
3737
66 6f 6f │ foo
3838
}
3939

40-
alloc11 (size: 3, align: 1) {
40+
ALLOC5 (size: 3, align: 1) {
4141
62 61 72 │ bar
4242
}
4343

44-
alloc15 (size: 24, align: 4) {
45-
0x00 │ ╾─alloc14─╼ 03 00 00 00 ╾─alloc16─╼ 03 00 00 00 │ ╾──╼....╾──╼....
46-
0x10 │ ╾─alloc17─╼ 04 00 00 00 │ ╾──╼....
44+
ALLOC3 (size: 24, align: 4) {
45+
0x00 │ ╾ALLOC6╼ 03 00 00 00 ╾ALLOC7╼ 03 00 00 00 │ ╾──╼....╾──╼....
46+
0x10 │ ╾ALLOC8╼ 04 00 00 00 │ ╾──╼....
4747
}
4848

49-
alloc14 (size: 3, align: 1) {
49+
ALLOC6 (size: 3, align: 1) {
5050
6d 65 68 │ meh
5151
}
5252

53-
alloc16 (size: 3, align: 1) {
53+
ALLOC7 (size: 3, align: 1) {
5454
6d 6f 70 │ mop
5555
}
5656

57-
alloc17 (size: 4, align: 1) {
57+
ALLOC8 (size: 4, align: 1) {
5858
6d c3 b6 70 │ m..p
5959
}

Diff for: tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() -> () {
88
bb0: {
99
StorageLive(_1);
1010
StorageLive(_2);
11-
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
11+
_2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
1212
_1 = (*_2);
1313
StorageDead(_2);
1414
StorageDead(_1);
@@ -17,47 +17,47 @@ fn main() -> () {
1717
}
1818
}
1919

20-
alloc1 (static: FOO, size: 16, align: 8) {
21-
───────alloc19───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
20+
ALLOC9 (static: FOO, size: 16, align: 8) {
21+
ALLOC0╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
2222
}
2323

24-
alloc19 (size: 72, align: 8) {
25-
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc6────────╼ │ ....░░░░╾──────╼
24+
ALLOC0 (size: 72, align: 8) {
25+
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ │ ....░░░░╾──────╼
2626
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
27-
0x20 │ ╾───────alloc10───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
28-
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc15───────╼ │ ....*...╾──────╼
27+
0x20 │ ╾ALLOC2╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
28+
0x30 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ │ ....*...╾──────╼
2929
0x40 │ 03 00 00 00 00 00 00 00 │ ........
3030
}
3131

32-
alloc6 (size: 0, align: 8) {}
32+
ALLOC1 (size: 0, align: 8) {}
3333

34-
alloc10 (size: 32, align: 8) {
35-
0x00 │ ╾───────alloc9────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
36-
0x10 │ ╾───────alloc11───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
34+
ALLOC2 (size: 32, align: 8) {
35+
0x00 │ ╾ALLOC4╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
36+
0x10 │ ╾ALLOC5╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
3737
}
3838

39-
alloc9 (size: 3, align: 1) {
39+
ALLOC4 (size: 3, align: 1) {
4040
66 6f 6f │ foo
4141
}
4242

43-
alloc11 (size: 3, align: 1) {
43+
ALLOC5 (size: 3, align: 1) {
4444
62 61 72 │ bar
4545
}
4646

47-
alloc15 (size: 48, align: 8) {
48-
0x00 │ ╾───────alloc14───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
49-
0x10 │ ╾───────alloc16───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
50-
0x20 │ ╾───────alloc17───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
47+
ALLOC3 (size: 48, align: 8) {
48+
0x00 │ ╾ALLOC6╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
49+
0x10 │ ╾ALLOC7╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
50+
0x20 │ ╾ALLOC8╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
5151
}
5252

53-
alloc14 (size: 3, align: 1) {
53+
ALLOC6 (size: 3, align: 1) {
5454
6d 65 68 │ meh
5555
}
5656

57-
alloc16 (size: 3, align: 1) {
57+
ALLOC7 (size: 3, align: 1) {
5858
6d 6f 70 │ mop
5959
}
6060

61-
alloc17 (size: 4, align: 1) {
61+
ALLOC8 (size: 4, align: 1) {
6262
6d c3 b6 70 │ m..p
6363
}

Diff for: tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() -> () {
88
bb0: {
99
StorageLive(_1);
1010
StorageLive(_2);
11-
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
11+
_2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
1212
_1 = (*_2);
1313
StorageDead(_2);
1414
StorageDead(_1);
@@ -17,42 +17,42 @@ fn main() -> () {
1717
}
1818
}
1919

20-
alloc1 (static: FOO, size: 8, align: 4) {
21-
─alloc23─╼ 03 00 00 00 │ ╾──╼....
20+
ALLOC9 (static: FOO, size: 8, align: 4) {
21+
ALLOC0╼ 03 00 00 00 │ ╾──╼....
2222
}
2323

24-
alloc23 (size: 48, align: 4) {
25-
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc10─╼ 00 00 00 00 │ ....░░░░╾──╼....
26-
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc15─╼ 02 00 00 00 │ ....░░░░╾──╼....
27-
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc21─╼ 03 00 00 00 │ ....*...╾──╼....
24+
ALLOC0 (size: 48, align: 4) {
25+
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ 00 00 00 00 │ ....░░░░╾──╼....
26+
0x10 │ 00 00 00 00 __ __ __ __ ╾ALLOC2╼ 02 00 00 00 │ ....░░░░╾──╼....
27+
0x20 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ 03 00 00 00 │ ....*...╾──╼....
2828
}
2929

30-
alloc10 (size: 0, align: 4) {}
30+
ALLOC1 (size: 0, align: 4) {}
3131

32-
alloc15 (size: 8, align: 4) {
33-
─alloc13─╼ ╾─alloc14─╼ │ ╾──╼╾──╼
32+
ALLOC2 (size: 8, align: 4) {
33+
ALLOC4╼ ╾ALLOC5╼ │ ╾──╼╾──╼
3434
}
3535

36-
alloc13 (size: 1, align: 1) {
36+
ALLOC4 (size: 1, align: 1) {
3737
05 │ .
3838
}
3939

40-
alloc14 (size: 1, align: 1) {
40+
ALLOC5 (size: 1, align: 1) {
4141
06 │ .
4242
}
4343

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

48-
alloc18 (size: 4, align: 1) {
48+
ALLOC6 (size: 4, align: 1) {
4949
2a 45 15 6f │ *E.o
5050
}
5151

52-
alloc19 (size: 1, align: 1) {
52+
ALLOC7 (size: 1, align: 1) {
5353
2a │ *
5454
}
5555

56-
alloc20 (size: 4, align: 1) {
56+
ALLOC8 (size: 4, align: 1) {
5757
2a 45 15 6f │ *E.o
5858
}

Diff for: tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() -> () {
88
bb0: {
99
StorageLive(_1);
1010
StorageLive(_2);
11-
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
11+
_2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
1212
_1 = (*_2);
1313
StorageDead(_2);
1414
StorageDead(_1);
@@ -17,45 +17,45 @@ fn main() -> () {
1717
}
1818
}
1919

20-
alloc1 (static: FOO, size: 16, align: 8) {
21-
───────alloc23───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
20+
ALLOC9 (static: FOO, size: 16, align: 8) {
21+
ALLOC0╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
2222
}
2323

24-
alloc23 (size: 72, align: 8) {
25-
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc10───────╼ │ ....░░░░╾──────╼
24+
ALLOC0 (size: 72, align: 8) {
25+
0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC1╼ │ ....░░░░╾──────╼
2626
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
27-
0x20 │ ╾───────alloc15───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
28-
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc21───────╼ │ ....*...╾──────╼
27+
0x20 │ ╾ALLOC2╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
28+
0x30 │ 01 00 00 00 2a 00 00 00 ╾ALLOC3╼ │ ....*...╾──────╼
2929
0x40 │ 03 00 00 00 00 00 00 00 │ ........
3030
}
3131

32-
alloc10 (size: 0, align: 8) {}
32+
ALLOC1 (size: 0, align: 8) {}
3333

34-
alloc15 (size: 16, align: 8) {
35-
───────alloc13───────╼ ╾───────alloc14───────╼ │ ╾──────╼╾──────╼
34+
ALLOC2 (size: 16, align: 8) {
35+
ALLOC4╼ ╾ALLOC5╼ │ ╾──────╼╾──────╼
3636
}
3737

38-
alloc13 (size: 1, align: 1) {
38+
ALLOC4 (size: 1, align: 1) {
3939
05 │ .
4040
}
4141

42-
alloc14 (size: 1, align: 1) {
42+
ALLOC5 (size: 1, align: 1) {
4343
06 │ .
4444
}
4545

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

51-
alloc18 (size: 4, align: 1) {
51+
ALLOC6 (size: 4, align: 1) {
5252
2a 45 15 6f │ *E.o
5353
}
5454

55-
alloc19 (size: 1, align: 1) {
55+
ALLOC7 (size: 1, align: 1) {
5656
2a │ *
5757
}
5858

59-
alloc20 (size: 4, align: 1) {
59+
ALLOC8 (size: 4, align: 1) {
6060
2a 45 15 6f │ *E.o
6161
}

0 commit comments

Comments
 (0)