Skip to content

Commit 26fc8e3

Browse files
committed
Trim set of candidates.
1 parent 6d86473 commit 26fc8e3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,27 @@ impl<'tcx> Candidates<'tcx> {
464464
appears_in_index: DenseBitSet::new_empty(body.local_decls.len()),
465465
};
466466
visitor.visit_body(body);
467+
let FindAssignments { mut candidates, appears_in_index, .. } = visitor;
468+
469+
// Allowing to merge with an arbitrary place creates a lot of candidates.
470+
// Trim the set a little before trying to apply them.
471+
candidates.retain(|&(s, d)| {
472+
let s_required = is_local_required(s, body);
473+
let d_required = is_local_required(d.local, body);
474+
if s_required && d_required {
475+
// We cannot merge locals if both are required.
476+
return false;
477+
}
478+
if !d.projection.is_empty() && (s_required || appears_in_index.contains(s)) {
479+
// We cannot merge a projection with a local that needs to remain bare.
480+
return false;
481+
}
482+
true
483+
});
467484

468-
visitor.candidates.sort_by_key(|&(s, d)| (s, d.local, d.projection.len()));
485+
candidates.sort_by_key(|&(s, d)| (s, d.local, d.projection.len()));
469486

470-
Candidates { c: visitor.candidates, appears_in_index: visitor.appears_in_index }
487+
Candidates { c: candidates, appears_in_index }
471488
}
472489
}
473490

0 commit comments

Comments
 (0)