Skip to content

Commit 1c46321

Browse files
authored
Rollup merge of rust-lang#152033 - Zalathar:dep-node-key, r=nnethercote
Rename trait `DepNodeParams` to `DepNodeKey` In query system plumbing, we usually refer to a query's explicit argument value as a “key”. The first few commits do some preliminary cleanup that would conflict with the rename; the rename itself is in the final commit. r? nnethercote (or compiler)
2 parents de786a0 + b902f89 commit 1c46321

10 files changed

Lines changed: 254 additions & 250 deletions

File tree

Lines changed: 3 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
use rustc_data_structures::fingerprint::Fingerprint;
2-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
1+
use rustc_hir::def_id::DefId;
32
use rustc_hir::definitions::DefPathHash;
4-
use rustc_hir::{HirId, ItemLocalId, OwnerId};
5-
pub use rustc_query_system::dep_graph::DepNode;
6-
use rustc_query_system::dep_graph::FingerprintStyle;
7-
pub use rustc_query_system::dep_graph::dep_node::DepKind;
8-
pub(crate) use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
3+
use rustc_query_system::dep_graph::dep_node::DepKind;
4+
use rustc_query_system::dep_graph::{DepContext, DepNode, FingerprintStyle};
95
use rustc_span::Symbol;
106

117
use crate::mir::mono::MonoItem;
@@ -176,223 +172,3 @@ pub fn dep_kind_from_label(label: &str) -> DepKind {
176172
dep_kind_from_label_string(label)
177173
.unwrap_or_else(|_| panic!("Query label {label} does not exist"))
178174
}
179-
180-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
181-
#[inline(always)]
182-
fn fingerprint_style() -> FingerprintStyle {
183-
FingerprintStyle::Unit
184-
}
185-
186-
#[inline(always)]
187-
fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint {
188-
Fingerprint::ZERO
189-
}
190-
191-
#[inline(always)]
192-
fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
193-
Some(())
194-
}
195-
}
196-
197-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
198-
#[inline(always)]
199-
fn fingerprint_style() -> FingerprintStyle {
200-
FingerprintStyle::DefPathHash
201-
}
202-
203-
#[inline(always)]
204-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
205-
tcx.def_path_hash(*self).0
206-
}
207-
208-
#[inline(always)]
209-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
210-
tcx.def_path_str(*self)
211-
}
212-
213-
#[inline(always)]
214-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
215-
dep_node.extract_def_id(tcx)
216-
}
217-
}
218-
219-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
220-
#[inline(always)]
221-
fn fingerprint_style() -> FingerprintStyle {
222-
FingerprintStyle::DefPathHash
223-
}
224-
225-
#[inline(always)]
226-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
227-
self.to_def_id().to_fingerprint(tcx)
228-
}
229-
230-
#[inline(always)]
231-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
232-
self.to_def_id().to_debug_str(tcx)
233-
}
234-
235-
#[inline(always)]
236-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
237-
dep_node.extract_def_id(tcx).map(|id| id.expect_local())
238-
}
239-
}
240-
241-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for OwnerId {
242-
#[inline(always)]
243-
fn fingerprint_style() -> FingerprintStyle {
244-
FingerprintStyle::DefPathHash
245-
}
246-
247-
#[inline(always)]
248-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
249-
self.to_def_id().to_fingerprint(tcx)
250-
}
251-
252-
#[inline(always)]
253-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
254-
self.to_def_id().to_debug_str(tcx)
255-
}
256-
257-
#[inline(always)]
258-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
259-
dep_node.extract_def_id(tcx).map(|id| OwnerId { def_id: id.expect_local() })
260-
}
261-
}
262-
263-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
264-
#[inline(always)]
265-
fn fingerprint_style() -> FingerprintStyle {
266-
FingerprintStyle::DefPathHash
267-
}
268-
269-
#[inline(always)]
270-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
271-
let def_id = self.as_def_id();
272-
def_id.to_fingerprint(tcx)
273-
}
274-
275-
#[inline(always)]
276-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
277-
tcx.crate_name(*self).to_string()
278-
}
279-
280-
#[inline(always)]
281-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
282-
dep_node.extract_def_id(tcx).map(|id| id.krate)
283-
}
284-
}
285-
286-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
287-
#[inline(always)]
288-
fn fingerprint_style() -> FingerprintStyle {
289-
FingerprintStyle::Opaque
290-
}
291-
292-
// We actually would not need to specialize the implementation of this
293-
// method but it's faster to combine the hashes than to instantiate a full
294-
// hashing context and stable-hashing state.
295-
#[inline(always)]
296-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
297-
let (def_id_0, def_id_1) = *self;
298-
299-
let def_path_hash_0 = tcx.def_path_hash(def_id_0);
300-
let def_path_hash_1 = tcx.def_path_hash(def_id_1);
301-
302-
def_path_hash_0.0.combine(def_path_hash_1.0)
303-
}
304-
305-
#[inline(always)]
306-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
307-
let (def_id_0, def_id_1) = *self;
308-
309-
format!("({}, {})", tcx.def_path_debug_str(def_id_0), tcx.def_path_debug_str(def_id_1))
310-
}
311-
}
312-
313-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
314-
#[inline(always)]
315-
fn fingerprint_style() -> FingerprintStyle {
316-
FingerprintStyle::HirId
317-
}
318-
319-
// We actually would not need to specialize the implementation of this
320-
// method but it's faster to combine the hashes than to instantiate a full
321-
// hashing context and stable-hashing state.
322-
#[inline(always)]
323-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
324-
let HirId { owner, local_id } = *self;
325-
let def_path_hash = tcx.def_path_hash(owner.to_def_id());
326-
Fingerprint::new(
327-
// `owner` is local, so is completely defined by the local hash
328-
def_path_hash.local_hash(),
329-
local_id.as_u32() as u64,
330-
)
331-
}
332-
333-
#[inline(always)]
334-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
335-
let HirId { owner, local_id } = *self;
336-
format!("{}.{}", tcx.def_path_str(owner), local_id.as_u32())
337-
}
338-
339-
#[inline(always)]
340-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
341-
if tcx.fingerprint_style(dep_node.kind) == FingerprintStyle::HirId {
342-
let (local_hash, local_id) = Fingerprint::from(dep_node.hash).split();
343-
let def_path_hash = DefPathHash::new(tcx.stable_crate_id(LOCAL_CRATE), local_hash);
344-
let def_id = tcx.def_path_hash_to_def_id(def_path_hash)?.expect_local();
345-
let local_id = local_id
346-
.as_u64()
347-
.try_into()
348-
.unwrap_or_else(|_| panic!("local id should be u32, found {local_id:?}"));
349-
Some(HirId { owner: OwnerId { def_id }, local_id: ItemLocalId::from_u32(local_id) })
350-
} else {
351-
None
352-
}
353-
}
354-
}
355-
356-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ModDefId {
357-
#[inline(always)]
358-
fn fingerprint_style() -> FingerprintStyle {
359-
FingerprintStyle::DefPathHash
360-
}
361-
362-
#[inline(always)]
363-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
364-
self.to_def_id().to_fingerprint(tcx)
365-
}
366-
367-
#[inline(always)]
368-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
369-
self.to_def_id().to_debug_str(tcx)
370-
}
371-
372-
#[inline(always)]
373-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
374-
DefId::recover(tcx, dep_node).map(ModDefId::new_unchecked)
375-
}
376-
}
377-
378-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalModDefId {
379-
#[inline(always)]
380-
fn fingerprint_style() -> FingerprintStyle {
381-
FingerprintStyle::DefPathHash
382-
}
383-
384-
#[inline(always)]
385-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
386-
self.to_def_id().to_fingerprint(tcx)
387-
}
388-
389-
#[inline(always)]
390-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
391-
self.to_def_id().to_debug_str(tcx)
392-
}
393-
394-
#[inline(always)]
395-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
396-
LocalDefId::recover(tcx, dep_node).map(LocalModDefId::new_unchecked)
397-
}
398-
}

0 commit comments

Comments
 (0)