Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
evnu opened this issue Feb 4, 2020 · 0 comments
Labels
A-codegen Area: Code generation 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.

Comments

@evnu
Copy link

evnu commented Feb 4, 2020

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
@jonas-schievink jonas-schievink added A-codegen Area: Code generation 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. labels Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation 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.
Projects
None yet
Development

No branches or pull requests

2 participants