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

Fix unknown-crate when using -Z self-profile with rustdoc #79586

Merged
merged 1 commit into from
Dec 3, 2020

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Dec 1, 2020

... by removing a duplicate crate_name field in interface::Config,
making it clear that rustdoc should be passing it to config::Options instead.

Unblocks rust-lang/rustc-perf#797.

@jyn514 jyn514 added A-driver Area: rustc_driver that ties everything together into the `rustc` compiler T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 1, 2020
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(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 Dec 1, 2020
@jyn514
Copy link
Member Author

jyn514 commented Dec 1, 2020

    Compiling test v0.0.0 (/checkout/library/test)
error: unused attribute
  --> library/test/src/lib.rs:20:1
   |
20 | #![crate_name = "test"]
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D unused-attributes` implied by `-D warnings`

error: crate-level attribute should be in the root module
  --> library/test/src/lib.rs:20:1
   |
20 | #![crate_name = "test"]
   | ^^^^^^^^^^^^^^^^^^^^^^^

I don't know why this is going wrong :/ the only behavior I changed in rustc was https://github.com/rust-lang/rust/pull/79586/files#diff-5d2a824073d4fcc6b4e60bae734988e6e37f6483fff54626ab3352774d2c55cfL188, which reads crate_name from opts instead of config, but config.crate_name is never set to anything other than None! What am I missing?

@jyn514
Copy link
Member Author

jyn514 commented Dec 1, 2020

Actually I might know the issue - crate_name is now Some where it was None before, so find_crate_name is never executed.

Is it intended that rustc looks at #[crate_name] even when --crate-name is passed? I found this comment:

// Look in attributes 100% of the time to make sure the attribute is marked
// as used. After doing this, however, we still prioritize a crate name from
// the command line over one found in the #[crate_name] attribute. If we
// find both we ensure that they're the same later on as well.
let attr_crate_name =
sess.find_by_name(attrs, sym::crate_name).and_then(|at| at.value_str().map(|s| (at, s)));

So I guess find_crate_name should be run whether or not --crate-name is set?

let parse_result = self.parse()?;
let krate = parse_result.peek();
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
find_crate_name(self.session(), &krate.attrs, &self.compiler.input)
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I am a bit worried -- is this a breaking change? It sounds like it would be, since we presumably weren't validating previously?

Copy link
Member Author

Choose a reason for hiding this comment

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

See #79586 (comment) - this is the same behavior as before, just easier to understand. Previously, the crate name would never be Some so this would always run.

@@ -400,6 +400,7 @@ impl SelfProfiler {
) -> Result<SelfProfiler, Box<dyn Error + Send + Sync>> {
fs::create_dir_all(output_directory)?;

debug!(?crate_name);
Copy link
Member

Choose a reason for hiding this comment

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

We probably don't want this debug statement, or at least, we don't want it in the current form 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what the policy on debug logging is - I'm happy to revert this, but I'm not sure what a better form would be.

Copy link
Member

Choose a reason for hiding this comment

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

I think in general we try to include some kind of context about what is going on when this value is logged. Seeing for example

[DEBUG]    rustc_data_structures::profiling     my_crate_name` 

isn't super useful but something like debug!("Creating self-profiler: output_directory = {:?}, crate_name = {:?}, event_filters = {:?}", output_directory, crate_name, event_filters); would add more context about what is being logged and could be useful for someone else in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, what does the prefixed ? do here?

Copy link
Member Author

Choose a reason for hiding this comment

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

compiler/rustc_session/src/session.rs Outdated Show resolved Hide resolved
... by removing a duplicate `crate_name` field in `interface::Config`,
making it clear that rustdoc should be passing it to `config::Options`
instead.
@davidtwco
Copy link
Member

LGTM and I think the review comments have been addressed:

@bors r+

@bors
Copy link
Contributor

bors commented Dec 3, 2020

📌 Commit 878cfb5 has been approved by davidtwco

@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 Dec 3, 2020
@bors
Copy link
Contributor

bors commented Dec 3, 2020

⌛ Testing commit 878cfb5 with merge 2203527...

@bors
Copy link
Contributor

bors commented Dec 3, 2020

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 2203527 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 3, 2020
@bors bors merged commit 2203527 into rust-lang:master Dec 3, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 3, 2020
@jyn514 jyn514 deleted the crate-name branch December 3, 2020 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants