rust/src/test/incremental
bors 1025db84a6 Auto merge of #85211 - Aaron1011:metadata-invalid-span, r=michaelwoerister
Preserve `SyntaxContext` for invalid/dummy spans in crate metadata

Fixes #85197

We already preserved the `SyntaxContext` for invalid/dummy spans in the
incremental cache, but we weren't doing the same for crate metadata.
If an invalid (lo/hi from different files) span is written to the
incremental cache, we will decode it with a 'dummy' location, but keep
the original `SyntaxContext`. Since the crate metadata encoder was only
checking for `DUMMY_SP` (dummy location + root `SyntaxContext`),
the metadata encoder would treat it as a normal span, encoding the
`SyntaxContext`. As a result, the final span encoded to the metadata
would change across sessions, even if the crate itself was unchanged.

This could lead to an 'unstable fingerprint' ICE under the following conditions:
1. We compile a crate with an invalid span using incremental compilation. The metadata encoder discards the `SyntaxContext` since the span is invalid, while the incremental cache encoder preserves the `SyntaxContext`
2. From another crate, we execute a foreign query, decoding the invalid span from the metadata as `DUMMY_SP` (e.g. with `SyntaxContext::root()`). This span gets hashed into the query fingerprint. So far, this has always happened through the `optimized_mir` query.
3. We recompile the first crate using our populated incremental cache, without changing anything. We load the (previously) invalid span from our incremental cache - it gets converted to a span with a dummy (but valid) location, along with the original `SyntaxContext`. This span gets written out to the crate metadata - since it now has a valid location, we preserve its `SyntaxContext`.
4. We recompile the second crate, again using a populated incremental cache. We now re-run the foreign query `optimized_mir` - the foreign crate hash is unchanged, but we end up decoding a different span (it now ha a non-root `SyntaxContext`). This results in the fingerprint changing, resulting in an ICE.

This PR updates our encoding of spans in the crate metadata to mirror
the encoding of spans into the incremental cache. We now always encode a
`SyntaxContext`, and encode location information for spans with a
non-dummy location.
2021-05-14 16:58:30 +00: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 Move parenting info to index_hir. 2021-04-29 21:36:55 +02: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
issue-85197-invalid-span Preserve SyntaxContext for invalid/dummy spans in crate metadata 2021-05-12 15:44:46 -04: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 Add integration test for --remap-pathh-prefix 2021-04-29 12:53:59 +00: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 Move parenting info to index_hir. 2021-04-29 21:36:55 +02:00
ich_resolve_results.rs Err if the debugging options are not passed. 2021-03-22 21:31:00 +01: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 fix test suite 2021-05-13 15:01:09 +02: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-80691-bad-eval-cache.rs Use EvaluatedToOkModuloRegions whenever we erase regions 2021-03-24 16:01:37 -04:00
issue-82920-predicate-order-miscompile.rs Avoid sorting predicates by DefId 2021-03-13 13:45:12 -05:00
issue-84252-global-alloc.rs Mark has_global_allocator query as eval_always 2021-04-16 16:28:54 -04: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 Err if the debugging options are not passed. 2021-03-22 21:31:00 +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