Skip to content

Commit 5d91359

Browse files
committed
fix(upstream): add Unnormalized and skip_norm_wip
1 parent 0613084 commit 5d91359

5 files changed

Lines changed: 59 additions & 36 deletions

File tree

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mir/drop_shim.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ pub fn build_drop_shim<'tcx>(
4141
if let ty::Coroutine(gen_def_id, args) = ty.kind() {
4242
let body = cx.analysis_mir(*gen_def_id).coroutine_drop().unwrap();
4343
let body = EarlyBinder::bind(body.clone()).instantiate(cx.tcx, args);
44-
return body;
44+
return body.skip_norm_wip();
4545
}
4646

4747
let args = cx.mk_args(&[ty.into()]);
48-
let sig = cx.fn_sig(def_id).instantiate(cx.tcx, args);
48+
let sig = cx.fn_sig(def_id).instantiate(cx.tcx, args).skip_norm_wip();
4949
let sig = cx.instantiate_bound_regions_with_erased(sig);
5050
let span = cx.def_span(def_id);
5151

src/mir/elaborate_drop.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_index::Idx;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::adjustment::PointerCoercion;
1313
use rustc_middle::ty::util::IntTypeExt;
14-
use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt};
14+
use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt, Unnormalized};
1515
use rustc_middle::{span_bug, traits};
1616
use rustc_span::{DUMMY_SP, Spanned, dummy_spanned};
1717
use tracing::{debug, instrument};
@@ -304,7 +304,10 @@ where
304304
// Resolving async_drop_in_place<T> function for drop_ty
305305
let drop_fn_def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, span);
306306
let trait_args = tcx.mk_args(&[drop_ty.into()]);
307-
let sig = tcx.fn_sig(drop_fn_def_id).instantiate(tcx, trait_args);
307+
let sig = tcx
308+
.fn_sig(drop_fn_def_id)
309+
.instantiate(tcx, trait_args)
310+
.skip_norm_wip();
308311
let sig = tcx.instantiate_bound_regions_with_erased(sig);
309312
(sig.output(), drop_fn_def_id, trait_args)
310313
};
@@ -558,9 +561,10 @@ where
558561
bug!()
559562
}
560563
}
564+
let field_ty = field.ty(tcx, args);
561565
let field_ty = match tcx.try_normalize_erasing_regions(
562566
self.elaborator.typing_env(),
563-
field.ty(tcx, args),
567+
Unnormalized::new_wip(field_ty),
564568
) {
565569
Ok(t) => t,
566570
Err(_) => Ty::new_error(

src/monomorphize_collector.rs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
2929
use rustc_middle::ty::layout::ValidityRequirement;
3030
use rustc_middle::ty::{
3131
self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Ty, TyCtxt, TypeFoldable,
32-
TypeVisitableExt, VtblEntry,
32+
TypeVisitableExt, Unnormalized, VtblEntry,
3333
};
3434
use rustc_session::config::{DebugInfo, EntryFnType};
3535
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Spanned, dummy_spanned, respan};
@@ -960,10 +960,14 @@ pub fn find_tails_for_unsizing<'tcx>(
960960
};
961961
let coerce_field = &source_adt_def.non_enum_variant().fields[coerce_index];
962962
// We're getting a possibly unnormalized type, so normalize it.
963-
let source_field =
964-
tcx.normalize_erasing_regions(typing_env, coerce_field.ty(*tcx, source_args));
965-
let target_field =
966-
tcx.normalize_erasing_regions(typing_env, coerce_field.ty(*tcx, target_args));
963+
let source_field = tcx.normalize_erasing_regions(
964+
typing_env,
965+
Unnormalized::new_wip(coerce_field.ty(*tcx, source_args)),
966+
);
967+
let target_field = tcx.normalize_erasing_regions(
968+
typing_env,
969+
Unnormalized::new_wip(coerce_field.ty(*tcx, target_args)),
970+
);
967971
find_tails_for_unsizing(tcx, typing_env, source_field, target_field)
968972
}
969973
_ => bug!(
@@ -1320,7 +1324,8 @@ impl<'v> RootCollector<'_, 'v> {
13201324
let ty = self
13211325
.tcx
13221326
.type_of(id.owner_id.to_def_id())
1323-
.instantiate(self.tcx, id_args);
1327+
.instantiate(self.tcx, id_args)
1328+
.skip_norm_wip();
13241329
assert!(!ty.has_non_region_param());
13251330
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
13261331
}
@@ -1379,25 +1384,36 @@ impl<'v> RootCollector<'_, 'v> {
13791384
match self.tcx.def_kind(def_id) {
13801385
DefKind::Closure => {
13811386
// for 'pub async fn foo(..)' also trying to monomorphize foo::{closure}
1382-
let is_pub_fn_coroutine =
1383-
match *self.tcx.type_of(def_id).instantiate_identity().kind() {
1384-
ty::Coroutine(cor_id, _args) => {
1385-
let tcx = self.tcx;
1386-
let parent_id = tcx.parent(cor_id);
1387-
tcx.def_kind(parent_id) == DefKind::Fn
1388-
&& tcx.asyncness(parent_id).is_async()
1389-
&& tcx.visibility(parent_id).is_public()
1390-
}
1391-
ty::Closure(..) | ty::CoroutineClosure(..) => false,
1392-
_ => unreachable!(),
1393-
};
1387+
let is_pub_fn_coroutine = match *self
1388+
.tcx
1389+
.type_of(def_id)
1390+
.instantiate_identity()
1391+
.skip_norm_wip()
1392+
.kind()
1393+
{
1394+
ty::Coroutine(cor_id, _args) => {
1395+
let tcx = self.tcx;
1396+
let parent_id = tcx.parent(cor_id);
1397+
tcx.def_kind(parent_id) == DefKind::Fn
1398+
&& tcx.asyncness(parent_id).is_async()
1399+
&& tcx.visibility(parent_id).is_public()
1400+
}
1401+
ty::Closure(..) | ty::CoroutineClosure(..) => false,
1402+
_ => unreachable!(),
1403+
};
13941404
if (self.strategy == MonoItemCollectionStrategy::Eager || is_pub_fn_coroutine)
13951405
&& !self
13961406
.tcx
13971407
.generics_of(self.tcx.typeck_root_def_id(def_id.to_def_id()))
13981408
.requires_monomorphization(self.tcx)
13991409
{
1400-
let instance = match *self.tcx.type_of(def_id).instantiate_identity().kind() {
1410+
let instance = match *self
1411+
.tcx
1412+
.type_of(def_id)
1413+
.instantiate_identity()
1414+
.skip_norm_wip()
1415+
.kind()
1416+
{
14011417
ty::Closure(def_id, args)
14021418
| ty::Coroutine(def_id, args)
14031419
| ty::CoroutineClosure(def_id, args) => {
@@ -1407,7 +1423,7 @@ impl<'v> RootCollector<'_, 'v> {
14071423
};
14081424
let Ok(instance) = self.tcx.try_normalize_erasing_regions(
14091425
ty::TypingEnv::fully_monomorphized(),
1410-
instance,
1426+
Unnormalized::new_wip(instance),
14111427
) else {
14121428
// Don't ICE on an impossible-to-normalize closure.
14131429
return;
@@ -1489,7 +1505,7 @@ impl<'v> RootCollector<'_, 'v> {
14891505
// listing.
14901506
let main_ret_ty = self.tcx.normalize_erasing_regions(
14911507
ty::TypingEnv::fully_monomorphized(),
1492-
main_ret_ty.no_bound_vars().unwrap(),
1508+
Unnormalized::new_wip(main_ret_ty.no_bound_vars().unwrap()),
14931509
);
14941510

14951511
let start_instance = Instance::expect_resolve(
@@ -1538,7 +1554,7 @@ fn create_mono_items_for_default_impls<'tcx>(
15381554
}
15391555
};
15401556
let impl_args = GenericArgs::for_item(tcx, item.owner_id.to_def_id(), only_region_params);
1541-
let trait_ref = impl_.trait_ref.instantiate(tcx, impl_args);
1557+
let trait_ref = impl_.trait_ref.instantiate(tcx, impl_args).skip_norm_wip();
15421558

15431559
// Unlike 'lazy' monomorphization that begins by collecting items transitively
15441560
// called by `main` or other global items, when eagerly monomorphizing impl
@@ -1554,7 +1570,7 @@ fn create_mono_items_for_default_impls<'tcx>(
15541570
}
15551571

15561572
let typing_env = ty::TypingEnv::fully_monomorphized();
1557-
let trait_ref = tcx.normalize_erasing_regions(typing_env, trait_ref);
1573+
let trait_ref = tcx.normalize_erasing_regions(typing_env, Unnormalized::new_wip(trait_ref));
15581574
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);
15591575
for method in tcx.provided_trait_methods(trait_ref.def_id) {
15601576
if overridden_methods.contains_key(&method.def_id) {

src/preempt_count/check.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::{self, Body, Location, visit::Visitor as MirVisitor};
1010
use rustc_middle::ty::adjustment::PointerCoercion;
1111
use rustc_middle::ty::{
1212
self, GenericArgs, GenericParamDefKind, Instance, PseudoCanonicalInput, Ty, TyCtxt,
13-
TypeFoldable, TypeVisitableExt, TypingEnv, Upcast,
13+
TypeFoldable, TypeVisitableExt, TypingEnv, Unnormalized, Upcast,
1414
};
1515
use rustc_span::{DUMMY_SP, Span};
1616

@@ -511,6 +511,7 @@ memoize!(
511511
let super_traits = cx
512512
.explicit_super_predicates_of(trait_ref.def_id())
513513
.iter_identity_copied()
514+
.map(Unnormalized::skip_norm_wip)
514515
.filter_map(|(pred, _)| {
515516
pred.instantiate_supertrait(cx.tcx, trait_ref)
516517
.as_trait_clause()
@@ -537,7 +538,9 @@ memoize!(
537538
let predicates = cx.predicates_of(entry).instantiate_own(cx.tcx, args);
538539
if rustc_trait_selection::traits::impossible_predicates(
539540
cx.tcx,
540-
predicates.map(|(predicate, _)| predicate).collect(),
541+
predicates
542+
.map(|(predicate, _)| predicate.skip_norm_wip())
543+
.collect(),
541544
) {
542545
continue;
543546
}

0 commit comments

Comments
 (0)