Skip to content

Commit a4ab2e0

Browse files
committed
Auto merge of #103975 - oli-obk:tracing, r=jackh726
Some tracing and comment cleanups Pulled out of #101900 to see if that is the perf impact
2 parents e6fead4 + 44d1936 commit a4ab2e0

File tree

10 files changed

+23
-56
lines changed

10 files changed

+23
-56
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl Qualif for NeedsNonConstDrop {
146146
qualifs.needs_non_const_drop
147147
}
148148

149+
#[instrument(level = "trace", skip(cx), ret)]
149150
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
150151
// Avoid selecting for simple cases, such as builtin types.
151152
if ty::util::is_trivially_const_drop(ty) {
@@ -174,6 +175,8 @@ impl Qualif for NeedsNonConstDrop {
174175
return true;
175176
};
176177

178+
trace!(?impl_src);
179+
177180
if !matches!(
178181
impl_src,
179182
ImplSource::ConstDestruct(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)

compiler/rustc_hir/src/hir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ impl<'hir> GenericArgs<'hir> {
388388
}
389389

390390
#[inline]
391+
/// This function returns the number of type and const generic params.
392+
/// It should only be used for diagnostics.
391393
pub fn num_generic_params(&self) -> usize {
392394
self.args.iter().filter(|arg| !matches!(arg, GenericArg::Lifetime(_))).count()
393395
}

compiler/rustc_hir_typeck/src/callee.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
129129
output
130130
}
131131

132+
#[instrument(level = "debug", skip(self, call_expr, callee_expr, arg_exprs, autoderef), ret)]
132133
fn try_overloaded_call_step(
133134
&self,
134135
call_expr: &'tcx hir::Expr<'tcx>,
@@ -138,10 +139,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
138139
) -> Option<CallStep<'tcx>> {
139140
let adjusted_ty =
140141
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
141-
debug!(
142-
"try_overloaded_call_step(call_expr={:?}, adjusted_ty={:?})",
143-
call_expr, adjusted_ty
144-
);
145142

146143
// If the callee is a bare function or a closure, then we're all set.
147144
match *adjusted_ty.kind() {

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
495495
}
496496
ty::ConstKind::Bound(debruijn, _) => {
497497
if debruijn >= self.binder_index {
498-
bug!("escaping bound type during canonicalization")
498+
bug!("escaping bound const during canonicalization")
499499
} else {
500500
return ct;
501501
}

compiler/rustc_middle/src/ty/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,12 @@ impl<'tcx> Instance<'tcx> {
511511
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
512512
}
513513

514+
#[instrument(level = "debug", skip(tcx), ret)]
514515
pub fn fn_once_adapter_instance(
515516
tcx: TyCtxt<'tcx>,
516517
closure_did: DefId,
517518
substs: ty::SubstsRef<'tcx>,
518519
) -> Option<Instance<'tcx>> {
519-
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
520520
let fn_once = tcx.require_lang_item(LangItem::FnOnce, None);
521521
let call_once = tcx
522522
.associated_items(fn_once)
@@ -536,7 +536,7 @@ impl<'tcx> Instance<'tcx> {
536536
assert_eq!(sig.inputs().len(), 1);
537537
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
538538

539-
debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
539+
debug!(?self_ty, ?sig);
540540
Some(Instance { def, substs })
541541
}
542542

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ where
407407
self.drop_ladder(fields, succ, unwind).0
408408
}
409409

410+
#[instrument(level = "debug", ret)]
410411
fn open_drop_for_box(&mut self, adt: ty::AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> BasicBlock {
411-
debug!("open_drop_for_box({:?}, {:?}, {:?})", self, adt, substs);
412-
413412
// drop glue is sent straight to codegen
414413
// box cannot be directly dereferenced
415414
let unique_ty = adt.non_enum_variant().fields[0].ty(self.tcx(), substs);
@@ -431,8 +430,8 @@ where
431430
self.drop_subpath(interior, interior_path, succ, unwind_succ)
432431
}
433432

433+
#[instrument(level = "debug", ret)]
434434
fn open_drop_for_adt(&mut self, adt: ty::AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> BasicBlock {
435-
debug!("open_drop_for_adt({:?}, {:?}, {:?})", self, adt, substs);
436435
if adt.variants().is_empty() {
437436
return self.elaborator.patch().new_block(BasicBlockData {
438437
statements: vec![],

compiler/rustc_mir_transform/src/shim.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,13 @@ impl<'tcx> CloneShimBuilder<'tcx> {
569569

570570
/// Builds a "call" shim for `instance`. The shim calls the function specified by `call_kind`,
571571
/// first adjusting its first argument according to `rcvr_adjustment`.
572+
#[instrument(level = "debug", skip(tcx), ret)]
572573
fn build_call_shim<'tcx>(
573574
tcx: TyCtxt<'tcx>,
574575
instance: ty::InstanceDef<'tcx>,
575576
rcvr_adjustment: Option<Adjustment>,
576577
call_kind: CallKind<'tcx>,
577578
) -> Body<'tcx> {
578-
debug!(
579-
"build_call_shim(instance={:?}, rcvr_adjustment={:?}, call_kind={:?})",
580-
instance, rcvr_adjustment, call_kind
581-
);
582-
583579
// `FnPtrShim` contains the fn pointer type that a call shim is being built for - this is used
584580
// to substitute into the signature of the shim. It is not necessary for users of this
585581
// MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`).
@@ -641,7 +637,7 @@ fn build_call_shim<'tcx>(
641637

642638
let span = tcx.def_span(def_id);
643639

644-
debug!("build_call_shim: sig={:?}", sig);
640+
debug!(?sig);
645641

646642
let mut local_decls = local_decls_for_sig(&sig, span);
647643
let source_info = SourceInfo::outermost(span);

compiler/rustc_trait_selection/src/infer.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
9393

9494
/// Normalizes associated types in `value`, potentially returning
9595
/// new obligations that must further be processed.
96+
#[instrument(level = "debug", skip(self, cause, param_env), ret)]
9697
fn partially_normalize_associated_types_in<T>(
9798
&self,
9899
cause: ObligationCause<'tcx>,
@@ -102,29 +103,20 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
102103
where
103104
T: TypeFoldable<'tcx>,
104105
{
105-
debug!("partially_normalize_associated_types_in(value={:?})", value);
106106
let mut selcx = traits::SelectionContext::new(self);
107107
let traits::Normalized { value, obligations } =
108108
traits::normalize(&mut selcx, param_env, cause, value);
109-
debug!(
110-
"partially_normalize_associated_types_in: result={:?} predicates={:?}",
111-
value, obligations
112-
);
113109
InferOk { value, obligations }
114110
}
115111

112+
#[instrument(level = "debug", skip(self), ret)]
116113
fn type_implements_trait(
117114
&self,
118115
trait_def_id: DefId,
119116
ty: Ty<'tcx>,
120117
params: SubstsRef<'tcx>,
121118
param_env: ty::ParamEnv<'tcx>,
122119
) -> traits::EvaluationResult {
123-
debug!(
124-
"type_implements_trait: trait_def_id={:?}, type={:?}, params={:?}, param_env={:?}",
125-
trait_def_id, ty, params, param_env
126-
);
127-
128120
let trait_ref =
129121
ty::TraitRef { def_id: trait_def_id, substs: self.tcx.mk_substs_trait(ty, params) };
130122

compiler/rustc_trait_selection/src/traits/mod.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ pub enum TraitQueryMode {
117117
}
118118

119119
/// Creates predicate obligations from the generic bounds.
120+
#[instrument(level = "debug", skip(cause, param_env))]
120121
pub fn predicates_for_generics<'tcx>(
121122
cause: impl Fn(usize, Span) -> ObligationCause<'tcx>,
122123
param_env: ty::ParamEnv<'tcx>,
123124
generic_bounds: ty::InstantiatedPredicates<'tcx>,
124125
) -> impl Iterator<Item = PredicateObligation<'tcx>> {
125-
let generic_bounds = generic_bounds;
126-
debug!("predicates_for_generics(generic_bounds={:?})", generic_bounds);
127-
128126
std::iter::zip(generic_bounds.predicates, generic_bounds.spans).enumerate().map(
129127
move |(idx, (predicate, span))| Obligation {
130128
cause: cause(idx, span),
@@ -140,19 +138,14 @@ pub fn predicates_for_generics<'tcx>(
140138
/// `bound` or is not known to meet bound (note that this is
141139
/// conservative towards *no impl*, which is the opposite of the
142140
/// `evaluate` methods).
141+
#[instrument(level = "debug", skip(infcx, param_env, span), ret)]
143142
pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
144143
infcx: &InferCtxt<'tcx>,
145144
param_env: ty::ParamEnv<'tcx>,
146145
ty: Ty<'tcx>,
147146
def_id: DefId,
148147
span: Span,
149148
) -> bool {
150-
debug!(
151-
"type_known_to_meet_bound_modulo_regions(ty={:?}, bound={:?})",
152-
ty,
153-
infcx.tcx.def_path_str(def_id)
154-
);
155-
156149
let trait_ref =
157150
ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) });
158151
let obligation = Obligation {
@@ -163,12 +156,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
163156
};
164157

165158
let result = infcx.predicate_must_hold_modulo_regions(&obligation);
166-
debug!(
167-
"type_known_to_meet_ty={:?} bound={} => {:?}",
168-
ty,
169-
infcx.tcx.def_path_str(def_id),
170-
result
171-
);
159+
debug!(?result);
172160

173161
if result && ty.has_non_region_infer() {
174162
// Because of inference "guessing", selection can sometimes claim
@@ -190,21 +178,9 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
190178
// *definitively* show that it implements `Copy`. Otherwise,
191179
// assume it is move; linear is always ok.
192180
match &errors[..] {
193-
[] => {
194-
debug!(
195-
"type_known_to_meet_bound_modulo_regions: ty={:?} bound={} success",
196-
ty,
197-
infcx.tcx.def_path_str(def_id)
198-
);
199-
true
200-
}
181+
[] => true,
201182
errors => {
202-
debug!(
203-
?ty,
204-
bound = %infcx.tcx.def_path_str(def_id),
205-
?errors,
206-
"type_known_to_meet_bound_modulo_regions"
207-
);
183+
debug!(?errors);
208184
false
209185
}
210186
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1132,12 +1132,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11321132

11331133
/// filter_impls filters constant trait obligations and candidates that have a positive impl
11341134
/// for a negative goal and a negative impl for a positive goal
1135-
#[instrument(level = "debug", skip(self))]
1135+
#[instrument(level = "debug", skip(self, candidates))]
11361136
fn filter_impls(
11371137
&mut self,
11381138
candidates: Vec<SelectionCandidate<'tcx>>,
11391139
obligation: &TraitObligation<'tcx>,
11401140
) -> Vec<SelectionCandidate<'tcx>> {
1141+
trace!("{candidates:#?}");
11411142
let tcx = self.tcx();
11421143
let mut result = Vec::with_capacity(candidates.len());
11431144

@@ -1177,6 +1178,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11771178
}
11781179
}
11791180

1181+
trace!("{result:#?}");
11801182
result
11811183
}
11821184

0 commit comments

Comments
 (0)