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

Tracking Issue for LLVM InstrProf code coverage (current flag: -Zinstrument-coverage) #79121

Closed
3 tasks done
richkadel opened this issue Nov 17, 2020 · 20 comments
Closed
3 tasks done
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@richkadel
Copy link
Contributor

richkadel commented Nov 17, 2020

This is a tracking issue for the MCP "Implement LLVM-compatible source-based code coverage" (rust-lang/compiler-team#278).

Original feature request: Issue #34701.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

There are no unresolved questions from the MCP.

Some implementation options were debated and, if deferred, were logged as FIXME comments in the compiler source code or tests. FIXME comments related to stabilization have been added as rust-lang/rust issues.

  • If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

  • The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

  • The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

  • What other questions need to be answered before the feature can be stabilized?

Open Issues related to this Tracking Issue

Somewhat ordered by priority:

Also, note the issue tracking label: A-code-coverage

Implementation history

@richkadel richkadel added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Nov 17, 2020
@richkadel
Copy link
Contributor Author

@tmandry @wesleywiser

@jonas-schievink jonas-schievink added A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2020
@richkadel
Copy link
Contributor Author

Just a quick note to the compiler team and interested contributors:

As of today, I'm going to be much less active on Rust Coverage, due to other work priorities.

I believe the implementation is essentially "complete" (including detailed documentation in the Rust Dev Guide that should help future contributors).

I plan to support any serious bugs in the implementation, as they arise, but otherwise, I encourage any contributors interested in taking on any of the "Open Issues" listed above. I should be able to advise/answer questions as needed.

Thank you so much to @tmandry and @wesleywiser for partnering with me on this feature, exceptionally detailed code reviews, and incredibly helpful guidance along the way!

Thanks also to the many other members of the Rust community who contributed requirements, testing, bug reports, and helpful tips along the way!

@wesleywiser
Copy link
Member

Thanks for your work on this @richkadel!

@clarfonthey
Copy link
Contributor

Is there an issue somewhere tracking potentially adding a cargo coverage command, or some way of making this interface nicely with cargo?

Right now all of the guides I see still rely on manually merging/searching for different files, so I imagine this would be nice to have, even if it didn't do anything other than just put the coverage data in an easy-to-access place.

@chadbrewbaker
Copy link

chadbrewbaker commented May 31, 2021

I ran into an issue for coreutils, uutils/coreutils#2324. The "ls" tests are angry at the default.profraw file. How do you set an environment variable so profiles write to a fixed directory like /tmp/coreutils-coverage?

@richkadel
Copy link
Contributor Author

Is there an issue somewhere tracking potentially adding a cargo coverage command, or some way of making this interface nicely with cargo?

Thanks for asking. This has been discussed, and I think it's a good idea. I don't have a timeline for working on this but I think there should at least be an issue to track it. I'll add one.

@richkadel
Copy link
Contributor Author

I ran into an issue for coreutils, uutils/coreutils#2324. The "ls" tests are angry at the default.profraw file. How do you set an environment variable so profiles write to a fixed directory like /tmp/coreutils-coverage?

@chadbrewbaker - Thanks for the comment. Can you create a separate issue on this, preferably with MCVE? Thank you!

@chadbrewbaker
Copy link

@richkadel According to https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#id4 there is a LLVM_PROFILE_FILE environment variable. I can't seem to figure out how to get it to write to a fixed directory.

@richkadel
Copy link
Contributor Author

@chadbrewbaker - This Tracking Issue isn't the right forum for discussing issues like that.

@chadbrewbaker
Copy link

Sorry, didn't mean to spam the wrong forum. What is "MCVE", and where would you suggest I move discussion of fixing the profile writing location within the current nightly toolchain?

@richkadel
Copy link
Contributor Author

If you believe there is a bug, please file a new issue.

The template includes a section "I tried this code". MCVE is cryptic (but google-able) for "a small example of code and steps so someone else can quickly and easily reproduce the issue" (my words). I use the term because it's used by Rust (label E-needs-mcve).

@jhpratt
Copy link
Member

jhpratt commented Jun 4, 2021

Haven't seen this mentioned yet, but @taiki-e has created cargo llvm-cov. I just tested it out and it works well.

cc @clarfonthey

@joshtriplett
Copy link
Member

From the unresolved questions:

The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

@joshtriplett
Copy link
Member

The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

I've submitted #90128 to propose stabilizing -C symbol-mangling-version=v0 (without changing the default).

@richkadel
Copy link
Contributor Author

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement.

@Swatinem - FYI, another data point on maintaining LLVM 11 support as long as it's feasible.

@joshtriplett
Copy link
Member

I submitted #90132 to propose stabilizing -C instrument-coverage.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2022
…overage, r=wesleywiser

Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: rust-lang#79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on rust-lang#90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](rust-lang#79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at rust-lang/compiler-team#278 . Based on that, `@pnkfelix` suggested that this needed a stabilization PR and a compiler-team FCP.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2022
…overage, r=wesleywiser

Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: rust-lang#79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on rust-lang#90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](rust-lang#79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at rust-lang/compiler-team#278 . Based on that, ``@pnkfelix`` suggested that this needed a stabilization PR and a compiler-team FCP.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2022
…overage, r=wesleywiser

Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: rust-lang#79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on rust-lang#90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](rust-lang#79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at rust-lang/compiler-team#278 . Based on that, ```@pnkfelix``` suggested that this needed a stabilization PR and a compiler-team FCP.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 4, 2022
…overage, r=wesleywiser

Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: rust-lang#79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on rust-lang#90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](rust-lang#79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at rust-lang/compiler-team#278 . Based on that, `@pnkfelix` suggested that this needed a stabilization PR and a compiler-team FCP.
@sourcefrog
Copy link
Contributor

Thanks for working on this.

I just wanted to note that the blog post https://blog.rust-lang.org/inside-rust/2020/11/12/source-based-code-coverage.html now has a broken link to https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/source-based-code-coverage.html under "how to get started" - maybe because it's stablizing? (Which is very exciting!)

@pierwill
Copy link
Member

pierwill commented Feb 13, 2022 via email

@clarfonthey
Copy link
Contributor

So, I commented on #79556 which seems to be the primary issue tracking this, but since this issue hasn't been closed yet, I figured I'd state this here for visibility.

A large number of targets seem to not support -Cinstrument-coverage out of the box due to the lack of a profiler_builtins crate, failing with a message along the lines of:

error[E0463]: can't find crate for `profiler_builtins`
  |
  = note: the compiler may have been built without the profiler runtime

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

After trialing multiple targets on cross, it appears that this applies for all targets besides the tier 1 targets.

I'm not sure the exact reasoning for holding off on closing this issue considering how this has already been released on stable rust and a blog post has been written about it, but I do think that the lack of support for tier 2 targets is a big deal that should probably be looked into.

@tmandry
Copy link
Member

tmandry commented Jul 13, 2022

@clarfonthey Thanks for bringing this up, I responded on that issue.

I'm also going to close this issue, since the feature has now been stabilized. Issues with the feature can be tracked using the label, A-code-coverage.

@tmandry tmandry closed this as completed Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants