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

Add #[track_caller] to the "From implies Into" impl #119807

Merged
merged 1 commit into from Jan 21, 2024

Conversation

Emilgardis
Copy link
Contributor

@Emilgardis Emilgardis commented Jan 10, 2024

This pr implements what was mentioned in #77474 (comment)

This follows from my URLO https://users.rust-lang.org/t/104497

#![allow(warnings)]
fn main() {
    // Gives a good location
    let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into()));

    // still doesn't work, gives location of `FnOnce::call_once()`
    let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into));
}

#[derive(Debug)]
pub struct Loc {
    pub l: &'static std::panic::Location<'static>,
}

impl From<()> for Loc {
    #[track_caller]
    fn from(_: ()) -> Self {
        Loc {
            l: std::panic::Location::caller(),
        }
    }
}

@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2024

r? @joshtriplett

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 10, 2024
@Emilgardis
Copy link
Contributor Author

Emilgardis commented Jan 10, 2024

This is a tiny but huge change, so probably needs a perf run if this ever is accepted, as mentioned earlier.

@fmease
Copy link
Member

fmease commented Jan 10, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 10, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 10, 2024
…to, r=<try>

Add `#[track_caller]` to the "From implies Into" impl

This pr implements what was mentioned in rust-lang#77474 (comment)

This follows from my URLO https://users.rust-lang.org/t/104497

```rust
#![allow(warnings)]
fn main() {
    // Gives a good location
    let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into()));

    // still doesn't work, gives location of `FnOnce::call_once()`
    let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into));
}

#[derive(Debug)]
pub struct Loc {
    pub l: &'static std::panic::Location<'static>,
}

impl From<()> for Loc {
    #[track_caller]
    fn from(_: ()) -> Self {
        Loc {
            l: std::panic::Location::caller(),
        }
    }
}
```
@bors
Copy link
Contributor

bors commented Jan 10, 2024

⌛ Trying commit 075f2e0 with merge 902a98b...

@bors
Copy link
Contributor

bors commented Jan 10, 2024

☀️ Try build successful - checks-actions
Build commit: 902a98b (902a98b337af1a2df4a8520fa7ca0eb92a5513de)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (902a98b): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.7% [0.5%, 1.0%] 3
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 2
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-1.0%, 1.0%] 4

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-0.6%, -0.6%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 666.26s -> 665.429s (-0.12%)
Artifact size: 308.39 MiB -> 308.40 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 10, 2024
@Emilgardis
Copy link
Contributor Author

Is that enough to validate this atleast? Don't know how many calls that are affected are hit in the runs, would it maybe be possible/needed to crater + perf instruction count?

@Nilstrieb
Copy link
Member

We will almost certainly get inlining here in one direction, either inlining from into into or if that doesn't happen, inlining into into the caller (or probably in many cases, both). Due to this, I don't expect this to have a large a overhead, track_caller is just a single pointer argument after all, which will be a lot smaller compared to the from impl (and if the from impl is small, then everything will be inlined and there won't be any overhead from track_caller).
rustc-perf agrees with this assessment, so I'm going to approve this. If anyone finds this to be a performance problem (which seems unlikely to me), we can always revert it.
@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jan 21, 2024

📌 Commit 075f2e0 has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 21, 2024
@bors
Copy link
Contributor

bors commented Jan 21, 2024

⌛ Testing commit 075f2e0 with merge d9d89fd...

@bors
Copy link
Contributor

bors commented Jan 21, 2024

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing d9d89fd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 21, 2024
@bors bors merged commit d9d89fd into rust-lang:master Jan 21, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 21, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d9d89fd): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.4%, 0.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
-2.6% [-3.8%, -1.4%] 2
All ❌✅ (primary) -2.8% [-2.8%, -2.8%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 663.269s -> 662.236s (-0.16%)
Artifact size: 308.35 MiB -> 308.38 MiB (0.01%)

@Emilgardis Emilgardis deleted the track_caller_from_impl_into branch January 21, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants