Skip to content

Commit

Permalink
Update for merge of CrateDisambiguator into StableCrateId
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 authored and jyn514 committed Jul 13, 2021
1 parent 1b56b09 commit 93422c2
Showing 1 changed file with 15 additions and 14 deletions.
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).

[`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

0 comments on commit 93422c2

Please sign in to comment.