Deduplicate closures #63660
Labels
A-closures
Area: Closures (`|…| { … }`)
A-codegen
Area: Code generation
A-MIR
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
#62429 manually deduplicated monomorphizations of closures. We should automate this during building instead of requiring users to do it manually. Ideally we'll revert the parts of #62429 that made things less readable as the last step of closing this issue.
I think the endgame would be that we'd deduplicate closures (in release mode only, so backtraces's file:line locations still make sense in debug mode), as long as their body is the same.
Not sure if that is possible, but random idea:
If we only care about monomorphizations in llvm, we could create a function that takes a closure's
mir::Body
, cleans it of all "unnecessary" info likeSpan
s and then feeds that through a query (which thus will only be called once with the same arguments), producing the appropriate codegen backend's function handle.If we want to reduce type lengths, too, we'd need to change the way closure substs are built, by computing the minimal required set ahead of time.
The text was updated successfully, but these errors were encountered: