]> git.proxmox.com Git - rustc.git/blobdiff - compiler/rustc_query_system/src/query/plumbing.rs
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / compiler / rustc_query_system / src / query / plumbing.rs
index c227c2aaff549164f2101449b12dac782666132e..3f22de6fba4077987d673cb21dfe8a4fea89b830 100644 (file)
@@ -9,7 +9,7 @@ use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
 use crate::query::job::{
     report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId,
 };
-use crate::query::{QueryContext, QueryMap, QueryStackFrame};
+use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
 
 use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::fx::{FxHashMap, FxHasher};
@@ -20,6 +20,7 @@ use rustc_data_structures::thin_vec::ThinVec;
 use rustc_errors::DiagnosticBuilder;
 use rustc_errors::{Diagnostic, FatalError};
 use rustc_span::{Span, DUMMY_SP};
+use std::cell::Cell;
 use std::collections::hash_map::Entry;
 use std::fmt::Debug;
 use std::hash::{Hash, Hasher};
@@ -129,8 +130,8 @@ where
             for (k, v) in shard.active.iter() {
                 if let QueryResult::Started(ref job) = *v {
                     let id = QueryJobId::new(job.id, shard_id, kind);
-                    let info = QueryInfo { span: job.span, query: make_query(tcx, k.clone()) };
-                    jobs.insert(id, QueryJobInfo { info, job: job.clone() });
+                    let query = make_query(tcx, k.clone());
+                    jobs.insert(id, QueryJobInfo { query, job: job.clone() });
                 }
             }
         }
@@ -479,8 +480,10 @@ where
 
         dep_graph.read_index(dep_node_index);
 
-        if unlikely!(!diagnostics.is_empty()) {
-            tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
+        let side_effects = QuerySideEffects { diagnostics };
+
+        if unlikely!(!side_effects.is_empty()) {
+            tcx.store_side_effects_for_anon_node(dep_node_index, side_effects);
         }
 
         return job.complete(result, dep_node_index);
@@ -616,12 +619,32 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
         } else {
             "`cargo clean`".to_string()
         };
-        tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
-            .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
-            .note(&format!("Please follow the instructions below to create a bug report with the provided information"))
-            .note(&format!("See <https://github.com/rust-lang/rust/issues/84970> for more information"))
-            .emit();
-        panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
+
+        // When we emit an error message and panic, we try to debug-print the `DepNode`
+        // and query result. Unforunately, this can cause us to run additional queries,
+        // which may result in another fingerprint mismatch while we're in the middle
+        // of processing this one. To avoid a double-panic (which kills the process
+        // before we can print out the query static), we print out a terse
+        // but 'safe' message if we detect a re-entrant call to this method.
+        thread_local! {
+            static INSIDE_VERIFY_PANIC: Cell<bool> = const { Cell::new(false) };
+        };
+
+        let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
+
+        if old_in_panic {
+            tcx.sess().struct_err("internal compiler error: re-entrant incremental verify failure, suppressing message")
+                .emit();
+        } else {
+            tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
+                .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
+                .note(&"Please follow the instructions below to create a bug report with the provided information")
+                .note(&"See <https://github.com/rust-lang/rust/issues/84970> for more information")
+                .emit();
+            panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
+        }
+
+        INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
     }
 }
 
@@ -677,8 +700,10 @@ where
 
     prof_timer.finish_with_query_invocation_id(dep_node_index.into());
 
-    if unlikely!(!diagnostics.is_empty()) && dep_node.kind != DepKind::NULL {
-        tcx.store_diagnostics(dep_node_index, diagnostics);
+    let side_effects = QuerySideEffects { diagnostics };
+
+    if unlikely!(!side_effects.is_empty()) && dep_node.kind != DepKind::NULL {
+        tcx.store_side_effects(dep_node_index, side_effects);
     }
 
     let result = job.complete(result, dep_node_index);