Skip to content

Commit 408e6e3

Browse files
Add a test case for incremental + codegen-units interaction.
1 parent 1e5b459 commit 408e6e3

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ignore-tidy-linelength
2+
// We specify -C incremental here because we want to test the partitioning for
3+
// incremental compilation
4+
// compile-flags:-Zprint-mono-items=lazy -Cincremental=tmp/partitioning-tests/incremental-merging
5+
// compile-flags:-Ccodegen-units=3
6+
7+
#![crate_type = "rlib"]
8+
9+
// This test makes sure that merging of CGUs works together with incremental
10+
// compilation but at the same time does not modify names of CGUs that were not
11+
// affected by merging.
12+
//
13+
// We expect CGUs `aaa` and `bbb` to be merged (because they are the smallest),
14+
// while `ccc` and `ddd` are supposed to stay untouched.
15+
16+
pub mod aaa {
17+
//~ MONO_ITEM fn incremental_merging::aaa[0]::foo[0] @@ incremental_merging-aaa--incremental_merging-bbb[External]
18+
pub fn foo(a: u64) -> u64 {
19+
a + 1
20+
}
21+
}
22+
23+
pub mod bbb {
24+
//~ MONO_ITEM fn incremental_merging::bbb[0]::foo[0] @@ incremental_merging-aaa--incremental_merging-bbb[External]
25+
pub fn foo(a: u64, b: u64) -> u64 {
26+
a + b + 1
27+
}
28+
}
29+
30+
pub mod ccc {
31+
//~ MONO_ITEM fn incremental_merging::ccc[0]::foo[0] @@ incremental_merging-ccc[External]
32+
pub fn foo(a: u64, b: u64, c: u64) -> u64 {
33+
a + b + c + 1
34+
}
35+
}
36+
37+
pub mod ddd {
38+
//~ MONO_ITEM fn incremental_merging::ddd[0]::foo[0] @@ incremental_merging-ddd[External]
39+
pub fn foo(a: u64, b: u64, c: u64, d: u64) -> u64 {
40+
a + b + c + d + 1
41+
}
42+
}

src/tools/compiletest/src/runtest.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ impl<'test> TestCx<'test> {
25172517
.filter(|s| !s.is_empty())
25182518
.map(|s| {
25192519
if cgu_has_crate_disambiguator {
2520-
remove_crate_disambiguator_from_cgu(s)
2520+
remove_crate_disambiguators_from_set_of_cgu_names(s)
25212521
} else {
25222522
s.to_string()
25232523
}
@@ -2567,6 +2567,16 @@ impl<'test> TestCx<'test> {
25672567

25682568
new_name
25692569
}
2570+
2571+
// The name of merged CGUs is constructed as the names of the original
2572+
// CGUs joined with "--". This function splits such composite CGU names
2573+
// and handles each component individually.
2574+
fn remove_crate_disambiguators_from_set_of_cgu_names(cgus: &str) -> String {
2575+
cgus.split("--")
2576+
.map(|cgu| remove_crate_disambiguator_from_cgu(cgu))
2577+
.collect::<Vec<_>>()
2578+
.join("--")
2579+
}
25702580
}
25712581

25722582
fn init_incremental_test(&self) {

0 commit comments

Comments
 (0)