Skip to content

Commit

Permalink
rustc: move some maps from ty to hir.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 6, 2016
1 parent ffca6c3 commit 20f0f3c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 40 deletions.
25 changes: 25 additions & 0 deletions src/librustc/hir/mod.rs
Expand Up @@ -33,6 +33,10 @@ pub use self::ViewPath_::*;
pub use self::Visibility::*;
pub use self::PathParameters::*;

use hir::def::Def;
use hir::def_id::DefId;
use util::nodemap::{NodeMap, FnvHashSet};

use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
use syntax::abi::Abi;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
Expand Down Expand Up @@ -1625,3 +1629,24 @@ impl ForeignItem_ {
}
}
}

/// A free variable referred to in a function.
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct Freevar {
/// The variable being accessed free.
pub def: Def,

// First span where it is accessed (there can be multiple).
pub span: Span
}

pub type FreevarMap = NodeMap<Vec<Freevar>>;

pub type CaptureModeMap = NodeMap<CaptureClause>;

// Trait method resolution
pub type TraitMap = NodeMap<Vec<DefId>>;

// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = NodeMap<FnvHashSet<Name>>;
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -27,7 +27,7 @@ use traits;
use ty::{self, TraitRef, Ty, TypeAndMut};
use ty::{TyS, TypeVariants};
use ty::{AdtDef, ClosureSubsts, ExistentialBounds, Region};
use ty::{FreevarMap};
use hir::FreevarMap;
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, TraitTy};
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
use ty::TypeVariants::*;
Expand Down
28 changes: 3 additions & 25 deletions src/librustc/ty/mod.rs
Expand Up @@ -33,7 +33,7 @@ use ty::fold::TypeFolder;
use ty::subst::{Subst, Substs, VecPerParamSpace};
use ty::walk::TypeWalker;
use util::common::MemoizationMap;
use util::nodemap::{NodeMap, NodeSet};
use util::nodemap::NodeSet;
use util::nodemap::FnvHashMap;

use serialize::{Encodable, Encoder, Decodable, Decoder};
Expand All @@ -44,7 +44,6 @@ use std::iter;
use std::rc::Rc;
use std::slice;
use std::vec::IntoIter;
use std::collections::{HashMap, HashSet};
use syntax::ast::{self, CrateNum, Name, NodeId};
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{DUMMY_SP, Span};
Expand Down Expand Up @@ -115,7 +114,7 @@ pub struct CrateAnalysis<'a> {
pub access_levels: middle::privacy::AccessLevels,
pub reachable: NodeSet,
pub name: &'a str,
pub glob_map: Option<GlobMap>,
pub glob_map: Option<hir::GlobMap>,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -2724,30 +2723,9 @@ pub enum ExplicitSelfCategory {
ByBox,
}

/// A free variable referred to in a function.
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct Freevar {
/// The variable being accessed free.
pub def: Def,

// First span where it is accessed (there can be multiple).
pub span: Span
}

pub type FreevarMap = NodeMap<Vec<Freevar>>;

pub type CaptureModeMap = NodeMap<hir::CaptureClause>;

// Trait method resolution
pub type TraitMap = NodeMap<Vec<DefId>>;

// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = HashMap<NodeId, HashSet<Name>>;

impl<'tcx> TyCtxt<'tcx> {
pub fn with_freevars<T, F>(&self, fid: NodeId, f: F) -> T where
F: FnOnce(&[Freevar]) -> T,
F: FnOnce(&[hir::Freevar]) -> T,
{
match self.freevars.borrow().get(&fid) {
None => f(&[]),
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/astencode.rs
Expand Up @@ -410,20 +410,20 @@ impl tr for Def {
// ______________________________________________________________________
// Encoding and decoding of freevar information

fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &ty::Freevar) {
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &hir::Freevar) {
(*fv).encode(rbml_w).unwrap();
}

trait rbml_decoder_helper {
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
-> ty::Freevar;
-> hir::Freevar;
fn read_capture_mode(&mut self) -> hir::CaptureClause;
}

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

Expand All @@ -433,9 +433,9 @@ impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
}
}

impl tr for ty::Freevar {
fn tr(&self, dcx: &DecodeContext) -> ty::Freevar {
ty::Freevar {
impl tr for hir::Freevar {
fn tr(&self, dcx: &DecodeContext) -> hir::Freevar {
hir::Freevar {
def: self.def.tr(dcx),
span: self.span.tr(dcx),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -958,7 +958,7 @@ fn overloaded_lvalue<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,

fn capture_freevar<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
closure_expr: &'tcx hir::Expr,
freevar: &ty::Freevar,
freevar: &hir::Freevar,
freevar_ty: Ty<'tcx>)
-> ExprRef<'tcx> {
let id_var = freevar.def.var_id();
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/lib.rs
Expand Up @@ -56,8 +56,8 @@ use rustc::hir::def::*;
use rustc::hir::def_id::DefId;
use rustc::hir::pat_util::pat_bindings;
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace};
use rustc::ty::{Freevar, FreevarMap, TraitMap, GlobMap};
use rustc::util::nodemap::{NodeMap, FnvHashMap};
use rustc::hir::{Freevar, FreevarMap, TraitMap, GlobMap};
use rustc::util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};

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

emit_errors: true,
make_glob_map: make_glob_map == MakeGlobMap::Yes,
glob_map: HashMap::new(),
glob_map: NodeMap(),

callback: None,
resolved: false,
Expand Down Expand Up @@ -1253,7 +1253,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return;
}

let mut new_set = HashSet::new();
let mut new_set = FnvHashSet();
new_set.insert(name);
self.glob_map.insert(import_id, new_set);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/lib.rs
Expand Up @@ -136,7 +136,7 @@ pub struct TypeAndSubsts<'tcx> {

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

pub fn check_crate(tcx: &TyCtxt, trait_map: ty::TraitMap) -> CompileResult {
pub fn check_crate(tcx: &TyCtxt, trait_map: hir::TraitMap) -> CompileResult {
let time_passes = tcx.sess.time_passes();
let ccx = CrateCtxt {
trait_map: trait_map,
Expand Down

0 comments on commit 20f0f3c

Please sign in to comment.