Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// In practice unless there are more than one field with the same type, we'll be
// suggesting a single field at a type, because we don't aggregate multiple borrow
// checker errors involving the functional record update syntax into a single one.
let field_ty = field.ty(self.infcx.tcx, args);
let field_ty = field.ty(self.infcx.tcx, args).skip_norm_wip();
let ident = field.ident(self.infcx.tcx);
if field_ty == ty && fields.iter().all(|field| field.ident.name != ident.name) {
// Suggest adding field and cloning it.
Expand Down Expand Up @@ -1314,10 +1314,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
} else if let ty::Adt(def, args) = ty.kind()
&& let Some(local_did) = def.did().as_local()
&& def.variants().iter().all(|variant| {
variant
.fields
.iter()
.all(|field| self.implements_clone(field.ty(self.infcx.tcx, args)))
variant.fields.iter().all(|field| {
self.implements_clone(field.ty(self.infcx.tcx, args).skip_norm_wip())
})
})
{
let ty_span = self.infcx.tcx.def_span(def.did());
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}

pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
pub(super) fn normalize<T>(
&mut self,
value: Unnormalized<'tcx, T>,
location: impl NormalizeLocation,
) -> T
where
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
{
self.normalize_with_category(
Unnormalized::new_wip(value),
location,
ConstraintCategory::Boring,
)
self.normalize_with_category(value, location, ConstraintCategory::Boring)
}

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

let mut normalize = |ty| self.normalize(ty, location);
let tail = tcx.struct_tail_raw(ty, &cause, &mut normalize, || {});
normalize(tail)
tcx.struct_tail_raw(ty, &cause, &mut normalize, || {})
}

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

let cause = ObligationCause::dummy_with_span(span);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(_) =
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
{
let b = self.normalize(b, Locations::All(span));
let b = self.normalize(ty::Unnormalized::new(b), Locations::All(span));
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
.unwrap_or_else(|terr| {
span_mirbug!(
Expand Down
50 changes: 30 additions & 20 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,28 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let projected_ty = curr_projected_ty.projection_ty_core(
Comment thread
lcnr marked this conversation as resolved.
tcx,
proj,
|ty| self.normalize(ty, locations),
|ty, variant_index, field, ()| PlaceTy::field_ty(tcx, ty, variant_index, field),
|ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
|ty, variant_index, field, ()| {
PlaceTy::field_ty(tcx, ty, variant_index, field).skip_norm_wip()
},
|_| unreachable!(),
);
curr_projected_ty = projected_ty;
}
trace!(?curr_projected_ty);

// Need to renormalize `a` as typecheck may have failed to normalize
// higher-ranked aliases if normalization was ambiguous due to inference.
let a = self.normalize(a, locations);
let ty = self.normalize(curr_projected_ty.ty, locations);
// Need to renormalize `a` in the old solver as typecheck may have failed
// to normalize higher-ranked aliases if normalization was ambiguous due
// to inference.
//
// We properly normalize higher-ranked aliases during writeback with the
// new solver, so this is no longer necessary.
let mut a = a;
let mut ty = curr_projected_ty.ty;
if !self.infcx.next_trait_solver() {
a = self.normalize(ty::Unnormalized::new_wip(a), locations);
ty = self.normalize(ty::Unnormalized::new_wip(ty), locations);
}
self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;

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

let place_ty = place.ty(self.body, tcx).ty;
debug!(?place_ty);
let place_ty = self.normalize(place_ty, location);
let place_ty = self.normalize(ty::Unnormalized::new_wip(place_ty), location);
debug!("place_ty normalized: {:?}", place_ty);
let rv_ty = rv.ty(self.body, tcx);
debug!(?rv_ty);
let rv_ty = self.normalize(rv_ty, location);
let rv_ty = self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
debug!("normalized rv_ty: {:?}", rv_ty);
if let Err(terr) =
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
Expand Down Expand Up @@ -1082,7 +1092,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
},
);

let src_ty = self.normalize(src_ty, location);
let src_ty =
self.normalize(ty::Unnormalized::new_wip(src_ty), location);
if let Err(terr) = self.sub_types(
src_ty,
*ty,
Expand Down Expand Up @@ -1124,7 +1135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// function definition. When we extract the
// signature, it comes from the `fn_sig` query,
// and hence may contain unnormalized results.
let src_ty = self.normalize(src_ty, location);
let src_ty = self.normalize(ty::Unnormalized::new_wip(src_ty), location);
if let Err(terr) = self.sub_types(
src_ty,
*ty,
Expand Down Expand Up @@ -1190,7 +1201,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// function definition. When we extract the
// signature, it comes from the `fn_sig` query,
// and hence may contain unnormalized results.
let fn_sig = self.normalize(fn_sig, location);
let fn_sig = self.normalize(ty::Unnormalized::new_wip(fn_sig), location);

let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);

Expand Down Expand Up @@ -1786,8 +1797,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
);
}
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
let unnormalized_ty =
tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip();
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
let normalized_ty = self.normalize(unnormalized_ty, locations);
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();

Expand Down Expand Up @@ -1876,7 +1886,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
| ProjectionElem::Subslice { .. }
| ProjectionElem::Downcast(..) => {}
ProjectionElem::Field(field, fty) => {
let fty = self.normalize(fty, location);
let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
let ty = self.normalize(ty, location);
debug!(?fty, ?ty);
Expand All @@ -1892,7 +1902,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}
ProjectionElem::OpaqueCast(ty) => {
let ty = self.normalize(ty, location);
let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
self.relate_types(
ty,
context.ambient_variance(),
Expand Down Expand Up @@ -1945,7 +1955,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
} else {
let dest_ty = destination.ty(self.body, tcx).ty;
let dest_ty = self.normalize(dest_ty, term_location);
let dest_ty = self.normalize(ty::Unnormalized::new_wip(dest_ty), term_location);
let category = match destination.as_local() {
Some(RETURN_PLACE) => {
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
Expand Down Expand Up @@ -2030,7 +2040,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
let op_arg_ty = op_arg.node.ty(self.body, self.tcx());

let op_arg_ty = self.normalize(op_arg_ty, term_location);
let op_arg_ty = self.normalize(ty::Unnormalized::new_wip(op_arg_ty), term_location);
let category = if call_source.from_hir_call() {
ConstraintCategory::CallArgument(Some(
self.infcx.tcx.erase_and_anonymize_regions(func_ty),
Expand Down Expand Up @@ -2302,7 +2312,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
};
let operand_ty = operand.ty(self.body, tcx);
let operand_ty = self.normalize(operand_ty, location);
let operand_ty = self.normalize(ty::Unnormalized::new_wip(operand_ty), location);

if let Err(terr) = self.sub_types(
operand_ty,
Expand Down Expand Up @@ -2513,8 +2523,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
else {
continue;
};
let dest_ty = dest_field.ty(tcx, dest_args);
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args);
let dest_ty = dest_field.ty(tcx, dest_args).skip_norm_wip();
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args).skip_norm_wip();
if let (
ty::Ref(borrow_region, _, Mutability::Mut),
ty::Ref(ref_region, _, Mutability::Not),
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
use rustc_hir as hir;
use rustc_middle::mir::BinOp;
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_middle::ty::{self, Ty, Unnormalized};
use rustc_middle::ty::{self, Ty};
use rustc_span::{Span, Symbol, sym};

use crate::builder::Builder;
Expand Down Expand Up @@ -539,10 +539,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *in_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(ty),
)
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
});
require!(
metadata.is_unit(),
Expand All @@ -556,10 +553,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *out_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(ty),
)
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
});
require!(
metadata.is_unit(),
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,12 +1241,9 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
}
};

assert!(
up_var_tys
.iter()
.all(|t| t
== cx.tcx.normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(t)))
);
for ty in up_var_tys.iter() {
cx.tcx.assert_fully_normalized(cx.typing_env(), ty);
}

let capture_names = cx.tcx.closure_saved_names_of_captured_variables(def_id);
let layout = cx.layout_of(closure_or_coroutine_ty);
Expand Down
50 changes: 7 additions & 43 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
use rustc_macros::StableHash;
use rustc_middle::bug;
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt, Unnormalized};
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt};

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

impl<'tcx> UniqueTypeId<'tcx> {
pub(crate) fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self {
assert_eq!(
t,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(t)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), t);
UniqueTypeId::Ty(t, private::HiddenZst)
}

pub(crate) fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self {
assert_eq!(
enum_ty,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(enum_ty)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
UniqueTypeId::VariantPart(enum_ty, private::HiddenZst)
}

Expand All @@ -76,13 +64,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
enum_ty: Ty<'tcx>,
variant_idx: VariantIdx,
) -> Self {
assert_eq!(
enum_ty,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(enum_ty)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
UniqueTypeId::VariantStructType(enum_ty, variant_idx, private::HiddenZst)
}

Expand All @@ -91,13 +73,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
enum_ty: Ty<'tcx>,
variant_idx: VariantIdx,
) -> Self {
assert_eq!(
enum_ty,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(enum_ty)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), enum_ty);
UniqueTypeId::VariantStructTypeCppLikeWrapper(enum_ty, variant_idx, private::HiddenZst)
}

Expand All @@ -106,20 +82,8 @@ impl<'tcx> UniqueTypeId<'tcx> {
self_type: Ty<'tcx>,
implemented_trait: Option<ExistentialTraitRef<'tcx>>,
) -> Self {
assert_eq!(
self_type,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(self_type)
)
);
assert_eq!(
implemented_trait,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(implemented_trait)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), self_type);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), implemented_trait);
UniqueTypeId::VTableTy(self_type, implemented_trait, private::HiddenZst)
}

Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use rustc_hir::find_attr;
use rustc_middle::mir::BinOp;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
use rustc_middle::ty::offload_meta::OffloadMetadata;
use rustc_middle::ty::{
self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv, Unnormalized,
};
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
use rustc_middle::{bug, span_bug};
use rustc_session::config::CrateType;
use rustc_session::errors::feature_err;
Expand Down Expand Up @@ -3053,7 +3051,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
match in_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
metadata.is_unit(),
Expand All @@ -3067,7 +3065,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
match out_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
metadata.is_unit(),
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,7 @@ fn push_generic_args_internal<'tcx>(
output: &mut String,
visited: &mut FxHashSet<Ty<'tcx>>,
) -> bool {
assert_eq!(
args,
tcx.normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
Unnormalized::new_wip(args)
)
);
tcx.assert_fully_normalized(ty::TypingEnv::fully_monomorphized(), args);
let mut args = args.non_erasable_generics().peekable();
if args.peek().is_none() {
return false;
Expand Down
Loading
Loading