Skip to content

Commit 625d5a6

Browse files
committed
Auto merge of #85829 - bjorn3:simplify_crate_num, r=jackh726
Remove CrateNum::ReservedForIncrCompCache It's only use is easily replaceable with `Option<CrateNum>`.
2 parents 7f9ab03 + 5ab25ab commit 625d5a6

File tree

7 files changed

+12
-71
lines changed

7 files changed

+12
-71
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
@@ -755,8 +755,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
755755
{
756756
let tcx = self.tcx();
757757

758-
let cache_key =
759-
ty::CReaderCacheKey { cnum: CrateNum::ReservedForIncrCompCache, pos: shorthand };
758+
let cache_key = ty::CReaderCacheKey { cnum: None, pos: shorthand };
760759

761760
if let Some(&ty) = tcx.ty_rcache.borrow().get(&cache_key) {
762761
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
@@ -9,76 +9,29 @@ use std::borrow::Borrow;
99
use std::fmt;
1010

1111
rustc_index::newtype_index! {
12-
pub struct CrateId {
12+
pub struct CrateNum {
1313
ENCODABLE = custom
14+
DEBUG_FORMAT = "crate{}"
1415
}
1516
}
1617

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

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

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

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

@@ -96,15 +49,6 @@ impl<D: Decoder> Decodable<D> for CrateNum {
9649
}
9750
}
9851

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

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.generics.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
11| 3| self.strength = new_strength;
1212
12| 3| }
1313
------------------
14-
| <generics::Firework<f64>>::set_strength:
15-
| 10| 2| fn set_strength(&mut self, new_strength: T) {
16-
| 11| 2| self.strength = new_strength;
17-
| 12| 2| }
18-
------------------
1914
| <generics::Firework<i32>>::set_strength:
2015
| 10| 1| fn set_strength(&mut self, new_strength: T) {
2116
| 11| 1| self.strength = new_strength;
2217
| 12| 1| }
18+
------------------
19+
| <generics::Firework<f64>>::set_strength:
20+
| 10| 2| fn set_strength(&mut self, new_strength: T) {
21+
| 11| 2| self.strength = new_strength;
22+
| 12| 2| }
2323
------------------
2424
13| |}
2525
14| |

0 commit comments

Comments
 (0)