Update for merge of CrateDisambiguator into StableCrateId

This commit is contained in:
bjorn3 2021-05-30 21:02:22 +02:00 committed by Joshua Nelson
parent 03faa9b900
commit a9dd88ec4c
1 changed files with 15 additions and 14 deletions

View File

@ -72,8 +72,8 @@ Here are a few highlights of things it contains:
from any other version. from any other version.
* The [Strict Version Hash](#strict-version-hash) (SVH). This helps ensure the * The [Strict Version Hash](#strict-version-hash) (SVH). This helps ensure the
correct dependency is loaded. correct dependency is loaded.
* The [Crate Disambiguator](#crate-disambiguator). This is a hash used * The [Stable Crate Id](#stable-crate-id). This is a hash used
to disambiguate between different crates of the same name. to identify crates.
* Information about all the source files in the library. This can be used for * 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 a variety of things, such as diagnostics pointing to sources in a
dependency. dependency.
@ -114,21 +114,22 @@ computed.
[incremental compilation]: ../queries/incremental-compilation.md [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 [`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 The [`StableCrateId`] is a 64-bit hash used to identify different crates with
different crates of the same name. It is a hash of all the [`-C metadata`] CLI potentially the same name. It is a hash of the crate name and all the
options computed in [`compute_crate_disambiguator`]. It is used in a variety [`-C metadata`] CLI options computed in [`StableCrateId::new`]. It is
of places, such as symbol name mangling, crate loading, and much more. 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 By default, all Rust symbols are mangled and incorporate the stable crate id.
hash. This allows multiple versions of the same crate to be included together. This allows multiple versions of the same crate to be included together. Cargo
Cargo automatically generates `-C metadata` hashes based on a variety of automatically generates `-C metadata` hashes based on a variety of factors,
factors, like the package version, source, and the target kind (a lib and bin like the package version, source, and the target kind (a lib and test can have
can have the same crate name, so they need to be disambiguated). 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 [`StableCrateId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.StableCrateId.html
[`compute_crate_disambiguator`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/util/fn.compute_crate_disambiguator.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 [`-C metadata`]: https://doc.rust-lang.org/rustc/codegen-options/index.html#metadata
## Crate loading ## Crate loading