@@ -6,6 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
66use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
77use rustc_data_structures:: steal:: Steal ;
88use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
9+ use rustc_data_structures:: OnDrop ;
910use rustc_index:: vec:: IndexVec ;
1011use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
1112use smallvec:: { smallvec, SmallVec } ;
@@ -676,49 +677,19 @@ impl<K: DepKind> DepGraph<K> {
676677 None => { }
677678 }
678679
679- let mut stack = smallvec ! [ prev_index] ;
680- let _backtrace_print =
681- MarkingStack { stack : & mut stack, sess : qcx. dep_context ( ) . sess ( ) , graph : data } ;
680+ let backtrace = backtrace_printer ( qcx. dep_context ( ) . sess ( ) , data, prev_index) ;
682681
683682 // This DepNode and the corresponding query invocation existed
684683 // in the previous compilation session too, so we can try to
685684 // mark it as green by recursively marking all of its
686685 // dependencies green.
687686 let ret = self
688- . try_mark_previous_green ( qcx, data, prev_index, & dep_node, _backtrace_print . stack )
687+ . try_mark_previous_green ( qcx, data, prev_index, & dep_node)
689688 . map ( |dep_node_index| ( prev_index, dep_node_index) ) ;
690689
691690 // We succeeded, no backtrace.
692- std :: mem :: forget ( _backtrace_print ) ;
691+ backtrace . disable ( ) ;
693692 return ret;
694-
695- /// Remember the stack of queries we are forcing in the event of an incr. comp. panic.
696- struct MarkingStack < ' a , ' v , K : DepKind > {
697- stack : & ' v mut SmallVec < [ SerializedDepNodeIndex ; 8 ] > ,
698- sess : & ' a rustc_session:: Session ,
699- graph : & ' a DepGraphData < K > ,
700- }
701-
702- impl < ' a , ' v , K : DepKind > Drop for MarkingStack < ' a , ' v , K > {
703- /// Print the forcing backtrace.
704- #[ inline( never) ]
705- #[ cold]
706- fn drop ( & mut self ) {
707- for & frame in self . stack . iter ( ) . rev ( ) {
708- let node = self . graph . previous . index_to_node ( frame) ;
709- // Do not try to rely on DepNode's Debug implementation,
710- // since it may panic.
711- let diag = rustc_errors:: Diagnostic :: new (
712- rustc_errors:: Level :: FailureNote ,
713- & format ! (
714- "encountered while trying to mark dependency green: {:?}({})" ,
715- node. kind, node. hash
716- ) ,
717- ) ;
718- self . sess . diagnostic ( ) . force_print_diagnostic ( diag) ;
719- }
720- }
721- }
722693 }
723694
724695 #[ instrument( skip( self , qcx, data, parent_dep_node_index) , level = "debug" ) ]
@@ -728,7 +699,6 @@ impl<K: DepKind> DepGraph<K> {
728699 data : & DepGraphData < K > ,
729700 parent_dep_node_index : SerializedDepNodeIndex ,
730701 dep_node : & DepNode < K > ,
731- stack : & mut SmallVec < [ SerializedDepNodeIndex ; 8 ] > ,
732702 ) -> Option < ( ) > {
733703 let dep_dep_node_color = data. colors . get ( parent_dep_node_index) ;
734704 let dep_dep_node = & data. previous . index_to_node ( parent_dep_node_index) ;
@@ -761,7 +731,7 @@ impl<K: DepKind> DepGraph<K> {
761731 ) ;
762732
763733 let node_index =
764- self . try_mark_previous_green ( qcx, data, parent_dep_node_index, dep_dep_node, stack ) ;
734+ self . try_mark_previous_green ( qcx, data, parent_dep_node_index, dep_dep_node) ;
765735
766736 if node_index. is_some ( ) {
767737 debug ! ( "managed to MARK dependency {dep_dep_node:?} as green" , ) ;
@@ -817,7 +787,6 @@ impl<K: DepKind> DepGraph<K> {
817787 data : & DepGraphData < K > ,
818788 prev_dep_node_index : SerializedDepNodeIndex ,
819789 dep_node : & DepNode < K > ,
820- stack : & mut SmallVec < [ SerializedDepNodeIndex ; 8 ] > ,
821790 ) -> Option < DepNodeIndex > {
822791 #[ cfg( not( parallel_compiler) ) ]
823792 {
@@ -833,9 +802,10 @@ impl<K: DepKind> DepGraph<K> {
833802 let prev_deps = data. previous . edge_targets_from ( prev_dep_node_index) ;
834803
835804 for & dep_dep_node_index in prev_deps {
836- stack. push ( dep_dep_node_index) ;
837- self . try_mark_parent_green ( qcx, data, dep_dep_node_index, dep_node, stack) ?;
838- stack. pop ( ) ;
805+ let backtrace = backtrace_printer ( qcx. dep_context ( ) . sess ( ) , data, dep_dep_node_index) ;
806+ let success = self . try_mark_parent_green ( qcx, data, dep_dep_node_index, dep_node) ;
807+ backtrace. disable ( ) ;
808+ success?;
839809 }
840810
841811 // If we got here without hitting a `return` that means that all
@@ -1405,3 +1375,26 @@ impl DepNodeColorMap {
14051375 )
14061376 }
14071377}
1378+
1379+ fn backtrace_printer < ' a , K : DepKind > (
1380+ sess : & ' a rustc_session:: Session ,
1381+ graph : & ' a DepGraphData < K > ,
1382+ node : SerializedDepNodeIndex ,
1383+ ) -> OnDrop < impl Fn ( ) + ' a > {
1384+ OnDrop (
1385+ #[ inline( never) ]
1386+ #[ cold]
1387+ move || {
1388+ let node = graph. previous . index_to_node ( node) ;
1389+ // Do not try to rely on DepNode's Debug implementation, since it may panic.
1390+ let diag = rustc_errors:: Diagnostic :: new (
1391+ rustc_errors:: Level :: FailureNote ,
1392+ & format ! (
1393+ "encountered while trying to mark dependency green: {:?}({})" ,
1394+ node. kind, node. hash
1395+ ) ,
1396+ ) ;
1397+ sess. diagnostic ( ) . force_print_diagnostic ( diag) ;
1398+ } ,
1399+ )
1400+ }
0 commit comments