Skip to content

Commit c8c4c83

Browse files
committed
Auto merge of rust-lang#156224 - khyperia:unnormalized-migration, r=BoxyUwU
Unnormalized migration: assert_fully_normalized, struct_tail, and `field.ty` tracking issue: rust-lang#155345 (first checkbox, and partial second checkbox, of that issue) I'm going a bit slower than expected (less free time than I'd hope, lots of GCA work that I'm doing instead), and figured I'd just submit what I have now rather than building up a big batch of changes. Slow and steady! r? @lcnr
2 parents 8b03437 + 44c4950 commit c8c4c83

77 files changed

Lines changed: 344 additions & 380 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12391239
// In practice unless there are more than one field with the same type, we'll be
12401240
// suggesting a single field at a type, because we don't aggregate multiple borrow
12411241
// checker errors involving the functional record update syntax into a single one.
1242-
let field_ty = field.ty(self.infcx.tcx, args);
1242+
let field_ty = field.ty(self.infcx.tcx, args).skip_norm_wip();
12431243
let ident = field.ident(self.infcx.tcx);
12441244
if field_ty == ty && fields.iter().all(|field| field.ident.name != ident.name) {
12451245
// Suggest adding field and cloning it.
@@ -1314,10 +1314,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13141314
} else if let ty::Adt(def, args) = ty.kind()
13151315
&& let Some(local_did) = def.did().as_local()
13161316
&& def.variants().iter().all(|variant| {
1317-
variant
1318-
.fields
1319-
.iter()
1320-
.all(|field| self.implements_clone(field.ty(self.infcx.tcx, args)))
1317+
variant.fields.iter().all(|field| {
1318+
self.implements_clone(field.ty(self.infcx.tcx, args).skip_norm_wip())
1319+
})
13211320
})
13221321
{
13231322
let ty_span = self.infcx.tcx.def_span(def.did());

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
183183
);
184184
}
185185

186-
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
186+
pub(super) fn normalize<T>(
187+
&mut self,
188+
value: Unnormalized<'tcx, T>,
189+
location: impl NormalizeLocation,
190+
) -> T
187191
where
188192
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
189193
{
190-
self.normalize_with_category(
191-
Unnormalized::new_wip(value),
192-
location,
193-
ConstraintCategory::Boring,
194-
)
194+
self.normalize_with_category(value, location, ConstraintCategory::Boring)
195195
}
196196

197197
pub(super) fn deeply_normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
@@ -241,8 +241,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
241241
);
242242

243243
let mut normalize = |ty| self.normalize(ty, location);
244-
let tail = tcx.struct_tail_raw(ty, &cause, &mut normalize, || {});
245-
normalize(tail)
244+
tcx.struct_tail_raw(ty, &cause, &mut normalize, || {})
246245
}
247246

248247
#[instrument(skip(self), level = "debug")]
@@ -287,7 +286,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
287286
// hack in `equate_inputs_and_outputs` which does have associated test cases.
288287
let mir_ty = match self.infcx.next_trait_solver() {
289288
true => mir_ty,
290-
false => self.normalize(mir_ty, Locations::All(span)),
289+
false => self.normalize(Unnormalized::new_wip(mir_ty), Locations::All(span)),
291290
};
292291

293292
let cause = ObligationCause::dummy_with_span(span);

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
235235
if let Err(_) =
236236
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
237237
{
238-
let b = self.normalize(b, Locations::All(span));
238+
let b = self.normalize(ty::Unnormalized::new(b), Locations::All(span));
239239
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
240240
.unwrap_or_else(|terr| {
241241
span_mirbug!(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,28 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
480480
let projected_ty = curr_projected_ty.projection_ty_core(
481481
tcx,
482482
proj,
483-
|ty| self.normalize(ty, locations),
484-
|ty, variant_index, field, ()| PlaceTy::field_ty(tcx, ty, variant_index, field),
483+
|ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
484+
|ty, variant_index, field, ()| {
485+
PlaceTy::field_ty(tcx, ty, variant_index, field).skip_norm_wip()
486+
},
485487
|_| unreachable!(),
486488
);
487489
curr_projected_ty = projected_ty;
488490
}
489491
trace!(?curr_projected_ty);
490492

491-
// Need to renormalize `a` as typecheck may have failed to normalize
492-
// higher-ranked aliases if normalization was ambiguous due to inference.
493-
let a = self.normalize(a, locations);
494-
let ty = self.normalize(curr_projected_ty.ty, locations);
493+
// Need to renormalize `a` in the old solver as typecheck may have failed
494+
// to normalize higher-ranked aliases if normalization was ambiguous due
495+
// to inference.
496+
//
497+
// We properly normalize higher-ranked aliases during writeback with the
498+
// new solver, so this is no longer necessary.
499+
let mut a = a;
500+
let mut ty = curr_projected_ty.ty;
501+
if !self.infcx.next_trait_solver() {
502+
a = self.normalize(ty::Unnormalized::new_wip(a), locations);
503+
ty = self.normalize(ty::Unnormalized::new_wip(ty), locations);
504+
}
495505
self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
496506

497507
Ok(())
@@ -639,11 +649,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
639649

640650
let place_ty = place.ty(self.body, tcx).ty;
641651
debug!(?place_ty);
642-
let place_ty = self.normalize(place_ty, location);
652+
let place_ty = self.normalize(ty::Unnormalized::new_wip(place_ty), location);
643653
debug!("place_ty normalized: {:?}", place_ty);
644654
let rv_ty = rv.ty(self.body, tcx);
645655
debug!(?rv_ty);
646-
let rv_ty = self.normalize(rv_ty, location);
656+
let rv_ty = self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
647657
debug!("normalized rv_ty: {:?}", rv_ty);
648658
if let Err(terr) =
649659
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
@@ -1082,7 +1092,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10821092
},
10831093
);
10841094

1085-
let src_ty = self.normalize(src_ty, location);
1095+
let src_ty =
1096+
self.normalize(ty::Unnormalized::new_wip(src_ty), location);
10861097
if let Err(terr) = self.sub_types(
10871098
src_ty,
10881099
*ty,
@@ -1124,7 +1135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11241135
// function definition. When we extract the
11251136
// signature, it comes from the `fn_sig` query,
11261137
// and hence may contain unnormalized results.
1127-
let src_ty = self.normalize(src_ty, location);
1138+
let src_ty = self.normalize(ty::Unnormalized::new_wip(src_ty), location);
11281139
if let Err(terr) = self.sub_types(
11291140
src_ty,
11301141
*ty,
@@ -1190,7 +1201,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11901201
// function definition. When we extract the
11911202
// signature, it comes from the `fn_sig` query,
11921203
// and hence may contain unnormalized results.
1193-
let fn_sig = self.normalize(fn_sig, location);
1204+
let fn_sig = self.normalize(ty::Unnormalized::new_wip(fn_sig), location);
11941205

11951206
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
11961207

@@ -1786,8 +1797,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
17861797
);
17871798
}
17881799
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
1789-
let unnormalized_ty =
1790-
tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip();
1800+
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
17911801
let normalized_ty = self.normalize(unnormalized_ty, locations);
17921802
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
17931803

@@ -1876,7 +1886,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18761886
| ProjectionElem::Subslice { .. }
18771887
| ProjectionElem::Downcast(..) => {}
18781888
ProjectionElem::Field(field, fty) => {
1879-
let fty = self.normalize(fty, location);
1889+
let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
18801890
let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
18811891
let ty = self.normalize(ty, location);
18821892
debug!(?fty, ?ty);
@@ -1892,7 +1902,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18921902
}
18931903
}
18941904
ProjectionElem::OpaqueCast(ty) => {
1895-
let ty = self.normalize(ty, location);
1905+
let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
18961906
self.relate_types(
18971907
ty,
18981908
context.ambient_variance(),
@@ -1945,7 +1955,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19451955
}
19461956
} else {
19471957
let dest_ty = destination.ty(self.body, tcx).ty;
1948-
let dest_ty = self.normalize(dest_ty, term_location);
1958+
let dest_ty = self.normalize(ty::Unnormalized::new_wip(dest_ty), term_location);
19491959
let category = match destination.as_local() {
19501960
Some(RETURN_PLACE) => {
19511961
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
@@ -2030,7 +2040,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20302040
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
20312041
let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
20322042

2033-
let op_arg_ty = self.normalize(op_arg_ty, term_location);
2043+
let op_arg_ty = self.normalize(ty::Unnormalized::new_wip(op_arg_ty), term_location);
20342044
let category = if call_source.from_hir_call() {
20352045
ConstraintCategory::CallArgument(Some(
20362046
self.infcx.tcx.erase_and_anonymize_regions(func_ty),
@@ -2302,7 +2312,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23022312
}
23032313
};
23042314
let operand_ty = operand.ty(self.body, tcx);
2305-
let operand_ty = self.normalize(operand_ty, location);
2315+
let operand_ty = self.normalize(ty::Unnormalized::new_wip(operand_ty), location);
23062316

23072317
if let Err(terr) = self.sub_types(
23082318
operand_ty,
@@ -2513,8 +2523,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25132523
else {
25142524
continue;
25152525
};
2516-
let dest_ty = dest_field.ty(tcx, dest_args);
2517-
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args);
2526+
let dest_ty = dest_field.ty(tcx, dest_args).skip_norm_wip();
2527+
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args).skip_norm_wip();
25182528
if let (
25192529
ty::Ref(borrow_region, _, Mutability::Mut),
25202530
ty::Ref(ref_region, _, Mutability::Not),

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
1616
use rustc_hir as hir;
1717
use rustc_middle::mir::BinOp;
1818
use rustc_middle::ty::layout::HasTyCtxt;
19-
use rustc_middle::ty::{self, Ty, Unnormalized};
19+
use rustc_middle::ty::{self, Ty};
2020
use rustc_span::{Span, Symbol, sym};
2121

2222
use crate::builder::Builder;
@@ -539,10 +539,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
539539
match *in_elem.kind() {
540540
ty::RawPtr(p_ty, _) => {
541541
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
542-
bx.tcx.normalize_erasing_regions(
543-
ty::TypingEnv::fully_monomorphized(),
544-
Unnormalized::new_wip(ty),
545-
)
542+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
546543
});
547544
require!(
548545
metadata.is_unit(),
@@ -556,10 +553,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
556553
match *out_elem.kind() {
557554
ty::RawPtr(p_ty, _) => {
558555
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
559-
bx.tcx.normalize_erasing_regions(
560-
ty::TypingEnv::fully_monomorphized(),
561-
Unnormalized::new_wip(ty),
562-
)
556+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
563557
});
564558
require!(
565559
metadata.is_unit(),

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,12 +1241,9 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
12411241
}
12421242
};
12431243

1244-
assert!(
1245-
up_var_tys
1246-
.iter()
1247-
.all(|t| t
1248-
== cx.tcx.normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(t)))
1249-
);
1244+
for ty in up_var_tys.iter() {
1245+
cx.tcx.assert_fully_normalized(cx.typing_env(), ty);
1246+
}
12501247

12511248
let capture_names = cx.tcx.closure_saved_names_of_captured_variables(def_id);
12521249
let layout = cx.layout_of(closure_or_coroutine_ty);

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
77
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
88
use rustc_macros::StableHash;
99
use rustc_middle::bug;
10-
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt, Unnormalized};
10+
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt};
1111

1212
use super::{DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
1313
use crate::common::CodegenCx;
@@ -50,24 +50,12 @@ pub(super) enum UniqueTypeId<'tcx> {
5050

5151
impl<'tcx> UniqueTypeId<'tcx> {
5252
pub(crate) fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self {
53-
assert_eq!(
54-
t,
55-
tcx.normalize_erasing_regions(
56-
ty::TypingEnv::fully_monomorphized(),
57-
Unnormalized::new_wip(t)
58-
)
59-
);
53+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), t);
6054
UniqueTypeId::Ty(t, private::HiddenZst)
6155
}
6256

6357
pub(crate) fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self {
64-
assert_eq!(
65-
enum_ty,
66-
tcx.normalize_erasing_regions(
67-
ty::TypingEnv::fully_monomorphized(),
68-
Unnormalized::new_wip(enum_ty)
69-
)
70-
);
58+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
7159
UniqueTypeId::VariantPart(enum_ty, private::HiddenZst)
7260
}
7361

@@ -76,13 +64,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
7664
enum_ty: Ty<'tcx>,
7765
variant_idx: VariantIdx,
7866
) -> Self {
79-
assert_eq!(
80-
enum_ty,
81-
tcx.normalize_erasing_regions(
82-
ty::TypingEnv::fully_monomorphized(),
83-
Unnormalized::new_wip(enum_ty)
84-
)
85-
);
67+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
8668
UniqueTypeId::VariantStructType(enum_ty, variant_idx, private::HiddenZst)
8769
}
8870

@@ -91,13 +73,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
9173
enum_ty: Ty<'tcx>,
9274
variant_idx: VariantIdx,
9375
) -> Self {
94-
assert_eq!(
95-
enum_ty,
96-
tcx.normalize_erasing_regions(
97-
ty::TypingEnv::fully_monomorphized(),
98-
Unnormalized::new_wip(enum_ty)
99-
)
100-
);
76+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
10177
UniqueTypeId::VariantStructTypeCppLikeWrapper(enum_ty, variant_idx, private::HiddenZst)
10278
}
10379

@@ -106,20 +82,8 @@ impl<'tcx> UniqueTypeId<'tcx> {
10682
self_type: Ty<'tcx>,
10783
implemented_trait: Option<ExistentialTraitRef<'tcx>>,
10884
) -> Self {
109-
assert_eq!(
110-
self_type,
111-
tcx.normalize_erasing_regions(
112-
ty::TypingEnv::fully_monomorphized(),
113-
Unnormalized::new_wip(self_type)
114-
)
115-
);
116-
assert_eq!(
117-
implemented_trait,
118-
tcx.normalize_erasing_regions(
119-
ty::TypingEnv::fully_monomorphized(),
120-
Unnormalized::new_wip(implemented_trait)
121-
)
122-
);
85+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), self_type);
86+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), implemented_trait);
12387
UniqueTypeId::VTableTy(self_type, implemented_trait, private::HiddenZst)
12488
}
12589

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_hir::find_attr;
1818
use rustc_middle::mir::BinOp;
1919
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
2020
use rustc_middle::ty::offload_meta::OffloadMetadata;
21-
use rustc_middle::ty::{
22-
self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv, Unnormalized,
23-
};
21+
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
2422
use rustc_middle::{bug, span_bug};
2523
use rustc_session::config::CrateType;
2624
use rustc_session::errors::feature_err;
@@ -3053,7 +3051,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
30533051
match in_elem.kind() {
30543052
ty::RawPtr(p_ty, _) => {
30553053
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
3056-
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
3054+
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
30573055
});
30583056
require!(
30593057
metadata.is_unit(),
@@ -3067,7 +3065,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
30673065
match out_elem.kind() {
30683066
ty::RawPtr(p_ty, _) => {
30693067
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
3070-
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
3068+
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
30713069
});
30723070
require!(
30733071
metadata.is_unit(),

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,7 @@ fn push_generic_args_internal<'tcx>(
658658
output: &mut String,
659659
visited: &mut FxHashSet<Ty<'tcx>>,
660660
) -> bool {
661-
assert_eq!(
662-
args,
663-
tcx.normalize_erasing_regions(
664-
ty::TypingEnv::fully_monomorphized(),
665-
Unnormalized::new_wip(args)
666-
)
667-
);
661+
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), args);
668662
let mut args = args.non_erasable_generics().peekable();
669663
if args.peek().is_none() {
670664
return false;

0 commit comments

Comments
 (0)