Skip to content

Deduplicate closures #63660

Closed
Closed
@oli-obk

Description

@oli-obk

#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 like Spans 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-closuresArea: Closures (`|…| { … }`)A-codegenArea: Code generationC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions