Skip to content

Commit 8d4da4f

Browse files
committed
Auto merge of #46881 - michaelwoerister:ensure-coherence, r=nikomatsakis
incr.comp.: Cache check_match and use ensure() for coherence-related queries. Some minor optimizations. r? @nikomatsakis
2 parents 1699293 + 44a0522 commit 8d4da4f

File tree

8 files changed

+62
-16
lines changed

8 files changed

+62
-16
lines changed

src/librustc/ty/maps/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
102102
}
103103

104104
impl<'tcx> QueryDescription<'tcx> for queries::coherent_trait<'tcx> {
105-
fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
105+
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
106106
format!("coherence checking all impls of trait `{}`",
107107
tcx.item_path_str(def_id))
108108
}
@@ -647,5 +647,6 @@ impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local());
647647
impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local());
648648
impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local());
649649
impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
650+
impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local());
650651
impl_disk_cacheable_query!(contains_extern_indicator, |_| true);
651652
impl_disk_cacheable_query!(def_symbol_name, |_| true);

src/librustc/ty/maps/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ define_maps! { <'tcx>
187187

188188
[] fn has_typeck_tables: HasTypeckTables(DefId) -> bool,
189189

190-
[] fn coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
190+
[] fn coherent_trait: CoherenceCheckTrait(DefId) -> (),
191191

192192
[] fn borrowck: BorrowCheck(DefId) -> Rc<BorrowCheckResult>,
193193

@@ -385,10 +385,6 @@ fn fulfill_obligation_dep_node<'tcx>((param_env, trait_ref):
385385
}
386386
}
387387

388-
fn coherent_trait_dep_node<'tcx>((_, def_id): (CrateNum, DefId)) -> DepConstructor<'tcx> {
389-
DepConstructor::CoherenceCheckTrait(def_id)
390-
}
391-
392388
fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
393389
DepConstructor::Coherence
394390
}

src/librustc/ty/maps/on_disk_cache.rs

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ impl<'sess> OnDiskCache<'sess> {
217217
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
218218
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
219219
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
220+
encode_query_results::<check_match, _>(tcx, enc, qri)?;
220221
}
221222

222223
// Encode diagnostics

src/librustc/ty/maps/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -978,4 +978,5 @@ impl_load_from_cache!(
978978
SymbolName => def_symbol_name,
979979
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
980980
ContainsExternIndicator => contains_extern_indicator,
981+
CheckMatch => check_match,
981982
);

src/librustc/ty/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! misc. type-system utilities too small to deserve their own file
1212
1313
use hir::def::Def;
14-
use hir::def_id::{DefId, LOCAL_CRATE};
14+
use hir::def_id::DefId;
1515
use hir::map::{DefPathData, Node};
1616
use hir;
1717
use ich::NodeIdHashingMode;
@@ -427,7 +427,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
427427
return None;
428428
};
429429

430-
self.coherent_trait((LOCAL_CRATE, drop_trait));
430+
ty::maps::queries::coherent_trait::ensure(self, drop_trait);
431431

432432
let mut dtor_did = None;
433433
let ty = self.type_of(adt_did);

src/librustc/util/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const FN_OUTPUT_NAME: &'static str = "Output";
2929

3030
// Useful type to use with `Result<>` indicate that an error has already
3131
// been reported to the user, so no need to continue checking.
32-
#[derive(Clone, Copy, Debug)]
32+
#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable)]
3333
pub struct ErrorReported;
3434

3535
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));

src/librustc_typeck/coherence/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// done by the orphan and overlap modules. Then we build up various
1616
// mappings. That mapping code resides here.
1717

18-
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
19-
use rustc::ty::{TyCtxt, TypeFoldable};
18+
use hir::def_id::{DefId, LOCAL_CRATE};
19+
use rustc::ty::{self, TyCtxt, TypeFoldable};
2020
use rustc::ty::maps::Providers;
2121

2222
use syntax::ast;
@@ -113,8 +113,7 @@ pub fn provide(providers: &mut Providers) {
113113
};
114114
}
115115

116-
fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
117-
(_, def_id): (CrateNum, DefId)) {
116+
fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
118117
let impls = tcx.hir.trait_impls(def_id);
119118
for &impl_id in impls {
120119
check_impl(tcx, impl_id);
@@ -127,14 +126,14 @@ fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
127126

128127
pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
129128
for &trait_def_id in tcx.hir.krate().trait_impls.keys() {
130-
tcx.coherent_trait((LOCAL_CRATE, trait_def_id));
129+
ty::maps::queries::coherent_trait::ensure(tcx, trait_def_id);
131130
}
132131

133132
unsafety::check(tcx);
134133
orphan::check(tcx);
135134
overlap::check_auto_impls(tcx);
136135

137136
// these queries are executed for side-effects (error reporting):
138-
tcx.crate_inherent_impls(LOCAL_CRATE);
139-
tcx.crate_inherent_impls_overlap_check(LOCAL_CRATE);
137+
ty::maps::queries::crate_inherent_impls::ensure(tcx, LOCAL_CRATE);
138+
ty::maps::queries::crate_inherent_impls_overlap_check::ensure(tcx, LOCAL_CRATE);
140139
}

src/libserialize/serialize.rs

+48
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,54 @@ impl<T:Decodable> Decodable for Option<T> {
618618
}
619619
}
620620

621+
impl<T1: Encodable, T2: Encodable> Encodable for Result<T1, T2> {
622+
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
623+
s.emit_enum("Result", |s| {
624+
match *self {
625+
Ok(ref v) => {
626+
s.emit_enum_variant("Ok", 0, 1, |s| {
627+
s.emit_enum_variant_arg(0, |s| {
628+
v.encode(s)
629+
})
630+
})
631+
}
632+
Err(ref v) => {
633+
s.emit_enum_variant("Err", 1, 1, |s| {
634+
s.emit_enum_variant_arg(0, |s| {
635+
v.encode(s)
636+
})
637+
})
638+
}
639+
}
640+
})
641+
}
642+
}
643+
644+
impl<T1:Decodable, T2:Decodable> Decodable for Result<T1, T2> {
645+
fn decode<D: Decoder>(d: &mut D) -> Result<Result<T1, T2>, D::Error> {
646+
d.read_enum("Result", |d| {
647+
d.read_enum_variant(&["Ok", "Err"], |d, disr| {
648+
match disr {
649+
0 => {
650+
Ok(Ok(d.read_enum_variant_arg(0, |d| {
651+
T1::decode(d)
652+
})?))
653+
}
654+
1 => {
655+
Ok(Err(d.read_enum_variant_arg(0, |d| {
656+
T2::decode(d)
657+
})?))
658+
}
659+
_ => {
660+
panic!("Encountered invalid discriminant while \
661+
decoding `Result`.");
662+
}
663+
}
664+
})
665+
})
666+
}
667+
}
668+
621669
macro_rules! peel {
622670
($name:ident, $($other:ident,)*) => (tuple! { $($other,)* })
623671
}

0 commit comments

Comments
 (0)