rust/src/test/incremental
Aaron Hill 06546d4b40
Avoid sorting predicates by `DefId`
Fixes issue #82920

Even if an item does not change between compilation sessions, it may end
up with a different `DefId`, since inserting/deleting an item affects
the `DefId`s of all subsequent items. Therefore, we use a `DefPathHash`
in the incremental compilation system, which is stable in the face of
changes to unrelated items.

In particular, the query system will consider the inputs to a query to
be unchanged if any `DefId`s in the inputs have their `DefPathHash`es
unchanged. Queries are pure functions, so the query result should be
unchanged if the query inputs are unchanged.

Unfortunately, it's possible to inadvertantly make a query result
incorrectly change across compilations, by relying on the specific value
of a `DefId`. Specifically, if the query result is a slice that gets
sorted by `DefId`, the precise order will depend on how the `DefId`s got
assigned in a particular compilation session. If some definitions end up
with different `DefId`s (but the same `DefPathHash`es) in a subsequent
compilation session, we will end up re-computing a *different* value for
the query, even though the query system expects the result to unchanged
due to the unchanged inputs.

It turns out that we have been sorting the predicates computed during
`astconv` by their `DefId`. These predicates make their way into the
`super_predicates_that_define_assoc_type`, which ends up getting used to
compute the vtables of trait objects. This, re-ordering these predicates
between compilation sessions can lead to undefined behavior at runtime -
the query system will re-use code built with a *differently ordered*
vtable, resulting in the wrong method being invoked at runtime.

This PR avoids sorting by `DefId` in `astconv`, fixing the
miscompilation. However, it's possible that other instances of this
issue exist - they could also be easily introduced in the future.

To fully fix this issue, we should
1. Turn on `-Z incremental-verify-ich` by default. This will cause the
   compiler to ICE whenver an 'unchanged' query result changes between
   compilation sessions, instead of causing a miscompilation.
2. Remove the `Ord` impls for `CrateNum` and `DefId`. This will make it
   difficult to introduce ICEs in the first place.
