-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rust generating LLVM IR for dependencies of inline functions #40392
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
Comments
Interesting. @eddyb, might this be related to some reachability changes because of |
Doubt it, the function itself isn't translated, just its dependencies. |
@michaelwoerister the commit 5f90947 is the first commit where this regression is triggered. |
I completely forgot about that. Nominating for priority assignment. |
triage: P-medium |
…ikomatsakis Only instantiate inline- and const-fns if they are referenced (again). It seems that we have regressed on not translating `#[inline]` functions unless they are actually used. This should bring back this optimization. I also added a regression test this time so it doesn't happen again accidentally. Fixes #40392. r? @alexcrichton UPDATE & PSA --------------------- This patch **makes translation very lazy** -- in general this is a good thing (we don't want the compiler to do unnecessary work) but it has two consequences: 1. Some error messages are only generated when an item is actually translated. Consequently, this patch will lead to more cases where the compiler will only start emitting errors when the erroneous function is actually used. This has always been true to some extend (e.g. when passing generic values to an intrinsic) but since this is something user-facing it's worth mentioning. 2. When writing tests, one has to make sure that the functions in question are actually generated. In other words, it must not be dead code. This can usually be achieved by either 1. making sure the function is exported from the resulting binary or 2. by making sure the function is called from something that is exported (or `main()`). Note that it depends on the crate type what functions are exported: 1. For rlibs and dylibs everything that is reachable from the outside is exported. 2. For executables, cdylibs, and staticlibs, items are only exported if they are additionally `#[no_mangle]` or have an `#[export_name]`. The commits in this PR contain many examples of how tests can be updated to comply to the new requirements.
Example code:
This is an inline function and as such it shouldn't generate any LLVM IR. If you check what the LLVM IR is with stable you see that it is pretty much empty.
If you switch to beta or nightly however, then the LLVM IR is filled with a bunch of junk that the function depends on, yet not the function itself.
The text was updated successfully, but these errors were encountered: