]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hygiene/load_cached_hygiene.rs
Auto merge of #80782 - petrochenkov:viscopes, r=matthewjasper
[rust.git] / src / test / incremental / hygiene / load_cached_hygiene.rs
1 // revisions:rpass1 rpass2
2 // compile-flags: -Z query-dep-graph -O
3 // aux-build:cached_hygiene.rs
4
5 // This tests the folllowing scenario
6 // 1. A foreign crate is compiled with incremental compilation.
7 //    This causes hygiene information to be saved to the incr cache.
8 // 2. One function is the foreign crate is modified. This causes the
9 //    optimized mir for an unmodified function to be loaded from the
10 //    incremental cache and written out to the crate metadata.
11 // 3. In the process of loading and writing out this function's MIR,
12 //    we load hygiene information from the incremental cache and
13 //    write it to our metadata.
14 // 4. This hygiene information is loaded by another crate (this file)
15
16 // Previously, this situation would cause hygiene identifiers
17 // (SyntaxContexts and ExpnIds) to get corrupted when we tried to
18 // serialize the hygiene information loaded from the incr cache into
19 // the metadata. Specifically, we were not resetting `orig_id`
20 // for an `EpxnData` generate in the current crate, which would cause
21 // us to serialize the `ExpnId` pointing to a garbage location in
22 // the metadata.o
23
24 // NOTE: We're explicitly passing the `-O` optimization flag because if optimizations are not
25 // enabled, then rustc will ignore the `#[inline(always)]` attribute which means we do not load
26 // the optimized mir for the unmodified function to be loaded and so the CGU containing that
27 // function will be reused.
28
29 #![feature(rustc_attrs)]
30
31 #![rustc_partition_reused(module="load_cached_hygiene-call_unchanged_function", cfg="rpass2")]
32 #![rustc_partition_codegened(module="load_cached_hygiene-call_changed_function", cfg="rpass2")]
33
34
35 extern crate cached_hygiene;
36
37 pub mod call_unchanged_function {
38
39     pub fn unchanged() {
40         cached_hygiene::unchanged_fn();
41     }
42 }
43
44 pub mod call_changed_function {
45     pub fn changed() {
46         cached_hygiene::changed_fn();
47     }
48 }
49
50 pub fn main() {
51     call_unchanged_function::unchanged();
52     call_changed_function::changed();
53 }