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

Shorten def_span for more items. #93967

Merged
merged 1 commit into from
Jul 1, 2022
Merged

Conversation

cjgillot
Copy link
Contributor

The def_span query only returns the signature span for functions.
Struct/enum/union definitions can also have a very long body.
This PR shortens the associated span.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 13, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 13, 2022
@petrochenkov
Copy link
Contributor

Is opt_span used anywhere on a "good path"?
guess_head_span may be expensive as an operation with the source map, let's check.
@bors try @rust-timer queue

Also, some rustdoc test has failed, not sure whether it's spurious or not.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 14, 2022
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 14, 2022
@bors
Copy link
Contributor

bors commented Feb 14, 2022

⌛ Trying commit 3b96c413bb87321cadff009a710d71a5b32ae940 with merge dc992527fcd1dd0d3df63152c8875601eb5781b9...

@bors
Copy link
Contributor

bors commented Feb 14, 2022

☀️ Try build successful - checks-actions
Build commit: dc992527fcd1dd0d3df63152c8875601eb5781b9 (dc992527fcd1dd0d3df63152c8875601eb5781b9)

@rust-timer
Copy link
Collaborator

Queued dc992527fcd1dd0d3df63152c8875601eb5781b9 with parent 902e590, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (dc992527fcd1dd0d3df63152c8875601eb5781b9): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 14, 2022
@cjgillot
Copy link
Contributor Author

Is opt_span used anywhere on a "good path"? guess_head_span may be expensive as an operation with the source map, let's check.

Yes. The def_span query is implemented in terms of it, and its output goes into metadata.

Also, some rustdoc test has failed, not sure whether it's spurious or not.

It looks like I need to reflect the change in line numbers in a doctest. The the link to source will only link to the struct head instead of the whole struct. (Like functions already do.)
Is it an issue? cc @camelid

Last question: should we also do this for trait definitions?
(It's just adding one extra match arm.)

@petrochenkov
Copy link
Contributor

Last question: should we also do this for trait definitions?

If we are doing this consistently, then the same span shortening is applicable to ItemKind::{Trait, Impl, Mod, ForeignMod, Macro} and also to Node::Variant as well (which is basically the same thing as ItemKind::Struct).

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2022
@camelid
Copy link
Member

camelid commented Feb 16, 2022

Also, some rustdoc test has failed, not sure whether it's spurious or not.

It looks like I need to reflect the change in line numbers in a doctest. The the link to source will only link to the struct head instead of the whole struct. (Like functions already do.) Is it an issue? cc @camelid

Hmm, I think it's fine, but just to be sure: @GuillaumeGomez can you check since you know this feature better?

@GuillaumeGomez
Copy link
Member

It doesn't seem to be a spurious failure. Something changed in the rendered output.

@camelid
Copy link
Member

camelid commented Feb 17, 2022

Yeah, IIUC it went from highlighting these lines:

struct Foo {
  bar: i32
}

to just the first:

struct Foo {

when you do a jump-to-def.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 20, 2022
@cjgillot cjgillot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 9, 2022
@cjgillot cjgillot force-pushed the short-struct-span branch from 3b96c41 to 686986f Compare June 19, 2022 17:38
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 1, 2022
@bors
Copy link
Contributor

bors commented Jul 1, 2022

⌛ Testing commit 42e4eee with merge 46b8c23...

@bors
Copy link
Contributor

bors commented Jul 1, 2022

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 46b8c23 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 1, 2022
@bors bors merged commit 46b8c23 into rust-lang:master Jul 1, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 1, 2022
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #93967!

Tested on commit 46b8c23.
Direct link to PR: #93967

💔 miri on windows: test-pass → test-fail (cc @RalfJung @oli-obk).
🎉 rls on linux: test-fail → test-pass (cc @Xanewok).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jul 1, 2022
Tested on commit rust-lang/rust@46b8c23.
Direct link to PR: <rust-lang/rust#93967>

💔 miri on windows: test-pass → test-fail (cc @RalfJung @oli-obk).
🎉 rls on linux: test-fail → test-pass (cc @Xanewok).
@cjgillot cjgillot deleted the short-struct-span branch July 2, 2022 07:34
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (46b8c23): comparison url.

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
2.1% 2.1% 1
Regressions 😿
(secondary)
3.9% 5.9% 3
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.7% -2.7% 1
All 😿🎉 (primary) 2.1% 2.1% 1

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
2.6% 3.2% 3
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.6% -4.6% 2
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 8, 2022
…=estebank

Shorten def_span of closures to just their header

Continuation of rust-lang#93967.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jul 14, 2022
Shorten def_span of closures to just their header

Continuation of rust-lang/rust#93967.
Dylan-DPC pushed a commit to Dylan-DPC/rust that referenced this pull request Jul 25, 2022
Remove reachable coverage without counters to maintain invariant that
either there is no coverage at all or there is a live coverage counter
left that provides the function source hash.

The motivating example would be a following closure:

```rust
    let f = |x: bool| {
        debug_assert!(x);
    };
```

Which, with span changes from rust-lang#93967, with disabled debug assertions,
after the final CFG simplifications but before removal of dead blocks,
gives rise to MIR:

```rust
fn main::{closure#0}(_1: &[[email protected]:2:13: 2:22], _2: bool) -> () {
    debug x => _2;
    let mut _0: ();

    bb0: {
        Coverage::Expression(4294967295) = 1 - 2;
        return;
    }

    ...
}
```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 25, 2022
Remove reachable coverage without counters

Remove reachable coverage without counters to maintain invariant that
either there is no coverage at all or there is a live coverage counter
left that provides the function source hash.

The motivating example would be a following closure:

```rust
    let f = |x: bool| {
        debug_assert!(x);
    };
```

Which, with span changes from rust-lang#93967, with disabled debug assertions,
after the final CFG simplifications but before removal of dead blocks,
gives rise to MIR:

```rust
fn main::{closure#0}(_1: &[[email protected]:2:13: 2:22], _2: bool) -> () {
    debug x => _2;
    let mut _0: ();

    bb0: {
        Coverage::Expression(4294967295) = 1 - 2;
        return;
    }

    ...
}
```

Which also makes the initial instrumentation quite suspect, although
this pull request doesn't attempt to address that aspect directly.

Fixes rust-lang#98833.

r? `@wesleywiser` `@richkadel`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 26, 2022
Remove reachable coverage without counters

Remove reachable coverage without counters to maintain invariant that
either there is no coverage at all or there is a live coverage counter
left that provides the function source hash.

The motivating example would be a following closure:

```rust
    let f = |x: bool| {
        debug_assert!(x);
    };
```

Which, with span changes from rust-lang#93967, with disabled debug assertions,
after the final CFG simplifications but before removal of dead blocks,
gives rise to MIR:

```rust
fn main::{closure#0}(_1: &[[email protected]:2:13: 2:22], _2: bool) -> () {
    debug x => _2;
    let mut _0: ();

    bb0: {
        Coverage::Expression(4294967295) = 1 - 2;
        return;
    }

    ...
}
```

Which also makes the initial instrumentation quite suspect, although
this pull request doesn't attempt to address that aspect directly.

Fixes rust-lang#98833.

r? ``@wesleywiser`` ``@richkadel``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.