Remove CrateNum::ReservedForIncrCompCache
This commit is contained in:
parent
d93b6a4598
commit
1ef98856c7
6 changed files with 7 additions and 66 deletions
|
@ -300,7 +300,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
let key = ty::CReaderCacheKey { cnum: self.cdata().cnum, pos: shorthand };
|
let key = ty::CReaderCacheKey { cnum: Some(self.cdata().cnum), pos: shorthand };
|
||||||
|
|
||||||
if let Some(&ty) = tcx.ty_rcache.borrow().get(&key) {
|
if let Some(&ty) = tcx.ty_rcache.borrow().get(&key) {
|
||||||
return Ok(ty);
|
return Ok(ty);
|
||||||
|
|
|
@ -269,7 +269,7 @@ pub struct CrateVariancesMap<'tcx> {
|
||||||
// the types of AST nodes.
|
// the types of AST nodes.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct CReaderCacheKey {
|
pub struct CReaderCacheKey {
|
||||||
pub cnum: CrateNum,
|
pub cnum: Option<CrateNum>,
|
||||||
pub pos: usize,
|
pub pos: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -758,8 +758,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
let cache_key =
|
let cache_key = ty::CReaderCacheKey { cnum: None, pos: shorthand };
|
||||||
ty::CReaderCacheKey { cnum: CrateNum::ReservedForIncrCompCache, pos: shorthand };
|
|
||||||
|
|
||||||
if let Some(&ty) = tcx.ty_rcache.borrow().get(&cache_key) {
|
if let Some(&ty) = tcx.ty_rcache.borrow().get(&cache_key) {
|
||||||
return Ok(ty);
|
return Ok(ty);
|
||||||
|
|
|
@ -116,7 +116,6 @@ use crate::util::pretty;
|
||||||
use crate::util::spanview::{self, SpanViewable};
|
use crate::util::spanview::{self, SpanViewable};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_index::vec::Idx;
|
|
||||||
use rustc_middle::mir::coverage::*;
|
use rustc_middle::mir::coverage::*;
|
||||||
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
|
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use gsgdt::{Edge, Graph, Node, NodeStyle};
|
use gsgdt::{Edge, Graph, Node, NodeStyle};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::vec::Idx;
|
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
|
|
|
@ -10,65 +10,21 @@ use std::borrow::Borrow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
pub struct CrateId {
|
pub struct CrateNum {
|
||||||
ENCODABLE = custom
|
ENCODABLE = custom
|
||||||
|
DEBUG_FORMAT = "crate{}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub enum CrateNum {
|
|
||||||
/// A special `CrateNum` that we use for the `tcx.rcache` when decoding from
|
|
||||||
/// the incr. comp. cache.
|
|
||||||
ReservedForIncrCompCache,
|
|
||||||
Index(CrateId),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Item definitions in the currently-compiled crate would have the `CrateNum`
|
/// Item definitions in the currently-compiled crate would have the `CrateNum`
|
||||||
/// `LOCAL_CRATE` in their `DefId`.
|
/// `LOCAL_CRATE` in their `DefId`.
|
||||||
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32(0));
|
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
|
||||||
|
|
||||||
impl Idx for CrateNum {
|
|
||||||
#[inline]
|
|
||||||
fn new(value: usize) -> Self {
|
|
||||||
CrateNum::Index(Idx::new(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn index(self) -> usize {
|
|
||||||
match self {
|
|
||||||
CrateNum::Index(idx) => Idx::index(idx),
|
|
||||||
_ => panic!("Tried to get crate index of {:?}", self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CrateNum {
|
impl CrateNum {
|
||||||
pub fn new(x: usize) -> CrateNum {
|
pub fn new(x: usize) -> CrateNum {
|
||||||
CrateNum::from_usize(x)
|
CrateNum::from_usize(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_usize(x: usize) -> CrateNum {
|
|
||||||
CrateNum::Index(CrateId::from_usize(x))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_u32(x: u32) -> CrateNum {
|
|
||||||
CrateNum::Index(CrateId::from_u32(x))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_usize(self) -> usize {
|
|
||||||
match self {
|
|
||||||
CrateNum::Index(id) => id.as_usize(),
|
|
||||||
_ => panic!("tried to get index of non-standard crate {:?}", self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_u32(self) -> u32 {
|
|
||||||
match self {
|
|
||||||
CrateNum::Index(id) => id.as_u32(),
|
|
||||||
_ => panic!("tried to get index of non-standard crate {:?}", self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_def_id(&self) -> DefId {
|
pub fn as_def_id(&self) -> DefId {
|
||||||
DefId { krate: *self, index: CRATE_DEF_INDEX }
|
DefId { krate: *self, index: CRATE_DEF_INDEX }
|
||||||
}
|
}
|
||||||
|
@ -76,10 +32,7 @@ impl CrateNum {
|
||||||
|
|
||||||
impl fmt::Display for CrateNum {
|
impl fmt::Display for CrateNum {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
fmt::Display::fmt(&self.private, f)
|
||||||
CrateNum::Index(id) => fmt::Display::fmt(&id.private, f),
|
|
||||||
CrateNum::ReservedForIncrCompCache => write!(f, "crate for decoding incr comp cache"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,15 +50,6 @@ impl<D: Decoder> Decodable<D> for CrateNum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::fmt::Debug for CrateNum {
|
|
||||||
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
|
|
||||||
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
|
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
|
||||||
/// stable across crate and compilation session boundaries. It consists of two
|
/// stable across crate and compilation session boundaries. It consists of two
|
||||||
/// separate 64-bit hashes. The first uniquely identifies the crate this
|
/// separate 64-bit hashes. The first uniquely identifies the crate this
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue