Skip to content

Commit e00bec2

Browse files
Allow 'tcx in define_dep_nodes! and deduplicate some DepNodes.
1 parent 9808661 commit e00bec2

File tree

4 files changed

+58
-72
lines changed

4 files changed

+58
-72
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ use hir::def_id::{CrateNum, DefId};
6464
use hir::map::DefPathHash;
6565

6666
use ich::Fingerprint;
67-
use ty::TyCtxt;
67+
use ty::fast_reject::SimplifiedType;
68+
use ty::{TyCtxt, Instance, InstanceDef};
6869
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
6970
use ich::StableHashingContext;
7071
use std::fmt;
@@ -78,7 +79,8 @@ macro_rules! erase {
7879
}
7980

8081
macro_rules! define_dep_nodes {
81-
($(
82+
(<$tcx:tt>
83+
$(
8284
$variant:ident $(( $($tuple_arg:tt),* ))*
8385
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
8486
,)*
@@ -92,7 +94,7 @@ macro_rules! define_dep_nodes {
9294
impl DepKind {
9395
#[allow(unreachable_code)]
9496
#[inline]
95-
pub fn can_reconstruct_query_key(&self) -> bool {
97+
pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
9698
match *self {
9799
$(
98100
DepKind :: $variant => {
@@ -139,7 +141,7 @@ macro_rules! define_dep_nodes {
139141
}
140142
}
141143

142-
pub enum DepConstructor {
144+
pub enum DepConstructor<$tcx> {
143145
$(
144146
$variant $(( $($tuple_arg),* ))*
145147
$({ $($struct_arg_name : $struct_arg_ty),* })*
@@ -155,7 +157,7 @@ macro_rules! define_dep_nodes {
155157

156158
impl DepNode {
157159
#[allow(unreachable_code, non_snake_case)]
158-
pub fn new(tcx: TyCtxt, dep: DepConstructor) -> DepNode {
160+
pub fn new<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(tcx: TyCtxt<'a, 'gcx, 'tcx>, dep: DepConstructor<'gcx>) -> DepNode {
159161
match dep {
160162
$(
161163
DepConstructor :: $variant $(( $($tuple_arg),* ))*
@@ -336,7 +338,7 @@ impl DefId {
336338
}
337339
}
338340

339-
define_dep_nodes!(
341+
define_dep_nodes!( <'tcx>
340342
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
341343
// distinct from the krate module). This is basically a hash of
342344
// the entire krate, so if you read from `Krate` (e.g., by calling
@@ -374,8 +376,11 @@ define_dep_nodes!(
374376

375377
// Represents the MIR for a fn; also used as the task node for
376378
// things read/modify that MIR.
377-
Mir(DefId),
378-
MirShim(DefIdList),
379+
MirConstQualif(DefId),
380+
MirConst(DefId),
381+
MirValidated(DefId),
382+
MirOptimized(DefId),
383+
MirShim { instance_def: InstanceDef<'tcx> },
379384

380385
BorrowCheckKrate,
381386
BorrowCheck(DefId),
@@ -414,8 +419,10 @@ define_dep_nodes!(
414419
InherentImpls(DefId),
415420
TypeckBodiesKrate,
416421
TypeckTables(DefId),
422+
HasTypeckTables(DefId),
417423
ConstEval(DefId),
418424
SymbolName(DefId),
425+
InstanceSymbolName { instance: Instance<'tcx> },
419426
SpecializationGraph(DefId),
420427
ObjectSafety(DefId),
421428
IsCopy(DefId),
@@ -424,14 +431,9 @@ define_dep_nodes!(
424431
NeedsDrop(DefId),
425432
Layout(DefId),
426433

427-
// The set of impls for a given trait. Ultimately, it would be
428-
// nice to get more fine-grained here (e.g., to include a
429-
// simplified type), but we can't do that until we restructure the
430-
// HIR to distinguish the *header* of an impl from its body. This
431-
// is because changes to the header may change the self-type of
432-
// the impl and hence would require us to be more conservative
433-
// than changes in the impl body.
434+
// The set of impls for a given trait.
434435
TraitImpls(DefId),
436+
RelevantTraitImpls(DefId, SimplifiedType),
435437

436438
AllLocalTraitImpls,
437439

src/librustc/ty/instance.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use dep_graph::DepConstructor;
1211
use hir::def_id::DefId;
1312
use ty::{self, Ty, TypeFoldable, Substs};
1413
use util::ppaux;
@@ -59,27 +58,6 @@ impl<'tcx> InstanceDef<'tcx> {
5958
pub fn attrs<'a>(&self, tcx: ty::TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
6059
tcx.get_attrs(self.def_id())
6160
}
62-
63-
pub //(crate)
64-
fn dep_node(&self) -> DepConstructor {
65-
// HACK: def-id binning, project-style; someone replace this with
66-
// real on-demand.
67-
let ty = match self {
68-
&InstanceDef::FnPtrShim(_, ty) => Some(ty),
69-
&InstanceDef::DropGlue(_, ty) => ty,
70-
_ => None
71-
}.into_iter();
72-
73-
DepConstructor::MirShim(
74-
Some(self.def_id()).into_iter().chain(
75-
ty.flat_map(|t| t.walk()).flat_map(|t| match t.sty {
76-
ty::TyAdt(adt_def, _) => Some(adt_def.did),
77-
ty::TyProjection(ref proj) => Some(proj.trait_ref.def_id),
78-
_ => None,
79-
})
80-
).collect()
81-
)
82-
}
8361
}
8462

8563
impl<'tcx> fmt::Display for Instance<'tcx> {

src/librustc/ty/maps.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use dep_graph::{DepConstructor, DepNode, DepTrackingMapConfig};
11+
use dep_graph::{DepConstructor, DepNode};
1212
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1313
use hir::def::Def;
1414
use hir;
@@ -261,11 +261,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
261261
}
262262
}
263263

264-
trait QueryDescription: DepTrackingMapConfig {
264+
pub trait QueryConfig {
265+
type Key: Eq + Hash + Clone;
266+
type Value;
267+
}
268+
269+
trait QueryDescription: QueryConfig {
265270
fn describe(tcx: TyCtxt, key: Self::Key) -> String;
266271
}
267272

268-
impl<M: DepTrackingMapConfig<Key=DefId>> QueryDescription for M {
273+
impl<M: QueryConfig<Key=DefId>> QueryDescription for M {
269274
default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
270275
format!("processing `{}`", tcx.item_path_str(def_id))
271276
}
@@ -550,18 +555,19 @@ macro_rules! define_maps {
550555
})*
551556
}
552557

553-
$(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
558+
$(impl<$tcx> QueryConfig for queries::$name<$tcx> {
554559
type Key = $K;
555560
type Value = $V;
561+
}
556562

563+
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
557564
#[allow(unused)]
558-
fn to_dep_node(tcx: TyCtxt, key: &$K) -> DepNode {
565+
fn to_dep_node(tcx: TyCtxt<'a, $tcx, 'lcx>, key: &$K) -> DepNode {
559566
use dep_graph::DepConstructor::*;
560567

561568
DepNode::new(tcx, $node(*key))
562569
}
563-
}
564-
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
570+
565571
fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
566572
mut span: Span,
567573
key: $K,
@@ -861,19 +867,19 @@ define_maps! { <'tcx>
861867
/// Maps DefId's that have an associated Mir to the result
862868
/// of the MIR qualify_consts pass. The actual meaning of
863869
/// the value isn't known except to the pass itself.
864-
[] mir_const_qualif: Mir(DefId) -> u8,
870+
[] mir_const_qualif: MirConstQualif(DefId) -> u8,
865871

866872
/// Fetch the MIR for a given def-id up till the point where it is
867873
/// ready for const evaluation.
868874
///
869875
/// See the README for the `mir` module for details.
870-
[] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
876+
[] mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
871877

872-
[] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
878+
[] mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
873879

874880
/// MIR after our optimization passes have run. This is MIR that is ready
875881
/// for trans. This is also the only query that can fetch non-local MIR, at present.
876-
[] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
882+
[] optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
877883

878884
/// Type of each closure. The def ID is the ID of the
879885
/// expression defining the closure.
@@ -890,7 +896,7 @@ define_maps! { <'tcx>
890896

891897
[] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
892898

893-
[] has_typeck_tables: TypeckTables(DefId) -> bool,
899+
[] has_typeck_tables: HasTypeckTables(DefId) -> bool,
894900

895901
[] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
896902

@@ -972,80 +978,80 @@ define_maps! { <'tcx>
972978
[] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
973979
}
974980

975-
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {
981+
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
976982
DepConstructor::TypeParamPredicates {
977983
item_id,
978984
param_id
979985
}
980986
}
981987

982-
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepConstructor {
988+
fn coherent_trait_dep_node<'tcx>((_, def_id): (CrateNum, DefId)) -> DepConstructor<'tcx> {
983989
DepConstructor::CoherenceCheckTrait(def_id)
984990
}
985991

986-
fn crate_inherent_impls_dep_node(_: CrateNum) -> DepConstructor {
992+
fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
987993
DepConstructor::Coherence
988994
}
989995

990-
fn reachability_dep_node(_: CrateNum) -> DepConstructor {
996+
fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
991997
DepConstructor::Reachability
992998
}
993999

994-
fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepConstructor {
995-
instance.dep_node()
1000+
fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
1001+
DepConstructor::MirShim {
1002+
instance_def
1003+
}
9961004
}
9971005

998-
fn symbol_name_dep_node(instance: ty::Instance) -> DepConstructor {
999-
// symbol_name uses the substs only to traverse them to find the
1000-
// hash, and that does not create any new dep-nodes.
1001-
DepConstructor::SymbolName(instance.def.def_id())
1006+
fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
1007+
DepConstructor::InstanceSymbolName { instance }
10021008
}
10031009

1004-
fn typeck_item_bodies_dep_node(_: CrateNum) -> DepConstructor {
1010+
fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10051011
DepConstructor::TypeckBodiesKrate
10061012
}
10071013

1008-
fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepConstructor {
1014+
fn const_eval_dep_node<'tcx>((def_id, _): (DefId, &Substs)) -> DepConstructor<'tcx> {
10091015
DepConstructor::ConstEval(def_id)
10101016
}
10111017

1012-
fn mir_keys(_: CrateNum) -> DepConstructor {
1018+
fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10131019
DepConstructor::MirKeys
10141020
}
10151021

1016-
fn crate_variances(_: CrateNum) -> DepConstructor {
1022+
fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10171023
DepConstructor::CrateVariances
10181024
}
10191025

1020-
fn relevant_trait_impls_for((def_id, _): (DefId, SimplifiedType)) -> DepConstructor {
1021-
DepConstructor::TraitImpls(def_id)
1026+
fn relevant_trait_impls_for<'tcx>((def_id, t): (DefId, SimplifiedType)) -> DepConstructor<'tcx> {
1027+
DepConstructor::RelevantTraitImpls(def_id, t)
10221028
}
10231029

1024-
fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1030+
fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
10251031
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
10261032
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
10271033
DepConstructor::IsCopy(def_id)
10281034
}
10291035

1030-
fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1036+
fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
10311037
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
10321038
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
10331039
DepConstructor::IsSized(def_id)
10341040
}
10351041

1036-
fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1042+
fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
10371043
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
10381044
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
10391045
DepConstructor::IsFreeze(def_id)
10401046
}
10411047

1042-
fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1048+
fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
10431049
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
10441050
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
10451051
DepConstructor::NeedsDrop(def_id)
10461052
}
10471053

1048-
fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
1054+
fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
10491055
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
10501056
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
10511057
DepConstructor::Layout(def_id)

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use cstore;
1212
use encoder;
1313
use schema;
1414

15-
use rustc::dep_graph::DepTrackingMapConfig;
15+
use rustc::ty::maps::QueryConfig;
1616
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
1717
NativeLibrary, MetadataLoader, LinkMeta,
1818
LinkagePreference, LoadedMacro, EncodedMetadata};
@@ -45,7 +45,7 @@ macro_rules! provide {
4545
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
4646
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
4747
-> <ty::queries::$name<$lt> as
48-
DepTrackingMapConfig>::Value {
48+
QueryConfig>::Value {
4949
assert!(!$def_id.is_local());
5050

5151
let def_path_hash = $tcx.def_path_hash($def_id);

0 commit comments

Comments
 (0)