Don't evaluate promoteds for each monomorphization if it does not depend on generic parameters #67176
Labels
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-compiletime
Issue: Problems and improvements with respect to compile times.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
In the following code snippet
we evaluate the
&(5 + 6)
for every monomorphization offoo
, even though we could just do this once. We should find a way to get rid of this duplicate evaluation. Maybe we can already do this at the time promoteds are created (const qualif +promote.rs
) by checkingpromoted_mir.needs_substs()
and if it's false, make thety::Const
that refers to it not have any substs itself.const_eval
will then automatically memoize all the evaluations of this promoted.Alternatively const prop could attempt to evaluate the promoted and if it fails, assume it has generics and leave it to monomorphization. This would require more CPU time than the const qualif version, since we'd do a lot of prospetive evaluations that may not succeed.
The text was updated successfully, but these errors were encountered: