Skip to content

Commit 8fbc91c

Browse files
incr.comp.: Make MIR encoding fit for incr.comp. caching.
1 parent 436ac89 commit 8fbc91c

File tree

8 files changed

+81
-27
lines changed

8 files changed

+81
-27
lines changed

src/librustc/ich/impls_mir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ for mir::Terminator<'gcx> {
9898
}
9999
}
100100

101-
impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearOnDecode<T>
101+
impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearCrossCrate<T>
102102
where T: HashStable<StableHashingContext<'gcx>>
103103
{
104104
#[inline]
@@ -107,8 +107,8 @@ impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearOnDecode<T>
107107
hasher: &mut StableHasher<W>) {
108108
mem::discriminant(self).hash_stable(hcx, hasher);
109109
match *self {
110-
mir::ClearOnDecode::Clear => {}
111-
mir::ClearOnDecode::Set(ref value) => {
110+
mir::ClearCrossCrate::Clear => {}
111+
mir::ClearCrossCrate::Set(ref value) => {
112112
value.hash_stable(hcx, hasher);
113113
}
114114
}

src/librustc/mir/mod.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct Mir<'tcx> {
7575

7676
/// Crate-local information for each visibility scope, that can't (and
7777
/// needn't) be tracked across crates.
78-
pub visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope, VisibilityScopeInfo>>,
78+
pub visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope, VisibilityScopeInfo>>,
7979

8080
/// Rvalues promoted from this function, such as borrows of constants.
8181
/// Each of them is the Mir of a constant with the fn's type parameters
@@ -129,8 +129,8 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
129129
impl<'tcx> Mir<'tcx> {
130130
pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
131131
visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
132-
visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope,
133-
VisibilityScopeInfo>>,
132+
visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope,
133+
VisibilityScopeInfo>>,
134134
promoted: IndexVec<Promoted, Mir<'tcx>>,
135135
yield_ty: Option<Ty<'tcx>>,
136136
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
@@ -283,15 +283,15 @@ impl<'tcx> Mir<'tcx> {
283283
}
284284
}
285285

286-
#[derive(Clone, Debug)]
286+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
287287
pub struct VisibilityScopeInfo {
288288
/// A NodeId with lint levels equivalent to this scope's lint levels.
289289
pub lint_root: ast::NodeId,
290290
/// The unsafe block that contains this node.
291291
pub safety: Safety,
292292
}
293293

294-
#[derive(Copy, Clone, Debug)]
294+
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
295295
pub enum Safety {
296296
Safe,
297297
/// Unsafe because of a PushUnsafeBlock
@@ -335,22 +335,13 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
335335
}
336336

337337
#[derive(Clone, Debug)]
338-
pub enum ClearOnDecode<T> {
338+
pub enum ClearCrossCrate<T> {
339339
Clear,
340340
Set(T)
341341
}
342342

343-
impl<T> serialize::Encodable for ClearOnDecode<T> {
344-
fn encode<S: serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
345-
serialize::Encodable::encode(&(), s)
346-
}
347-
}
348-
349-
impl<T> serialize::Decodable for ClearOnDecode<T> {
350-
fn decode<D: serialize::Decoder>(d: &mut D) -> Result<Self, D::Error> {
351-
serialize::Decodable::decode(d).map(|()| ClearOnDecode::Clear)
352-
}
353-
}
343+
impl<T: serialize::Encodable> serialize::UseSpecializedEncodable for ClearCrossCrate<T> {}
344+
impl<T: serialize::Decodable> serialize::UseSpecializedDecodable for ClearCrossCrate<T> {}
354345

355346
/// Grouped information about the source code origin of a MIR entity.
356347
/// Intended to be inspected by diagnostics and debuginfo.

src/librustc/ty/maps/on_disk_cache.rs

+45
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId,
1515
RESERVED_FOR_INCR_COMP_CACHE, LOCAL_CRATE};
1616
use hir::map::definitions::DefPathHash;
1717
use middle::cstore::CrateStore;
18+
use mir;
1819
use rustc_data_structures::fx::FxHashMap;
1920
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2021
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque,
@@ -36,6 +37,9 @@ use ty::context::TyCtxt;
3637
const PREV_DIAGNOSTICS_TAG: u64 = 0x1234_5678_A1A1_A1A1;
3738
const QUERY_RESULT_INDEX_TAG: u64 = 0x1234_5678_C3C3_C3C3;
3839

40+
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
41+
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
42+
3943
/// `OnDiskCache` provides an interface to incr. comp. data cached from the
4044
/// previous compilation session. This data will eventually include the results
4145
/// of a few selected queries (like `typeck_tables_of` and `mir_optimized`) and
@@ -518,12 +522,32 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<hir::HirId> for CacheDecoder<'a, 'tcx, 'x>
518522
// NodeIds are not stable across compilation sessions, so we store them in their
519523
// HirId representation. This allows use to map them to the current NodeId.
520524
impl<'a, 'tcx, 'x> SpecializedDecoder<NodeId> for CacheDecoder<'a, 'tcx, 'x> {
525+
#[inline]
521526
fn specialized_decode(&mut self) -> Result<NodeId, Self::Error> {
522527
let hir_id = hir::HirId::decode(self)?;
523528
Ok(self.tcx().hir.hir_to_node_id(hir_id))
524529
}
525530
}
526531

532+
impl<'a, 'tcx, 'x, T: Decodable> SpecializedDecoder<mir::ClearCrossCrate<T>>
533+
for CacheDecoder<'a, 'tcx, 'x> {
534+
#[inline]
535+
fn specialized_decode(&mut self) -> Result<mir::ClearCrossCrate<T>, Self::Error> {
536+
let discr = u8::decode(self)?;
537+
538+
match discr {
539+
TAG_CLEAR_CROSS_CRATE_CLEAR => Ok(mir::ClearCrossCrate::Clear),
540+
TAG_CLEAR_CROSS_CRATE_SET => {
541+
let val = T::decode(self)?;
542+
Ok(mir::ClearCrossCrate::Set(val))
543+
}
544+
_ => {
545+
unreachable!()
546+
}
547+
}
548+
}
549+
}
550+
527551
//- ENCODING -------------------------------------------------------------------
528552

529553
struct CacheEncoder<'enc, 'a, 'tcx, E>
@@ -658,6 +682,27 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'enc, 'a, 't
658682
}
659683
}
660684

685+
impl<'enc, 'a, 'tcx, E, T> SpecializedEncoder<mir::ClearCrossCrate<T>>
686+
for CacheEncoder<'enc, 'a, 'tcx, E>
687+
where E: 'enc + ty_codec::TyEncoder,
688+
T: Encodable,
689+
{
690+
#[inline]
691+
fn specialized_encode(&mut self,
692+
val: &mir::ClearCrossCrate<T>)
693+
-> Result<(), Self::Error> {
694+
match *val {
695+
mir::ClearCrossCrate::Clear => {
696+
TAG_CLEAR_CROSS_CRATE_CLEAR.encode(self)
697+
}
698+
mir::ClearCrossCrate::Set(ref val) => {
699+
TAG_CLEAR_CROSS_CRATE_SET.encode(self)?;
700+
val.encode(self)
701+
}
702+
}
703+
}
704+
}
705+
661706
macro_rules! encoder_methods {
662707
($($name:ident($ty:ty);)*) => {
663708
$(fn $name(&mut self, value: $ty) -> Result<(), Self::Error> {

src/librustc_metadata/decoder.rs

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc::hir::def::{self, Def, CtorKind};
2121
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
2222
use rustc::ich::Fingerprint;
2323
use rustc::middle::lang_items;
24+
use rustc::mir;
2425
use rustc::session::Session;
2526
use rustc::ty::{self, Ty, TyCtxt};
2627
use rustc::ty::codec::TyDecoder;
@@ -327,6 +328,14 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
327328
}
328329
}
329330

331+
impl<'a, 'tcx, T: Decodable> SpecializedDecoder<mir::ClearCrossCrate<T>>
332+
for DecodeContext<'a, 'tcx> {
333+
#[inline]
334+
fn specialized_decode(&mut self) -> Result<mir::ClearCrossCrate<T>, Self::Error> {
335+
Ok(mir::ClearCrossCrate::Clear)
336+
}
337+
}
338+
330339
implement_ty_decoder!( DecodeContext<'a, 'tcx> );
331340

332341
impl<'a, 'tcx> MetadataBlob {

src/librustc_metadata/encoder.rs

+9
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ impl<'a, 'tcx> SpecializedEncoder<ty::GenericPredicates<'tcx>> for EncodeContext
157157
}
158158
}
159159

160+
impl<'a, 'tcx, T: Encodable> SpecializedEncoder<mir::ClearCrossCrate<T>>
161+
for EncodeContext<'a, 'tcx> {
162+
fn specialized_encode(&mut self,
163+
_: &mir::ClearCrossCrate<T>)
164+
-> Result<(), Self::Error> {
165+
Ok(())
166+
}
167+
}
168+
160169
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
161170
fn position(&self) -> usize {
162171
self.opaque.position()

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
543543

544544
Mir::new(self.cfg.basic_blocks,
545545
self.visibility_scopes,
546-
ClearOnDecode::Set(self.visibility_scope_info),
546+
ClearCrossCrate::Set(self.visibility_scope_info),
547547
IndexVec::new(),
548548
yield_ty,
549549
self.local_decls,

src/librustc_mir/shim.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
198198
IndexVec::from_elem_n(
199199
VisibilityScopeData { span: span, parent_scope: None }, 1
200200
),
201-
ClearOnDecode::Clear,
201+
ClearCrossCrate::Clear,
202202
IndexVec::new(),
203203
None,
204204
local_decls_for_sig(&sig, span),
@@ -345,7 +345,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
345345
IndexVec::from_elem_n(
346346
VisibilityScopeData { span: self.span, parent_scope: None }, 1
347347
),
348-
ClearOnDecode::Clear,
348+
ClearCrossCrate::Clear,
349349
IndexVec::new(),
350350
None,
351351
self.local_decls,
@@ -807,7 +807,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
807807
IndexVec::from_elem_n(
808808
VisibilityScopeData { span: span, parent_scope: None }, 1
809809
),
810-
ClearOnDecode::Clear,
810+
ClearCrossCrate::Clear,
811811
IndexVec::new(),
812812
None,
813813
local_decls,
@@ -885,7 +885,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
885885
IndexVec::from_elem_n(
886886
VisibilityScopeData { span: span, parent_scope: None }, 1
887887
),
888-
ClearOnDecode::Clear,
888+
ClearCrossCrate::Clear,
889889
IndexVec::new(),
890890
None,
891891
local_decls,

src/librustc_mir/transform/check_unsafety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
320320
let mir = &tcx.mir_built(def_id).borrow();
321321

322322
let visibility_scope_info = match mir.visibility_scope_info {
323-
ClearOnDecode::Set(ref data) => data,
324-
ClearOnDecode::Clear => {
323+
ClearCrossCrate::Set(ref data) => data,
324+
ClearCrossCrate::Clear => {
325325
debug!("unsafety_violations: {:?} - remote, skipping", def_id);
326326
return UnsafetyCheckResult {
327327
violations: Rc::new([]),

0 commit comments

Comments
 (0)