Skip to content

Commit af5f158

Browse files
committed
Use tracing::instrument for better analzyabilty of logs around impl trait
1 parent 2aafe45 commit af5f158

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub struct OpaqueTypeDecl<'tcx> {
9595
}
9696

9797
/// Whether member constraints should be generated for all opaque types
98+
#[derive(Debug)]
9899
pub enum GenerateMemberConstraints {
99100
/// The default, used by typeck
100101
WhenRequired,
@@ -183,6 +184,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
183184
/// obligations
184185
/// - `value` -- the value within which we are instantiating opaque types
185186
/// - `value_span` -- the span where the value came from, used in error reporting
187+
#[instrument(level = "debug", skip(self))]
188+
// FIXME(oli-obk): this function is invoked twice: once with the crate root, and then for each body that
189+
// actually could be a defining use. It is unclear to me why we run all of it twice. Figure out what
190+
// happens and document that or fix it.
186191
fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
187192
&self,
188193
parent_def_id: LocalDefId,
@@ -191,11 +196,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
191196
value: T,
192197
value_span: Span,
193198
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
194-
debug!(
195-
"instantiate_opaque_types(value={:?}, parent_def_id={:?}, body_id={:?}, \
196-
param_env={:?}, value_span={:?})",
197-
value, parent_def_id, body_id, param_env, value_span,
198-
);
199199
let mut instantiator = Instantiator {
200200
infcx: self,
201201
parent_def_id,
@@ -389,22 +389,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
389389
}
390390

391391
/// See `constrain_opaque_types` for documentation.
392+
#[instrument(level = "debug", skip(self, free_region_relations))]
392393
fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
393394
&self,
394395
def_id: DefId,
395396
opaque_defn: &OpaqueTypeDecl<'tcx>,
396397
mode: GenerateMemberConstraints,
397398
free_region_relations: &FRR,
398399
) {
399-
debug!("constrain_opaque_type()");
400-
debug!("constrain_opaque_type: def_id={:?}", def_id);
401-
debug!("constrain_opaque_type: opaque_defn={:#?}", opaque_defn);
402-
403400
let tcx = self.tcx;
404401

405402
let concrete_ty = self.resolve_vars_if_possible(opaque_defn.concrete_ty);
406403

407-
debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
404+
debug!(?concrete_ty);
408405

409406
let first_own_region = match opaque_defn.origin {
410407
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => {
@@ -469,8 +466,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
469466
};
470467

471468
// Compute the least upper bound of it with the other regions.
472-
debug!("constrain_opaque_types: least_region={:?}", least_region);
473-
debug!("constrain_opaque_types: subst_region={:?}", subst_region);
469+
debug!(?least_region);
470+
debug!(?subst_region);
474471
match least_region {
475472
None => least_region = Some(subst_region),
476473
Some(lr) => {
@@ -997,8 +994,8 @@ struct Instantiator<'a, 'tcx> {
997994
}
998995

999996
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
997+
#[instrument(level = "debug", skip(self))]
1000998
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
1001-
debug!("instantiate_opaque_types_in_map(value={:?})", value);
1002999
let tcx = self.infcx.tcx;
10031000
value.fold_with(&mut BottomUpFolder {
10041001
tcx,
@@ -1075,12 +1072,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10751072
return self.fold_opaque_ty(ty, def_id.to_def_id(), substs, origin);
10761073
}
10771074

1078-
debug!(
1079-
"instantiate_opaque_types_in_map: \
1080-
encountered opaque outside its definition scope \
1081-
def_id={:?}",
1082-
def_id,
1083-
);
1075+
debug!(?def_id, "encountered opaque outside its definition scope");
10841076
}
10851077
}
10861078

@@ -1091,6 +1083,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10911083
})
10921084
}
10931085

1086+
#[instrument(level = "debug", skip(self))]
10941087
fn fold_opaque_ty(
10951088
&mut self,
10961089
ty: Ty<'tcx>,
@@ -1101,16 +1094,14 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11011094
let infcx = self.infcx;
11021095
let tcx = infcx.tcx;
11031096

1104-
debug!("instantiate_opaque_types: Opaque(def_id={:?}, substs={:?})", def_id, substs);
1105-
11061097
// Use the same type variable if the exact same opaque type appears more
11071098
// than once in the return type (e.g., if it's passed to a type alias).
11081099
if let Some(opaque_defn) = self.opaque_types.get(&def_id) {
11091100
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
11101101
return opaque_defn.concrete_ty;
11111102
}
11121103
let span = tcx.def_span(def_id);
1113-
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
1104+
debug!(?self.value_span, ?span);
11141105
let ty_var = infcx
11151106
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
11161107

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,19 +915,19 @@ fn check_fn_or_method<'fcx, 'tcx>(
915915
/// fn b<T>() -> Foo<T, u32> { .. }
916916
/// ```
917917
///
918+
#[instrument(level = "debug", skip(tcx, fcx))]
918919
fn check_opaque_types<'fcx, 'tcx>(
919920
tcx: TyCtxt<'tcx>,
920921
fcx: &FnCtxt<'fcx, 'tcx>,
921922
fn_def_id: LocalDefId,
922923
span: Span,
923924
ty: Ty<'tcx>,
924925
) {
925-
trace!("check_opaque_types(ty={:?})", ty);
926926
ty.fold_with(&mut ty::fold::BottomUpFolder {
927927
tcx: fcx.tcx,
928928
ty_op: |ty| {
929929
if let ty::Opaque(def_id, substs) = *ty.kind() {
930-
trace!("check_opaque_types: opaque_ty, {:?}, {:?}", def_id, substs);
930+
trace!(?def_id, ?substs, "opaque type");
931931
let generics = tcx.generics_of(def_id);
932932

933933
let opaque_hir_id = if let Some(local_id) = def_id.as_local() {
@@ -965,7 +965,7 @@ fn check_opaque_types<'fcx, 'tcx>(
965965
if !may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) {
966966
return ty;
967967
}
968-
trace!("check_opaque_types: may define, generics={:#?}", generics);
968+
trace!(?generics, "may define");
969969
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default();
970970
for (i, arg) in substs.iter().enumerate() {
971971
let arg_is_param = match arg.unpack() {

0 commit comments

Comments
 (0)