-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix Iter exhaustion in prove_predicates when debug is on #50076
Conversation
@@ -1534,16 +1534,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | |||
predicates: impl IntoIterator<Item = ty::Predicate<'tcx>>, | |||
location: Location, | |||
) { | |||
let mut predicates_iter = predicates.into_iter(); | |||
let predicates_vec = predicates.into_iter().by_ref().collect::<Vec<_>>(); |
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.
yikes, this seems excessive. why not just duplicate the iterator?
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.
that was the first thing I've tried but I can't ...
error[E0599]: no method named `clone` found for type `impl IntoIterator<Item = ty::Predicate<'tcx>>` in the current scope
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.
We were talking with @pnkfelix to maybe do that thing only in the debug case and avoid the extra cost when debug is off. He said that it may not worth, I'm ok with changing this to whatever is better :).
In fact, I don't see why making this function take an iterator is better - I think just reverting 0e2e179 is the right thing here 🤷♂️ |
@tamird yeah we were originally discussing this with @nikomatsakis and agreed to move that to an iterator. I agree with you now though that reverting would be better. |
5c05ba9
to
8dfa4b5
Compare
Ok, changed the commit in this PR to a revert + a fix to another call to prove_predicates that arrived in another commit. |
I have a slightly nicer patch, but I won't lie, it took some battles with the compiler. The TL;DR is that you want diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index acd246b703..e9c86ea99b 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -275,7 +275,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
tcx.predicates_of(def_id).instantiate(tcx, substs);
let predicates =
type_checker.normalize(&instantiated_predicates.predicates, location);
- type_checker.prove_predicates(predicates.iter().cloned(), location);
+ type_checker.prove_predicates(predicates, location);
}
value.ty
@@ -1516,34 +1516,33 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
let predicates = self.normalize(&instantiated_predicates.predicates, location);
debug!("prove_aggregate_predicates: predicates={:?}", predicates);
- self.prove_predicates(predicates.iter().cloned(), location);
+ self.prove_predicates(predicates, location);
}
fn prove_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>, location: Location) {
self.prove_predicates(
- [ty::Predicate::Trait(
+ Some(ty::Predicate::Trait(
trait_ref.to_poly_trait_ref().to_poly_trait_predicate(),
- )].iter()
- .cloned(),
+ )),
location,
);
}
- fn prove_predicates(
- &mut self,
- predicates: impl IntoIterator<Item = ty::Predicate<'tcx>>,
- location: Location,
- ) {
- let mut predicates_iter = predicates.into_iter();
+ fn prove_predicates<T>(&mut self, predicates: T, location: Location)
+ where T: IntoIterator<Item = ty::Predicate<'tcx>>,
+ T::IntoIter: Clone,
+ {
+ let predicates = predicates.into_iter();
debug!(
"prove_predicates(predicates={:?}, location={:?})",
- predicates_iter.by_ref().collect::<Vec<_>>(),
- location
+ predicates.clone().collect::<Vec<_>>(),
+ location,
);
self.fully_perform_op(location.at_self(), |this| {
let cause = this.misc(this.last_span);
- let obligations = predicates_iter
+ let obligations = predicates
+ .into_iter()
.map(|p| traits::Obligation::new(cause.clone(), this.param_env, p))
.collect();
Ok(InferOk {
Feel free to use this, or lmk and I'll open a new PR. |
Very nice trick @tamird |
4283cb0
to
3271608
Compare
pushed again, thanks @tamird |
fn prove_predicates<T>(&mut self, predicates: T, location: Location) | ||
where | ||
T: IntoIterator<Item = ty::Predicate<'tcx>>, | ||
T::IntoIter: Iterator + Clone, |
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: I updated my diff after posting; this can just be Clone
; Iterator
is implied by IntoIterator
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.
Done!
3271608
to
55054ee
Compare
} | ||
|
||
fn prove_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>, location: Location) { | ||
self.prove_predicates( | ||
[ty::Predicate::Trait( | ||
Some(ty::Predicate::Trait( |
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.
FYI changing this to Option
can be reverted when/if #49000 is merged.
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.
👍
@bors r+ |
📌 Commit 55054ee has been approved by |
⌛ Testing commit 55054ee with merge b12e96f3cc3875b0ec5cc183b5fbd5fc9981330f... |
💔 Test failed - status-appveyor |
Looks like a spurious linking failure. |
Fix Iter exhaustion in prove_predicates when debug is on Fixes the issue noted in this comment https://github.com/rust-lang/rust/pull/49885/files#r182560268 r? @pnkfelix /cc @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Fixes the issue noted in this comment https://github.com/rust-lang/rust/pull/49885/files#r182560268
r? @pnkfelix
/cc @nikomatsakis