Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging of capture analysis #25

Closed
wants to merge 2 commits into from
Closed

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Oct 22, 2020

This PR aims to improve the logging of capture analysis by reducing the verbosity of the logs.

For instance, consider the following test case: src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs

Previously, the logs would have outputted the following to stdout:

For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): capture information: {
    Place {
        base_ty: Point,
        base: Upvar(
            UpvarId(HirId { owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main), local_id: 1 };`p`;DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0})),
        ),
        projections: [
            Projection {
                ty: i32,
                kind: Field(
                    0,
                    0,
                ),
            },
        ],
    }: CaptureInfo {
        expr_id: Some(
            HirId {
                owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main),
                local_id: 15,
            },
        ),
        capture_kind: ByRef(
            UpvarBorrow(MutBorrow, '_#34r),
        ),
    },
    Place {
        base_ty: Point,
        base: Upvar(
            UpvarId(HirId { owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main), local_id: 1 };`p`;DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0})),
        ),
        projections: [],
    }: CaptureInfo {
        expr_id: Some(
            HirId {
                owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main),
                local_id: 35,
            },
        ),
        capture_kind: ByRef(
            UpvarBorrow(ImmBorrow, '_#35r),
        ),
    },
}

and the following to stderr:

error[E0658]: attributes on expressions are experimental
  --> $DIR/simple-struct-min-capture.rs:25:17
   |
LL |     let mut c = #[rustc_capture_analysis]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
   = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
  --> $DIR/simple-struct-min-capture.rs:3:12
   |
LL | #![feature(capture_disjoint_fields)]
   |            ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(incomplete_features)]` on by default
   = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.

After the changes, the following is being outputted to stderr:

error[E0658]: attributes on expressions are experimental
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:25:17
   |
25 |     let mut c = #[rustc_capture_analysis]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
   = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:3:12
  |
3 | #![feature(capture_disjoint_fields)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): Using new-style capture analysis
error: Capturing p[(0, 0)] -> MutBorrow
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:28:9
   |
28 |         p.x += 10;
   |         ^^^

error: Capturing p[] -> ImmBorrow
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:29:26
   |
29 |         println!("{:?}", p);
   |                          ^

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.

Closes rust-lang/project-rfc-2229#19


This change is Reviewable

Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
@arora-aman arora-aman changed the base branch from master to use_places_new October 22, 2020 01:16
compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

compiler/rustc_typeck/src/check/upvar.rs Show resolved Hide resolved
compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
Co-authored-by: Jenny Wills <wills.jenniferg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve logging of capture analysis
2 participants