Skip to content

Commit 9bdf054

Browse files
committed
Only store the result of mir_borrowck for closures
1 parent 219f818 commit 9bdf054

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

src/librustc/ty/query/config.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
5151
fn describe(tcx: TyCtxt<'_, '_, '_>, key: Self::Key) -> Cow<'static, str>;
5252

5353
#[inline]
54-
fn cache_on_disk(_: Self::Key) -> bool {
54+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
5555
false
5656
}
5757

@@ -387,7 +387,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> {
387387
}
388388

389389
#[inline]
390-
fn cache_on_disk(_key: Self::Key) -> bool {
390+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _key: Self::Key) -> bool {
391391
true
392392
}
393393

@@ -407,7 +407,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> {
407407
}
408408

409409
#[inline]
410-
fn cache_on_disk(_key: Self::Key) -> bool {
410+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _key: Self::Key) -> bool {
411411
true
412412
}
413413

@@ -431,7 +431,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
431431
}
432432

433433
#[inline]
434-
fn cache_on_disk(_: Self::Key) -> bool {
434+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
435435
true
436436
}
437437

@@ -505,7 +505,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_sta
505505
}
506506

507507
#[inline]
508-
fn cache_on_disk(_: Self::Key) -> bool {
508+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
509509
true
510510
}
511511

@@ -539,7 +539,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::codegen_fulfill_obligation<'tcx>
539539
}
540540

541541
#[inline]
542-
fn cache_on_disk(_: Self::Key) -> bool {
542+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: Self::Key) -> bool {
543543
true
544544
}
545545

@@ -877,7 +877,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::features_query<'tcx> {
877877

878878
impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
879879
#[inline]
880-
fn cache_on_disk(def_id: Self::Key) -> bool {
880+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
881881
def_id.is_local()
882882
}
883883

@@ -894,7 +894,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
894894

895895
impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
896896
#[inline]
897-
fn cache_on_disk(def_id: Self::Key) -> bool {
897+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
898898
def_id.is_local()
899899
}
900900

@@ -933,7 +933,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
933933

934934
impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> {
935935
#[inline]
936-
fn cache_on_disk(def_id: Self::Key) -> bool {
936+
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
937937
def_id.is_local()
938938
}
939939

@@ -983,10 +983,10 @@ impl<'tcx> QueryDescription<'tcx> for queries::backend_optimization_level<'tcx>
983983
}
984984

985985
macro_rules! impl_disk_cacheable_query(
986-
($query_name:ident, |$key:tt| $cond:expr) => {
986+
($query_name:ident, |$tcx:tt, $key:tt| $cond:expr) => {
987987
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
988988
#[inline]
989-
fn cache_on_disk($key: Self::Key) -> bool {
989+
fn cache_on_disk($tcx: TyCtxt<'_, 'tcx, 'tcx>, $key: Self::Key) -> bool {
990990
$cond
991991
}
992992

@@ -1000,14 +1000,17 @@ macro_rules! impl_disk_cacheable_query(
10001000
}
10011001
);
10021002

1003-
impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local());
1004-
impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local());
1005-
impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local());
1006-
impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
1007-
impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local());
1008-
impl_disk_cacheable_query!(def_symbol_name, |_| true);
1009-
impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local());
1010-
impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local());
1011-
impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local());
1012-
impl_disk_cacheable_query!(codegen_fn_attrs, |_| true);
1013-
impl_disk_cacheable_query!(specialization_graph_of, |_| true);
1003+
impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
1004+
def_id.is_local() && tcx.is_closure(def_id)
1005+
});
1006+
1007+
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
1008+
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
1009+
impl_disk_cacheable_query!(mir_const_qualif, |_, def_id| def_id.is_local());
1010+
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
1011+
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
1012+
impl_disk_cacheable_query!(type_of, |_, def_id| def_id.is_local());
1013+
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
1014+
impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local());
1015+
impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true);
1016+
impl_disk_cacheable_query!(specialization_graph_of, |_, _| true);

src/librustc/ty/query/on_disk_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'sess> OnDiskCache<'sess> {
230230
assert!(cache.active.is_empty());
231231
for (key, entry) in cache.results.iter() {
232232
use ty::query::config::QueryDescription;
233-
if const_eval::cache_on_disk(key.clone()) {
233+
if const_eval::cache_on_disk(tcx, key.clone()) {
234234
if let Ok(ref value) = entry.value {
235235
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
236236

@@ -1086,7 +1086,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10861086
let map = Q::query_cache(tcx).borrow();
10871087
assert!(map.active.is_empty());
10881088
for (key, entry) in map.results.iter() {
1089-
if Q::cache_on_disk(key.clone()) {
1089+
if Q::cache_on_disk(tcx, key.clone()) {
10901090
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
10911091

10921092
// Record position of the cache entry

src/librustc/ty/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
434434
debug_assert!(self.dep_graph.is_green(dep_node));
435435

436436
// First we try to load the result from the on-disk cache
437-
let result = if Q::cache_on_disk(key.clone()) &&
437+
let result = if Q::cache_on_disk(self.global_tcx(), key.clone()) &&
438438
self.sess.opts.debugging_opts.incremental_queries {
439439
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index);
440440

@@ -1443,7 +1443,7 @@ macro_rules! impl_load_from_cache {
14431443
match self.kind {
14441444
$(DepKind::$dep_kind => {
14451445
let def_id = self.extract_def_id(tcx).unwrap();
1446-
queries::$query_name::cache_on_disk(def_id)
1446+
queries::$query_name::cache_on_disk(tcx.global_tcx(), def_id)
14471447
})*
14481448
_ => false
14491449
}

src/librustc_mir/transform/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
228228
fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> {
229229
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
230230
// execute before we can steal.
231-
let _ = tcx.mir_borrowck(def_id);
231+
tcx.ensure().mir_borrowck(def_id);
232232

233233
if tcx.use_ast_borrowck() {
234-
let _ = tcx.borrowck(def_id);
234+
tcx.ensure().borrowck(def_id);
235235
}
236236

237237
let mut mir = tcx.mir_validated(def_id).steal();

0 commit comments

Comments
 (0)