Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove some allocations in predicate evaluation
  • Loading branch information
estebank committed Apr 20, 2020
commit e7e3001557cc9a2e13bce599e374b474392eb779
7 changes: 3 additions & 4 deletions src/librustc_infer/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,20 @@ impl Elaborator<'tcx> {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());

let obligations = predicates.predicates.iter().map(|(pred, span)| {
let obligations = predicates.predicates.into_iter().map(|(pred, span)| {
predicate_obligation(
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
Some(*span),
)
});
debug!("super_predicates: data={:?} predicates={:?}", data, &obligations);
debug!("super_predicates: data={:?}", data);

// Only keep those bounds that we haven't already seen.
// This is necessary to prevent infinite recursion in some
// cases. One common case is when people define
// `trait Sized: Sized { }` rather than `trait Sized { }`.
let visited = &mut self.visited;
let obligations =
obligations.filter(|obligation| visited.insert(&obligation.predicate));
let obligations = obligations.filter(|o| visited.insert(&o.predicate));

self.stack.extend(obligations);
}
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_trait_selection/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl AutoTraitFinder<'tcx> {
},
}));

let mut computed_preds: FxHashSet<_> = param_env.caller_bounds.iter().cloned().collect();
let computed_preds = param_env.caller_bounds.iter().cloned();
let mut user_computed_preds: FxHashSet<_> =
user_env.caller_bounds.iter().cloned().collect();

Expand Down Expand Up @@ -358,9 +358,11 @@ impl AutoTraitFinder<'tcx> {
_ => panic!("Unexpected error for '{:?}': {:?}", ty, result),
};

computed_preds.extend(user_computed_preds.iter().cloned());
let normalized_preds =
elaborate_predicates(tcx, computed_preds.iter().cloned()).map(|o| o.predicate);
let normalized_preds = elaborate_predicates(
tcx,
computed_preds.clone().chain(user_computed_preds.iter().cloned()),
)
.map(|o| o.predicate);
new_env =
ty::ParamEnv::new(tcx.mk_predicates(normalized_preds), param_env.reveal, None);
}
Expand Down Expand Up @@ -738,7 +740,7 @@ impl AutoTraitFinder<'tcx> {
if p.ty().skip_binder().has_infer_types() {
if !self.evaluate_nested_obligations(
ty,
v.clone().iter().cloned(),
v.into_iter(),
computed_preds,
fresh_preds,
predicates,
Expand Down