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

Update for merge of CrateDisambiguator into StableCrateId #1135

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/backend/libs-and-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ Here are a few highlights of things it contains:
from any other version.
* The [Strict Version Hash](#strict-version-hash) (SVH). This helps ensure the
correct dependency is loaded.
* The [Crate Disambiguator](#crate-disambiguator). This is a hash used
to disambiguate between different crates of the same name.
* The [Stable Crate Id](#stable-crate-id). This is a hash used
to identify crates.
* Information about all the source files in the library. This can be used for
a variety of things, such as diagnostics pointing to sources in a
dependency.
Expand Down Expand Up @@ -114,21 +114,22 @@ computed.
[incremental compilation]: ../queries/incremental-compilation.md
[`finalize_and_compute_crate_hash`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/collector/struct.NodeCollector.html#method.finalize_and_compute_crate_hash

### Crate Disambiguator
### Stable Crate Id

The [`CrateDisambiguator`] is a 128-bit hash used to distinguish between
different crates of the same name. It is a hash of all the [`-C metadata`] CLI
options computed in [`compute_crate_disambiguator`]. It is used in a variety
of places, such as symbol name mangling, crate loading, and much more.
The [`StableCrateId`] is a 64-bit hash used to identify different crates with
potentially the same name. It is a hash of the crate name and all the
[`-C metadata`] CLI options computed in [`StableCrateId::new`]. It is
used in a variety of places, such as symbol name mangling, crate loading, and
much more.

By default, all Rust symbols are mangled and incorporate the disambiguator
hash. This allows multiple versions of the same crate to be included together.
Cargo automatically generates `-C metadata` hashes based on a variety of
factors, like the package version, source, and the target kind (a lib and bin
can have the same crate name, so they need to be disambiguated).
By default, all Rust symbols are mangled and incorporate the stable crate id.
This allows multiple versions of the same crate to be included together. Cargo
automatically generates `-C metadata` hashes based on a variety of factors,
like the package version, source, and the target kind (a lib and test can have
the same crate name, so they need to be disambiguated).
Comment on lines +128 to +129
Copy link
Member Author

Choose a reason for hiding this comment

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

If the bin crate type is used, this is included in the hash and as such a lib and bin never have the same hash. The comment about this describes this exact use case. This was true even before CrateDisambiguator was merged into StableCrateId.


[`CrateDisambiguator`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/crate_disambiguator/struct.CrateDisambiguator.html
[`compute_crate_disambiguator`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/util/fn.compute_crate_disambiguator.html
[`StableCrateId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.StableCrateId.html
[`StableCrateId::new`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.StableCrateId.html#method.new
[`-C metadata`]: https://doc.rust-lang.org/rustc/codegen-options/index.html#metadata

## Crate loading
Expand Down