Skip to content

Commit 1168837

Browse files
authored
Rollup merge of rust-lang#127925 - compiler-errors:tag, r=lcnr
Remove tag field from `Relation`s Can just use the relation name w/ `std::any::type_name`. Also changes some printing to use instrument. Also changes some instrument levels to `trace` since I expect relations are somewhat hot, so having them print on debug is probably noisy. r? lcnr
2 parents f4a9f7f + 8dbb63a commit 1168837

File tree

11 files changed

+34
-62
lines changed

11 files changed

+34
-62
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

-4
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
313313
self.type_checker.infcx.tcx
314314
}
315315

316-
fn tag(&self) -> &'static str {
317-
"nll::subtype"
318-
}
319-
320316
#[instrument(skip(self, info), level = "trace", ret)]
321317
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
322318
&mut self,

compiler/rustc_infer/src/error_reporting/infer/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1934,10 +1934,6 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameTypeModuloInfer<'_, 'tcx> {
19341934
self.0.tcx
19351935
}
19361936

1937-
fn tag(&self) -> &'static str {
1938-
"SameTypeModuloInfer"
1939-
}
1940-
19411937
fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>(
19421938
&mut self,
19431939
_variance: ty::Variance,

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
110110

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

135135
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> {
136-
fn tag(&self) -> &'static str {
137-
"MatchAgainstHigherRankedOutlives"
138-
}
139-
140136
fn cx(&self) -> TyCtxt<'tcx> {
141137
self.tcx
142138
}
@@ -154,13 +150,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
154150
if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) }
155151
}
156152

157-
#[instrument(skip(self), level = "debug")]
153+
#[instrument(skip(self), level = "trace")]
158154
fn regions(
159155
&mut self,
160156
pattern: ty::Region<'tcx>,
161157
value: ty::Region<'tcx>,
162158
) -> RelateResult<'tcx, ty::Region<'tcx>> {
163-
debug!("self.pattern_depth = {:?}", self.pattern_depth);
164159
if let ty::RegionKind::ReBound(depth, br) = pattern.kind()
165160
&& depth == self.pattern_depth
166161
{
@@ -172,7 +167,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
172167
}
173168
}
174169

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

188-
#[instrument(skip(self), level = "debug")]
183+
#[instrument(skip(self), level = "trace")]
189184
fn consts(
190185
&mut self,
191186
pattern: ty::Const<'tcx>,
192187
value: ty::Const<'tcx>,
193188
) -> RelateResult<'tcx, ty::Const<'tcx>> {
194-
debug!("{}.consts({:?}, {:?})", self.tag(), pattern, value);
195189
if pattern == value {
196190
Ok(pattern)
197191
} else {
198192
relate::structurally_relate_consts(self, pattern, value)
199193
}
200194
}
201195

196+
#[instrument(skip(self), level = "trace")]
202197
fn binders<T>(
203198
&mut self,
204199
pattern: ty::Binder<'tcx, T>,

compiler/rustc_infer/src/infer/relate/combine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl<'tcx> InferCtxt<'tcx> {
7979
where
8080
R: PredicateEmittingRelation<InferCtxt<'tcx>>,
8181
{
82+
debug!("super_combine_tys::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b);
8283
debug_assert!(!a.has_escaping_bound_vars());
8384
debug_assert!(!b.has_escaping_bound_vars());
8485

@@ -174,9 +175,10 @@ impl<'tcx> InferCtxt<'tcx> {
174175
where
175176
R: PredicateEmittingRelation<InferCtxt<'tcx>>,
176177
{
177-
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
178+
debug!("super_combine_consts::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b);
178179
debug_assert!(!a.has_escaping_bound_vars());
179180
debug_assert!(!b.has_escaping_bound_vars());
181+
180182
if a == b {
181183
return Ok(a);
182184
}

compiler/rustc_infer/src/infer/relate/generalize.rs

-4
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
401401
self.infcx.tcx
402402
}
403403

404-
fn tag(&self) -> &'static str {
405-
"Generalizer"
406-
}
407-
408404
fn relate_item_args(
409405
&mut self,
410406
item_def_id: DefId,

compiler/rustc_infer/src/infer/relate/glb.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ impl<'combine, 'infcx, 'tcx> Glb<'combine, 'infcx, 'tcx> {
2323
}
2424

2525
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
26-
fn tag(&self) -> &'static str {
27-
"Glb"
28-
}
29-
3026
fn cx(&self) -> TyCtxt<'tcx> {
3127
self.fields.tcx()
3228
}
@@ -47,17 +43,17 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
4743
}
4844
}
4945

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

51+
#[instrument(skip(self), level = "trace")]
5452
fn regions(
5553
&mut self,
5654
a: ty::Region<'tcx>,
5755
b: ty::Region<'tcx>,
5856
) -> RelateResult<'tcx, ty::Region<'tcx>> {
59-
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
60-
6157
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
6258
// GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8
6359
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
@@ -68,6 +64,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
6864
))
6965
}
7066

