carbon-lang
carbon-lang copied to clipboard
Termination rule should also apply to instantiating specifics
trafficstars
In this example:
interface I {
let T:! type;
default fn F() -> T;
}
fn I.F() -> T {
class C {
// `I` is complete, but `I.F`'s default
// value is still being defined.
impl as I where .T = i32 {}
}
}
If the default definition of I.F is eveer used, it will lead to an infinite instantiation loop. This is because forming the specific for a given type U will trigger creation of a new class C(U), which itself has an impl of I that uses the default value of I.F.
We should apply the termination check to formation of specifics to detect this problem, since each instantiation is strictly more complex.