summaryrefslogtreecommitdiffstats
path: root/tests/incremental/hygiene
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/incremental/hygiene
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/incremental/hygiene')
-rw-r--r--tests/incremental/hygiene/auxiliary/cached_hygiene.rs36
-rw-r--r--tests/incremental/hygiene/load_cached_hygiene.rs48
2 files changed, 84 insertions, 0 deletions
diff --git a/tests/incremental/hygiene/auxiliary/cached_hygiene.rs b/tests/incremental/hygiene/auxiliary/cached_hygiene.rs
new file mode 100644
index 000000000..b31f60e97
--- /dev/null
+++ b/tests/incremental/hygiene/auxiliary/cached_hygiene.rs
@@ -0,0 +1,36 @@
+// revisions:rpass1 rpass2
+// compile-flags: -Z query-dep-graph
+
+// We use #[inline(always)] to ensure that the downstream crate
+// will always load the MIR for these functions
+
+#![feature(rustc_attrs)]
+
+#[allow(unused)]
+macro_rules! first_macro {
+ () => {
+ println!("New call!");
+ }
+}
+
+#[rustc_clean(except="hir_owner_nodes,typeck,optimized_mir,promoted_mir", cfg="rpass2")]
+#[inline(always)]
+pub fn changed_fn() {
+ // This will cause additional hygiene to be generate,
+ // which will cause the SyntaxContext/ExpnId raw ids to be
+ // different when we write out `my_fn` to the crate metadata.
+ #[cfg(rpass2)]
+ first_macro!();
+}
+
+macro_rules! print_loc {
+ () => {
+ println!("Caller loc: {}", std::panic::Location::caller());
+ }
+}
+
+#[rustc_clean(cfg="rpass2")]
+#[inline(always)]
+pub fn unchanged_fn() {
+ print_loc!();
+}
diff --git a/tests/incremental/hygiene/load_cached_hygiene.rs b/tests/incremental/hygiene/load_cached_hygiene.rs
new file mode 100644
index 000000000..355d33458
--- /dev/null
+++ b/tests/incremental/hygiene/load_cached_hygiene.rs
@@ -0,0 +1,48 @@
+// revisions:rpass1 rpass2
+// compile-flags: -Z query-dep-graph
+// aux-build:cached_hygiene.rs
+
+// This tests the following scenario
+// 1. A foreign crate is compiled with incremental compilation.
+// This causes hygiene information to be saved to the incr cache.
+// 2. One function is the foreign crate is modified. This causes the
+// optimized mir for an unmodified function to be loaded from the
+// incremental cache and written out to the crate metadata.
+// 3. In the process of loading and writing out this function's MIR,
+// we load hygiene information from the incremental cache and
+// write it to our metadata.
+// 4. This hygiene information is loaded by another crate (this file)
+
+// Previously, this situation would cause hygiene identifiers
+// (SyntaxContexts and ExpnIds) to get corrupted when we tried to
+// serialize the hygiene information loaded from the incr cache into
+// the metadata. Specifically, we were not resetting `orig_id`
+// for an `EpxnData` generate in the current crate, which would cause
+// us to serialize the `ExpnId` pointing to a garbage location in
+// the metadata.
+
+#![feature(rustc_attrs)]
+
+#![rustc_partition_reused(module="load_cached_hygiene-call_unchanged_function", cfg="rpass2")]
+#![rustc_partition_codegened(module="load_cached_hygiene-call_changed_function", cfg="rpass2")]
+
+
+extern crate cached_hygiene;
+
+pub mod call_unchanged_function {
+
+ pub fn unchanged() {
+ cached_hygiene::unchanged_fn();
+ }
+}
+
+pub mod call_changed_function {
+ pub fn changed() {
+ cached_hygiene::changed_fn();
+ }
+}
+
+pub fn main() {
+ call_unchanged_function::unchanged();
+ call_changed_function::changed();
+}