Rollup merge of #109109 - compiler-errors:polymorphize-foreign, r=Nilstrieb
Use `unused_generic_params` from crate metadata Due to the way that `separate_provide_extern` interacted with the implementation of `<ty::InstanceDef<'tcx> as Key>::query_crate_is_local`, we actually never hit the foreign provider for `unused_generic_params`. Additionally, since the *local* provider of `unused_generic_params` calls `should_polymorphize`, which always returns false if the def-id is foreign, this means that we never actually polymorphize monomorphic instances originating from foreign crates. We don't actually encode `unused_generic_params` for items where all generics are used, so I had to tweak the foreign provider to fall back to `ty::UnusedGenericParams::new_all_used()` to avoid more ICEs when the above bugs were fixed.
This commit is contained in:
commit
2aa3eea5fc
@ -226,7 +226,15 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
lookup_default_body_stability => { table }
|
||||
lookup_deprecation_entry => { table }
|
||||
params_in_repr => { table }
|
||||
unused_generic_params => { table }
|
||||
// FIXME: Could be defaulted, but `LazyValue<UnusedGenericParams>` is not `FixedSizeEncoding`..
|
||||
unused_generic_params => {
|
||||
cdata
|
||||
.root
|
||||
.tables
|
||||
.unused_generic_params
|
||||
.get(cdata, def_id.index)
|
||||
.map_or_else(|| ty::UnusedGenericParams::new_all_used(), |lazy| lazy.decode((cdata, tcx)))
|
||||
}
|
||||
opt_def_kind => { table_direct }
|
||||
impl_parent => { table }
|
||||
impl_polarity => { table_direct }
|
||||
|
@ -63,7 +63,7 @@ impl<'tcx> Key for ty::InstanceDef<'tcx> {
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
self.def_id().is_local()
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
@ -76,7 +76,7 @@ impl<'tcx> Key for ty::Instance<'tcx> {
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
self.def_id().is_local()
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
@ -36,6 +36,8 @@ fn unused_generic_params<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: ty::InstanceDef<'tcx>,
|
||||
) -> UnusedGenericParams {
|
||||
assert!(instance.def_id().is_local());
|
||||
|
||||
if !tcx.sess.opts.unstable_opts.polymorphize {
|
||||
// If polymorphization disabled, then all parameters are used.
|
||||
return UnusedGenericParams::new_all_used();
|
||||
@ -100,13 +102,6 @@ fn should_polymorphize<'tcx>(
|
||||
return false;
|
||||
}
|
||||
|
||||
// Polymorphization results are stored in cross-crate metadata only when there are unused
|
||||
// parameters, so assume that non-local items must have only used parameters (else this query
|
||||
// would not be invoked, and the cross-crate metadata used instead).
|
||||
if !def_id.is_local() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Foreign items have no bodies to analyze.
|
||||
if tcx.is_foreign_item(def_id) {
|
||||
return false;
|
||||
|
@ -0,0 +1,4 @@
|
||||
// compile-flags: -Zpolymorphize=on
|
||||
|
||||
#[inline(never)]
|
||||
pub fn foo<T>() {}
|
11
tests/codegen-units/polymorphization/poly-foreign.rs
Normal file
11
tests/codegen-units/polymorphization/poly-foreign.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// aux-build:poly-dep.rs
|
||||
// compile-flags: --crate-type=lib -Zprint-mono-items=eager -Zpolymorphize=on
|
||||
|
||||
extern crate poly_dep;
|
||||
|
||||
pub static FN1: fn() = poly_dep::foo::<i32>;
|
||||
pub static FN2: fn() = poly_dep::foo::<u32>;
|
||||
|
||||
//~ MONO_ITEM static FN1
|
||||
//~ MONO_ITEM static FN2
|
||||
//~ MONO_ITEM fn poly_dep::foo::<T>
|
Loading…
Reference in New Issue
Block a user