Skip to content

Commit

Permalink
instance: avoid unnecessary mk_ calls
Browse files Browse the repository at this point in the history
This commit avoids unnecessary calls to `mk_closure` and `mk_generator`
by checking if the polymorphized substs match the original substs.

Signed-off-by: David Wood <david@davidtw.co>
  • Loading branch information
davidtwco committed Aug 7, 2020
1 parent 5827b5a commit 4ccaf6f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/librustc_middle/ty/instance.rs
Expand Up @@ -506,11 +506,19 @@ fn polymorphize<'tcx>(
match ty.kind {
ty::Closure(def_id, substs) => {
let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
self.tcx.mk_closure(def_id, polymorphized_substs)
if substs == polymorphized_substs {
ty
} else {
self.tcx.mk_closure(def_id, polymorphized_substs)
}
}
ty::Generator(def_id, substs, movability) => {
let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
self.tcx.mk_generator(def_id, polymorphized_substs, movability)
if substs == polymorphized_substs {
ty
} else {
self.tcx.mk_generator(def_id, polymorphized_substs, movability)
}
}
_ => ty.super_fold_with(self),
}
Expand Down

0 comments on commit 4ccaf6f

Please sign in to comment.