-
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
Future-proof MIR for dedicated debuginfo. #56278
Conversation
b4c1d38
to
58ff04b
Compare
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.
these changes look fine, though I'd be happier if we could make some nice queries for getting info about the Nth upvar of a closure, so that the code would be a bit cleaner
src/librustc_mir/borrow_check/mod.rs
Outdated
@@ -141,6 +142,40 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( | |||
.as_local_node_id(def_id) | |||
.expect("do_mir_borrowck: non-local DefId"); | |||
|
|||
// Gather the upvars of a closure, if any. | |||
let upvars: Vec<_> = tcx.with_freevars(id, |freevars| { |
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.
This really feels like information that could be encoded in the MIR, no? Well, I guess I can see an argument both ways.
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.
At minimum I would prefer if we can factor it out from borrow check into some kind of helper table that would be more re-usable.
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 I don't know that I want to block the PR on it. In general I feel like the borrow check code is kind of noodly and could use some extractions of this kind.
src/librustc/mir/mod.rs
Outdated
/// Mark an argument local (which must be a tuple) as getting passed as | ||
/// its individual components at the LLVM level. | ||
/// | ||
/// This is used for the "rust-call" ABI. | ||
pub spread_arg: Option<Local>, | ||
|
||
/// Names and capture modes of all the closure upvars, assuming | ||
/// the first argument is either the closure or a reference to it. | ||
pub upvar_decls: Vec<UpvarDecl>, |
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 that if there are fields that are "debuginfo" that you feel other people should not rely on, we should comment that =)
(Like this one, judging from previous commit)
PathElem::ClosureVar(Symbol::intern(&field.to_string())) | ||
let mut name = None; | ||
if let Some(node_id) = self.ecx.tcx.hir.as_local_node_id(def_id) { | ||
self.ecx.tcx.with_freevars(node_id, |freevars| { |
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 wonder if this has any overlap with the borrow check code I was noting earlier? (i.e., if some common helper could make both of these more concise)
// debuginfo generation, and will be removed at some point. | ||
// Do **NOT** use it for anything else, upvar information should not be | ||
// in the MIR, please rely on local crate HIR or other side-channels. | ||
pub __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>, |
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.
lol ok I guess that addresses my earlier concern
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 would like this to be part of the doc comment please though, why use only //
?
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 got used to only using //
for NOTE/FIXME/HACK, but I'll go change it.
src/librustc_mir/borrow_check/mod.rs
Outdated
@@ -2208,3 +2277,15 @@ impl ContextKind { | |||
} | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
crate struct Upvar { |
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.
Yeah I think I would prefer to see closure_upvars(def_id, n) -> Upvar
that returns this information "nicely collected".... (or closure_upvars(def_id) -> &[Upvar]
).
But I won't hold up the PR on it.
r=me, depending on how you feel @eddyb
☔ The latest upstream changes (presumably #56198) made this pull request unmergeable. Please resolve the merge conflicts. |
Triage; @eddyb Hello, have you been able to get back to this PR? |
Triage; @eddyb Hello again, have you been able to get back to this PR? |
Ping from triage @eddyb: What is the status of this PR? |
ping from triage @eddyb Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
I've started rebasing this, I'll try to get it merged next week. |
58ff04b
to
2b546c4
Compare
I think I want to get rid of |
☔ The latest upstream changes (presumably #56113) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @eddyb any updates? you have conflicts to resolve |
Regarding #56278 (comment), the rust/src/librustc_mir/build/mod.rs Lines 628 to 640 in e4e032a
|
2b546c4
to
b6055ef
Compare
…info_upvar_ops_sequence.
b6055ef
to
c3ca9a3
Compare
@bors r=nikomatsakis |
📌 Commit c3ca9a3 has been approved by |
mir.local_decls[*borrowed_local].visibility_scope; | ||
|
||
if mir.is_sub_scope(borrowed_local_scope, dropped_local_scope) | ||
if mir.local_decls[*borrowed_local].name.is_some() |
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.
Why isn't this checking is_user_variable
?
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.
Oh, looks like is_user_variable
is newer than this PR originally, and is actually part of the set of things I meant to review at some point.
…tsakis Future-proof MIR for dedicated debuginfo. This is rust-lang#56231 without the last commit (the one that actually moves to `VarDebuginfo`). Nothing should be broken, but it should no longer depend on debuginfo for anything else. r? @nikomatsakis
⌛ Testing commit c3ca9a3 with merge d101749a5366c81e052027e957d90b7430566438... |
…tsakis Future-proof MIR for dedicated debuginfo. This is rust-lang#56231 without the last commit (the one that actually moves to `VarDebuginfo`). Nothing should be broken, but it should no longer depend on debuginfo for anything else. r? @nikomatsakis
@bors retry |
Rollup of 5 pull requests Successful merges: - #56278 (Future-proof MIR for dedicated debuginfo.) - #59739 (Stabilize futures_api) - #59822 (Fix dark css rule) - #60186 (Temporarily accept [i|u][32|size] suffixes on a tuple index and warn) - #60190 (Don't generate unnecessary rmeta files.) Failed merges: r? @ghost
This is #56231 without the last commit (the one that actually moves to
VarDebuginfo
).Nothing should be broken, but it should no longer depend on debuginfo for anything else.
r? @nikomatsakis