use util::common::time;
use util::ppaux::Repr;
use util::ppaux;
-use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
+use util::nodemap::{DefIdMap, FnvHashMap};
use std::cell::RefCell;
use std::rc::Rc;
-use std::vec_ng::Vec;
use collections::List;
use syntax::codemap::Span;
use syntax::print::pprust::*;
substs: ty::substs
}
-#[deriving(Clone, Eq, Hash)]
+#[deriving(Clone, Eq, TotalEq, Hash, Show)]
pub struct MethodCall {
expr_id: ast::NodeId,
autoderef: u32
}
impl Repr for vtable_origin {
- fn repr(&self, tcx: ty::ctxt) -> ~str {
+ fn repr(&self, tcx: &ty::ctxt) -> ~str {
match *self {
vtable_static(def_id, ref tys, ref vtable_res) => {
format!("vtable_static({:?}:{}, {}, {})",
}
}
-pub type vtable_map = @RefCell<NodeMap<vtable_res>>;
+pub type vtable_map = @RefCell<FnvHashMap<MethodCall, vtable_res>>;
// Information about the vtable resolutions for a trait impl.
}
impl Repr for impl_res {
- fn repr(&self, tcx: ty::ctxt) -> ~str {
+ fn repr(&self, tcx: &ty::ctxt) -> ~str {
format!("impl_res \\{trait_vtables={}, self_vtables={}\\}",
self.trait_vtables.repr(tcx),
self.self_vtables.repr(tcx))
pub type impl_vtable_map = RefCell<DefIdMap<impl_res>>;
-pub struct CrateCtxt {
+pub struct CrateCtxt<'a> {
// A mapping from method call sites to traits that have that method.
trait_map: resolve::TraitMap,
method_map: MethodMap,
vtable_map: vtable_map,
- tcx: ty::ctxt
+ tcx: &'a ty::ctxt
}
// Functions that write types into the node type table
-pub fn write_ty_to_tcx(tcx: ty::ctxt, node_id: ast::NodeId, ty: ty::t) {
+pub fn write_ty_to_tcx(tcx: &ty::ctxt, node_id: ast::NodeId, ty: ty::t) {
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_str(tcx, ty));
assert!(!ty::type_needs_infer(ty));
- let mut node_types = tcx.node_types.borrow_mut();
- node_types.get().insert(node_id as uint, ty);
+ tcx.node_types.borrow_mut().insert(node_id as uint, ty);
}
-pub fn write_substs_to_tcx(tcx: ty::ctxt,
+pub fn write_substs_to_tcx(tcx: &ty::ctxt,
node_id: ast::NodeId,
substs: Vec<ty::t> ) {
if substs.len() > 0u {
substs.map(|t| ppaux::ty_to_str(tcx, *t)));
assert!(substs.iter().all(|t| !ty::type_needs_infer(*t)));
- let mut node_type_substs = tcx.node_type_substs.borrow_mut();
- node_type_substs.get().insert(node_id, substs);
+ tcx.node_type_substs.borrow_mut().insert(node_id, substs);
}
}
-pub fn write_tpt_to_tcx(tcx: ty::ctxt,
+pub fn write_tpt_to_tcx(tcx: &ty::ctxt,
node_id: ast::NodeId,
tpt: &ty::ty_param_substs_and_ty) {
write_ty_to_tcx(tcx, node_id, tpt.ty);
}
}
-pub fn lookup_def_tcx(tcx: ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def {
- let def_map = tcx.def_map.borrow();
- match def_map.get().find(&id) {
+pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def {
+ match tcx.def_map.borrow().find(&id) {
Some(&x) => x,
_ => {
tcx.sess.span_fatal(sp, "internal error looking up a definition")
}
}
-pub fn require_same_types(tcx: ty::ctxt,
+pub fn require_same_types(tcx: &ty::ctxt,
maybe_infcx: Option<&infer::InferCtxt>,
t1_is_expected: bool,
span: Span,
}
}
-pub fn check_crate(tcx: ty::ctxt,
+pub fn check_crate(tcx: &ty::ctxt,
trait_map: resolve::TraitMap,
krate: &ast::Crate)
-> (MethodMap, vtable_map) {
let time_passes = tcx.sess.time_passes();
- let ccx = @CrateCtxt {
+ let ccx = CrateCtxt {
trait_map: trait_map,
method_map: @RefCell::new(FnvHashMap::new()),
- vtable_map: @RefCell::new(NodeMap::new()),
+ vtable_map: @RefCell::new(FnvHashMap::new()),
tcx: tcx
};
time(time_passes, "type collecting", (), |_|
- collect::collect_item_types(ccx, krate));
+ collect::collect_item_types(&ccx, krate));
// this ensures that later parts of type checking can assume that items
// have valid types and not error
variance::infer_variance(tcx, krate));
time(time_passes, "coherence checking", (), |_|
- coherence::check_coherence(ccx, krate));
+ coherence::check_coherence(&ccx, krate));
time(time_passes, "type checking", (), |_|
- check::check_item_types(ccx, krate));
+ check::check_item_types(&ccx, krate));
- check_for_entry_fn(ccx);
+ check_for_entry_fn(&ccx);
tcx.sess.abort_if_errors();
(ccx.method_map, ccx.vtable_map)
}