Skip to content

rustc generates a lot of LLVM IR when using a match in struct field initialization #68822

Open
@evnu

Description

@evnu

In rusterlium/rustler#299, we detected compile time to increase non-linearly when using a rather simple proc-macro. In rusterlium/rustler#299 (comment), we found that our decoder function results in a lot of IR. We were able to fix the issue in rusterlium/rustler#300 by making a simple transformation for generated struct initialization.

Transformation

The change to our proc-macro resulted in the following transformation of the resulting code.

Before:

Ok(SomeStruct {
  field1: match Decoder::decode(term[1usize])? { ... }
// .. more fields
})

After:

let field1 = match Decoder::decode(term[1usize]) { ... };
// .. more bindings
Ok(SomeStruct {
  field1,
// .. more fields
})

Simplification

I simplified our case in https://github.com/evnu/rust-slow-compilation. I haven't been able to simplify this further: when I tried to get rid of the rustler-specific Decoder, or when using map_err(), compilation became very fast. The README of the repository indicates compilation times on my machine for specific revisions of the repository.

Meta

$ rustc --version --verbose
rustc 1.40.0 (73528e339 2019-12-16)
binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16
host: x86_64-unknown-linux-gnu
release: 1.40.0
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.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