Do not fetch HIR to monomorphize impls.
This commit is contained in:
parent
facecf6e1b
commit
0d39f9d94d
1 changed files with 44 additions and 74 deletions
|
@ -1191,28 +1191,14 @@ impl<'v> RootCollector<'_, 'v> {
|
||||||
fn process_item(&mut self, id: hir::ItemId) {
|
fn process_item(&mut self, id: hir::ItemId) {
|
||||||
match self.tcx.def_kind(id.owner_id) {
|
match self.tcx.def_kind(id.owner_id) {
|
||||||
DefKind::Enum | DefKind::Struct | DefKind::Union => {
|
DefKind::Enum | DefKind::Struct | DefKind::Union => {
|
||||||
let item = self.tcx.hir().item(id);
|
if self.tcx.generics_of(id.owner_id).count() == 0
|
||||||
match item.kind {
|
&& self.mode == MonoItemCollectionMode::Eager
|
||||||
hir::ItemKind::Enum(_, ref generics)
|
{
|
||||||
| hir::ItemKind::Struct(_, ref generics)
|
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
|
||||||
| hir::ItemKind::Union(_, ref generics) => {
|
|
||||||
if generics.params.is_empty() {
|
|
||||||
if self.mode == MonoItemCollectionMode::Eager {
|
|
||||||
debug!(
|
|
||||||
"RootCollector: ADT drop-glue for {}",
|
|
||||||
self.tcx.def_path_str(item.owner_id.to_def_id())
|
|
||||||
);
|
|
||||||
|
|
||||||
let ty = Instance::new(
|
let ty =
|
||||||
item.owner_id.to_def_id(),
|
self.tcx.bound_type_of(id.owner_id.to_def_id()).no_bound_vars().unwrap();
|
||||||
InternalSubsts::empty(),
|
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
|
||||||
)
|
|
||||||
.ty(self.tcx, ty::ParamEnv::reveal_all());
|
|
||||||
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => bug!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::GlobalAsm => {
|
DefKind::GlobalAsm => {
|
||||||
|
@ -1240,8 +1226,7 @@ impl<'v> RootCollector<'_, 'v> {
|
||||||
}
|
}
|
||||||
DefKind::Impl { .. } => {
|
DefKind::Impl { .. } => {
|
||||||
if self.mode == MonoItemCollectionMode::Eager {
|
if self.mode == MonoItemCollectionMode::Eager {
|
||||||
let item = self.tcx.hir().item(id);
|
create_mono_items_for_default_impls(self.tcx, id, self.output);
|
||||||
create_mono_items_for_default_impls(self.tcx, item, self.output);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::Fn => {
|
DefKind::Fn => {
|
||||||
|
@ -1326,66 +1311,51 @@ fn item_requires_monomorphization(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||||
generics.requires_monomorphization(tcx)
|
generics.requires_monomorphization(tcx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(tcx, output))]
|
||||||
fn create_mono_items_for_default_impls<'tcx>(
|
fn create_mono_items_for_default_impls<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
item: &'tcx hir::Item<'tcx>,
|
item: hir::ItemId,
|
||||||
output: &mut MonoItems<'tcx>,
|
output: &mut MonoItems<'tcx>,
|
||||||
) {
|
) {
|
||||||
match item.kind {
|
let polarity = tcx.impl_polarity(item.owner_id);
|
||||||
hir::ItemKind::Impl(ref impl_) => {
|
if matches!(polarity, ty::ImplPolarity::Negative) {
|
||||||
if matches!(impl_.polarity, hir::ImplPolarity::Negative(_)) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for param in impl_.generics.params {
|
if tcx.generics_of(item.owner_id).own_requires_monomorphization() {
|
||||||
match param.kind {
|
return;
|
||||||
hir::GenericParamKind::Lifetime { .. } => {}
|
}
|
||||||
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) else {
|
||||||
"create_mono_items_for_default_impls(item={})",
|
return;
|
||||||
tcx.def_path_str(item.owner_id.to_def_id())
|
};
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
let trait_ref = trait_ref.subst_identity();
|
||||||
let trait_ref = trait_ref.subst_identity();
|
|
||||||
|
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
let param_env = ty::ParamEnv::reveal_all();
|
||||||
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
||||||
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);
|
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);
|
||||||
for method in tcx.provided_trait_methods(trait_ref.def_id) {
|
for method in tcx.provided_trait_methods(trait_ref.def_id) {
|
||||||
if overridden_methods.contains_key(&method.def_id) {
|
if overridden_methods.contains_key(&method.def_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcx.generics_of(method.def_id).own_requires_monomorphization() {
|
if tcx.generics_of(method.def_id).own_requires_monomorphization() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let substs =
|
let substs = InternalSubsts::for_item(tcx, method.def_id, |param, _| match param.kind {
|
||||||
InternalSubsts::for_item(tcx, method.def_id, |param, _| match param.kind {
|
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
|
||||||
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
|
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
|
||||||
GenericParamDefKind::Type { .. }
|
trait_ref.substs[param.index as usize]
|
||||||
| GenericParamDefKind::Const { .. } => {
|
}
|
||||||
trait_ref.substs[param.index as usize]
|
});
|
||||||
}
|
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, substs);
|
||||||
});
|
|
||||||
let instance =
|
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
||||||
ty::Instance::expect_resolve(tcx, param_env, method.def_id, substs);
|
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, &instance) {
|
||||||
|
output.push(mono_item);
|
||||||
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
|
||||||
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, &instance)
|
|
||||||
{
|
|
||||||
output.push(mono_item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => bug!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue