polymorphize: polymorphize shims

This commit removes the restriction of `InstanceDef::Item` on
polymorphization, so that shims can now be polymorphized.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2021-10-01 17:08:06 +00:00
parent 4528b8e581
commit 76b05531ca
7 changed files with 112 additions and 61 deletions

View file

@ -936,21 +936,13 @@ fn visit_instance_use<'tcx>(
}
}
// Returns `true` if we should codegen an instance in the local crate.
// Returns `false` if we can just link to the upstream crate and therefore don't
// need a mono item.
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
/// can just link to the upstream crate and therefore don't need a mono item.
fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> bool {
let def_id = match instance.def {
ty::InstanceDef::Item(def) => def.did,
ty::InstanceDef::DropGlue(def_id, Some(_)) => def_id,
ty::InstanceDef::VtableShim(..)
| ty::InstanceDef::ReifyShim(..)
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::Virtual(..)
| ty::InstanceDef::FnPtrShim(..)
| ty::InstanceDef::DropGlue(..)
| ty::InstanceDef::Intrinsic(_)
| ty::InstanceDef::CloneShim(..) => return true,
let def_id = if let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() {
def_id
} else {
return true;
};
if tcx.is_foreign_item(def_id) {