Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tag field from Relations #127925

Merged
merged 1 commit into from
Jul 19, 2024
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
4 changes: 0 additions & 4 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
self.type_checker.infcx.tcx
}

fn tag(&self) -> &'static str {
"nll::subtype"
}

#[instrument(skip(self, info), level = "trace", ret)]
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
&mut self,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_infer/src/error_reporting/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,10 +1934,6 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameTypeModuloInfer<'_, 'tcx> {
self.0.tcx
}

fn tag(&self) -> &'static str {
"SameTypeModuloInfer"
}

fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>(
&mut self,
_variance: ty::Variance,
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_infer/src/infer/outlives/test_type_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {

/// Binds the pattern variable `br` to `value`; returns an `Err` if the pattern
/// is already bound to a different value.
#[instrument(level = "debug", skip(self))]
#[instrument(level = "trace", skip(self))]
fn bind(
&mut self,
br: ty::BoundRegion,
Expand All @@ -133,10 +133,6 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
}

impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> {
fn tag(&self) -> &'static str {
"MatchAgainstHigherRankedOutlives"
}

fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}
Expand All @@ -154,13 +150,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) }
}

#[instrument(skip(self), level = "debug")]
#[instrument(skip(self), level = "trace")]
fn regions(
&mut self,
pattern: ty::Region<'tcx>,
value: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("self.pattern_depth = {:?}", self.pattern_depth);
if let ty::RegionKind::ReBound(depth, br) = pattern.kind()
&& depth == self.pattern_depth
{
Expand All @@ -172,7 +167,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
}
}

#[instrument(skip(self), level = "debug")]
#[instrument(skip(self), level = "trace")]
fn tys(&mut self, pattern: Ty<'tcx>, value: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
// FIXME(non_lifetime_binders): What to do here?
if matches!(pattern.kind(), ty::Error(_) | ty::Bound(..)) {
Expand All @@ -185,20 +180,20 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
}
}

#[instrument(skip(self), level = "debug")]
#[instrument(skip(self), level = "trace")]
fn consts(
&mut self,
pattern: ty::Const<'tcx>,
value: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
debug!("{}.consts({:?}, {:?})", self.tag(), pattern, value);
if pattern == value {
Ok(pattern)
} else {
relate::structurally_relate_consts(self, pattern, value)
}
}

#[instrument(skip(self), level = "trace")]
fn binders<T>(
&mut self,
pattern: ty::Binder<'tcx, T>,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_infer/src/infer/relate/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'tcx> InferCtxt<'tcx> {
where
R: PredicateEmittingRelation<InferCtxt<'tcx>>,
{
debug!("super_combine_tys::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b);
debug_assert!(!a.has_escaping_bound_vars());
debug_assert!(!b.has_escaping_bound_vars());

Expand Down Expand Up @@ -174,9 +175,10 @@ impl<'tcx> InferCtxt<'tcx> {
where
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!(!b.has_escaping_bound_vars());

if a == b {
return Ok(a);
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,6 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
self.infcx.tcx
}

fn tag(&self) -> &'static str {
"Generalizer"
}

fn relate_item_args(
&mut self,
item_def_id: DefId,
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_infer/src/infer/relate/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ impl<'combine, 'infcx, 'tcx> Glb<'combine, 'infcx, 'tcx> {
}

impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"Glb"
}

fn cx(&self) -> TyCtxt<'tcx> {
self.fields.tcx()
}
Expand All @@ -47,17 +43,17 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
}
}

#[instrument(skip(self), level = "trace")]
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
lattice::super_lattice_tys(self, a, b)
}

#[instrument(skip(self), level = "trace")]
fn regions(
&mut self,
a: ty::Region<'tcx>,
b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);

let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
// GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
Expand All @@ -68,6 +64,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
))
}

