Skip to content

Commit 2f96703

Browse files
committed
regression tests for problems that are exposed by mir-inlining policy that we are reverting for 1.64-beta.
1 parent 2741dd8 commit 2f96703

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// check-pass
2+
3+
// compile-flags: --emit=mir,link -O
4+
5+
// There is an ICE somewhere in type normalization, and we are hitting it during
6+
// the MIR inlining pass on this code.
7+
//
8+
// Long term, we should fix that ICE and change the compile-flags for this test
9+
// to explicitly enable MIR inlining.
10+
//
11+
// Short term, we are diabling MIR inlining for Rust 1.64-beta, so that we avoid
12+
// this ICE in this instance.
13+
14+
pub trait Trait {
15+
type Associated;
16+
}
17+
impl<T> Trait for T {
18+
type Associated = T;
19+
}
20+
21+
pub struct Struct<T>(<T as Trait>::Associated);
22+
23+
pub fn foo<T>() -> Struct<T>
24+
where
25+
T: Trait,
26+
{
27+
bar()
28+
}
29+
30+
#[inline]
31+
fn bar<T>() -> Struct<T> {
32+
Struct(baz())
33+
}
34+
35+
fn baz<T>() -> T {
36+
unimplemented!()
37+
}
38+
39+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// check-pass
2+
3+
// compile-flags: --emit=mir,link -O
4+
5+
// At one point the MIR inlining, when guarding against infinitely (or even just
6+
// excessive) recursion, was using `ty::Instance` as the basis for its history
7+
// check. The problem is that when you have polymorphic recursion, you can have
8+
// distinct instances of the same code (because you're inlining the same code
9+
// with differing substitutions), causing the amount of inlining to blow up
10+
// exponentially.
11+
//
12+
// This test illustrates an example of that filed in issue rust#100476.
13+
14+
#![allow(unconditional_recursion)]
15+
#![feature(decl_macro)]
16+
17+
macro emit($($m:ident)*) {$(
18+
// Randomize `def_path_hash` by defining them under a module with
19+
// different names
20+
pub mod $m {
21+
pub trait Tr {
22+
type Next: Tr;
23+
}
24+
25+
pub fn hoge<const N: usize, T: Tr>() {
26+
inner::<N, T>();
27+
}
28+
29+
#[inline(always)]
30+
fn inner<const N: usize, T: Tr>() {
31+
inner::<N, T::Next>();
32+
}
33+
}
34+
)*}
35+
36+
// Increase the chance of triggering the bug
37+
emit!(
38+
m00 m01 m02 m03 m04 m05 m06 m07 m08 m09
39+
m10 m11 m12 m13 m14 m15 m16 m17 m18 m19
40+
);
41+
42+
fn main() { }

0 commit comments

Comments
 (0)