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

Refactor HIR places #14

Closed
1 of 5 tasks
arora-aman opened this issue May 29, 2020 · 2 comments
Closed
1 of 5 tasks

Refactor HIR places #14

arora-aman opened this issue May 29, 2020 · 2 comments
Assignees
Projects
Milestone

Comments

@arora-aman
Copy link
Member

arora-aman commented May 29, 2020

Discussion: https://rust-lang.zulipchat.com/#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/refactoring.20.60hir.3A.3APlace.60.20and.20.60hir_id.60

  • Investigate usage of usage of hir_id of hir::Place and confirm it is only being used for error reporting.

The current suggestion is to

  • Refactor code and rename Place to PlaceReference
  • Reintroduce Place except hir_id and span are not part of Place anymore
  • Modify PlaceReference so it looks something like this:
struct PlaceReference {
    hir_id: HirId,
    span: Span,
    place: Place,
}
  • Replace PlaceReference to Place if it does not need hir_id and span

Place documentation

@arora-aman arora-aman added this to the 2229-MVP milestone May 29, 2020
@arora-aman arora-aman added this to To Do in RFC 2229 via automation May 29, 2020
@arora-aman arora-aman moved this from To Do to In Progress in RFC 2229 May 29, 2020
@arora-aman arora-aman self-assigned this May 29, 2020
@roxelo
Copy link
Member

roxelo commented Jun 1, 2020

The current suggestion is to

  • Refactor code and rename Place to PlaceReference
  • Reintroduce Place except hir_id and span are not part of Place anymore
  • Modify PlaceReference so it looks something like this:
struct PlaceReference {
    hir_id: HirId,
    span: Span,
    place: Place,
}
  • Replace PlaceReference to Place if it does not need hir_id and span

Place documentation

First step is to look at the usage of hir_id of hir::Place and confirm it is only being used for error reporting.

@roxelo roxelo self-assigned this Jun 1, 2020
@arora-aman
Copy link
Member Author

arora-aman commented Jun 3, 2020

Within librustc_typchk, HirPlace is referred as mc::Place outside it is referred toi as rustc_typeck::expr_use_visitor::Place.

Easiest way I could think of was to check for files where expr_use_visitor::Place was being included.

  1. rg "expr_use.*\*", Search for patterns like "expr_use<anything>* to match for an include all from expr_use_visitor, returned nothing.
  2. rg "\bexpr.*\bPlace\b". \b is used to mark a word boundry. So this will allow patterns like expr_use_visitior::Place but not someexprPlace. The intent was to search for lines like expr_use_visitor{Place

Removing results from within typchk and some extra unintended matches we have:

librustc_mir_build/build/expr/as_place.rs
69:    crate fn as_place<M>(&mut self, mut block: BasicBlock, expr: M) -> BlockAnd<Place<'tcx>>

librustc_mir_build/build/expr/into.rs
398:                debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
406:                debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
415:                debug_assert!(Category::of(&expr.kind) == Some(Category::Place));

tools/clippy/clippy_lints/src/escape.rs
9:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

tools/clippy/clippy_lints/src/loops.rs
31:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

tools/clippy/clippy_lints/src/utils/usage.rs
11:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

MIR relies on hir::Expr for lowering and not HirPlace (thanks to Matthew Jaspeer) so we are left with


tools/clippy/clippy_lints/src/escape.rs
9:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

tools/clippy/clippy_lints/src/loops.rs
31:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

tools/clippy/clippy_lints/src/utils/usage.rs
11:use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

More info on ripgrep/rg: https://github.com/sexxi-goose/internal_fydp_documentation/wiki/Dev-Setup#searching-the-codebase

RFC 2229 automation moved this from In Progress to Done Jun 20, 2020
sexxi-bot pushed a commit that referenced this issue Oct 5, 2020
This is a combination of 18 commits.

Commit #2:

Additional examples and some small improvements.

Commit #3:

fixed mir-opt non-mir extensions and spanview title elements

Corrected a fairly recent assumption in runtest.rs that all MIR dump
files end in .mir. (It was appending .mir to the graphviz .dot and
spanview .html file names when generating blessed output files. That
also left outdated files in the baseline alongside the files with the
incorrect names, which I've now removed.)

Updated spanview HTML title elements to match their content, replacing a
hardcoded and incorrect name that was left in accidentally when
originally submitted.

Commit #4:

added more test examples

also improved Makefiles with support for non-zero exit status and to
force validation of tests unless a specific test overrides it with a
specific comment.

Commit #5:

Fixed rare issues after testing on real-world crate

Commit #6:

Addressed PR feedback, and removed temporary -Zexperimental-coverage

-Zinstrument-coverage once again supports the latest capabilities of
LLVM instrprof coverage instrumentation.

Also fixed a bug in spanview.

Commit #7:

Fix closure handling, add tests for closures and inner items

And cleaned up other tests for consistency, and to make it more clear
where spans start/end by breaking up lines.

Commit #8:

renamed "typical" test results "expected"

Now that the `llvm-cov show` tests are improved to normally expect
matching actuals, and to allow individual tests to override that
expectation.

Commit #9:

test coverage of inline generic struct function

Commit #10:

Addressed review feedback

* Removed unnecessary Unreachable filter.
* Replaced a match wildcard with remining variants.
* Added more comments to help clarify the role of successors() in the
CFG traversal

Commit #11:

refactoring based on feedback

* refactored `fn coverage_spans()`.
* changed the way I expand an empty coverage span to improve performance
* fixed a typo that I had accidently left in, in visit.rs

Commit #12:

Optimized use of SourceMap and SourceFile

Commit rust-lang#13:

Fixed a regression, and synched with upstream

Some generated test file names changed due to some new change upstream.

Commit #14:

Stripping out crate disambiguators from demangled names

These can vary depending on the test platform.

Commit #15:

Ignore llvm-cov show diff on test with generics, expand IO error message

Tests with generics produce llvm-cov show results with demangled names
that can include an unstable "crate disambiguator" (hex value). The
value changes when run in the Rust CI Windows environment. I added a sed
filter to strip them out (in a prior commit), but sed also appears to
fail in the same environment. Until I can figure out a workaround, I'm
just going to ignore this specific test result. I added a FIXME to
follow up later, but it's not that critical.

I also saw an error with Windows GNU, but the IO error did not
specify a path for the directory or file that triggered the error. I
updated the error messages to provide more info for next, time but also
noticed some other tests with similar steps did not fail. Looks
spurious.

Commit #16:

Modify rust-demangler to strip disambiguators by default

Commit #17:

Remove std::process::exit from coverage tests

Due to Issue rust-lang#77553, programs that call std::process::exit() do not
generate coverage results on Windows MSVC.

Commit #18:

fix: test file paths exceeding Windows max path len
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
RFC 2229
  
Done
Development

No branches or pull requests

2 participants