Skip to content
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

builtin arithmetic ops should be inlined when used in a generic function #12279

Closed
thestinger opened this issue Feb 14, 2014 · 9 comments
Closed
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@thestinger
Copy link
Contributor

The basic operations on the built-in types compile to inferior code in generic functions without --opt-level=2 for heuristic-based inlining. The library should define these operations in the same way to avoid a distinction as not inlining them only slows down compile-time and doesn't aid in debugging.

@alexcrichton
Copy link
Member

Can you provide any concrete numbers, data, statistics, or examples to go along with this assertion?

@thestinger
Copy link
Contributor Author

Outside of a generic function, a + b is a single operation. Inside of a generic function, it's a method call. I think we should ensure that it's the same in both places. This is a rare place where #[inline(always)] doesn't hurt debugging, and speeds up compile times. I didn't make it clear enough that this is what I meant.

@steveklabnik
Copy link
Member

triage: as far as I can tell, the IR for a generic and specific a + b are different, and so nothing has changed here.

@arielb1
Copy link
Contributor

arielb1 commented Sep 27, 2015

Does not seem to be relevant for Rust 1.3+ - could you provide an example?

@arielb1 arielb1 changed the title code should not become slower in generics builtin arithmetic ops should be inlined when used in a generic function Sep 27, 2015
@arielb1
Copy link
Contributor

arielb1 commented Sep 27, 2015

Actually, this is talking about:

fn foo<T: Add>(t: T) { t + t }
fn main() { t(4u32); }

@jfager
Copy link
Contributor

jfager commented Mar 21, 2017

Triage: still produces slower code without -O (godbolt link).

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 20, 2017
@hanna-kruppe
Copy link
Contributor

Triage: Still true. Smaller test program (no I/O or formatting): https://godbolt.org/g/B9t75L

@bluss
Copy link
Member

bluss commented Dec 29, 2017

Current impl is here; is it really just about using inline(always) here? Any drawbacks to that?

macro_rules! add_impl {
    ($($t:ty)*) => ($(
        #[stable(feature = "rust1", since = "1.0.0")]
        impl Add for $t {
            type Output = $t;

            #[inline]
            #[rustc_inherit_overflow_checks]
            fn add(self, other: $t) -> $t { self + other }
        }

        forward_ref_binop! { impl Add, add for $t, $t }
    )*)
}

@Mark-Simulacrum Mark-Simulacrum added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jul 28, 2018
@Mark-Simulacrum
Copy link
Member

Performance of compile times and run times was gathered based on #62095 but no measureable difference whether inline(always) is applied or not could be determined, so I'm closing this issue.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
…icola

Increase defalt chalk overflow depth to match max solver size

TBC:

 - rust-lang#12279: ok above 480
 - ~~rust-lang#12182~~
 - ~~rust-lang#12095~~
 - rust-lang#11902: ok above 350
 - ~~rust-lang#11668~~
 - rust-lang#11370: ok above 450
 - rust-lang#9754: probably ok above 250 (!), and the code in cause and branch are gone

Closes rust-lang#12279
Closes rust-lang#11902
Closes rust-lang#11370
Closes rust-lang#9754
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 26, 2024
Fix: no_effect_underscore_binding fires on ignored parameters of async fns

Fixes rust-lang#12279
changelog: Fix [`no_effect_underscore_binding`])

The warning is no longer displayed when an underscore is given in the parameter name of an asynchronous function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants