Only store the result of mir_borrowck for closures

This commit is contained in:
John Kåre Alsaker 2019-01-26 15:58:39 +01:00
parent 219f818c1b
commit 9bdf054dc8
4 changed files with 31 additions and 28 deletions

View file

@ -51,7 +51,7 @@ pub(super) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
fn describe(tcx: TyCtxt<'_, '_, '_>, key: Self::Key) -> Cow<'static, str>; fn describe(tcx: TyCtxt<'_, '_, '_>, key: Self::Key) -> Cow<'static, str>;
#[inline] #[inline]
fn cache_on_disk(_: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
false false
} }
@ -387,7 +387,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> {
} }
#[inline] #[inline]
fn cache_on_disk(_key: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _key: Self::Key) -> bool {
true true
} }
@ -407,7 +407,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> {
} }
#[inline] #[inline]
fn cache_on_disk(_key: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _key: Self::Key) -> bool {
true true
} }
@ -431,7 +431,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
} }
#[inline] #[inline]
fn cache_on_disk(_: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
true true
} }
@ -505,7 +505,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_sta
} }
#[inline] #[inline]
fn cache_on_disk(_: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
true true
} }
@ -539,7 +539,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::codegen_fulfill_obligation<'tcx>
} }
#[inline] #[inline]
fn cache_on_disk(_: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
true true
} }
@ -877,7 +877,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::features_query<'tcx> {
impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
#[inline] #[inline]
fn cache_on_disk(def_id: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
def_id.is_local() def_id.is_local()
} }
@ -894,7 +894,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
#[inline] #[inline]
fn cache_on_disk(def_id: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
def_id.is_local() def_id.is_local()
} }
@ -933,7 +933,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> {
#[inline] #[inline]
fn cache_on_disk(def_id: Self::Key) -> bool { fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
def_id.is_local() def_id.is_local()
} }
@ -983,10 +983,10 @@ impl<'tcx> QueryDescription<'tcx> for queries::backend_optimization_level<'tcx>
} }
macro_rules! impl_disk_cacheable_query( macro_rules! impl_disk_cacheable_query(
($query_name:ident, |$key:tt| $cond:expr) => { ($query_name:ident, |$tcx:tt, $key:tt| $cond:expr) => {
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
#[inline] #[inline]
fn cache_on_disk($key: Self::Key) -> bool { fn cache_on_disk($tcx: TyCtxt<'_, 'tcx, 'tcx>, $key: Self::Key) -> bool {
$cond $cond
} }
@ -1000,14 +1000,17 @@ macro_rules! impl_disk_cacheable_query(
} }
); );
impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local()); impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local()); def_id.is_local() && tcx.is_closure(def_id)
impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local()); });
impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local()); impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(def_symbol_name, |_| true); impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local()); impl_disk_cacheable_query!(mir_const_qualif, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local()); impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local()); impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
impl_disk_cacheable_query!(codegen_fn_attrs, |_| true); impl_disk_cacheable_query!(type_of, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(specialization_graph_of, |_| true); impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true);
impl_disk_cacheable_query!(specialization_graph_of, |_, _| true);

View file

@ -230,7 +230,7 @@ impl<'sess> OnDiskCache<'sess> {
assert!(cache.active.is_empty()); assert!(cache.active.is_empty());
for (key, entry) in cache.results.iter() { for (key, entry) in cache.results.iter() {
use ty::query::config::QueryDescription; use ty::query::config::QueryDescription;
if const_eval::cache_on_disk(key.clone()) { if const_eval::cache_on_disk(tcx, key.clone()) {
if let Ok(ref value) = entry.value { if let Ok(ref value) = entry.value {
let dep_node = SerializedDepNodeIndex::new(entry.index.index()); let dep_node = SerializedDepNodeIndex::new(entry.index.index());
@ -1086,7 +1086,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let map = Q::query_cache(tcx).borrow(); let map = Q::query_cache(tcx).borrow();
assert!(map.active.is_empty()); assert!(map.active.is_empty());
for (key, entry) in map.results.iter() { for (key, entry) in map.results.iter() {
if Q::cache_on_disk(key.clone()) { if Q::cache_on_disk(tcx, key.clone()) {
let dep_node = SerializedDepNodeIndex::new(entry.index.index()); let dep_node = SerializedDepNodeIndex::new(entry.index.index());
// Record position of the cache entry // Record position of the cache entry

View file

@ -434,7 +434,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
debug_assert!(self.dep_graph.is_green(dep_node)); debug_assert!(self.dep_graph.is_green(dep_node));
// First we try to load the result from the on-disk cache // First we try to load the result from the on-disk cache
let result = if Q::cache_on_disk(key.clone()) && let result = if Q::cache_on_disk(self.global_tcx(), key.clone()) &&
self.sess.opts.debugging_opts.incremental_queries { self.sess.opts.debugging_opts.incremental_queries {
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index); let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index);
@ -1443,7 +1443,7 @@ macro_rules! impl_load_from_cache {
match self.kind { match self.kind {
$(DepKind::$dep_kind => { $(DepKind::$dep_kind => {
let def_id = self.extract_def_id(tcx).unwrap(); let def_id = self.extract_def_id(tcx).unwrap();
queries::$query_name::cache_on_disk(def_id) queries::$query_name::cache_on_disk(tcx.global_tcx(), def_id)
})* })*
_ => false _ => false
} }

View file

@ -228,10 +228,10 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> { fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> {
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal. // execute before we can steal.
let _ = tcx.mir_borrowck(def_id); tcx.ensure().mir_borrowck(def_id);
if tcx.use_ast_borrowck() { if tcx.use_ast_borrowck() {
let _ = tcx.borrowck(def_id); tcx.ensure().borrowck(def_id);
} }
let mut mir = tcx.mir_validated(def_id).steal(); let mut mir = tcx.mir_validated(def_id).steal();