#[instrument(skip(self), level = "trace")]
fn consts(
&mut self,
a: ty::Const<'tcx>,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_infer/src/infer/relate/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub fn super_lattice_tys<'a, 'tcx: 'a, L>(
where
L: LatticeDir<'a, 'tcx>,
{
debug!("{}", this.tag());

if a == b {
return Ok(a);
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_infer/src/infer/relate/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ impl<'combine, 'infcx, 'tcx> Lub<'combine, 'infcx, 'tcx> {
}

impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"Lub"
}

fn cx(&self) -> TyCtxt<'tcx> {
self.fields.tcx()
}
Expand All @@ -51,13 +47,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
lattice::super_lattice_tys(self, a, b)
}

#[instrument(skip(self), level = "trace")]
fn regions(
&mut self,
a: ty::Region<'tcx>,
b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);

let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
// LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
Expand All @@ -68,6 +63,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
))
}

#[instrument(skip(self), level = "trace")]
fn consts(
&mut self,
a: ty::Const<'tcx>,
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_infer/src/infer/relate/type_relating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
}

impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
fn tag(&self) -> &'static str {
"TypeRelating"
}

fn cx(&self) -> TyCtxt<'tcx> {
self.fields.infcx.tcx
}
Expand Down Expand Up @@ -71,7 +67,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
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>> {
if a == b {
return Ok(a);
Expand Down Expand Up @@ -166,12 +162,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
Ok(a)
}

#[instrument(skip(self), level = "trace")]
fn regions(
&mut self,
a: ty::Region<'tcx>,
b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));

match self.ambient_variance {
Expand Down Expand Up @@ -209,6 +205,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
Ok(a)
}

#[instrument(skip(self), level = "trace")]
fn consts(
&mut self,
a: ty::Const<'tcx>,
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_trait_selection/src/traits/select/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_infer::infer::relate::{
};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
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
/// instantiated with values so as to make it equal to A. Matching is
Expand Down Expand Up @@ -32,10 +32,6 @@ impl<'tcx> MatchAgainstFreshVars<'tcx> {
}

impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
fn tag(&self) -> &'static str {
"MatchAgainstFreshVars"
}

fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}
Expand All @@ -50,7 +46,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
self.relate(a, b)
}

#[instrument(skip(self), level = "debug")]
#[instrument(skip(self), level = "trace")]
fn regions(
&mut self,
a: ty::Region<'tcx>,
Expand All @@ -59,7 +55,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
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>> {
if a == b {
return Ok(a);
Expand All @@ -83,12 +79,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
}
}

#[instrument(skip(self), level = "trace")]
fn consts(
&mut self,
a: ty::Const<'tcx>,
b: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
if a == b {
return Ok(a);
}
Expand Down
25 changes: 14 additions & 11 deletions compiler/rustc_type_ir/src/relate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::iter;

use rustc_ast_ir::Mutability;
use tracing::{debug, instrument};
use tracing::{instrument, trace};

use crate::error::{ExpectedFound, TypeError};
use crate::fold::TypeFoldable;
Expand Down Expand Up @@ -58,9 +58,6 @@ impl<I: Interner> VarianceDiagInfo<I> {
pub trait TypeRelation<I: Interner>: Sized {
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.
fn relate<T: Relate<I>>(&mut self, a: T, b: T) -> RelateResult<I, T> {
Relate::relate(self, a, b)
Expand All @@ -69,17 +66,13 @@ pub trait TypeRelation<I: Interner>: Sized {
/// Relate the two args for the given item. The default
/// is to look up the variance for the item and proceed
/// accordingly.
#[instrument(skip(self), level = "trace")]
fn relate_item_args(
&mut self,
item_def_id: I::DefId,
a_arg: I::GenericArgs,
b_arg: 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 opt_variances = cx.variances_of(item_def_id);
relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true)
Expand Down Expand Up @@ -571,15 +564,25 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
mut a: I::Const,
mut b: 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();

if cx.features().generic_const_exprs() {
a = cx.expand_abstract_consts(a);
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,
// and those that derive both `PartialEq` and `Eq`, corresponding
Expand Down
Loading