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

caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!. #65973

Merged
merged 2 commits into from
Nov 6, 2019

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Oct 30, 2019

The main change here is to core::panic!, trying to fix this remaining regression: #65927 (comment)

However, in order for caller_location to be usable from macros the same way file!()/line!() are, it needs to have the same behavior (of extracting the macro invocation site Span and using that).

Arguably we would've had to do this at some point anyway, if we want to use #[track_caller] to replace the file!()/line!() uses from macros, but I'm not sure the RFC mentions this at all.

r? @petrochenkov cc @anp @nnethercote

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 30, 2019
@eddyb
Copy link
Member Author

eddyb commented Oct 30, 2019

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 30, 2019

⌛ Trying commit 49f9626 with merge d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d...

@@ -98,7 +98,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
match intrinsic_name {
"caller_location" => {
let caller = self.tcx.sess.source_map().lookup_char_pos(span.lo());
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we de-dup this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could pass Span into the query, but @anp ran into trouble with that, I think the result was ICEs from the incremental system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do:

fn caller(&self, span: Span) -> Whatever {
    let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
    self.sess.source_map().lookup_char_pos(topmost.lo())
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would you put this? Also, "caller" is misleading, in fact the name of caller_location is suboptimal (likely due to the RFC assuming an implementation strategy less versatile than the one being followed by @anp).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb I think you are taking the snippet too literally; rename it to anything you see fit. It would be placed on TyCtxt -- it could also be placed on SourceMap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, like, there is little generality in it. It's literally "caller_location helper" if it does those two things, and that doesn't feel right to put anywhere outside the query for it (which, again, would ideally take Span).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, but it does make sure the logics don't grow apart. I guess we'll have to ensure that through reviews instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW "you could just do" is my least favorite way to phrase review feedback.

@eddyb is correct that I had ICEs when using a Span as a parameter to a query. I agree with them that two callsites does not a need for deduplication make (yet).

@petrochenkov
Copy link
Contributor

cc #65664 (need to read before reviewing this)

@bors
Copy link
Contributor

bors commented Oct 30, 2019

☀️ Try build successful - checks-azure
Build commit: d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d (d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d)

@rust-timer
Copy link
Collaborator

Queued d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d with parent c553e8e, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d, comparison URL.

@eddyb
Copy link
Member Author

eddyb commented Oct 31, 2019

Looks like it fixed the regression, and comparing before the original PR to after this change agrees.

@Centril Centril added the F-track_caller `#![feature(track_caller)]` label Nov 1, 2019
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2019

📌 Commit 49f9626 has been approved by petrochenkov

@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 Nov 3, 2019
// the `caller_location` intrinsic, but once `#[track_caller]` is implemented,
// `panicking::{panic, panic_fmt}` can use that instead of a `Location` argument.
core_intrinsics,
)]
#[stable(feature = "core", since = "1.6.0")]
macro_rules! panic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I think a previous PR forgot to change the macro in libstd (which is not the same as the one in libcore). cc @anp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anp told me it was intentional, as they use different entry-points, and we can probably wait to have full #[track_caller] before changing libstd.

Centril added a commit to Centril/rust that referenced this pull request Nov 6, 2019
…ochenkov

caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.

The main change here is to `core::panic!`, trying to fix this remaining regression: rust-lang#65927 (comment)

However, in order for `caller_location` to be usable from macros the same way `file!()`/`line!()` are, it needs to have the same behavior (of extracting the macro invocation site `Span` and using that).

Arguably we would've had to do this at some point anyway, if we want to use `#[track_caller]` to replace the `file!()`/`line!()` uses from macros, but I'm not sure the RFC mentions this at all.

r? @petrochenkov cc @anp @nnethercote
bors added a commit that referenced this pull request Nov 6, 2019
Rollup of 9 pull requests

Successful merges:

 - #65776 (Rename `LocalInternedString` and more)
 - #65973 (caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.)
 - #66015 (librustc_lexer: Refactor the module)
 - #66062 (Configure LLVM module PIC level)
 - #66086 (bump smallvec to 1.0)
 - #66092 (Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.)
 - #66103 (Add target thumbv7neon-unknown-linux-musleabihf)
 - #66133 (Update the bundled `wasi-libc` repository)
 - #66139 (use American spelling for `pluralize!`)

Failed merges:

r? @ghost
@bors bors merged commit 49f9626 into rust-lang:master Nov 6, 2019
@eddyb eddyb deleted the caller-location-panic branch November 6, 2019 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-track_caller `#![feature(track_caller)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants