Remove tag field from relations

This commit is contained in:
Michael Goulet 2024-07-18 13:01:52 -04:00
parent 5753b30676
commit 8dbb63a585
11 changed files with 34 additions and 62 deletions

View File

@ -313,10 +313,6 @@ fn cx(&self) -> TyCtxt<'tcx> {
self.type_checker.infcx.tcx self.type_checker.infcx.tcx
} }
fn tag(&self) -> &'static str {
"nll::subtype"
}
#[instrument(skip(self, info), level = "trace", ret)] #[instrument(skip(self, info), level = "trace", ret)]
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>( fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
&mut self, &mut self,

View File

@ -1934,10 +1934,6 @@ fn cx(&self) -> TyCtxt<'tcx> {
self.0.tcx self.0.tcx
} }
fn tag(&self) -> &'static str {
"SameTypeModuloInfer"
}
fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>( fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>(
&mut self, &mut self,
_variance: ty::Variance, _variance: ty::Variance,

View File

@ -110,7 +110,7 @@ fn no_match<T>(&self) -> RelateResult<'tcx, T> {
/// Binds the pattern variable `br` to `value`; returns an `Err` if the pattern /// Binds the pattern variable `br` to `value`; returns an `Err` if the pattern
/// is already bound to a different value. /// is already bound to a different value.
#[instrument(level = "debug", skip(self))] #[instrument(level = "trace", skip(self))]
fn bind( fn bind(
&mut self, &mut self,
br: ty::BoundRegion, br: ty::BoundRegion,
@ -133,10 +133,6 @@ fn bind(
} }
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> { impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> {
fn tag(&self) -> &'static str {
"MatchAgainstHigherRankedOutlives"
}
fn cx(&self) -> TyCtxt<'tcx> { fn cx(&self) -> TyCtxt<'tcx> {
self.tcx self.tcx
} }
@ -154,13 +150,12 @@ fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) } if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) }
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn regions( fn regions(
&mut self, &mut self,
pattern: ty::Region<'tcx>, pattern: ty::Region<'tcx>,
value: ty::Region<'tcx>, value: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("self.pattern_depth = {:?}", self.pattern_depth);
if let ty::RegionKind::ReBound(depth, br) = pattern.kind() if let ty::RegionKind::ReBound(depth, br) = pattern.kind()
&& depth == self.pattern_depth && depth == self.pattern_depth
{ {
@ -172,7 +167,7 @@ fn regions(
} }
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn tys(&mut self, pattern: Ty<'tcx>, value: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { fn tys(&mut self, pattern: Ty<'tcx>, value: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
// FIXME(non_lifetime_binders): What to do here? // FIXME(non_lifetime_binders): What to do here?
if matches!(pattern.kind(), ty::Error(_) | ty::Bound(..)) { if matches!(pattern.kind(), ty::Error(_) | ty::Bound(..)) {
@ -185,13 +180,12 @@ fn tys(&mut self, pattern: Ty<'tcx>, value: Ty<'tcx>) -> RelateResult<'tcx, Ty<'
} }
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn consts( fn consts(
&mut self, &mut self,
pattern: ty::Const<'tcx>, pattern: ty::Const<'tcx>,
value: ty::Const<'tcx>, value: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> { ) -> RelateResult<'tcx, ty::Const<'tcx>> {
debug!("{}.consts({:?}, {:?})", self.tag(), pattern, value);
if pattern == value { if pattern == value {
Ok(pattern) Ok(pattern)
} else { } else {
@ -199,6 +193,7 @@ fn consts(
} }
} }
#[instrument(skip(self), level = "trace")]
fn binders<T>( fn binders<T>(
&mut self, &mut self,
pattern: ty::Binder<'tcx, T>, pattern: ty::Binder<'tcx, T>,

View File

@ -79,6 +79,7 @@ pub fn super_combine_tys<R>(
where where
R: PredicateEmittingRelation<InferCtxt<'tcx>>, R: PredicateEmittingRelation<InferCtxt<'tcx>>,
{ {
debug!("super_combine_tys::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b);
debug_assert!(!a.has_escaping_bound_vars()); debug_assert!(!a.has_escaping_bound_vars());
debug_assert!(!b.has_escaping_bound_vars()); debug_assert!(!b.has_escaping_bound_vars());
@ -174,9 +175,10 @@ pub fn super_combine_consts<R>(
where where
R: PredicateEmittingRelation<InferCtxt<'tcx>>, R: PredicateEmittingRelation<InferCtxt<'tcx>>,
{ {
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b); debug!("super_combine_consts::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b);
debug_assert!(!a.has_escaping_bound_vars()); debug_assert!(!a.has_escaping_bound_vars());
debug_assert!(!b.has_escaping_bound_vars()); debug_assert!(!b.has_escaping_bound_vars());
if a == b { if a == b {
return Ok(a); return Ok(a);
} }

View File

@ -401,10 +401,6 @@ fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx self.infcx.tcx
} }
fn tag(&self) -> &'static str {
"Generalizer"
}
fn relate_item_args( fn relate_item_args(
&mut self, &mut self,
item_def_id: DefId, item_def_id: DefId,

View File

@ -23,10 +23,6 @@ pub fn new(fields: &'combine mut CombineFields<'infcx, 'tcx>) -> Glb<'combine, '
} }
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> { impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"Glb"
}
fn cx(&self) -> TyCtxt<'tcx> { fn cx(&self) -> TyCtxt<'tcx> {
self.fields.tcx() self.fields.tcx()
} }
@ -47,17 +43,17 @@ fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
} }
} }
#[instrument(skip(self), level = "trace")]
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
lattice::super_lattice_tys(self, a, b) lattice::super_lattice_tys(self, a, b)
} }
#[instrument(skip(self), level = "trace")]
fn regions( fn regions(
&mut self, &mut self,
a: ty::Region<'tcx>, a: ty::Region<'tcx>,
b: ty::Region<'tcx>, b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone())); let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
// GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8 // GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions( Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
@ -68,6 +64,7 @@ fn regions(
)) ))
} }
#[instrument(skip(self), level = "trace")]
fn consts( fn consts(
&mut self, &mut self,
a: ty::Const<'tcx>, a: ty::Const<'tcx>,

View File

@ -56,8 +56,6 @@ pub fn super_lattice_tys<'a, 'tcx: 'a, L>(
where where
L: LatticeDir<'a, 'tcx>, L: LatticeDir<'a, 'tcx>,
{ {
debug!("{}", this.tag());
if a == b { if a == b {
return Ok(a); return Ok(a);
} }

View File

@ -23,10 +23,6 @@ pub fn new(fields: &'combine mut CombineFields<'infcx, 'tcx>) -> Lub<'combine, '
} }
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> { impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"Lub"
}
fn cx(&self) -> TyCtxt<'tcx> { fn cx(&self) -> TyCtxt<'tcx> {
self.fields.tcx() self.fields.tcx()
} }
@ -51,13 +47,12 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
lattice::super_lattice_tys(self, a, b) lattice::super_lattice_tys(self, a, b)
} }
#[instrument(skip(self), level = "trace")]
fn regions( fn regions(
&mut self, &mut self,
a: ty::Region<'tcx>, a: ty::Region<'tcx>,
b: ty::Region<'tcx>, b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone())); let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
// LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8 // LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions( Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
@ -68,6 +63,7 @@ fn regions(
)) ))
} }
#[instrument(skip(self), level = "trace")]
fn consts( fn consts(
&mut self, &mut self,
a: ty::Const<'tcx>, a: ty::Const<'tcx>,

View File

@ -28,10 +28,6 @@ pub fn new(
} }
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> { impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"TypeRelating"
}
fn cx(&self) -> TyCtxt<'tcx> { fn cx(&self) -> TyCtxt<'tcx> {
self.fields.infcx.tcx self.fields.infcx.tcx
} }
@ -71,7 +67,7 @@ fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
r r
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
if a == b { if a == b {
return Ok(a); return Ok(a);
@ -166,12 +162,12 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
Ok(a) Ok(a)
} }
#[instrument(skip(self), level = "trace")]
fn regions( fn regions(
&mut self, &mut self,
a: ty::Region<'tcx>, a: ty::Region<'tcx>,
b: ty::Region<'tcx>, b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone())); let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
match self.ambient_variance { match self.ambient_variance {
@ -209,6 +205,7 @@ fn regions(
Ok(a) Ok(a)
} }
#[instrument(skip(self), level = "trace")]
fn consts( fn consts(
&mut self, &mut self,
a: ty::Const<'tcx>, a: ty::Const<'tcx>,

View File

@ -3,7 +3,7 @@
}; };
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt}; use rustc_middle::ty::{self, InferConst, Ty, TyCtxt};
use tracing::{debug, instrument}; use tracing::instrument;
/// A type "A" *matches* "B" if the fresh types in B could be /// A type "A" *matches* "B" if the fresh types in B could be
/// instantiated with values so as to make it equal to A. Matching is /// instantiated with values so as to make it equal to A. Matching is
@ -32,10 +32,6 @@ pub fn new(tcx: TyCtxt<'tcx>) -> MatchAgainstFreshVars<'tcx> {
} }
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> { impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
fn tag(&self) -> &'static str {
"MatchAgainstFreshVars"
}
fn cx(&self) -> TyCtxt<'tcx> { fn cx(&self) -> TyCtxt<'tcx> {
self.tcx self.tcx
} }
@ -50,7 +46,7 @@ fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
self.relate(a, b) self.relate(a, b)
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn regions( fn regions(
&mut self, &mut self,
a: ty::Region<'tcx>, a: ty::Region<'tcx>,
@ -59,7 +55,7 @@ fn regions(
Ok(a) Ok(a)
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "trace")]
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
if a == b { if a == b {
return Ok(a); return Ok(a);
@ -83,12 +79,12 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
} }
} }
#[instrument(skip(self), level = "trace")]
fn consts( fn consts(
&mut self, &mut self,
a: ty::Const<'tcx>, a: ty::Const<'tcx>,
b: ty::Const<'tcx>, b: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> { ) -> RelateResult<'tcx, ty::Const<'tcx>> {
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
if a == b { if a == b {
return Ok(a); return Ok(a);
} }

View File

@ -1,7 +1,7 @@
use std::iter; use std::iter;
use rustc_ast_ir::Mutability; use rustc_ast_ir::Mutability;
use tracing::{debug, instrument}; use tracing::{instrument, trace};
use crate::error::{ExpectedFound, TypeError}; use crate::error::{ExpectedFound, TypeError};
use crate::fold::TypeFoldable; use crate::fold::TypeFoldable;
@ -58,9 +58,6 @@ pub fn xform(self, other: VarianceDiagInfo<I>) -> VarianceDiagInfo<I> {
pub trait TypeRelation<I: Interner>: Sized { pub trait TypeRelation<I: Interner>: Sized {
fn cx(&self) -> I; fn cx(&self) -> I;
/// Returns a static string we can use for printouts.
fn tag(&self) -> &'static str;
/// Generic relation routine suitable for most anything. /// Generic relation routine suitable for most anything.
fn relate<T: Relate<I>>(&mut self, a: T, b: T) -> RelateResult<I, T> { fn relate<T: Relate<I>>(&mut self, a: T, b: T) -> RelateResult<I, T> {
Relate::relate(self, a, b) Relate::relate(self, a, b)
@ -69,17 +66,13 @@ fn relate<T: Relate<I>>(&mut self, a: T, b: T) -> RelateResult<I, T> {
/// Relate the two args for the given item. The default /// Relate the two args for the given item. The default
/// is to look up the variance for the item and proceed /// is to look up the variance for the item and proceed
/// accordingly. /// accordingly.
#[instrument(skip(self), level = "trace")]
fn relate_item_args( fn relate_item_args(
&mut self, &mut self,
item_def_id: I::DefId, item_def_id: I::DefId,
a_arg: I::GenericArgs, a_arg: I::GenericArgs,
b_arg: I::GenericArgs, b_arg: I::GenericArgs,
) -> RelateResult<I, I::GenericArgs> { ) -> RelateResult<I, I::GenericArgs> {
debug!(
"relate_item_args(item_def_id={:?}, a_arg={:?}, b_arg={:?})",
item_def_id, a_arg, b_arg
);
let cx = self.cx(); let cx = self.cx();
let opt_variances = cx.variances_of(item_def_id); let opt_variances = cx.variances_of(item_def_id);
relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true) relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true)
@ -571,7 +564,12 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
mut a: I::Const, mut a: I::Const,
mut b: I::Const, mut b: I::Const,
) -> RelateResult<I, I::Const> { ) -> RelateResult<I, I::Const> {
debug!("{}.structurally_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b); trace!(
"structurally_relate_consts::<{}>(a = {:?}, b = {:?})",
std::any::type_name::<R>(),
a,
b
);
let cx = relation.cx(); let cx = relation.cx();
if cx.features().generic_const_exprs() { if cx.features().generic_const_exprs() {
@ -579,7 +577,12 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
b = cx.expand_abstract_consts(b); b = cx.expand_abstract_consts(b);
} }
debug!("{}.structurally_relate_consts(normed_a = {:?}, normed_b = {:?})", relation.tag(), a, b); trace!(
"structurally_relate_consts::<{}>(normed_a = {:?}, normed_b = {:?})",
std::any::type_name::<R>(),
a,
b
);
// Currently, the values that can be unified are primitive types, // Currently, the values that can be unified are primitive types,
// and those that derive both `PartialEq` and `Eq`, corresponding // and those that derive both `PartialEq` and `Eq`, corresponding