Skip to content

Commit 1ef9885

Browse files
committed
Remove CrateNum::ReservedForIncrCompCache
1 parent d93b6a4 commit 1ef9885

File tree

6 files changed

+7
-66
lines changed

6 files changed

+7
-66
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
300300
{
301301
let tcx = self.tcx();
302302

303-
let key = ty::CReaderCacheKey { cnum: self.cdata().cnum, pos: shorthand };
303+
let key = ty::CReaderCacheKey { cnum: Some(self.cdata().cnum), pos: shorthand };
304304

305305
if let Some(&ty) = tcx.ty_rcache.borrow().get(&key) {
306306
return Ok(ty);

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub struct CrateVariancesMap<'tcx> {
269269
// the types of AST nodes.
270270
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
271271
pub struct CReaderCacheKey {
272-
pub cnum: CrateNum,
272+
pub cnum: Option<CrateNum>,
273273
pub pos: usize,
274274
}
275275

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
758758
{
759759
let tcx = self.tcx();
760760

761-
let cache_key =
762-
ty::CReaderCacheKey { cnum: CrateNum::ReservedForIncrCompCache, pos: shorthand };
761+
let cache_key = ty::CReaderCacheKey { cnum: None, pos: shorthand };
763762

764763
if let Some(&ty) = tcx.ty_rcache.borrow().get(&cache_key) {
765764
return Ok(ty);

compiler/rustc_mir/src/transform/coverage/debug.rs

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ use crate::util::pretty;
116116
use crate::util::spanview::{self, SpanViewable};
117117

118118
use rustc_data_structures::fx::FxHashMap;
119-
use rustc_index::vec::Idx;
120119
use rustc_middle::mir::coverage::*;
121120
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
122121
use rustc_middle::ty::TyCtxt;

compiler/rustc_mir/src/util/generic_graph.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use gsgdt::{Edge, Graph, Node, NodeStyle};
22
use rustc_hir::def_id::DefId;
3-
use rustc_index::vec::Idx;
43
use rustc_middle::mir::*;
54
use rustc_middle::ty::TyCtxt;
65

compiler/rustc_span/src/def_id.rs

+4-60
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,29 @@ use std::borrow::Borrow;
1010
use std::fmt;
1111

1212
rustc_index::newtype_index! {
13-
pub struct CrateId {
13+
pub struct CrateNum {
1414
ENCODABLE = custom
15+
DEBUG_FORMAT = "crate{}"
1516
}
1617
}
1718

18-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
19-
pub enum CrateNum {
20-
/// A special `CrateNum` that we use for the `tcx.rcache` when decoding from
21-
/// the incr. comp. cache.
22-
ReservedForIncrCompCache,
23-
Index(CrateId),
24-
}
25-
2619
/// Item definitions in the currently-compiled crate would have the `CrateNum`
2720
/// `LOCAL_CRATE` in their `DefId`.
28-
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32(0));
29-
30-
impl Idx for CrateNum {
31-
#[inline]
32-
fn new(value: usize) -> Self {
33-
CrateNum::Index(Idx::new(value))
34-
}
35-
36-
#[inline]
37-
fn index(self) -> usize {
38-
match self {
39-
CrateNum::Index(idx) => Idx::index(idx),
40-
_ => panic!("Tried to get crate index of {:?}", self),
41-
}
42-
}
43-
}
21+
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
4422

4523
impl CrateNum {
4624
pub fn new(x: usize) -> CrateNum {
4725
CrateNum::from_usize(x)
4826
}
4927

50-
pub fn from_usize(x: usize) -> CrateNum {
51-
CrateNum::Index(CrateId::from_usize(x))
52-
}
53-
54-
pub fn from_u32(x: u32) -> CrateNum {
55-
CrateNum::Index(CrateId::from_u32(x))
56-
}
57-
58-
pub fn as_usize(self) -> usize {
59-
match self {
60-
CrateNum::Index(id) => id.as_usize(),
61-
_ => panic!("tried to get index of non-standard crate {:?}", self),
62-
}
63-
}
64-
65-
pub fn as_u32(self) -> u32 {
66-
match self {
67-
CrateNum::Index(id) => id.as_u32(),
68-
_ => panic!("tried to get index of non-standard crate {:?}", self),
69-
}
70-
}
71-
7228
pub fn as_def_id(&self) -> DefId {
7329
DefId { krate: *self, index: CRATE_DEF_INDEX }
7430
}
7531
}
7632

7733
impl fmt::Display for CrateNum {
7834
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79-
match self {
80-
CrateNum::Index(id) => fmt::Display::fmt(&id.private, f),
81-
CrateNum::ReservedForIncrCompCache => write!(f, "crate for decoding incr comp cache"),
82-
}
35+
fmt::Display::fmt(&self.private, f)
8336
}
8437
}
8538

@@ -97,15 +50,6 @@ impl<D: Decoder> Decodable<D> for CrateNum {
9750
}
9851
}
9952

100-
impl ::std::fmt::Debug for CrateNum {
101-
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
102-
match self {
103-
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
104-
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
105-
}
106-
}
107-
}
108-
10953
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
11054
/// stable across crate and compilation session boundaries. It consists of two
11155
/// separate 64-bit hashes. The first uniquely identifies the crate this

0 commit comments

Comments
 (0)