Skip to content

Commit 20f0f3c

Browse files
committed
rustc: move some maps from ty to hir.
1 parent ffca6c3 commit 20f0f3c

File tree

7 files changed

+43
-40
lines changed

7 files changed

+43
-40
lines changed

src/librustc/hir/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub use self::ViewPath_::*;
3333
pub use self::Visibility::*;
3434
pub use self::PathParameters::*;
3535

36+
use hir::def::Def;
37+
use hir::def_id::DefId;
38+
use util::nodemap::{NodeMap, FnvHashSet};
39+
3640
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
3741
use syntax::abi::Abi;
3842
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
@@ -1625,3 +1629,24 @@ impl ForeignItem_ {
16251629
}
16261630
}
16271631
}
1632+
1633+
/// A free variable referred to in a function.
1634+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
1635+
pub struct Freevar {
1636+
/// The variable being accessed free.
1637+
pub def: Def,
1638+
1639+
// First span where it is accessed (there can be multiple).
1640+
pub span: Span
1641+
}
1642+
1643+
pub type FreevarMap = NodeMap<Vec<Freevar>>;
1644+
1645+
pub type CaptureModeMap = NodeMap<CaptureClause>;
1646+
1647+
// Trait method resolution
1648+
pub type TraitMap = NodeMap<Vec<DefId>>;
1649+
1650+
// Map from the NodeId of a glob import to a list of items which are actually
1651+
// imported.
1652+
pub type GlobMap = NodeMap<FnvHashSet<Name>>;

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use traits;
2727
use ty::{self, TraitRef, Ty, TypeAndMut};
2828
use ty::{TyS, TypeVariants};
2929
use ty::{AdtDef, ClosureSubsts, ExistentialBounds, Region};
30-
use ty::{FreevarMap};
30+
use hir::FreevarMap;
3131
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, TraitTy};
3232
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
3333
use ty::TypeVariants::*;

src/librustc/ty/mod.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ty::fold::TypeFolder;
3333
use ty::subst::{Subst, Substs, VecPerParamSpace};
3434
use ty::walk::TypeWalker;
3535
use util::common::MemoizationMap;
36-
use util::nodemap::{NodeMap, NodeSet};
36+
use util::nodemap::NodeSet;
3737
use util::nodemap::FnvHashMap;
3838

3939
use serialize::{Encodable, Encoder, Decodable, Decoder};
@@ -44,7 +44,6 @@ use std::iter;
4444
use std::rc::Rc;
4545
use std::slice;
4646
use std::vec::IntoIter;
47-
use std::collections::{HashMap, HashSet};
4847
use syntax::ast::{self, CrateNum, Name, NodeId};
4948
use syntax::attr::{self, AttrMetaMethods};
5049
use syntax::codemap::{DUMMY_SP, Span};
@@ -115,7 +114,7 @@ pub struct CrateAnalysis<'a> {
115114
pub access_levels: middle::privacy::AccessLevels,
116115
pub reachable: NodeSet,
117116
pub name: &'a str,
118-
pub glob_map: Option<GlobMap>,
117+
pub glob_map: Option<hir::GlobMap>,
119118
}
120119

121120
#[derive(Copy, Clone)]
@@ -2724,30 +2723,9 @@ pub enum ExplicitSelfCategory {
27242723
ByBox,
27252724
}
27262725

2727-
/// A free variable referred to in a function.
2728-
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
2729-
pub struct Freevar {
2730-
/// The variable being accessed free.
2731-
pub def: Def,
2732-
2733-
// First span where it is accessed (there can be multiple).
2734-
pub span: Span
2735-
}
2736-
2737-
pub type FreevarMap = NodeMap<Vec<Freevar>>;
2738-
2739-
pub type CaptureModeMap = NodeMap<hir::CaptureClause>;
2740-
2741-
// Trait method resolution
2742-
pub type TraitMap = NodeMap<Vec<DefId>>;
2743-
2744-
// Map from the NodeId of a glob import to a list of items which are actually
2745-
// imported.
2746-
pub type GlobMap = HashMap<NodeId, HashSet<Name>>;
2747-
27482726
impl<'tcx> TyCtxt<'tcx> {
27492727
pub fn with_freevars<T, F>(&self, fid: NodeId, f: F) -> T where
2750-
F: FnOnce(&[Freevar]) -> T,
2728+
F: FnOnce(&[hir::Freevar]) -> T,
27512729
{
27522730
match self.freevars.borrow().get(&fid) {
27532731
None => f(&[]),

src/librustc_metadata/astencode.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -410,20 +410,20 @@ impl tr for Def {
410410
// ______________________________________________________________________
411411
// Encoding and decoding of freevar information
412412

413-
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &ty::Freevar) {
413+
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &hir::Freevar) {
414414
(*fv).encode(rbml_w).unwrap();
415415
}
416416

417417
trait rbml_decoder_helper {
418418
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
419-
-> ty::Freevar;
419+
-> hir::Freevar;
420420
fn read_capture_mode(&mut self) -> hir::CaptureClause;
421421
}
422422

423423
impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
424424
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
425-
-> ty::Freevar {
426-
let fv: ty::Freevar = Decodable::decode(self).unwrap();
425+
-> hir::Freevar {
426+
let fv: hir::Freevar = Decodable::decode(self).unwrap();
427427
fv.tr(dcx)
428428
}
429429

@@ -433,9 +433,9 @@ impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
433433
}
434434
}
435435

436-
impl tr for ty::Freevar {
437-
fn tr(&self, dcx: &DecodeContext) -> ty::Freevar {
438-
ty::Freevar {
436+
impl tr for hir::Freevar {
437+
fn tr(&self, dcx: &DecodeContext) -> hir::Freevar {
438+
hir::Freevar {
439439
def: self.def.tr(dcx),
440440
span: self.span.tr(dcx),
441441
}

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ fn overloaded_lvalue<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
958958

959959
fn capture_freevar<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
960960
closure_expr: &'tcx hir::Expr,
961-
freevar: &ty::Freevar,
961+
freevar: &hir::Freevar,
962962
freevar_ty: Ty<'tcx>)
963963
-> ExprRef<'tcx> {
964964
let id_var = freevar.def.var_id();

src/librustc_resolve/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ use rustc::hir::def::*;
5656
use rustc::hir::def_id::DefId;
5757
use rustc::hir::pat_util::pat_bindings;
5858
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace};
59-
use rustc::ty::{Freevar, FreevarMap, TraitMap, GlobMap};
60-
use rustc::util::nodemap::{NodeMap, FnvHashMap};
59+
use rustc::hir::{Freevar, FreevarMap, TraitMap, GlobMap};
60+
use rustc::util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
6161

6262
use syntax::ast::{self, FloatTy};
6363
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
@@ -1186,7 +1186,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11861186

11871187
emit_errors: true,
11881188
make_glob_map: make_glob_map == MakeGlobMap::Yes,
1189-
glob_map: HashMap::new(),
1189+
glob_map: NodeMap(),
11901190

11911191
callback: None,
11921192
resolved: false,
@@ -1253,7 +1253,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12531253
return;
12541254
}
12551255

1256-
let mut new_set = HashSet::new();
1256+
let mut new_set = FnvHashSet();
12571257
new_set.insert(name);
12581258
self.glob_map.insert(import_id, new_set);
12591259
}

src/librustc_typeck/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub struct TypeAndSubsts<'tcx> {
136136

137137
pub struct CrateCtxt<'a, 'tcx: 'a> {
138138
// A mapping from method call sites to traits that have that method.
139-
pub trait_map: ty::TraitMap,
139+
pub trait_map: hir::TraitMap,
140140
/// A vector of every trait accessible in the whole crate
141141
/// (i.e. including those from subcrates). This is used only for
142142
/// error reporting, and so is lazily initialised and generally
@@ -329,7 +329,7 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
329329
}
330330
}
331331

332-
pub fn check_crate(tcx: &TyCtxt, trait_map: ty::TraitMap) -> CompileResult {
332+
pub fn check_crate(tcx: &TyCtxt, trait_map: hir::TraitMap) -> CompileResult {
333333
let time_passes = tcx.sess.time_passes();
334334
let ccx = CrateCtxt {
335335
trait_map: trait_map,

0 commit comments

Comments
 (0)