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

Show files produced by --emit foo in json artifact notifications #122597

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

pacak
Copy link
Contributor

@pacak pacak commented Mar 16, 2024

Right now it is possible to ask rustc to save some intermediate representation into one or more files with --emit=foo, but figuring out what exactly was produced is difficult. This pull request adds information about llvm_ir and asm intermediate files into notifications produced by --json=artifacts.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - cargo-show-asm parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now rustc will emit a new artifact notification for every artifact type user asked to --emit, for example for --emit asm those will include all the .s files.

Most users won't notice this behavior, to be affected by it all of the following must hold:

@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 16, 2024
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Seems reasonable.
r? @bjorn3 do you have an opinion on this?

@rustbot rustbot assigned bjorn3 and unassigned petrochenkov Mar 19, 2024
src/doc/rustc/src/json.md Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Mar 21, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@pacak pacak force-pushed the master branch 3 times, most recently from 973a0fb to 50538e5 Compare March 21, 2024 14:26
@pacak
Copy link
Contributor Author

pacak commented Mar 21, 2024

I changed the documentation a bit, now it mentions that notifications can have file of the same type mentioned several times, added support for all the files that can be emitted (I hope), changed llvm_bc -> llvm-bc to match the documentation.

Now I'm getting something like this:

% /home/pacak/ej/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc --crate-name smo --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=239 --crate-type lib --emit=dep-info,metadata,link,llvm-ir,llvm-bc,asm,mir,obj -C opt-level=3 -C codegen-units=16
{"$message_type":"artifact","artifact":"smo.d","emit":"dep-info"}
{"$message_type":"artifact","artifact":"libsmo.rmeta","emit":"metadata"}
{"$message_type":"artifact","artifact":"smo.mir","emit":"mir"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.2.rcgu.bc","emit":"llvm-bc"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.2.rcgu.ll","emit":"llvm-ir"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.0.rcgu.bc","emit":"llvm-bc"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.0.rcgu.ll","emit":"llvm-ir"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.2.rcgu.s","emit":"asm"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.2.rcgu.o","emit":"obj"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.1.rcgu.bc","emit":"llvm-bc"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.1.rcgu.ll","emit":"llvm-ir"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.0.rcgu.s","emit":"asm"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.0.rcgu.o","emit":"obj"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.1.rcgu.s","emit":"asm"}
{"$message_type":"artifact","artifact":"smo.smo.9eb4b431c6ed4cc9-cgu.1.rcgu.o","emit":"obj"}
{"$message_type":"diagnostic","message":"ignoring emit path because multiple .bc files were produced","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: ignoring emit path because multiple .bc files were produced\u001b[0m\n\n"}
{"$message_type":"diagnostic","message":"ignoring emit path because multiple .s files were produced","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: ignoring emit path because multiple .s files were produced\u001b[0m\n\n"}
{"$message_type":"diagnostic","message":"ignoring emit path because multiple .ll files were produced","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: ignoring emit path because multiple .ll files were produced\u001b[0m\n\n"}
{"$message_type":"diagnostic","message":"ignoring emit path because multiple .o files were produced","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: ignoring emit path because multiple .o files were produced\u001b[0m\n\n"}
{"$message_type":"artifact","artifact":"libsmo.rlib","emit":"link"}
{"$message_type":"diagnostic","message":"4 warnings emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 4 warnings emitted\u001b[0m\n\n"}

Error messages are wrong - I'm not passing an emit path, ticket is here #122509 - I think I'll just make a fix later.

Now I'm trying to figure out how to run parser from cargo-metadata on this output...

@rust-log-analyzer

This comment has been minimized.

@pacak
Copy link
Contributor Author

pacak commented Mar 21, 2024

Well, failing tests are asking to emit obj files, directly or indirectly as well as json information about artifacts. test runner finds unexpected new information about the obj files and fails. This new information is kind of the whole point of this pull request so saving this as expected output makes sense, but I'm not sure about how stable random looking parts of the name are - I don't want to introduce flaky tests.

I think my options are

  • don't emit information about obj files unless --emit obj is present
  • figure out how to normalize random looking part of the name and save new expected test output...

Went with the normalization approach.

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

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

Would you mind also adding this to rustc_codegen_cranelift?

The changes in this PR LGTM minus the couple of small changes below. I don't think I can approve an insta-stable change like myself this though. Maybe put it behind an unstable flag?

compiler/rustc_codegen_gcc/src/back/write.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_gcc/src/back/write.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_gcc/src/back/write.rs Outdated Show resolved Hide resolved
@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

Would you mind also adding this to rustc_codegen_cranelift?

Is it actually producing intermediate artifacts? I didn't add it because I couldn't find any apart from crate::pretty_clif::write_clif_file which feels like it's doing something slightly different. I can add support for it or any other places if you point them to me,

The changes in this PR LGTM minus the couple of small changes below.

fixed

I don't think I can approve an insta-stable change like myself this though. Maybe put it behind an unstable flag?

Hmm... Should we poke somebody else then? It's not really a behavior change, more like extending existing diagnostic that you have to ask specifically for with two separate flags - emit intermediates and emit artifact notifications.

@bjorn3
Copy link
Member

bjorn3 commented Mar 22, 2024

Is it actually producing intermediate artifacts?

It produces object files. Bitcode doesn't exist for Cranelift (and LTO isn't supported either) --emit asm isn't supported either. --emit llvm-ir emits cranelift ir text files, but unlike the other backends it doesn't emit one file per cgu, but a directory with one file for each individual function. It makes sense to me to skip that one too. So Only for object files the artifact notification should be added.

@bjorn3
Copy link
Member

bjorn3 commented Mar 22, 2024

Hmm... Should we poke somebody else then?

You could ask on zulip in #t-compiler. Or maybe ask during a compiler team meeting: https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings (every thursday, not sure about what time it would be in your timezone)

@pacak
Copy link
Contributor Author

pacak commented Mar 25, 2024

Would you mind also adding this to rustc_codegen_cranelift?

I'm still not sure where it produces those object files or how to compile and run rustc with cranelift. If you can point me at exact line/function - I'll try to add the support, otherwise - I'll pass.

@bjorn3
Copy link
Member

bjorn3 commented Mar 25, 2024

The object files for a cgu are all emitted right before

It is probably easier to iterate through modules at though as you have access to the Session there and object files are copied from the incr comp cache just a bit earlier in this function. By the way are you emitting artifact notifications for object files copied from the incr comp cache for the LLVM backend?

@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@pacak
Copy link
Contributor Author

pacak commented Mar 25, 2024

The object files for a cgu are all emitted right before

Okay, at least I was looking in the right file :) Added, seem to work.

By the way are you emitting artifact notifications for object files copied from the incr comp cache for the LLVM backend?

Added this as well. Now I'm wondering how notifications for asm/llvm are interacting with incremental cache...

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 23, 2024
@rfcbot
Copy link

rfcbot commented May 23, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label May 23, 2024
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 2, 2024
@rfcbot
Copy link

rfcbot commented Jun 2, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@bjorn3
Copy link
Member

bjorn3 commented Jun 3, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jun 3, 2024

📌 Commit c8390cd has been approved by bjorn3

It is now in the queue for this repository.

@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-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jun 3, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#122597 (Show files produced by `--emit foo` in json artifact notifications)
 - rust-lang#125886 (Migrate run make issue 15460)
 - rust-lang#125893 (Handle all GVN binops in a single place.)
 - rust-lang#125903 (rustc_span: Inline some hot functions)
 - rust-lang#125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE)
 - rust-lang#125917 (Create `run-make` `env_var` and `env_var_os` helpers)
 - rust-lang#125919 (Remove stray "this")

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122597 (Show files produced by `--emit foo` in json artifact notifications)
 - rust-lang#124486 (Add tracking issue and unstable book page for `"vectorcall"` ABI)
 - rust-lang#125380 (Make `WHERE_CLAUSES_OBJECT_SAFETY` a regular object safety violation)
 - rust-lang#125690 (ARM Target Docs Update)
 - rust-lang#125865 (Fix ICE caused by ignoring EffectVars in type inference)
 - rust-lang#125893 (Handle all GVN binops in a single place.)
 - rust-lang#125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE)
 - rust-lang#125918 (Revert: create const block bodies in typeck via query feeding)
 - rust-lang#125919 (Remove stray "this")

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122597 (Show files produced by `--emit foo` in json artifact notifications)
 - rust-lang#124486 (Add tracking issue and unstable book page for `"vectorcall"` ABI)
 - rust-lang#125380 (Make `WHERE_CLAUSES_OBJECT_SAFETY` a regular object safety violation)
 - rust-lang#125690 (ARM Target Docs Update)
 - rust-lang#125865 (Fix ICE caused by ignoring EffectVars in type inference)
 - rust-lang#125893 (Handle all GVN binops in a single place.)
 - rust-lang#125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE)
 - rust-lang#125918 (Revert: create const block bodies in typeck via query feeding)
 - rust-lang#125919 (Remove stray "this")

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122597 (Show files produced by `--emit foo` in json artifact notifications)
 - rust-lang#124486 (Add tracking issue and unstable book page for `"vectorcall"` ABI)
 - rust-lang#125690 (ARM Target Docs Update)
 - rust-lang#125865 (Fix ICE caused by ignoring EffectVars in type inference)
 - rust-lang#125893 (Handle all GVN binops in a single place.)
 - rust-lang#125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE)
 - rust-lang#125918 (Revert: create const block bodies in typeck via query feeding)
 - rust-lang#125919 (Remove stray "this")
 - rust-lang#125927 (Ignore `vec_deque_alloc_error::test_shrink_to_unwind` test on non-unwind targets)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Jun 4, 2024

⌛ Testing commit c8390cd with merge 1689a5a...

@bors
Copy link
Contributor

bors commented Jun 4, 2024

☀️ Test successful - checks-actions
Approved by: bjorn3
Pushing 1689a5a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 4, 2024
@bors bors merged commit 1689a5a into rust-lang:master Jun 4, 2024
13 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 4, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1689a5a): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) -0.9% [-0.9%, -0.9%] 1

Max RSS (memory usage)

Results (secondary 3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [2.9%, 3.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 671.059s -> 673.132s (0.31%)
Artifact size: 319.05 MiB -> 318.94 MiB (-0.03%)

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jun 7, 2024
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Jun 30, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. 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.