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:
parent
303d8aff60
commit
bee151308d
7 changed files with 103 additions and 84 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue