Skip to content

Commit

Permalink
add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Aug 19, 2019
1 parent f86521e commit b51df1d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/librustc/hir/lowering.rs
Expand Up @@ -322,7 +322,7 @@ enum ParenthesizedGenericArgs {
/// `resolve_lifetime` module. Often we "fallthrough" to that code by generating
/// an "elided" or "underscore" lifetime name. In the future, we probably want to move
/// everything into HIR lowering.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
enum AnonymousLifetimeMode {
/// For **Modern** cases, create a new anonymous region parameter
/// and reference that.
Expand Down Expand Up @@ -715,10 +715,16 @@ impl<'a> LoweringContext<'a> {
anonymous_lifetime_mode: AnonymousLifetimeMode,
op: impl FnOnce(&mut Self) -> R,
) -> R {
debug!(
"with_anonymous_lifetime_mode(anonymous_lifetime_mode={:?})",
anonymous_lifetime_mode,
);
let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode;
self.anonymous_lifetime_mode = anonymous_lifetime_mode;
let result = op(self);
self.anonymous_lifetime_mode = old_anonymous_lifetime_mode;
debug!("with_anonymous_lifetime_mode: restoring anonymous_lifetime_mode={:?}",
old_anonymous_lifetime_mode);
result
}

Expand Down Expand Up @@ -1355,6 +1361,13 @@ impl<'a> LoweringContext<'a> {
opaque_ty_node_id: NodeId,
lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds,
) -> hir::TyKind {
debug!(
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
fn_def_id,
opaque_ty_node_id,
span,
);

// Make sure we know that some funky desugaring has been going on here.
// This is a first: there is code in other places like for loop
// desugaring that explicitly states that we don't want to track that.
Expand Down Expand Up @@ -1382,6 +1395,14 @@ impl<'a> LoweringContext<'a> {
&hir_bounds,
);

debug!(
"lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,
);

debug!(
"lower_opaque_impl_trait: lifetime_defs={:#?}", lifetime_defs,
);

self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
Expand All @@ -1397,7 +1418,7 @@ impl<'a> LoweringContext<'a> {
origin: hir::OpaqueTyOrigin::FnReturn,
};

trace!("exist ty from impl trait def-index: {:#?}", opaque_ty_def_index);
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_index);
let opaque_ty_id = lctx.generate_opaque_type(
opaque_ty_node_id,
opaque_ty_item,
Expand Down Expand Up @@ -1445,6 +1466,13 @@ impl<'a> LoweringContext<'a> {
parent_index: DefIndex,
bounds: &hir::GenericBounds,
) -> (HirVec<hir::GenericArg>, HirVec<hir::GenericParam>) {
debug!(
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
parent_index={:?}, \
bounds={:#?})",
opaque_ty_id, parent_index, bounds,
);

// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
// appear in the bounds, excluding lifetimes that are created within the bounds.
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
Expand Down Expand Up @@ -2182,6 +2210,14 @@ impl<'a> LoweringContext<'a> {
fn_def_id: DefId,
opaque_ty_node_id: NodeId,
) -> hir::FunctionRetTy {
debug!(
"lower_async_fn_ret_ty(\
output={:?}, \
fn_def_id={:?}, \
opaque_ty_node_id={:?})",
output, fn_def_id, opaque_ty_node_id,
);

let span = output.span();

let opaque_ty_span = self.mark_span_with_reason(
Expand Down Expand Up @@ -2264,6 +2300,8 @@ impl<'a> LoweringContext<'a> {
),
);

debug!("lower_async_fn_ret_ty: future_bound={:#?}", future_bound);

// Calculate all the lifetimes that should be captured
// by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band.
Expand Down
1 change: 1 addition & 0 deletions src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -1108,6 +1108,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// 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) = self.opaque_types.get(&def_id) {
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
return opaque_defn.concrete_ty;
}
let span = tcx.def_span(def_id);
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -585,6 +585,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.is_in_fn_syntax = was_in_fn_syntax;
}
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
}
Expand Down Expand Up @@ -897,6 +898,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}

fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
debug!("visit_lifetime(lifetime_ref={:?})", lifetime_ref);
if lifetime_ref.is_elided() {
self.resolve_elided_lifetimes(vec![lifetime_ref]);
return;
Expand Down Expand Up @@ -2347,6 +2349,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}

fn resolve_elided_lifetimes(&mut self, lifetime_refs: Vec<&'tcx hir::Lifetime>) {
debug!("resolve_elided_lifetimes(lifetime_refs={:?})", lifetime_refs);

if lifetime_refs.is_empty() {
return;
}
Expand Down Expand Up @@ -2539,6 +2543,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}

fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
debug!("resolve_object_lifetime_default(lifetime_ref={:?})", lifetime_ref);
let mut late_depth = 0;
let mut scope = self.scope;
let lifetime = loop {
Expand Down

0 comments on commit b51df1d

Please sign in to comment.