Skip to content

Commit b39e915

Browse files
committed
polymorphize: don't normalize self-ty need substs
`characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function, resulting in an ICE in the 'generic-names' debuginfo test. If partitioning is enabled and the instance needs substitution then this is now skipped. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 76b0553 commit b39e915

File tree

1 file changed

+16
-9
lines changed
  • compiler/rustc_monomorphize/src/partitioning

1 file changed

+16
-9
lines changed

compiler/rustc_monomorphize/src/partitioning/default.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::middle::exported_symbols::SymbolExportLevel;
99
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility};
1010
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
1111
use rustc_middle::ty::print::characteristic_def_id_of_type;
12-
use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
12+
use rustc_middle::ty::{self, fold::TypeFoldable, DefIdTree, InstanceDef, TyCtxt};
1313
use rustc_span::symbol::Symbol;
1414

1515
use super::PartitioningCx;
@@ -300,14 +300,21 @@ fn characteristic_def_id_of_mono_item<'tcx>(
300300
// call it.
301301
return None;
302302
}
303-
// This is a method within an impl, find out what the self-type is:
304-
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
305-
instance.substs,
306-
ty::ParamEnv::reveal_all(),
307-
tcx.type_of(impl_def_id),
308-
);
309-
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
310-
return Some(def_id);
303+
304+
// When polymorphization is enabled, methods which do not depend on their generic
305+
// parameters, but the self-type of their impl block do will fail to normalize.
306+
if !tcx.sess.opts.debugging_opts.polymorphize
307+
|| !instance.definitely_needs_subst(tcx)
308+
{
309+
// This is a method within an impl, find out what the self-type is:
310+
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
311+
instance.substs,
312+
ty::ParamEnv::reveal_all(),
313+
tcx.type_of(impl_def_id),
314+
);
315+
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
316+
return Some(def_id);
317+
}
311318
}
312319
}
313320

0 commit comments

Comments
 (0)