-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ 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()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())
}
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
cc #65664 (need to read before reviewing this) |
☀️ Try build successful - checks-azure |
Queued d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d with parent c553e8e, future comparison URL. |
Finished benchmarking try commit d9ee820ba4b43bd12ef85454cdcd7d55f2763b6d, comparison URL. |
Looks like it fixed the regression, and comparing before the original PR to after this change agrees. |
@bors r+ |
📌 Commit 49f9626 has been approved by |
// 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
…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
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
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 wayfile!()
/line!()
are, it needs to have the same behavior (of extracting the macro invocation siteSpan
and using that).Arguably we would've had to do this at some point anyway, if we want to use
#[track_caller]
to replace thefile!()
/line!()
uses from macros, but I'm not sure the RFC mentions this at all.r? @petrochenkov cc @anp @nnethercote