67+
#[instrument(skip(self), level = "trace")]
7168
fn consts(
7269
&mut self,
7370
a: ty::Const<'tcx>,

compiler/rustc_infer/src/infer/relate/lattice.rs

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ pub fn super_lattice_tys<'a, 'tcx: 'a, L>(
5656
where
5757
L: LatticeDir<'a, 'tcx>,
5858
{
59-
debug!("{}", this.tag());
60-
6159
if a == b {
6260
return Ok(a);
6361
}

compiler/rustc_infer/src/infer/relate/lub.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ impl<'combine, 'infcx, 'tcx> Lub<'combine, 'infcx, 'tcx> {
2323
}
2424

2525
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
26-
fn tag(&self) -> &'static str {
27-
"Lub"
28-
}
29-
3026
fn cx(&self) -> TyCtxt<'tcx> {
3127
self.fields.tcx()
3228
}
@@ -51,13 +47,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
5147
lattice::super_lattice_tys(self, a, b)
5248
}
5349

50+
#[instrument(skip(self), level = "trace")]
5451
fn regions(
5552
&mut self,
5653
a: ty::Region<'tcx>,
5754
b: ty::Region<'tcx>,
5855
) -> RelateResult<'tcx, ty::Region<'tcx>> {
59-
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
60-
6156
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
6257
// LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8
6358
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
@@ -68,6 +63,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
6863
))
6964
}
7065

66+
#[instrument(skip(self), level = "trace")]
7167
fn consts(
7268
&mut self,
7369
a: ty::Const<'tcx>,

compiler/rustc_infer/src/infer/relate/type_relating.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
2828
}
2929

3030
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
31-
fn tag(&self) -> &'static str {
32-
"TypeRelating"
33-
}
34-
3531
fn cx(&self) -> TyCtxt<'tcx> {
3632
self.fields.infcx.tcx
3733
}
@@ -71,7 +67,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
7167
r
7268
}
7369

74-
#[instrument(skip(self), level = "debug")]
70+
#[instrument(skip(self), level = "trace")]
7571
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
7672
if a == b {
7773
return Ok(a);
@@ -166,12 +162,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
166162
Ok(a)
167163
}
168164

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

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

208+
#[instrument(skip(self), level = "trace")]
212209
fn consts(
213210
&mut self,
214211
a: ty::Const<'tcx>,

compiler/rustc_trait_selection/src/traits/select/_match.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_infer::infer::relate::{
33
};
44
use rustc_middle::ty::error::{ExpectedFound, TypeError};
55
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt};
6-
use tracing::{debug, instrument};
6+
use tracing::instrument;
77

88
/// A type "A" *matches* "B" if the fresh types in B could be
99
/// instantiated with values so as to make it equal to A. Matching is
@@ -32,10 +32,6 @@ impl<'tcx> MatchAgainstFreshVars<'tcx> {
3232
}
3333

3434
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
35-
fn tag(&self) -> &'static str {
36-
"MatchAgainstFreshVars"
37-
}
38-
3935
fn cx(&self) -> TyCtxt<'tcx> {
4036
self.tcx
4137
}
@@ -50,7 +46,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
5046
self.relate(a, b)
5147
}
5248

53-
#[instrument(skip(self), level = "debug")]
49+
#[instrument(skip(self), level = "trace")]
5450
fn regions(
5551
&mut self,
5652
a: ty::Region<'tcx>,
@@ -59,7 +55,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
5955
Ok(a)
6056
}
6157

62-
#[instrument(skip(self), level = "debug")]
58+
#[instrument(skip(self), level = "trace")]
6359
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
6460
if a == b {
6561
return Ok(a);
@@ -83,12 +79,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
8379
}
8480
}
8581

82+
#[instrument(skip(self), level = "trace")]
8683
fn consts(
8784
&mut self,
8885
a: ty::Const<'tcx>,
8986
b: ty::Const<'tcx>,
9087
) -> RelateResult<'tcx, ty::Const<'tcx>> {
91-
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
9288
if a == b {
9389
return Ok(a);
9490
}

compiler/rustc_type_ir/src/relate.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter;
22

33
use rustc_ast_ir::Mutability;
4-
use tracing::{debug, instrument};
4+
use tracing::{instrument, trace};
55

66
use crate::error::{ExpectedFound, TypeError};
77
use crate::fold::TypeFoldable;
@@ -58,9 +58,6 @@ impl<I: Interner> VarianceDiagInfo<I> {
5858
pub trait TypeRelation<I: Interner>: Sized {
5959
fn cx(&self) -> I;
6060

61-
/// Returns a static string we can use for printouts.
62-
fn tag(&self) -> &'static str;
63-
6461
/// Generic relation routine suitable for most anything.
6562
fn relate<T: Relate<I>>(&mut self, a: T, b: T) -> RelateResult<I, T> {
6663
Relate::relate(self, a, b)
@@ -69,17 +66,13 @@ pub trait TypeRelation<I: Interner>: Sized {
6966
/// Relate the two args for the given item. The default
7067
/// is to look up the variance for the item and proceed
7168
/// accordingly.
69+
#[instrument(skip(self), level = "trace")]
7270
fn relate_item_args(
7371
&mut self,
7472
item_def_id: I::DefId,
7573
a_arg: I::GenericArgs,
7674
b_arg: I::GenericArgs,
7775
) -> RelateResult<I, I::GenericArgs> {
78-
debug!(
79-
"relate_item_args(item_def_id={:?}, a_arg={:?}, b_arg={:?})",
80-
item_def_id, a_arg, b_arg
81-
);
82-
8376
let cx = self.cx();
8477
let opt_variances = cx.variances_of(item_def_id);
8578
relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true)
@@ -571,15 +564,25 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
571564
mut a: I::Const,
572565
mut b: I::Const,
573566
) -> RelateResult<I, I::Const> {
574-
debug!("{}.structurally_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b);
567+
trace!(
568+
"structurally_relate_consts::<{}>(a = {:?}, b = {:?})",
569+
std::any::type_name::<R>(),
570+
a,
571+
b
572+
);
575573
let cx = relation.cx();
576574

577575
if cx.features().generic_const_exprs() {
578576
a = cx.expand_abstract_consts(a);
579577
b = cx.expand_abstract_consts(b);
580578
}
581579

582-
debug!("{}.structurally_relate_consts(normed_a = {:?}, normed_b = {:?})", relation.tag(), a, b);
580+
trace!(
581+
"structurally_relate_consts::<{}>(normed_a = {:?}, normed_b = {:?})",
582+
std::any::type_name::<R>(),
583+
a,
584+
b
585+
);
583586

584587
// Currently, the values that can be unified are primitive types,
585588
// and those that derive both `PartialEq` and `Eq`, corresponding

0 commit comments

Comments
 (0)