rust/compiler
bors 76c500ec6c Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix
Let a portion of DefPathHash uniquely identify the DefPath's crate.

This allows to directly map from a `DefPathHash` to the crate it originates from, without constructing side tables to do that mapping -- something that is useful for incremental compilation where we deal with `DefPathHash` instead of `DefId` a lot.

It also allows to reliably and cheaply check for `DefPathHash` collisions which allows the compiler to gracefully abort compilation instead of running into a subsequent ICE at some random place in the code.

The following new piece of documentation describes the most interesting aspects of the changes:

```rust
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
/// stable across crate and compilation session boundaries. It consists of two
/// separate 64-bit hashes. The first uniquely identifies the crate this
/// `DefPathHash` originates from (see [StableCrateId]), and the second
/// uniquely identifies the corresponding `DefPath` within that crate. Together
/// they form a unique identifier within an entire crate graph.
///
/// There is a very small chance of hash collisions, which would mean that two
/// different `DefPath`s map to the same `DefPathHash`. Proceeding compilation
/// with such a hash collision would very probably lead to an ICE and, in the
/// worst case, to a silent mis-compilation. The compiler therefore actively
/// and exhaustively checks for such hash collisions and aborts compilation if
/// it finds one.
///
/// `DefPathHash` uses 64-bit hashes for both the crate-id part and the
/// crate-internal part, even though it is likely that there are many more
/// `LocalDefId`s in a single crate than there are individual crates in a crate
/// graph. Since we use the same number of bits in both cases, the collision
/// probability for the crate-local part will be quite a bit higher (though
/// still very small).
///
/// This imbalance is not by accident: A hash collision in the
/// crate-local part of a `DefPathHash` will be detected and reported while
/// compiling the crate in question. Such a collision does not depend on
/// outside factors and can be easily fixed by the crate maintainer (e.g. by
/// renaming the item in question or by bumping the crate version in a harmless
/// way).
///
/// A collision between crate-id hashes on the other hand is harder to fix
/// because it depends on the set of crates in the entire crate graph of a
/// compilation session. Again, using the same crate with a different version
/// number would fix the issue with a high probability -- but that might be
/// easier said then done if the crates in questions are dependencies of
/// third-party crates.
///
/// That being said, given a high quality hash function, the collision
/// probabilities in question are very small. For example, for a big crate like
/// `rustc_middle` (with ~50000 `LocalDefId`s as of the time of writing) there
/// is a probability of roughly 1 in 14,750,000,000 of a crate-internal
/// collision occurring. For a big crate graph with 1000 crates in it, there is
/// a probability of 1 in 36,890,000,000,000 of a `StableCrateId` collision.
```

Given the probabilities involved I hope that no one will ever actually see the error messages. Nonetheless, I'd be glad about some feedback on how to improve them. Should we create a GH issue describing the problem and possible solutions to point to? Or a page in the rustc book?

r? `@pnkfelix` (feel free to re-assign)
2021-03-07 23:45:57 +00:00
..
rustc Fix typo 2021-03-06 09:16:29 +05:30
rustc_apfloat bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_arena Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
rustc_ast Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_ast_lowering Auto merge of #82447 - Amanieu:legacy_const_generics, r=oli-obk 2021-02-25 18:14:50 +00:00
rustc_ast_passes Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis 2021-02-23 16:10:23 +01:00
rustc_ast_pretty Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011 2021-02-19 02:49:08 +01:00
rustc_attr Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis 2021-03-05 05:28:07 +00:00
rustc_builtin_macros Remove some P-s 2021-02-20 10:51:26 +01:00
rustc_codegen_cranelift Merge commit '9a0c32934ebe376128230aa8da3275697b2053e7' into sync_cg_clif-2021-03-05 2021-03-05 19:12:59 +01:00
rustc_codegen_llvm Auto merge of #82285 - nhwn:nonzero-debug, r=nagisa 2021-03-07 20:23:23 +00:00
rustc_codegen_ssa Rollup merge of #80723 - rylev:noop-lint-pass, r=estebank 2021-03-05 10:57:14 +01:00
rustc_data_structures Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_driver Auto merge of #82304 - LeSeulArtichaut:unpretty-ast, r=spastorino 2021-03-04 05:46:43 +00:00
rustc_error_codes Rollup merge of #80527 - jyn514:rustdoc-lints, r=GuillaumeGomez 2021-03-04 20:01:01 +09:00
rustc_errors Even faster counting of digits for error line numbers 2021-02-27 15:28:58 +01:00
rustc_expand Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis 2021-03-05 05:28:07 +00:00
rustc_feature Rollup merge of #82697 - jplatte:patch-1, r=davidtwco 2021-03-04 20:01:07 +09:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_hir_pretty Auto merge of #81611 - cjgillot:meowner, r=estebank 2021-02-16 22:14:32 +00:00
rustc_incremental Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
rustc_index Miscellaneous inlining improvements 2021-02-26 00:00:00 +00:00
rustc_infer Rollup merge of #82635 - pierwill:edit-infer, r=oli-obk 2021-03-01 11:25:10 -05:00
rustc_interface Fix rustc_driver self text and bump the mir_opt_level 2021-03-05 17:13:58 -03:00
rustc_lexer
rustc_lint Rollup merge of #80723 - rylev:noop-lint-pass, r=estebank 2021-03-05 10:57:14 +01:00
rustc_lint_defs Make invalid_doc_attribute lint plural 2021-03-05 14:44:31 +01:00
rustc_llvm Schedule ThinLTOBuffer passes again after sanitizer passes 2021-03-03 20:48:37 +01:00
rustc_macros replaced some map_or with map_or_else 2021-02-24 02:43:35 +03:00
rustc_metadata Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_middle Auto merge of #82795 - m-ou-se:rollup-uzx0b92, r=m-ou-se 2021-03-05 13:34:33 +00:00
rustc_mir Rollup merge of #82736 - spastorino:mir-opt-level-perf-changes, r=oli-obk 2021-03-05 21:44:40 +01:00
rustc_mir_build Rollup merge of #80723 - rylev:noop-lint-pass, r=estebank 2021-03-05 10:57:14 +01:00
rustc_parse Detect match arm body without braces 2021-03-03 12:17:26 -08:00
rustc_parse_format
rustc_passes Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez 2021-03-07 10:41:13 +09:00
rustc_plugin_impl Only store a LocalDefId in hir::Item. 2021-02-15 19:32:10 +01:00
rustc_privacy Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726 2021-02-18 16:57:34 +01:00
rustc_query_impl Simplify hashing. 2021-02-21 12:22:22 +01:00
rustc_query_system Simplify hashing. 2021-02-21 12:22:22 +01:00
rustc_resolve Rollup merge of #80763 - petrochenkov:pubusecrate, r=estebank 2021-03-05 10:57:15 +01:00
rustc_save_analysis Only store a LocalDefId in hir::ForeignItem. 2021-02-15 19:32:29 +01:00
rustc_serialize Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
rustc_session Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_span Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_symbol_mangling Use less HirId when referring to items. 2021-02-15 19:36:12 +01:00
rustc_target Rollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=joshtriplett 2021-03-07 10:41:04 +09:00
rustc_trait_selection Fix tests 2021-03-03 11:22:44 +01:00
rustc_traits Fix tests 2021-03-03 11:22:44 +01:00
rustc_ty_utils Auto merge of #82159 - BoxyUwU:uwu, r=varkor 2021-02-24 21:54:52 +00:00
rustc_type_ir New pass to deduplicate blocks 2021-02-21 21:51:54 +01:00
rustc_typeck Rollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk 2021-03-07 10:41:15 +09:00