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

Merge CrateDisambiguator into StableCrateId #85804

Merged
merged 4 commits into from
May 30, 2021

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented May 29, 2021

This simplifies the code and potentially improves performance by reducing the amount of hashed data.

Fixes #85795

@bjorn3 bjorn3 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 29, 2021
@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(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 May 29, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the merge_crate_disambiguator branch from 2eaeaff to 2a2d4af Compare May 29, 2021 10:31
@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member Author

bjorn3 commented May 29, 2021

@bors try @rust-timer queue

@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 May 29, 2021
@bors
Copy link
Contributor

bors commented May 29, 2021

⌛ Trying commit 195e4a24be951480d9d27bd44a0f30771e374ae3 with merge 621a481ceedc7341caa1c2cdb9f083e0a2d47de4...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 29, 2021

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

@rust-timer
Copy link
Collaborator

Queued 621a481ceedc7341caa1c2cdb9f083e0a2d47de4 with parent f77b1a5, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (621a481ceedc7341caa1c2cdb9f083e0a2d47de4): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 29, 2021
@bjorn3
Copy link
Member Author

bjorn3 commented May 29, 2021

Overall this seems to be a slight perf improvement. I would guess that the regressions are caused by the fact that the StableCrateId of crates has changed and not by anything else.

@bjorn3 bjorn3 force-pushed the merge_crate_disambiguator branch from 195e4a2 to d7408a7 Compare May 29, 2021 15:50
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the merge_crate_disambiguator branch from d7408a7 to 329187f Compare May 29, 2021 16:08
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the merge_crate_disambiguator branch from 56ac1c2 to 576488e Compare May 29, 2021 16:57
@bors
Copy link
Contributor

bors commented May 29, 2021

☔ The latest upstream changes (presumably #85698) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented May 30, 2021

⌛ Testing commit e0e0cfa with merge 5957990...

@bors
Copy link
Contributor

bors commented May 30, 2021

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 5957990 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 30, 2021
@bors bors merged commit 5957990 into rust-lang:master May 30, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 30, 2021
@bjorn3 bjorn3 deleted the merge_crate_disambiguator branch May 30, 2021 17:18
@ehuss
Copy link
Contributor

ehuss commented May 30, 2021

Would you mind updating the rustc-dev-guide to accommodate this change? https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html#crate-disambiguator

Also, this seems to drop the hash size from 128 bits to 64 bits, but I don't see any discussion here if that might cause any problems?

@bjorn3
Copy link
Member Author

bjorn3 commented May 30, 2021

Would you mind updating the rustc-dev-guide to accommodate this change? https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html#crate-disambiguator

Sure

Edit: rust-lang/rustc-dev-guide#1135

Also, this seems to drop the hash size from 128 bits to 64 bits, but I don't see any discussion here if that might cause any problems?

It was already impossible to have two crates with different disambiguators but identical StableCrateId in the same crate graph. If anything this reduces the likelyhood of a hash conflict as now only one hash can conflict while previously two hashes could conflict. As for the possibility of two crates with identical name and StableCrateId, but previously distinct disambiguators silently getting collapsed, the SVH would be different in that case thus causing an error.

@ehuss
Copy link
Contributor

ehuss commented May 30, 2021

Thanks I appreciate it!

@Mark-Simulacrum
Copy link
Member

@bjorn3 It seems like this was a regression on landing - https://perf.rust-lang.org/compare.html?start=2023cc3aa1ea98530f3124ed07713e6f95fd26ab&end=59579907ab52ad2369735622185a26f158bf0f0f&stat=instructions%3Au . This seems held up by further perf runs over the course of the week, too, so likely not spurious.

I think we should measure a revert PR, at the very least; would you be up for posting that?

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 1, 2021

It seems like this was a regression on landing

Strange. The previous perf run showed that it was an improvement.

I think we should measure a revert PR, at the very least; would you be up for posting that?

Done: #85891

pub struct StableCrateId(u64);

impl StableCrateId {
pub fn to_u64(self) -> u64 {
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 forgot to mark this as #[inline]. Maybe that is responsible for the perf regression?

pub fn generate_proc_macro_decls_symbol(&self, disambiguator: CrateDisambiguator) -> String {
format!("__rustc_proc_macro_decls_{}__", disambiguator.to_fingerprint().to_hex())
pub fn generate_proc_macro_decls_symbol(&self, stable_crate_id: StableCrateId) -> String {
format!("__rustc_proc_macro_decls_{:08x}__", stable_crate_id.to_u64())
Copy link
Member Author

Choose a reason for hiding this comment

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

Using {:08x} instead of {:x} like to_hex() seems to have used may also be part of the problem.

let crate_name = tcx.original_crate_name(cnum).to_string();
let crate_disambiguator = tcx.crate_disambiguator(cnum);
((crate_name, crate_disambiguator), cnum)
let stable_crate_id = tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
Copy link
Member Author

Choose a reason for hiding this comment

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

Avoiding the def_path_hash call here in favor of directly looking up the StableCrateId by CrateNum from the CStore may also help.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2021
…or, r=Mark-Simulacrum

Revert "Merge CrateDisambiguator into StableCrateId"

This reverts rust-lang#85804
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 6, 2021
…mbiguator, r=michaelwoerister

Reland "Merge CrateDisambiguator into StableCrateId"

Reverts rust-lang#85891 as this revert of rust-lang#85804 made perf even worse.

r? `@Mark-Simulacrum`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. 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.

Merge CrateDisambiguator into StableCrateId
10 participants