44use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span } ;
55
66use crate :: dep_graph;
7- use crate :: dep_graph:: { DepKind , DepNodeKey } ;
7+ use crate :: dep_graph:: DepNodeKey ;
88use crate :: query:: erase:: { self , Erasable , Erased } ;
99use crate :: query:: plumbing:: QueryVTable ;
1010use crate :: query:: { EnsureMode , QueryCache , QueryMode } ;
@@ -98,26 +98,26 @@ where
9898 }
9999}
100100
101- /// Common implementation of query feeding, used by `define_feedable!`.
101+ /// "Feeds" a feedable query by adding a given key/value pair to its in-memory cache.
102+ /// Called by macro-generated methods of [`rustc_middle::ty::TyCtxtFeed`].
102103pub ( crate ) fn query_feed < ' tcx , C > (
103104 tcx : TyCtxt < ' tcx > ,
104- dep_kind : DepKind ,
105- query_vtable : & QueryVTable < ' tcx , C > ,
105+ query : & ' tcx QueryVTable < ' tcx , C > ,
106106 key : C :: Key ,
107107 value : C :: Value ,
108108) where
109109 C : QueryCache ,
110110 C :: Key : DepNodeKey < ' tcx > ,
111111{
112- let format_value = query_vtable . format_value ;
112+ let format_value = query . format_value ;
113113
114114 // Check whether the in-memory cache already has a value for this key.
115- match try_get_cached ( tcx, & query_vtable . cache , key) {
115+ match try_get_cached ( tcx, & query . cache , key) {
116116 Some ( old) => {
117117 // The query already has a cached value for this key.
118118 // That's OK if both values are the same, i.e. they have the same hash,
119119 // so now we check their hashes.
120- if let Some ( hash_value_fn) = query_vtable . hash_value_fn {
120+ if let Some ( hash_value_fn) = query . hash_value_fn {
121121 let ( old_hash, value_hash) = tcx. with_stable_hashing_context ( |ref mut hcx| {
122122 ( hash_value_fn ( hcx, & old) , hash_value_fn ( hcx, & value) )
123123 } ) ;
@@ -126,7 +126,7 @@ pub(crate) fn query_feed<'tcx, C>(
126126 // results is tainted by errors. In this case, delay a bug to
127127 // ensure compilation is doomed, and keep the `old` value.
128128 tcx. dcx ( ) . delayed_bug ( format ! (
129- "Trying to feed an already recorded value for query {dep_kind :?} key={key:?}:\n \
129+ "Trying to feed an already recorded value for query {query :?} key={key:?}:\n \
130130 old value: {old}\n new value: {value}",
131131 old = format_value( & old) ,
132132 value = format_value( & value) ,
@@ -137,7 +137,7 @@ pub(crate) fn query_feed<'tcx, C>(
137137 // If feeding the same value multiple times needs to be supported,
138138 // the query should not be marked `no_hash`.
139139 bug ! (
140- "Trying to feed an already recorded value for query {dep_kind :?} key={key:?}:\n \
140+ "Trying to feed an already recorded value for query {query :?} key={key:?}:\n \
141141 old value: {old}\n new value: {value}",
142142 old = format_value( & old) ,
143143 value = format_value( & value) ,
@@ -147,15 +147,15 @@ pub(crate) fn query_feed<'tcx, C>(
147147 None => {
148148 // There is no cached value for this key, so feed the query by
149149 // adding the provided value to the cache.
150- let dep_node = dep_graph:: DepNode :: construct ( tcx, dep_kind, & key) ;
150+ let dep_node = dep_graph:: DepNode :: construct ( tcx, query . dep_kind , & key) ;
151151 let dep_node_index = tcx. dep_graph . with_feed_task (
152152 dep_node,
153153 tcx,
154154 & value,
155- query_vtable . hash_value_fn ,
156- query_vtable . format_value ,
155+ query . hash_value_fn ,
156+ query . format_value ,
157157 ) ;
158- query_vtable . cache . complete ( key, value, dep_node_index) ;
158+ query . cache . complete ( key, value, dep_node_index) ;
159159 }
160160 }
161161}
0 commit comments