codegen/mir: support polymorphic InstanceDefs

This commit modifies the use of `subst_and_normalize_erasing_regions` on
parts of the MIR bodies returned from `instance_mir`, so that
`InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a
type) do not perform substitutions. This avoids double substitutions and
enables polymorphic `InstanceDef`s.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood 2020-03-11 19:36:07 +00:00
parent 303d8aff60
commit bee151308d
No known key found for this signature in database
GPG key ID: 2592E76C87381FD9
7 changed files with 103 additions and 84 deletions

View file

@ -86,13 +86,18 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn monomorphize<T>(&self, value: &T) -> T
where
T: TypeFoldable<'tcx>,
T: Copy + TypeFoldable<'tcx>,
{
self.cx.tcx().subst_and_normalize_erasing_regions(
self.instance.substs,
ty::ParamEnv::reveal_all(),
value,
)
debug!("monomorphize: self.instance={:?}", self.instance);
if let Some(substs) = self.instance.substs_for_mir_body() {
self.cx.tcx().subst_and_normalize_erasing_regions(
substs,
ty::ParamEnv::reveal_all(),
&value,
)
} else {
self.cx.tcx().normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
}
}
}