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

Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name #122842

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

pacak
Copy link
Contributor

@pacak pacak commented Mar 21, 2024

Fixes #122509

You can ask rustc to produce some intermediate results with --emit foo, this operation comes in two flavors: --emit asm and --emit asm=foo.s. First one produces one or more .s files without any name guarantees, second one renames it into foo.s. Second version only works when compiler produces a single file - for asm files this means using a single compilation unit for example.

In case compilation produced more than a single file rustc runs following check to emit some warnings:

            if crate_output.outputs.contains_key(&output_type) {
                // 2) Multiple codegen units, with `--emit foo=some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });
            } else if crate_output.single_output_file.is_some() {
                // 3) Multiple codegen units, with `-o some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringOutput { extension });
            } else {
                // 4) Multiple codegen units, but no explicit name. We
                //    just leave the `foo.0.x` files in place.
                // (We don't have to do any work in this case.)
            }

Comment in the final else branch implies that if user didn't ask for a specific name - there's no need to emit warnings. However because of the internal representation of crate_output.outputs - this doesn't work as expected: if user asked to produce an asm file without giving it an implicit name it will contain Some(None).

To fix the problem new code actually checks if user gave an explicit name. I think this was an original intentional behavior, at least comments imply that.

@rustbot
Copy link
Collaborator

rustbot commented Mar 21, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (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 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 21, 2024
@michaelwoerister
Copy link
Member

Thanks for the PR, @pacak!

Would you mind adding a regression test?
https://rustc-dev-guide.rust-lang.org/tests/adding.html

Let me know if you need any help with that.

@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

Absolutely. What is the most reliable way to ensure that the code will be compiled with at least two codegen units?

@michaelwoerister
Copy link
Member

Passing -Ccodegen-units=2 and having at least two mods should do the trick.

@michaelwoerister
Copy link
Member

Compile flags like that can be set in the test file: https://rustc-dev-guide.rust-lang.org/tests/headers.html

@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

I think that's it. It supposed to produce an error before (I didn't check though) and it is not producing an error now.

@rust-log-analyzer

This comment has been minimized.

@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

tidy error: file tests/ui/issue-122509.rs must begin with a descriptive name, consider {reason}-issue-122509.rs

Looking at other tests that do start with just issue - "all tests are equal, but some are more equal..."

@rust-log-analyzer

This comment has been minimized.

@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

tidy error: following path contains more than 859 entries, you should move the test to some relevant subdirectory (current: 860): /checkout/tests/ui

There's no relevant subdirectory for invalid warnings though as far as I can see. I tried moving it into issues - it also complains about having too many items...

@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

Adding a directory to tests/ui doesn't work either.

I give up.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Mar 22, 2024
@pacak
Copy link
Contributor Author

pacak commented Mar 22, 2024

So, please avoid putting a new test there and try to find a more relevant place.

Okay, now there's a sub directory for warnings.

@michaelwoerister
Copy link
Member

I'm sorry those tidy errors seemed to have sent you on a wild goose chase. There indeed doesn't seem to be a relevant pre-existing subdirectory for that test.

The test and the fix both look good!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 25, 2024

📌 Commit b84326e has been approved by michaelwoerister

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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 25, 2024
@pacak
Copy link
Contributor Author

pacak commented Mar 25, 2024

I'm sorry those tidy errors seemed to have sent you on a wild goose chase.

Not your fault. And now I know where to look and why is it happening :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 25, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122842 (Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name)
 - rust-lang#122881 (Delegation: fix ICE on `bound_vars` divergence)
 - rust-lang#122910 (Validate that we're only matching on unit struct for path pattern)
 - rust-lang#122970 (Use `chunk_by` when building `ReverseSccGraph`)
 - rust-lang#122988 (add even more tests! )
 - rust-lang#122999 (Fix unpretty UI test when /tmp does not exist)
 - rust-lang#123001 (Rename `{enter,exit}_lint_attrs` to `check_attributes{,_post}`)
 - rust-lang#123022 (Add `async-closures/once.rs` back to cranelift tests)
 - rust-lang#123034 (Add a bunch of needs-unwind annotations to tests)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ded16b3 into rust-lang:master Mar 25, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 25, 2024
Rollup merge of rust-lang#122842 - pacak:explicit_name, r=michaelwoerister

Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name

Fixes rust-lang#122509

You can ask `rustc` to produce some intermediate results with `--emit foo`, this operation comes in two flavors: `--emit asm` and `--emit asm=foo.s`. First one produces one or more `.s` files without any name guarantees, second one renames it into `foo.s`. Second version only works when compiler produces a single file - for asm files this means using a single compilation unit for example.

In case compilation produced more than a single file `rustc` runs following check to emit some warnings:

```rust
            if crate_output.outputs.contains_key(&output_type) {
                // 2) Multiple codegen units, with `--emit foo=some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });
            } else if crate_output.single_output_file.is_some() {
                // 3) Multiple codegen units, with `-o some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringOutput { extension });
            } else {
                // 4) Multiple codegen units, but no explicit name. We
                //    just leave the `foo.0.x` files in place.
                // (We don't have to do any work in this case.)
            }
```

Comment in the final `else` branch implies that if user didn't ask for a specific name - there's no need to emit warnings. However because of the internal representation of `crate_output.outputs` - this doesn't work as expected: if user asked to produce an asm file without giving it an implicit name it will contain `Some(None)`.

To fix the problem new code actually checks if user gave an explicit name. I think this was an original intentional behavior, at least comments imply that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

Invalid "ignoring emit path because multiple .s files were produced" message
5 participants