rustc: move some maps from ty to hir.

This commit is contained in:
Eduard Burtescu 2016-03-29 13:14:01 +03:00
parent ffca6c3e15
commit 20f0f3c1f1
7 changed files with 43 additions and 40 deletions

View File

@ -33,6 +33,10 @@
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};
@ -1625,3 +1629,24 @@ pub fn descriptive_variant(&self) -> &str {
}
}
}
/// 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>>;

View File

@ -27,7 +27,7 @@
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::*;

View File

@ -33,7 +33,7 @@
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};
@ -44,7 +44,6 @@
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};
@ -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)]
@ -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(&[]),

View File

@ -410,20 +410,20 @@ fn tr(&self, dcx: &DecodeContext) -> 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)
}
@ -433,9 +433,9 @@ fn read_capture_mode(&mut self) -> hir::CaptureClause {
}
}
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),
}

View File

@ -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();

View File

@ -56,8 +56,8 @@
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};
@ -1186,7 +1186,7 @@ fn new(session: &'a Session,
emit_errors: true,
make_glob_map: make_glob_map == MakeGlobMap::Yes,
glob_map: HashMap::new(),
glob_map: NodeMap(),
callback: None,
resolved: false,
@ -1253,7 +1253,7 @@ fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>
return;
}
let mut new_set = HashSet::new();
let mut new_set = FnvHashSet();
new_set.insert(name);
self.glob_map.insert(import_id, new_set);
}

View File

@ -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
@ -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,