[Pre-RFC] Flow-Directed Monomorphization Collection in MIR
Thanks for your advice!
I have updated the pre-rfc. Link to the paper is attached.
And in summary, the motivation is:
Finite lowering of hidden type flow.
impl Trait,async fn, TAIT, and RPITIT introduce opaque but concrete types. A type-flow graph makes their dependence on generic parameters explicit.Closed-world generic dispatch. A generic
dynmethod such asencode<T>is not open-world object-safe, but it may have a finite set of reachable instantiations in a closed world. Flow analysis is the decision procedure for that lowering.Higher-rank and existential-like specialization. The paper shows that these forms are monomorphizable when type flow has a finite solution; they do not require fundamentally different mechanisms. This makes powerful features possible for rust.
Non-finite cases are rejected structurally. A cycle such as
T ↦ Option<T>is evidence that specialization does not close; the compiler need not discover this by recursive expansion.
Discussion in the ATmosphere