mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
rustc: move some maps from ty to hir.
This commit is contained in:
parent
ffca6c3e15
commit
20f0f3c1f1
@ -33,6 +33,10 @@ pub use self::ViewPath_::*;
|
|||||||
pub use self::Visibility::*;
|
pub use self::Visibility::*;
|
||||||
pub use self::PathParameters::*;
|
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::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
|
||||||
use syntax::abi::Abi;
|
use syntax::abi::Abi;
|
||||||
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
|
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
|
||||||
@ -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>>;
|
||||||
|
@ -27,7 +27,7 @@ use traits;
|
|||||||
use ty::{self, TraitRef, Ty, TypeAndMut};
|
use ty::{self, TraitRef, Ty, TypeAndMut};
|
||||||
use ty::{TyS, TypeVariants};
|
use ty::{TyS, TypeVariants};
|
||||||
use ty::{AdtDef, ClosureSubsts, ExistentialBounds, Region};
|
use ty::{AdtDef, ClosureSubsts, ExistentialBounds, Region};
|
||||||
use ty::{FreevarMap};
|
use hir::FreevarMap;
|
||||||
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, TraitTy};
|
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, TraitTy};
|
||||||
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
|
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
|
||||||
use ty::TypeVariants::*;
|
use ty::TypeVariants::*;
|
||||||
|
@ -33,7 +33,7 @@ use ty::fold::TypeFolder;
|
|||||||
use ty::subst::{Subst, Substs, VecPerParamSpace};
|
use ty::subst::{Subst, Substs, VecPerParamSpace};
|
||||||
use ty::walk::TypeWalker;
|
use ty::walk::TypeWalker;
|
||||||
use util::common::MemoizationMap;
|
use util::common::MemoizationMap;
|
||||||
use util::nodemap::{NodeMap, NodeSet};
|
use util::nodemap::NodeSet;
|
||||||
use util::nodemap::FnvHashMap;
|
use util::nodemap::FnvHashMap;
|
||||||
|
|
||||||
use serialize::{Encodable, Encoder, Decodable, Decoder};
|
use serialize::{Encodable, Encoder, Decodable, Decoder};
|
||||||
@ -44,7 +44,6 @@ use std::iter;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use syntax::ast::{self, CrateNum, Name, NodeId};
|
use syntax::ast::{self, CrateNum, Name, NodeId};
|
||||||
use syntax::attr::{self, AttrMetaMethods};
|
use syntax::attr::{self, AttrMetaMethods};
|
||||||
use syntax::codemap::{DUMMY_SP, Span};
|
use syntax::codemap::{DUMMY_SP, Span};
|
||||||
@ -115,7 +114,7 @@ pub struct CrateAnalysis<'a> {
|
|||||||
pub access_levels: middle::privacy::AccessLevels,
|
pub access_levels: middle::privacy::AccessLevels,
|
||||||
pub reachable: NodeSet,
|
pub reachable: NodeSet,
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
pub glob_map: Option<GlobMap>,
|
pub glob_map: Option<hir::GlobMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -2724,30 +2723,9 @@ pub enum ExplicitSelfCategory {
|
|||||||
ByBox,
|
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> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn with_freevars<T, F>(&self, fid: NodeId, f: F) -> T where
|
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) {
|
match self.freevars.borrow().get(&fid) {
|
||||||
None => f(&[]),
|
None => f(&[]),
|
||||||
|
@ -410,20 +410,20 @@ impl tr for Def {
|
|||||||
// ______________________________________________________________________
|
// ______________________________________________________________________
|
||||||
// Encoding and decoding of freevar information
|
// 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();
|
(*fv).encode(rbml_w).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
trait rbml_decoder_helper {
|
trait rbml_decoder_helper {
|
||||||
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
|
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
|
||||||
-> ty::Freevar;
|
-> hir::Freevar;
|
||||||
fn read_capture_mode(&mut self) -> hir::CaptureClause;
|
fn read_capture_mode(&mut self) -> hir::CaptureClause;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
|
impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
|
||||||
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
|
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
|
||||||
-> ty::Freevar {
|
-> hir::Freevar {
|
||||||
let fv: ty::Freevar = Decodable::decode(self).unwrap();
|
let fv: hir::Freevar = Decodable::decode(self).unwrap();
|
||||||
fv.tr(dcx)
|
fv.tr(dcx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,9 +433,9 @@ impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl tr for ty::Freevar {
|
impl tr for hir::Freevar {
|
||||||
fn tr(&self, dcx: &DecodeContext) -> ty::Freevar {
|
fn tr(&self, dcx: &DecodeContext) -> hir::Freevar {
|
||||||
ty::Freevar {
|
hir::Freevar {
|
||||||
def: self.def.tr(dcx),
|
def: self.def.tr(dcx),
|
||||||
span: self.span.tr(dcx),
|
span: self.span.tr(dcx),
|
||||||
}
|
}
|
||||||
|
@ -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>,
|
fn capture_freevar<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
|
||||||
closure_expr: &'tcx hir::Expr,
|
closure_expr: &'tcx hir::Expr,
|
||||||
freevar: &ty::Freevar,
|
freevar: &hir::Freevar,
|
||||||
freevar_ty: Ty<'tcx>)
|
freevar_ty: Ty<'tcx>)
|
||||||
-> ExprRef<'tcx> {
|
-> ExprRef<'tcx> {
|
||||||
let id_var = freevar.def.var_id();
|
let id_var = freevar.def.var_id();
|
||||||
|
@ -56,8 +56,8 @@ use rustc::hir::def::*;
|
|||||||
use rustc::hir::def_id::DefId;
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::hir::pat_util::pat_bindings;
|
use rustc::hir::pat_util::pat_bindings;
|
||||||
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace};
|
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace};
|
||||||
use rustc::ty::{Freevar, FreevarMap, TraitMap, GlobMap};
|
use rustc::hir::{Freevar, FreevarMap, TraitMap, GlobMap};
|
||||||
use rustc::util::nodemap::{NodeMap, FnvHashMap};
|
use rustc::util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
|
||||||
|
|
||||||
use syntax::ast::{self, FloatTy};
|
use syntax::ast::{self, FloatTy};
|
||||||
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
|
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
|
||||||
@ -1186,7 +1186,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
|
|
||||||
emit_errors: true,
|
emit_errors: true,
|
||||||
make_glob_map: make_glob_map == MakeGlobMap::Yes,
|
make_glob_map: make_glob_map == MakeGlobMap::Yes,
|
||||||
glob_map: HashMap::new(),
|
glob_map: NodeMap(),
|
||||||
|
|
||||||
callback: None,
|
callback: None,
|
||||||
resolved: false,
|
resolved: false,
|
||||||
@ -1253,7 +1253,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut new_set = HashSet::new();
|
let mut new_set = FnvHashSet();
|
||||||
new_set.insert(name);
|
new_set.insert(name);
|
||||||
self.glob_map.insert(import_id, new_set);
|
self.glob_map.insert(import_id, new_set);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ pub struct TypeAndSubsts<'tcx> {
|
|||||||
|
|
||||||
pub struct CrateCtxt<'a, 'tcx: 'a> {
|
pub struct CrateCtxt<'a, 'tcx: 'a> {
|
||||||
// A mapping from method call sites to traits that have that method.
|
// 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
|
/// A vector of every trait accessible in the whole crate
|
||||||
/// (i.e. including those from subcrates). This is used only for
|
/// (i.e. including those from subcrates). This is used only for
|
||||||
/// error reporting, and so is lazily initialised and generally
|
/// 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 time_passes = tcx.sess.time_passes();
|
||||||
let ccx = CrateCtxt {
|
let ccx = CrateCtxt {
|
||||||
trait_map: trait_map,
|
trait_map: trait_map,
|
||||||
|
Loading…
Reference in New Issue
Block a user