-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Clone region var origins instead of taking them in borrowck #109753
Clone region var origins instead of taking them in borrowck #109753
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Grr, meant to |
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.
nit
r=me afterwards
.as_mut() | ||
.expect("region constraints already solved") | ||
// Replace region constraints if they've been taken. | ||
// This should only happen on an error path, so delay a bug. |
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 should only happen on an error path, so delay a bug. | |
// This should only happen on an error path, so delay a bug. | |
// | |
// This is only allowed so one can use the existing inference | |
// context for diagnostics. |
.get_or_insert_with(|| { | ||
ty::tls::with(|tcx| { | ||
tcx.sess.delay_span_bug(DUMMY_SP, "region constraints already solved"); | ||
}); | ||
RegionConstraintStorage::default() | ||
}) |
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 don't think RegionConstraintStorage::default()
is a sane value. This resets the region variables counter and thus nullifies the whole point of using the existing InferCtxt.
How about changing InferCtxt::take_region_var_origins
to clone region VarInfos instead of removing them? and probably using better name for it.
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.
Maybe we can keep it named take_
name, but set some flag that the infos have been taken, and delay a bug if we try to take them again or try to borrow them again?
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.
Mm, I have no strong opinion here, but I don't like delaying a bug in InferCtxt. I prefer the code there to be independent from the compilation session as much as possible.
Changing take_region_var_infos
is unfortunate as it would no longer guard against future addition of region constraints, but I think it's the best option here given that it's used only once in borrowck and we don't expect users of InferCtxt to implement their own region resolution.
☔ The latest upstream changes (presumably #109849) made this pull request unmergeable. Please resolve the merge conflicts. |
4e1c9b3
to
08101d6
Compare
Ok, took the alternative approach. @rustbot ready |
08101d6
to
3d604ea
Compare
/// `resolve_regions_and_report_errors` is invoked, this gets set to `None` | ||
/// -- further attempts to perform unification, etc., may fail if new | ||
/// region constraints would've been added. | ||
region_constraint_storage: Option<RegionConstraintStorage<'tcx>>, |
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 think it's worth keeping this Option
and clearing it in InferCtxt::{resolve_regions,skip_region_resolution} . This way limit this hack to MIR borrowck, rather that lexical region resolver which is more commonly used.
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.
r? @aliemjay
looks good. r=me with or without the previous nit.
3d604ea
to
72ffa11
Compare
InferCtxt::probe
is called after resolve_regions
Ok, changed it back to @bors r=aliemjay |
📌 Commit 72ffa1160aab7b92a20260c3bbe651119935952e has been approved by It is now in the queue for this repository. |
☔ The latest upstream changes (presumably #110458) made this pull request unmergeable. Please resolve the merge conflicts. |
72ffa11
to
964600b
Compare
Rebased @bors r=aliemjay |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4396cec): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
…r=compiler-errors Fix comment for `get_region_var_origins` rust-lang#109753 changed the logic but not the comment. r? `@compiler-errors`
Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls
InferCtxt::evaluate_obligation
.This also removes a handful of unnecessary
tcx.infer_ctxt().build()
calls that are only there to mitigate this same exact issue, but with the old solver.Fixes compiler-errors/next-solver-hir-issues#12.
This implements @aliemjay's solution where we just don't take the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.