2021-03-13 13:45:12 -05:00
..
add_private_fn_at_krate_root_cc Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
auxiliary Use `def_path_hash_to_def_id` when re-using a `RawDefId` 2020-12-10 16:04:19 -05:00
callee_caller_cross_crate Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
change_add_field Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
change_crate_order Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
change_implementation_cross_crate Add a test for #37333 2020-01-01 13:07:41 +01:00
change_private_fn Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
change_private_fn_cc Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
change_private_impl_method Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
change_private_impl_method_cc Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
change_pub_inherent_method_body Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
change_pub_inherent_method_sig Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
const-generics adjust tests 2020-05-09 14:40:17 +02:00
extern_static Remove licenses 2018-12-25 21:08:33 -07:00
hashes Bless tests. 2021-03-09 19:27:59 +01:00
hygiene Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2, r=davidtwco,wesleywiser" 2021-01-11 16:27:59 -03:00
inlined_hir_34991 Replace `Hir` with `hir_owner` in tests 2020-03-14 22:52:31 +01:00
issue-39828 Remove licenses 2018-12-25 21:08:33 -07:00
issue-49595 Remove FIXME comment from incremental 2020-11-20 21:33:48 +09:00
krate_reassign_34991 Remove double trailing newlines 2019-04-22 16:57:01 +01:00
remapped_paths_cc Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2, r=davidtwco,wesleywiser" 2021-01-11 16:27:59 -03:00
remove-private-item-cross-crate Remove licenses 2018-12-25 21:08:33 -07:00
remove_crate Remove licenses 2018-12-25 21:08:33 -07:00
remove_source_file Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
rlib_cross_crate Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
span_hash_stable Replace `Hir` with `hir_owner` in tests 2020-03-14 22:52:31 +01:00
static_cycle Remove licenses 2018-12-25 21:08:33 -07:00
static_refering_to_other_static Remove licenses 2018-12-25 21:08:33 -07:00
static_refering_to_other_static2 Remove licenses 2018-12-25 21:08:33 -07:00
static_refering_to_other_static3 Remove licenses 2018-12-25 21:08:33 -07:00
static_stable_hash Remove licenses 2018-12-25 21:08:33 -07:00
struct_change_field_type_cross_crate Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
thinlto Use llvm::computeLTOCacheKey to determine post-ThinLTO CGU reuse 2020-09-17 22:04:13 -04:00
type_alias_cross_crate Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
cache_file_headers.rs Remove licenses 2018-12-25 21:08:33 -07:00
change_crate_dep_kind.rs Re-enable Emscripten's exception handling support 2019-10-25 15:16:36 -07:00
change_name_of_static_in_fn.rs Remove leading newlines 2019-04-22 17:01:33 +01:00
change_symbol_export_status.rs fix pre-expansion linting infra 2020-03-18 15:08:25 +01:00
commandline-args.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
crate_hash_reorder.rs Move the `krate` method to Hir and remove the Krate dep node 2020-02-06 13:23:32 +01:00
cyclic-trait-hierarchy.rs Revert "Auto merge of #79637 - spastorino:revert-trait-inheritance-self, r=Mark-Simulacrum" 2021-02-05 18:56:56 -03:00
delayed_span_bug.rs was not the same replace as others 2019-11-05 22:49:19 +01:00
dirty_clean.rs pretty: trim paths of unique symbols 2020-09-02 22:26:37 +03:00
feature_gate.rs update tests for migrate mode by default 2019-04-22 08:40:08 +01:00
foreign.rs Update tests for extern block linting 2021-01-13 07:49:16 -05:00
hello_world.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
ich_method_call_trait_scope.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
ich_nested_items.rs hir: replace "items" terminology with "nodes" where appropriate. 2020-03-19 14:36:04 +02:00
ich_resolve_results.rs hir: replace "items" terminology with "nodes" where appropriate. 2020-03-19 14:36:04 +02:00
incremental_proc_macro.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
issue-35593.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-38222.rs Move the `krate` method to Hir and remove the Krate dep node 2020-02-06 13:23:32 +01:00
issue-39569.rs Remove double trailing newlines 2019-04-22 16:57:01 +01:00
issue-42602.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
issue-49043.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-49482.rs Moved issue tests to subdirs and normalised names. 2019-03-14 01:00:49 +00:00
issue-51409.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-54059.rs Moved issue tests to subdirs and normalised names. 2019-03-14 01:00:49 +00:00
issue-54242.rs Remove predicates on associated types from traits 2020-10-06 11:19:31 +01:00
issue-59523-on-implemented-is-not-unused.rs gate rustc_on_unimplemented under rustc_attrs 2019-11-06 07:34:51 +01:00
issue-59524-layout-scalar-valid-range-is-not-unused.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
issue-60629.rs add regression test for #60629 2019-05-10 12:59:40 +02:00
issue-61323.rs Make try_mark_previous_green aware of cycles. 2019-12-06 12:48:53 +03:00
issue-61530.rs Revert "Rollup merge of #69280 - ecstatic-morse:promote-shuffle-no-special-case, r=petrochenkov" 2020-02-20 16:00:39 -08:00
issue-62649-path-collisions-happen.rs Collisions in the dep-graph due to path-reuse are rare but can occur. 2020-01-27 17:06:06 +01:00
issue-69596.rs Add test for #69596 2020-03-14 22:52:31 +01:00
issue-72386.rs Add missing ASM arena declaration to librustc_middle 2020-05-23 15:50:37 -04:00
issue-79661-missing-def-path-hash.rs Properly re-use def path hash in incremental mode 2020-12-04 22:16:40 -05:00
issue-79890-imported-crates-changed.rs Use `def_path_hash_to_def_id` when re-using a `RawDefId` 2020-12-10 16:04:19 -05:00
issue-80336-invalid-span.rs Properly handle `SyntaxContext` of dummy spans in incr comp 2021-01-13 15:20:29 -05:00
issue-82920-predicate-order-miscompile.rs Avoid sorting predicates by `DefId` 2021-03-13 13:45:12 -05:00
krate-inherent.rs Move the `krate` method to Hir and remove the Krate dep node 2020-02-06 13:23:32 +01:00
krate-inlined.rs Move the `krate` method to Hir and remove the Krate dep node 2020-02-06 13:23:32 +01:00
lto-in-linker.rs Fix disagreeement about CGU reuse and LTO 2020-05-09 19:30:48 -07:00
lto.rs rustc: Implement incremental "fat" LTO 2019-02-12 04:58:31 -08:00
macro_export.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
no_mangle.rs compiletest: Remove `skip-codegen` 2019-06-16 12:23:22 +03:00
rlib-lto.rs Fix disagreeement about CGU reuse and LTO 2020-05-09 19:30:48 -07:00
source_loc_macros.rs hir: replace "items" terminology with "nodes" where appropriate. 2020-03-19 14:36:04 +02:00
spans_in_type_debuginfo.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
spans_significant_w_debuginfo.rs hir: replace "items" terminology with "nodes" where appropriate. 2020-03-19 14:36:04 +02:00
spans_significant_w_panic.rs Add no_hash to query macro and move some queries over 2019-03-20 16:06:09 +01:00
spike-neg1.rs Remove licenses 2018-12-25 21:08:33 -07:00
spike-neg2.rs Remove licenses 2018-12-25 21:08:33 -07:00
spike.rs Remove licenses 2018-12-25 21:08:33 -07:00
string_constant.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
struct_add_field.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
struct_change_field_name.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
struct_change_field_type.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
struct_change_nothing.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
struct_remove_field.rs Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
unchecked_dirty_clean.rs Replace `Hir` with `hir_owner` in tests 2020-03-14 22:52:31 +01:00
warnings-reemitted.rs Moving more build-pass tests to check-pass 2020-04-23 20:21:38 -07:00