Skip to content

Commit 894152f

Browse files
committed
Change two maps over to DepTrackingMaps
1 parent f3d8be1 commit 894152f

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/librustc/middle/ty/context.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use middle::ty::{FreevarMap, GenericPredicates};
3434
use middle::ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, TraitTy};
3535
use middle::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
3636
use middle::ty::TypeVariants::*;
37+
use middle::ty::maps;
3738
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
3839
use util::nodemap::FnvHashMap;
3940

@@ -248,7 +249,7 @@ pub struct ctxt<'tcx> {
248249
pub tables: RefCell<Tables<'tcx>>,
249250

250251
/// Maps from a trait item to the trait item "descriptor"
251-
pub impl_or_trait_items: RefCell<DefIdMap<ty::ImplOrTraitItem<'tcx>>>,
252+
pub impl_or_trait_items: RefCell<DepTrackingMap<maps::ImplOrTraitItems<'tcx>>>,
252253

253254
/// Maps from a trait def-id to a list of the def-ids of its trait items
254255
pub trait_item_def_ids: RefCell<DefIdMap<Rc<Vec<ty::ImplOrTraitItemId>>>>,
@@ -274,7 +275,7 @@ pub struct ctxt<'tcx> {
274275

275276
pub map: ast_map::Map<'tcx>,
276277
pub freevars: RefCell<FreevarMap>,
277-
pub tcache: RefCell<DefIdMap<ty::TypeScheme<'tcx>>>,
278+
pub tcache: RefCell<DepTrackingMap<maps::Tcache<'tcx>>>,
278279
pub rcache: RefCell<FnvHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
279280
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, ty::contents::TypeContents>>,
280281
pub ast_ty_to_ty_cache: RefCell<NodeMap<Ty<'tcx>>>,
@@ -512,11 +513,11 @@ impl<'tcx> ctxt<'tcx> {
512513
fulfilled_predicates: RefCell::new(traits::FulfilledPredicates::new()),
513514
map: map,
514515
freevars: RefCell::new(freevars),
515-
tcache: RefCell::new(DefIdMap()),
516+
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
516517
rcache: RefCell::new(FnvHashMap()),
517518
tc_cache: RefCell::new(FnvHashMap()),
518519
ast_ty_to_ty_cache: RefCell::new(NodeMap()),
519-
impl_or_trait_items: RefCell::new(DefIdMap()),
520+
impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
520521
trait_item_def_ids: RefCell::new(DefIdMap()),
521522
trait_items_cache: RefCell::new(DefIdMap()),
522523
ty_param_defs: RefCell::new(NodeMap()),

src/librustc/middle/ty/maps.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use dep_graph::{DepNode, DepTrackingMapId};
12+
use middle::def_id::DefId;
13+
use middle::ty;
14+
use std::marker::PhantomData;
15+
16+
macro_rules! dep_map_ty {
17+
($name:ident : ($key:ty) -> $value:ty) => {
18+
pub struct $name<'tcx> {
19+
data: PhantomData<&'tcx ()>
20+
}
21+
22+
impl<'tcx> DepTrackingMapId for $name<'tcx> {
23+
type Key = $key;
24+
type Value = $value;
25+
fn to_dep_node(key: &$key) -> DepNode { DepNode::$name(*key) }
26+
}
27+
}
28+
}
29+
30+
dep_map_ty! { ImplOrTraitItems: (DefId) -> ty::ImplOrTraitItem<'tcx> }
31+
dep_map_ty! { Tcache: (DefId) -> ty::TypeScheme<'tcx> }

src/librustc/middle/ty/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub mod error;
8484
pub mod fast_reject;
8585
pub mod fold;
8686
pub mod _match;
87+
pub mod maps;
8788
pub mod outlives;
8889
pub mod relate;
8990
pub mod walk;
@@ -1365,6 +1366,10 @@ pub struct TraitDef<'tcx> {
13651366
}
13661367

13671368
impl<'tcx> TraitDef<'tcx> {
1369+
pub fn def_id(&self) -> DefId {
1370+
self.trait_ref.def_id
1371+
}
1372+
13681373
// returns None if not yet calculated
13691374
pub fn object_safety(&self) -> Option<bool> {
13701375
if self.flags.get().intersects(TraitFlags::OBJECT_SAFETY_VALID) {

0 commit comments

Comments
 (0)