Skip to content

Commit

Permalink
Auto merge of rust-lang#50102 - Zoxc:query-nomacro, r=michaelwoerister
Browse files Browse the repository at this point in the history
Move query code outside macros and store query jobs separately from query results

Based on rust-lang#50067

r? @michaelwoerister
  • Loading branch information
bors committed Apr 27, 2018
2 parents 71d3dac + f678bf0 commit 3c43aa5
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 509 deletions.
31 changes: 26 additions & 5 deletions src/librustc/ty/maps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,45 @@
// except according to those terms.

use dep_graph::SerializedDepNodeIndex;
use dep_graph::DepNode;
use hir::def_id::{CrateNum, DefId, DefIndex};
use mir::interpret::{GlobalId};
use traits::query::{CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal};
use ty::{self, ParamEnvAnd, Ty, TyCtxt};
use ty::subst::Substs;
use ty::maps::queries;
use ty::maps::Query;
use ty::maps::QueryMap;

use std::hash::Hash;
use std::fmt::Debug;
use syntax_pos::symbol::InternedString;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::stable_hasher::HashStable;
use ich::StableHashingContext;

/// Query configuration and description traits.

pub trait QueryConfig {
type Key: Eq + Hash + Clone;
type Value;
pub trait QueryConfig<'tcx> {
const NAME: &'static str;

type Key: Eq + Hash + Clone + Debug;
type Value: Clone + for<'a> HashStable<StableHashingContext<'a>>;

fn query(key: Self::Key) -> Query<'tcx>;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_map<'a>(tcx: TyCtxt<'a, 'tcx, '_>) -> &'a Lock<QueryMap<'tcx, Self>>;

fn to_dep_node(tcx: TyCtxt<'_, 'tcx, '_>, key: &Self::Key) -> DepNode;

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value;

fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value;
}

pub(super) trait QueryDescription<'tcx>: QueryConfig {
pub trait QueryDescription<'tcx>: QueryConfig<'tcx> {
fn describe(tcx: TyCtxt, key: Self::Key) -> String;

#[inline]
Expand All @@ -41,7 +62,7 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig {
}
}

impl<'tcx, M: QueryConfig<Key=DefId>> QueryDescription<'tcx> for M {
impl<'tcx, M: QueryConfig<'tcx, Key=DefId>> QueryDescription<'tcx> for M {
default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
if !tcx.sess.verbose() {
format!("processing `{}`", tcx.item_path_str(def_id))
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/ty/maps/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ use ty::context::TyCtxt;
use errors::Diagnostic;

/// Indicates the state of a query for a given key in a query map
pub(super) enum QueryResult<'tcx, T> {
pub(super) enum QueryResult<'tcx> {
/// An already executing query. The query job can be used to await for its completion
Started(Lrc<QueryJob<'tcx>>),

/// The query is complete and produced `T`
Complete(T),

/// The query panicked. Queries trying to wait on this will raise a fatal error / silently panic
Poisoned,
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use dep_graph::{DepConstructor, DepNode};
use errors::DiagnosticBuilder;
use hir::def_id::{CrateNum, DefId, DefIndex};
use hir::def::{Def, Export};
use hir::{self, TraitCandidate, ItemLocalId, TransFnAttrs};
Expand Down Expand Up @@ -43,7 +42,7 @@ use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
use ty::steal::Steal;
use ty::subst::Substs;
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
use util::common::{profq_msg, ErrorReported, ProfileQueriesMsg};
use util::common::{ErrorReported};

use rustc_data_structures::indexed_set::IdxSetBuf;
use rustc_target::spec::PanicStrategy;
Expand All @@ -68,7 +67,6 @@ pub use self::plumbing::force_from_dep_node;

mod job;
pub use self::job::{QueryJob, QueryInfo};
use self::job::QueryResult;

mod keys;
pub use self::keys::Key;
Expand Down
21 changes: 8 additions & 13 deletions src/librustc/ty/maps/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use syntax::codemap::{CodeMap, StableFilemapId};
use syntax_pos::{BytePos, Span, DUMMY_SP, FileMap};
use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo};
use ty;
use ty::maps::job::QueryResult;
use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
use ty::context::TyCtxt;
use util::common::time;
Expand Down Expand Up @@ -239,14 +238,12 @@ impl<'sess> OnDiskCache<'sess> {
encode_query_results::<specialization_graph_of, _>(tcx, enc, qri)?;

// const eval is special, it only encodes successfully evaluated constants
use ty::maps::plumbing::GetCacheInternal;
for (key, entry) in const_eval::get_cache_internal(tcx).map.iter() {
use ty::maps::QueryConfig;
let map = const_eval::query_map(tcx).borrow();
assert!(map.active.is_empty());
for (key, entry) in map.results.iter() {
use ty::maps::config::QueryDescription;
if const_eval::cache_on_disk(key.clone()) {
let entry = match *entry {
QueryResult::Complete(ref v) => v,
_ => panic!("incomplete query"),
};
if let Ok(ref value) = entry.value {
let dep_node = SerializedDepNodeIndex::new(entry.index.index());

Expand Down Expand Up @@ -1124,7 +1121,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
encoder: &mut CacheEncoder<'enc, 'a, 'tcx, E>,
query_result_index: &mut EncodedQueryResultIndex)
-> Result<(), E::Error>
where Q: super::plumbing::GetCacheInternal<'tcx>,
where Q: super::config::QueryDescription<'tcx>,
E: 'enc + TyEncoder,
Q::Value: Encodable,
{
Expand All @@ -1133,12 +1130,10 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

time(tcx.sess, desc, || {

for (key, entry) in Q::get_cache_internal(tcx).map.iter() {
let map = Q::query_map(tcx).borrow();
assert!(map.active.is_empty());
for (key, entry) in map.results.iter() {
if Q::cache_on_disk(key.clone()) {
let entry = match *entry {
QueryResult::Complete(ref v) => v,
_ => panic!("incomplete query"),
};
let dep_node = SerializedDepNodeIndex::new(entry.index.index());

// Record position of the cache entry
Expand Down
Loading

0 comments on commit 3c43aa5

Please sign in to comment.