]> git.lizzy.rs Git - rust.git/commitdiff
Do not re-hash foreign spans.
authorCamille GILLOT <gillot.camille@gmail.com>
Sat, 2 Oct 2021 19:14:52 +0000 (21:14 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Wed, 6 Oct 2021 17:10:07 +0000 (19:10 +0200)
compiler/rustc_query_impl/src/on_disk_cache.rs
src/test/incremental/mir-opt.rs [new file with mode: 0644]

index f93623e445c2282126c29352f08996519830b61a..48eb488792d8973b05fe582fa329c0c4679e854a 100644 (file)
@@ -664,7 +664,21 @@ fn decode(decoder: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
 
             let data: ExpnData = decoder
                 .with_position(pos.to_usize(), |decoder| decode_tagged(decoder, TAG_EXPN_DATA))?;
 
             let data: ExpnData = decoder
                 .with_position(pos.to_usize(), |decoder| decode_tagged(decoder, TAG_EXPN_DATA))?;
-            rustc_span::hygiene::register_local_expn_id(data, hash)
+            let expn_id = rustc_span::hygiene::register_local_expn_id(data, hash);
+
+            #[cfg(debug_assertions)]
+            {
+                use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+                let mut hcx = decoder.tcx.create_stable_hashing_context();
+                let mut hasher = StableHasher::new();
+                hcx.while_hashing_spans(true, |hcx| {
+                    expn_id.expn_data().hash_stable(hcx, &mut hasher)
+                });
+                let local_hash: u64 = hasher.finish();
+                debug_assert_eq!(hash.local_hash(), local_hash);
+            }
+
+            expn_id
         } else {
             let index_guess = decoder.foreign_expn_data[&hash];
             decoder.tcx.cstore_untracked().expn_hash_to_expn_id(
         } else {
             let index_guess = decoder.foreign_expn_data[&hash];
             decoder.tcx.cstore_untracked().expn_hash_to_expn_id(
@@ -675,16 +689,7 @@ fn decode(decoder: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
             )
         };
 
             )
         };
 
-        #[cfg(debug_assertions)]
-        {
-            use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
-            let mut hcx = decoder.tcx.create_stable_hashing_context();
-            let mut hasher = StableHasher::new();
-            hcx.while_hashing_spans(true, |hcx| expn_id.expn_data().hash_stable(hcx, &mut hasher));
-            let local_hash: u64 = hasher.finish();
-            debug_assert_eq!(hash.local_hash(), local_hash);
-        }
-
+        debug_assert_eq!(expn_id.krate, krate);
         Ok(expn_id)
     }
 }
         Ok(expn_id)
     }
 }
diff --git a/src/test/incremental/mir-opt.rs b/src/test/incremental/mir-opt.rs
new file mode 100644 (file)
index 0000000..5bd8634
--- /dev/null
@@ -0,0 +1,11 @@
+// MIR optimizations can create expansions after the TyCtxt has been created.
+// This test verifies that those expansions can be decoded correctly.
+
+// revisions:rpass1 rpass2
+// compile-flags: -Z query-dep-graph -Z mir-opt-level=3
+
+fn main() {
+    if std::env::var("a").is_ok() {
+        println!("b");
+    }
+}