-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Don't generate code for unused #[inline] function #36280
Comments
cc @rust-lang/compiler - especially @michaelwoerister, I believe the collector should be able to reliably detect whether an |
Afaict, the only thing that needs to be adapted should be TransItem::is_instantiated_only_on_demand(). There's also |
I did a simple patch which changed that function and it didn't really affect compile times. In fact the LLVM IR is just as big, leading me to conclude that there is more going on to decide whether to instantiate something than that function. I'll let someone else take it from here because this is beyond my knowledge of rustc: retep998@e8d9b86 |
@retep998 Do you have an example of a function that you would expect not to be generated? |
@michaelwoerister For example a simple |
If the function isn't used or referenced anywhere in the crate then the modification you made should have done the trick. I'll take a look when I find the time. |
I'm removing the nominated tag, this doesn't really need discussion in the meeting, it should just be investigated and fixed. |
…r=nikomatsakis trans: Only instantiate #[inline] functions in codegen units referencing them This PR changes how `#[inline]` functions are translated. Before, there was one "master instance" of the function with `external` linkage and a number of on-demand instances with `available_externally` linkage in each codegen unit that referenced the function. This had two downsides: * Public functions marked with `#[inline]` would be present in machine code of libraries unnecessarily (see #36280 for an example) * LLVM would crash on `i686-pc-windows-msvc` due to what I suspect to be a bug in LLVM's Win32 exception handling code, because it doesn't like `available_externally` there (#36309). This PR changes the behavior, so that there is no master instance and only on-demand instances with `internal` linkage. The downside of this is potential code-bloat if LLVM does not completely inline away the `internal` instances because then there'd be N instances of the function instead of 1. However, this can only become a problem when using more than one codegen unit per crate. cc @rust-lang/compiler
This was fixed by #36524 |
Awesome! 🎉 This improved compile times of winrt-rust quite a lot:
"Before" is |
@Boddlnagg oh nice results! |
ndarray (a much smaller crate) had compile time improve by 20% (with deps). Its release mode time for llvm passes dropped from 1.2 s to 0.2 s (just the crate itself). |
…matthewjasper Export `#[inline]` fns with extern indicators In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However, - rust-lang#72944 - rust-lang#72463 observe that when writing something like ```rust #![crate_type = "cdylib"] #[no_mangle] #[inline] pub extern "C" fn foo() { // ... } ``` we really _do_ want `foo` to be codegened. This change makes this the case. Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
…matthewjasper Export `#[inline]` fns with extern indicators In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However, - rust-lang#72944 - rust-lang#72463 observe that when writing something like ```rust #![crate_type = "cdylib"] #[no_mangle] #[inline] pub extern "C" fn foo() { // ... } ``` we really _do_ want `foo` to be codegened. This change makes this the case. Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
…matthewjasper Export `#[inline]` fns with extern indicators In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However, - rust-lang#72944 - rust-lang#72463 observe that when writing something like ```rust #![crate_type = "cdylib"] #[no_mangle] #[inline] pub extern "C" fn foo() { // ... } ``` we really _do_ want `foo` to be codegened. This change makes this the case. Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
…matthewjasper Export `#[inline]` fns with extern indicators In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However, - rust-lang#72944 - rust-lang#72463 observe that when writing something like ```rust #![crate_type = "cdylib"] #[no_mangle] #[inline] pub extern "C" fn foo() { // ... } ``` we really _do_ want `foo` to be codegened. This change makes this the case. Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
If a function or method is marked
#[inline]
and it isn't actually called anywhere in that crate, then no code should be generated for it. This would save a lot of time on translation and LLVM passes for certain crates, such as winapi.@eddyb told me to open this issue. Blame him.
The text was updated successfully, but these errors were encountered: