From 5afeed05e84afc5ee9bec6a8cc1003e0b97aa7fb Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 10 Aug 2021 11:28:54 +0000 Subject: [PATCH] Use tracing debugging in `fold_opaque_ty` --- .../rustc_trait_selection/src/opaque_types.rs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 8abcdb5e89b..221ce0062a6 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -863,7 +863,6 @@ struct Instantiator<'a, 'tcx> { } impl<'a, 'tcx> Instantiator<'a, 'tcx> { - #[instrument(level = "debug", skip(self))] fn instantiate_opaque_types_in_map>(&mut self, value: T) -> T { let tcx = self.infcx.tcx; value.fold_with(&mut BottomUpFolder { @@ -954,6 +953,7 @@ fn instantiate_opaque_types_in_map>(&mut self, value: T) - }) } + #[instrument(skip(self), level = "debug")] fn fold_opaque_ty( &mut self, ty: Ty<'tcx>, @@ -961,28 +961,20 @@ fn fold_opaque_ty( origin: hir::OpaqueTyOrigin, ) -> Ty<'tcx> { let infcx = self.infcx; - let tcx = infcx.tcx; let OpaqueTypeKey { def_id, substs } = opaque_type_key; - debug!("instantiate_opaque_types: Opaque(def_id={:?}, substs={:?})", def_id, substs); - // Use the same type variable if the exact same opaque type appears more // than once in the return type (e.g., if it's passed to a type alias). if let Some(opaque_defn) = infcx.inner.borrow().opaque_types.get(&opaque_type_key) { - debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty); + debug!("re-using cached concrete type {:?}", opaque_defn.concrete_ty.kind()); return opaque_defn.concrete_ty; } + let ty_var = infcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span: self.value_span, }); - // Make sure that we are in fact defining the *entire* type - // (e.g., `type Foo = impl Bar;` needs to be - // defined by a function like `fn foo() -> Foo`). - debug!("instantiate_opaque_types: param_env={:#?}", self.param_env,); - debug!("instantiate_opaque_types: generics={:#?}", tcx.generics_of(def_id),); - // Ideally, we'd get the span where *this specific `ty` came // from*, but right now we just use the span from the overall // value being folded. In simple cases like `-> impl Foo`, @@ -999,7 +991,7 @@ fn fold_opaque_ty( infcx.opaque_types_vars.insert(ty_var, ty); } - debug!("instantiate_opaque_types: ty_var={:?}", ty_var); + debug!("generated new type inference var {:?}", ty_var.kind()); self.compute_opaque_type_obligations(opaque_type_key); ty_var @@ -1011,7 +1003,7 @@ fn compute_opaque_type_obligations(&mut self, opaque_type_key: OpaqueTypeKey<'tc let OpaqueTypeKey { def_id, substs } = opaque_type_key; let item_bounds = tcx.explicit_item_bounds(def_id); - debug!("instantiate_opaque_types: bounds={:#?}", item_bounds); + debug!(?item_bounds); let bounds: Vec<_> = item_bounds.iter().map(|(bound, _)| bound.subst(tcx, substs)).collect(); @@ -1023,7 +1015,7 @@ fn compute_opaque_type_obligations(&mut self, opaque_type_key: OpaqueTypeKey<'tc ); self.obligations.extend(obligations); - debug!("instantiate_opaque_types: bounds={:?}", bounds); + debug!(?bounds); for predicate in &bounds { if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {