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

Extract rustc_ast_passes, move gating, & refactor linting #67806

Merged
merged 18 commits into from
Jan 11, 2020

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Jan 2, 2020

Based on #67770.

This PR extracts a crate rustc_ast_passes:

  • ast_validation.rs, which is contributed by rustc_passes (now only has HIR based passes) -- the goal here is to improve recompilation of the parser,
  • feature_gate.rs, which is contributed by syntax and performs post-expansion-gating & final erroring for pre-expansion gating,
  • show_span, which is contributed by syntax.

To facilitate this, we first have to also:

  • Move {leveled_}feature_err{_err} from syntax::feature_gate::check into rustc_session::parse.
  • Move get_features into rustc_parse::config, the only place it is used.
  • Move some some lint datatypes and traits, e.g. LintBuffer, BufferedEarlyLint, BuiltinLintDiagnostics, LintPass, and LintArray into rustc_session::lint.
  • Move all the hard-wired lint statics into rustc_session::lint::builtin.

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 4, 2020
@Centril Centril force-pushed the splitsynmore branch 3 times, most recently from 9e9898d to 4d9771c Compare January 5, 2020 05:34
@rust-highfive

This comment has been minimized.

@Centril Centril changed the title [WIP] syntax: split out feature gating & feature collection Extract rustc_ast_passes, move gating, & refactor linting Jan 5, 2020
@Centril
Copy link
Contributor Author

Centril commented Jan 5, 2020

r? @petrochenkov

@bors

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@@ -10,6 +10,7 @@ path = "lib.rs"

[dependencies]
log = "0.4"
rustc_error_codes = { path = "../librustc_error_codes" }
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened with the idea of rustc_driver being the only crate depending on rustc_error_codes?
Without that the separation of error codes into a single crate only made things worse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's on my agenda to fix this but I haven't gotten around to it yet. Basically you only need to remove the let _= $code; thing and you can remove all the dependencies.

@@ -70,6 +72,20 @@ pub enum GateStrength {
Soft,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, looks like we have two mechanisms for soft feature-gating - this one and the soft_unstable lint - of which this one is unused.

I think we should remove GateStrength entirely and simplify the feature gating infra.
"Soft" feature gates are exceptional and having an isolated lint is more than enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, placing the feature gating stuff into parse.rs looks strange, it's not related to parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should remove GateStrength entirely and simplify the feature gating infra.

Sure, that seems like a good idea, though it seems like an independent change?

Also, placing the feature gating stuff into parse.rs looks strange, it's not related to parsing.

Well... GatedSpans is inside rustc_session::parse. My goal here is to remove any mentions of ParseSess within syntax so that I can invert the current dependency on rustc_session that syntax has and which is bad for parallelism. This parse.rs file felt like the best location to put it besides a new module, but I know you don't like those tiny ones. ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, that seems like a good idea, though it seems like an independent change?

Yeah, this is material for a different PR (perhaps I'll do it myself today).

My goal here is to remove any mentions of ParseSess within syntax so that I can invert the current dependency on rustc_session that syntax

I see.

Copy link
Contributor

Choose a reason for hiding this comment

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

So rustc_session::parse means ParseSess and its methods.
I guess I can live with that, especially given that #68018 reduces the surface of feature gating API exposed by rustc_session::parse.

@petrochenkov
Copy link
Contributor

Two questions:

  • Why is some feature gating moved to rustc_session instead of staying in syntax?
    The primary feature gating pass is in rustc_ast_passes, but rustc_ast_passes still depends on syntax (and will depend on rustc_ast in the future), so moving feature gating doesn't break any dependencies.
  • How is the linting infra refactoring related to the rest of the PR. As I understand, the lint infra is moved earlier so that a single lint infra can be used in the whole compiler instead of having some separate "early buffered linting" for the frontend crates.
    However, this move doesn't break any dependencies (with rustc_ast_passes in particular), and I'd prefer someone else (e.g. Mark-Simulacrum) to review it.

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Jan 6, 2020

Why is some feature gating moved to rustc_session instead of staying in syntax?

See #67806 (comment).

How is the linting infra refactoring related to the rest of the PR. As I understand, the lint infra is moved earlier so that a single lint infra can be used in the whole compiler instead of having some separate "early buffered linting" for the frontend crates.
However, this move doesn't break any dependencies (with rustc_ast_passes in particular), and I'd prefer someone else (e.g. Mark-Simulacrum) to review it.

The reason I included the lint infra refactoring in this PR is because it allows us to break rustc_ast_passes's dependency on rustc, which is always nice for parallelism and incr.comp. This is also not the only crate which would benefit from this. For example, rustc_ast_lowering needs to refer to a specific &'static Lint as well as the LintBuffer type, but is otherwise close to losing its dependency on rustc as well (this is my overall strategy: I look for imports to rustc:: and then try to remove them over time in various PRs -- but I try to do it in a way that makes sense semantically).

Bigger picture, my goal with lints is to move out these data+traits parts of the rustc::lint infrastructure into rustc_session::lint. Eventually, this can become its own crate (e.g. rustc_lint_infra and we might be able to nix rustc::lint entirely.

@rust-highfive

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Jan 7, 2020

r? @Mark-Simulacrum

@bors

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Jan 8, 2020
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 8, 2020
@Centril
Copy link
Contributor Author

Centril commented Jan 11, 2020

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Jan 11, 2020

📌 Commit 682f500 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 11, 2020
Centril added a commit to Centril/rust that referenced this pull request Jan 11, 2020
Extract `rustc_ast_passes`, move gating, & refactor linting

Based on rust-lang#67770.

This PR extracts a crate `rustc_ast_passes`:

- `ast_validation.rs`, which is contributed by `rustc_passes` (now only has HIR based passes) -- the goal here is to improve recompilation of the parser,
- `feature_gate.rs`, which is contributed by `syntax` and performs post-expansion-gating & final erroring for pre-expansion gating,
- `show_span`, which is contributed by `syntax`.

To facilitate this, we first have to also:

- Move `{leveled_}feature_err{_err}` from `syntax::feature_gate::check` into `rustc_session::parse`.
- Move `get_features` into `rustc_parse::config`, the only place it is used.
- Move some some lint datatypes and traits, e.g. `LintBuffer`, `BufferedEarlyLint`, `BuiltinLintDiagnostics`, `LintPass`, and `LintArray` into `rustc_session::lint`.
- Move all the hard-wired lint `static`s into `rustc_session::lint::builtin`.
Centril added a commit to Centril/rust that referenced this pull request Jan 11, 2020
Extract `rustc_ast_passes`, move gating, & refactor linting

Based on rust-lang#67770.

This PR extracts a crate `rustc_ast_passes`:

- `ast_validation.rs`, which is contributed by `rustc_passes` (now only has HIR based passes) -- the goal here is to improve recompilation of the parser,
- `feature_gate.rs`, which is contributed by `syntax` and performs post-expansion-gating & final erroring for pre-expansion gating,
- `show_span`, which is contributed by `syntax`.

To facilitate this, we first have to also:

- Move `{leveled_}feature_err{_err}` from `syntax::feature_gate::check` into `rustc_session::parse`.
- Move `get_features` into `rustc_parse::config`, the only place it is used.
- Move some some lint datatypes and traits, e.g. `LintBuffer`, `BufferedEarlyLint`, `BuiltinLintDiagnostics`, `LintPass`, and `LintArray` into `rustc_session::lint`.
- Move all the hard-wired lint `static`s into `rustc_session::lint::builtin`.
bors added a commit that referenced this pull request Jan 11, 2020
Rollup of 8 pull requests

Successful merges:

 - #67666 (make use of pointer::is_null)
 - #67806 (Extract `rustc_ast_passes`, move gating, & refactor linting)
 - #68043 (Add some missing timers)
 - #68074 (Add `llvm-skip-rebuild` flag to `x.py`)
 - #68079 (Clarify suggestion for E0013)
 - #68084 (Do not ICE on unicode next point)
 - #68102 (Inline some conversion methods around OsStr)
 - #68106 (Fix issue with using `self` module via indirection)

Failed merges:

r? @ghost
@bors bors merged commit 682f500 into rust-lang:master Jan 11, 2020
@Centril Centril deleted the splitsynmore branch January 11, 2020 06:34
Centril added a commit to Centril/rust that referenced this pull request Jan 11, 2020
feature_gate: Remove `GateStrength`

The "soft feature gating" from `feature_gate/check.rs` is unused, and even if it were used, hardcoded warning is not a good solution and [deny-by-default lint](rust-lang#64266) would be a better way to do this.

cc rust-lang#67806 (comment)
r? @Centril
Centril added a commit to Centril/rust that referenced this pull request Jan 11, 2020
feature_gate: Remove `GateStrength`

The "soft feature gating" from `feature_gate/check.rs` is unused, and even if it were used, hardcoded warning is not a good solution and [deny-by-default lint](rust-lang#64266) would be a better way to do this.

cc rust-lang#67806 (comment)
r? @Centril
JohnTitor added a commit to JohnTitor/rust-clippy that referenced this pull request Jan 11, 2020
JohnTitor added a commit to JohnTitor/rust-clippy that referenced this pull request Jan 11, 2020
Centril added a commit to Centril/rust that referenced this pull request Jan 11, 2020
…lacrum

Move more of `rustc::lint` into `rustc_lint`

Based on rust-lang#67806.

Here we try to consolidate more of the linting infra into `rustc::lint`. Some high-level notes:

- We now store an `Lrc<dyn Any + Send + Sync>` as opposed to `Lrc<LintStore>` in the `GlobalCtxt`. This enables us to avoid referring to the type, breaking a cyclic dependency, and so we can move things from `rustc::lint` to `rustc_lint`.

- `in_derive_expansion` is, and needs to, be moved as a method on `Span`.

- We reduce the number of ways on `tcx` to emit a lint so that the developer UX is more streamlined.

- `LintLevelsBuilder` is moved to `rustc_lint::levels`, leaving behind `LintLevelMap/Set` in a purified form due to current constraints (hopefully fixable in the future after rust-lang#68133).

- `struct_lint_level` is moved to `rustc::lint` due to current dependency constraints.

- `rustc::context` is moved to `rustc_lint::context`.

- The visitors in `rustc::lint` are moved to `rustc_lint::passes`.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 11, 2020
…lacrum

Move more of `rustc::lint` into `rustc_lint`

Based on rust-lang#67806.

Here we try to consolidate more of the linting infra into `rustc::lint`. Some high-level notes:

- We now store an `Lrc<dyn Any + Send + Sync>` as opposed to `Lrc<LintStore>` in the `GlobalCtxt`. This enables us to avoid referring to the type, breaking a cyclic dependency, and so we can move things from `rustc::lint` to `rustc_lint`.

- `in_derive_expansion` is, and needs to, be moved as a method on `Span`.

- We reduce the number of ways on `tcx` to emit a lint so that the developer UX is more streamlined.

- `LintLevelsBuilder` is moved to `rustc_lint::levels`, leaving behind `LintLevelMap/Set` in a purified form due to current constraints (hopefully fixable in the future after rust-lang#68133).

- `struct_lint_level` is moved to `rustc::lint` due to current dependency constraints.

- `rustc::lint::context` is moved to `rustc_lint::context`.

- The visitors in `rustc::lint` are moved to `rustc_lint::passes`.
Centril added a commit to Centril/rust that referenced this pull request Jan 12, 2020
…lacrum

Move more of `rustc::lint` into `rustc_lint`

Based on rust-lang#67806.

Here we try to consolidate more of the linting infra into `rustc::lint`. Some high-level notes:

- We now store an `Lrc<dyn Any + Send + Sync>` as opposed to `Lrc<LintStore>` in the `GlobalCtxt`. This enables us to avoid referring to the type, breaking a cyclic dependency, and so we can move things from `rustc::lint` to `rustc_lint`.

- `in_derive_expansion` is, and needs to, be moved as a method on `Span`.

- We reduce the number of ways on `tcx` to emit a lint so that the developer UX is more streamlined.

- `LintLevelsBuilder` is moved to `rustc_lint::levels`, leaving behind `LintLevelMap/Set` in a purified form due to current constraints (hopefully fixable in the future after rust-lang#68133).

- `struct_lint_level` is moved to `rustc::lint` due to current dependency constraints.

- `rustc::lint::context` is moved to `rustc_lint::context`.

- The visitors in `rustc::lint` are moved to `rustc_lint::passes`.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 13, 2020
Fix crate paths in comments

Tiny follow-up of rust-lang#67806 and others

r? @Centril
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants