instance: avoid unnecessary mk_ calls

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>
This commit is contained in:
David Wood 2020-08-07 17:51:40 +01:00
parent 5827b5a4bd
commit 4ccaf6f38c
No known key found for this signature in database
GPG key ID: 2592E76C87381FD9

View file

@ -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),
}