diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 14311cf88fd..cf0e7e161c1 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -316,7 +316,7 @@ pub fn phase_3_run_analysis_passes(sess: Session, sess.diagnostic(), krate))); let freevars = time(time_passes, "freevar finding", (), |_| - freevars::annotate_freevars(def_map, krate)); + freevars::annotate_freevars(&def_map, krate)); let region_map = time(time_passes, "region resolution", (), |_| middle::region::resolve_crate(&sess, krate)); diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 799da4150c5..a43c6ac594b 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -23,7 +23,6 @@ use metadata::loader; use metadata::loader::Os; use metadata::loader::CratePaths; -use std::cell::RefCell; use std::rc::Rc; use collections::HashMap; use syntax::ast; @@ -317,7 +316,7 @@ fn resolve_crate<'a>(e: &mut Env, let cnum_map = if should_link { resolve_crate_deps(e, root, metadata.as_slice(), span) } else { - @RefCell::new(HashMap::new()) + HashMap::new() }; // Claim this crate number and cache it if we're linking to the @@ -365,10 +364,7 @@ fn resolve_crate_deps(e: &mut Env, debug!("resolving deps of external crate"); // The map from crate numbers in the crate we're resolving to local crate // numbers - let mut cnum_map = HashMap::new(); - let r = decoder::get_crate_deps(cdata); - for dep in r.iter() { - let extrn_cnum = dep.cnum; + decoder::get_crate_deps(cdata).iter().map(|dep| { debug!("resolving dep crate {} hash: `{}`", dep.crate_id, dep.hash); let (local_cnum, _, _) = resolve_crate(e, root, dep.crate_id.name.as_slice(), @@ -376,9 +372,8 @@ fn resolve_crate_deps(e: &mut Env, Some(&dep.hash), true, span); - cnum_map.insert(extrn_cnum, local_cnum); - } - return @RefCell::new(cnum_map); + (dep.cnum, local_cnum) + }).collect() } pub struct Loader<'a> { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 2d46f92e88f..537f3cf206d 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -30,7 +30,7 @@ use syntax::parse::token::IdentInterner; // local crate numbers (as generated during this session). Each external // crate may refer to types in other external crates, and each has their // own crate numbers. -pub type cnum_map = @RefCell>; +pub type cnum_map = HashMap; pub enum MetadataBlob { MetadataVec(CVec), @@ -155,7 +155,7 @@ impl CStore { ordering: &mut Vec) { if ordering.as_slice().contains(&cnum) { return } let meta = cstore.get_crate_data(cnum); - for (_, &dep) in meta.cnum_map.borrow().iter() { + for (_, &dep) in meta.cnum_map.iter() { visit(cstore, dep, ordering); } ordering.push(cnum); diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index b1cede8e410..a83ef1f5a9f 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1155,7 +1155,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { return ast::DefId { krate: cdata.cnum, node: did.node }; } - match cdata.cnum_map.borrow().find(&did.krate) { + match cdata.cnum_map.find(&did.krate) { Some(&n) => { ast::DefId { krate: n, diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index d42e1d6479b..b167af268a3 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -52,9 +52,6 @@ use syntax::visit; use syntax; use writer = serialize::ebml::writer; -// used by astencode: -pub type abbrev_map = @RefCell>; - /// A borrowed version of ast::InlinedItem. pub enum InlinedItemRef<'a> { IIItemRef(&'a ast::Item), @@ -71,7 +68,7 @@ pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext, pub struct EncodeParams<'a> { pub diag: &'a SpanHandler, pub tcx: &'a ty::ctxt, - pub reexports2: middle::resolve::ExportMap2, + pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, pub non_inlineable_statics: &'a RefCell, pub link_meta: &'a LinkMeta, @@ -99,13 +96,13 @@ pub struct EncodeContext<'a> { pub diag: &'a SpanHandler, pub tcx: &'a ty::ctxt, pub stats: @Stats, - pub reexports2: middle::resolve::ExportMap2, + pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, pub non_inlineable_statics: &'a RefCell, pub link_meta: &'a LinkMeta, pub cstore: &'a cstore::CStore, pub encode_inlined_item: EncodeInlinedItem<'a>, - pub type_abbrevs: abbrev_map, + pub type_abbrevs: tyencode::abbrev_map, } fn encode_name(ebml_w: &mut Encoder, name: Name) { @@ -134,7 +131,7 @@ fn encode_trait_ref(ebml_w: &mut Encoder, diag: ecx.diag, ds: def_to_str, tcx: ecx.tcx, - abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs) + abbrevs: &ecx.type_abbrevs }; ebml_w.start_tag(tag); @@ -170,7 +167,7 @@ fn encode_ty_type_param_defs(ebml_w: &mut Encoder, diag: ecx.diag, ds: def_to_str, tcx: ecx.tcx, - abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs) + abbrevs: &ecx.type_abbrevs }; for param in params.iter() { ebml_w.start_tag(tag); @@ -227,7 +224,7 @@ pub fn write_type(ecx: &EncodeContext, diag: ecx.diag, ds: def_to_str, tcx: ecx.tcx, - abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs) + abbrevs: &ecx.type_abbrevs }; tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ); } @@ -249,7 +246,7 @@ fn encode_method_fty(ecx: &EncodeContext, diag: ecx.diag, ds: def_to_str, tcx: ecx.tcx, - abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs) + abbrevs: &ecx.type_abbrevs }; tyencode::enc_bare_fn_ty(ebml_w.writer, ty_str_ctxt, typ); @@ -290,7 +287,7 @@ fn encode_parent_item(ebml_w: &mut Encoder, id: DefId) { } fn encode_struct_fields(ebml_w: &mut Encoder, - fields: &Vec, + fields: &[ty::field_ty], origin: DefId) { for f in fields.iter() { if f.name == special_idents::unnamed_field.name { @@ -313,7 +310,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, ebml_w: &mut Encoder, id: NodeId, variants: &[P], - index: @RefCell> >, + index: &mut Vec>, generics: &ast::Generics) { debug!("encode_enum_variant_info(id={:?})", id); @@ -323,7 +320,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, ast::DefId { krate: LOCAL_CRATE, node: id }); for variant in variants.iter() { let def_id = local_def(variant.node.id); - index.borrow_mut().push(entry { + index.push(entry { val: variant.node.id as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -347,11 +344,10 @@ fn encode_enum_variant_info(ecx: &EncodeContext, let fields = ty::lookup_struct_fields(ecx.tcx, def_id); let idx = encode_info_for_struct(ecx, ebml_w, - &fields, + fields.as_slice(), index); - encode_struct_fields(ebml_w, &fields, def_id); - let bkts = create_index(idx); - encode_index(ebml_w, bkts, write_i64); + encode_struct_fields(ebml_w, fields.as_slice(), def_id); + encode_index(ebml_w, idx, write_i64); } } if vi.get(i).disr_val != disr_val { @@ -666,8 +662,8 @@ fn encode_provided_source(ebml_w: &mut Encoder, /* Returns an index of items in this class */ fn encode_info_for_struct(ecx: &EncodeContext, ebml_w: &mut Encoder, - fields: &Vec, - global_index: @RefCell> >) + fields: &[ty::field_ty], + global_index: &mut Vec>) -> Vec> { /* Each class has its own index, since different classes may have fields with the same name */ @@ -680,7 +676,7 @@ fn encode_info_for_struct(ecx: &EncodeContext, let id = field.id.node; index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()}); - global_index.borrow_mut().push(entry { + global_index.push(entry { val: id as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -700,9 +696,9 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext, ebml_w: &mut Encoder, name: ast::Ident, ctor_id: NodeId, - index: @RefCell> >, + index: &mut Vec>, struct_id: NodeId) { - index.borrow_mut().push(entry { + index.push(entry { val: ctor_id as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -825,7 +821,7 @@ fn encode_inherent_implementations(ecx: &EncodeContext, def_id: DefId) { match ecx.tcx.inherent_impls.borrow().find(&def_id) { None => {} - Some(&implementations) => { + Some(implementations) => { for implementation in implementations.borrow().iter() { ebml_w.start_tag(tag_items_data_item_inherent_impl); encode_def_id(ebml_w, implementation.did); @@ -841,7 +837,7 @@ fn encode_extension_implementations(ecx: &EncodeContext, trait_def_id: DefId) { match ecx.tcx.trait_impls.borrow().find(&trait_def_id) { None => {} - Some(&implementations) => { + Some(implementations) => { for implementation in implementations.borrow().iter() { ebml_w.start_tag(tag_items_data_item_extension_impl); encode_def_id(ebml_w, implementation.did); @@ -854,14 +850,14 @@ fn encode_extension_implementations(ecx: &EncodeContext, fn encode_info_for_item(ecx: &EncodeContext, ebml_w: &mut Encoder, item: &Item, - index: @RefCell> >, + index: &mut Vec>, path: PathElems, vis: ast::Visibility) { let tcx = ecx.tcx; fn add_to_index(item: &Item, ebml_w: &Encoder, - index: @RefCell> >) { - index.borrow_mut().push(entry { + index: &mut Vec>) { + index.push(entry { val: item.id as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -988,7 +984,7 @@ fn encode_info_for_item(ecx: &EncodeContext, class itself */ let idx = encode_info_for_struct(ecx, ebml_w, - &fields, + fields.as_slice(), index); /* Index the class*/ @@ -1009,7 +1005,7 @@ fn encode_info_for_item(ecx: &EncodeContext, /* Encode def_ids for each field and method for methods, write all the stuff get_trait_method needs to know*/ - encode_struct_fields(ebml_w, &fields, def_id); + encode_struct_fields(ebml_w, fields.as_slice(), def_id); (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); @@ -1017,8 +1013,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_inherent_implementations(ecx, ebml_w, def_id); /* Each class has its own index -- encode it */ - let bkts = create_index(idx); - encode_index(ebml_w, bkts, write_i64); + encode_index(ebml_w, idx, write_i64); ebml_w.end_tag(); // If this is a tuple-like struct, encode the type of the constructor. @@ -1077,7 +1072,7 @@ fn encode_info_for_item(ecx: &EncodeContext, Some(*ast_methods.get(i)) } else { None }; - index.borrow_mut().push(entry { + index.push(entry { val: m.def_id.node as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -1135,7 +1130,7 @@ fn encode_info_for_item(ecx: &EncodeContext, let method_ty = ty::method(tcx, method_def_id); - index.borrow_mut().push(entry { + index.push(entry { val: method_def_id.node as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -1202,10 +1197,10 @@ fn encode_info_for_item(ecx: &EncodeContext, fn encode_info_for_foreign_item(ecx: &EncodeContext, ebml_w: &mut Encoder, nitem: &ForeignItem, - index: @RefCell> >, + index: &mut Vec>, path: PathElems, abi: abi::Abi) { - index.borrow_mut().push(entry { + index.push(entry { val: nitem.id as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -1244,7 +1239,7 @@ fn my_visit_expr(_e: &Expr) { } fn my_visit_item(i: &Item, ebml_w: &mut Encoder, ecx_ptr: *int, - index: @RefCell> >) { + index: &mut Vec>) { let mut ebml_w = unsafe { ebml_w.unsafe_clone() }; // See above let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; @@ -1256,7 +1251,7 @@ fn my_visit_item(i: &Item, fn my_visit_foreign_item(ni: &ForeignItem, ebml_w: &mut Encoder, ecx_ptr:*int, - index: @RefCell> >) { + index: &mut Vec>) { // See above let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; debug!("writing foreign item {}::{}", @@ -1277,7 +1272,7 @@ fn my_visit_foreign_item(ni: &ForeignItem, struct EncodeVisitor<'a,'b> { ebml_w_for_visit_item: &'a mut Encoder<'b>, ecx_ptr:*int, - index: @RefCell> >, + index: &'a mut Vec>, } impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> { @@ -1305,9 +1300,9 @@ fn encode_info_for_items(ecx: &EncodeContext, ebml_w: &mut Encoder, krate: &Crate) -> Vec> { - let index = @RefCell::new(Vec::new()); + let mut index = Vec::new(); ebml_w.start_tag(tag_items_data); - index.borrow_mut().push(entry { + index.push(entry { val: CRATE_NODE_ID as i64, pos: ebml_w.writer.tell().unwrap(), }); @@ -1321,53 +1316,34 @@ fn encode_info_for_items(ecx: &EncodeContext, // See comment in `encode_side_tables_for_ii` in astencode let ecx_ptr: *int = unsafe { cast::transmute(ecx) }; - { - let mut visitor = EncodeVisitor { - index: index, - ecx_ptr: ecx_ptr, - ebml_w_for_visit_item: &mut *ebml_w, - }; - - visit::walk_crate(&mut visitor, krate, ()); - } + visit::walk_crate(&mut EncodeVisitor { + index: &mut index, + ecx_ptr: ecx_ptr, + ebml_w_for_visit_item: &mut *ebml_w, + }, krate, ()); ebml_w.end_tag(); - return /*bad*/index.borrow().clone(); + index } // Path and definition ID indexing -fn create_index( - index: Vec> ) - -> Vec<@Vec> > { - let mut buckets: Vec<@RefCell> >> = Vec::new(); - for _ in range(0u, 256u) { - buckets.push(@RefCell::new(Vec::new())); - } - for elt in index.iter() { +fn encode_index(ebml_w: &mut Encoder, index: Vec>, + write_fn: |&mut MemWriter, &T|) { + let mut buckets: Vec>> = Vec::from_fn(256, |_| Vec::new()); + for elt in index.move_iter() { let h = hash::hash(&elt.val) as uint; - buckets.get_mut(h % 256).borrow_mut().push((*elt).clone()); + buckets.get_mut(h % 256).push(elt); } - let mut buckets_frozen = Vec::new(); - for bucket in buckets.iter() { - buckets_frozen.push(@/*bad*/bucket.borrow().clone()); - } - return buckets_frozen; -} - -fn encode_index( - ebml_w: &mut Encoder, - buckets: Vec<@Vec> > , - write_fn: |&mut MemWriter, &T|) { ebml_w.start_tag(tag_index); let mut bucket_locs = Vec::new(); ebml_w.start_tag(tag_index_buckets); for bucket in buckets.iter() { bucket_locs.push(ebml_w.writer.tell().unwrap()); ebml_w.start_tag(tag_index_buckets_bucket); - for elt in (**bucket).iter() { + for elt in bucket.iter() { ebml_w.start_tag(tag_index_buckets_bucket_elt); assert!(elt.pos < 0xffff_ffff); { @@ -1614,7 +1590,7 @@ impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> { fn visit_item(&mut self, item: &Item, _: ()) { match item.node { ItemImpl(_, Some(ref trait_ref), _, _) => { - let def_map = self.ecx.tcx.def_map; + let def_map = &self.ecx.tcx.def_map; let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id); let def_id = ast_util::def_id_of_def(trait_def); @@ -1749,19 +1725,17 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) non_inlineable_statics, .. } = parms; - let type_abbrevs = @RefCell::new(HashMap::new()); - let stats = @stats; let ecx = EncodeContext { diag: diag, tcx: tcx, - stats: stats, + stats: @stats, reexports2: reexports2, item_symbols: item_symbols, non_inlineable_statics: non_inlineable_statics, link_meta: link_meta, cstore: cstore, encode_inlined_item: encode_inlined_item, - type_abbrevs: type_abbrevs, + type_abbrevs: RefCell::new(HashMap::new()), }; let mut ebml_w = writer::Encoder(wr); @@ -1815,8 +1789,7 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) ecx.stats.item_bytes.set(ebml_w.writer.tell().unwrap() - i); i = ebml_w.writer.tell().unwrap(); - let items_buckets = create_index(items_index); - encode_index(&mut ebml_w, items_buckets, write_i64); + encode_index(&mut ebml_w, items_index, write_i64); ecx.stats.index_bytes.set(ebml_w.writer.tell().unwrap() - i); ebml_w.end_tag(); @@ -1848,12 +1821,12 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) // Get the encoded string for a type pub fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> ~str { - let cx = &tyencode::ctxt { + let mut wr = MemWriter::new(); + tyencode::enc_ty(&mut wr, &tyencode::ctxt { diag: tcx.sess.diagnostic(), ds: def_to_str, tcx: tcx, - abbrevs: tyencode::ac_no_abbrevs}; - let mut wr = MemWriter::new(); - tyencode::enc_ty(&mut wr, cx, t); + abbrevs: &RefCell::new(HashMap::new()) + }, t); str::from_utf8_owned(wr.get_ref().to_owned()).unwrap() } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 1d7d43f895e..9134afd640d 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -17,7 +17,6 @@ use std::cell::RefCell; use collections::HashMap; use std::io; use std::io::MemWriter; -use std::str; use std::fmt; use middle::ty::param_ty; @@ -39,7 +38,7 @@ pub struct ctxt<'a> { pub ds: fn(DefId) -> ~str, // The type context. pub tcx: &'a ty::ctxt, - pub abbrevs: abbrev_ctxt + pub abbrevs: &'a abbrev_map } // Compact string representation for ty.t values. API ty_str & parse_from_str. @@ -51,61 +50,35 @@ pub struct ty_abbrev { s: ~str } -pub enum abbrev_ctxt { - ac_no_abbrevs, - ac_use_abbrevs(@RefCell>), -} +pub type abbrev_map = RefCell>; fn mywrite(w: &mut MemWriter, fmt: &fmt::Arguments) { fmt::write(&mut *w as &mut io::Writer, fmt); } pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) { - match cx.abbrevs { - ac_no_abbrevs => { - let result_str_opt = cx.tcx.short_names_cache.borrow() - .find(&t) - .map(|result| { - (*result).clone() - }); - let result_str = match result_str_opt { - Some(s) => s, - None => { - let wr = &mut MemWriter::new(); - enc_sty(wr, cx, &ty::get(t).sty); - let s = str::from_utf8(wr.get_ref()).unwrap(); - cx.tcx.short_names_cache.borrow_mut().insert(t, s.to_str()); - s.to_str() - } - }; - w.write(result_str.as_bytes()); - } - ac_use_abbrevs(abbrevs) => { - match abbrevs.borrow_mut().find(&t) { - Some(a) => { w.write(a.s.as_bytes()); return; } - None => {} - } - let pos = w.tell().unwrap(); - enc_sty(w, cx, &ty::get(t).sty); - let end = w.tell().unwrap(); - let len = end - pos; - fn estimate_sz(u: u64) -> u64 { - let mut n = u; - let mut len = 0; - while n != 0 { len += 1; n = n >> 4; } - return len; - } - let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len); - if abbrev_len < len { - // I.e. it's actually an abbreviation. - let s = format!("\\#{:x}:{:x}\\#", pos, len); - let a = ty_abbrev { pos: pos as uint, - len: len as uint, - s: s }; - abbrevs.borrow_mut().insert(t, a); - } - return; - } + match cx.abbrevs.borrow_mut().find(&t) { + Some(a) => { w.write(a.s.as_bytes()); return; } + None => {} + } + let pos = w.tell().unwrap(); + enc_sty(w, cx, &ty::get(t).sty); + let end = w.tell().unwrap(); + let len = end - pos; + fn estimate_sz(u: u64) -> u64 { + let mut n = u; + let mut len = 0; + while n != 0 { len += 1; n = n >> 4; } + return len; + } + let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len); + if abbrev_len < len { + // I.e. it's actually an abbreviation. + cx.abbrevs.borrow_mut().insert(t, ty_abbrev { + pos: pos as uint, + len: len as uint, + s: format!("\\#{:x}:{:x}\\#", pos, len) + }); } } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 44469dacee8..6cee7398877 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -820,7 +820,7 @@ impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> { diag: self.tcx.sess.diagnostic(), ds: e::def_to_str, tcx: self.tcx, - abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs) + abbrevs: &self.type_abbrevs } } } diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index e4178cee144..ef98cdc0cae 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -146,7 +146,7 @@ fn gather_loans_in_local(this: &mut GatherLoanCtxt, None => { // Variable declarations without initializers are considered "moves": let tcx = this.bccx.tcx; - pat_util::pat_bindings(tcx.def_map, local.pat, |_, id, span, _| { + pat_util::pat_bindings(&tcx.def_map, local.pat, |_, id, span, _| { gather_moves::gather_decl(this.bccx, &this.move_data, id, @@ -821,7 +821,7 @@ impl<'a> GatherLoanCtxt<'a> { ast::PatIdent(bm, _, _) if self.pat_is_binding(pat) => { // Each match binding is effectively an assignment. let tcx = self.bccx.tcx; - pat_util::pat_bindings(tcx.def_map, pat, |_, id, span, _| { + pat_util::pat_bindings(&tcx.def_map, pat, |_, id, span, _| { gather_moves::gather_assignment(self.bccx, &self.move_data, id, @@ -919,7 +919,7 @@ impl<'a> GatherLoanCtxt<'a> { } pub fn pat_is_binding(&self, pat: &ast::Pat) -> bool { - pat_util::pat_is_binding(self.bccx.tcx.def_map, pat) + pat_util::pat_is_binding(&self.bccx.tcx.def_map, pat) } pub fn report_potential_errors(&self) { diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 0a040eb4e23..df8d882864e 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -86,7 +86,7 @@ pub fn check_crate(tcx: &ty::ctxt, moves_map: moves_map, moved_variables_set: moved_variables_set, capture_map: capture_map, - root_map: root_map(), + root_map: RefCell::new(HashMap::new()), stats: @BorrowStats { loaned_paths_same: Cell::new(0), loaned_paths_imm: Cell::new(0), @@ -94,28 +94,27 @@ pub fn check_crate(tcx: &ty::ctxt, guaranteed_paths: Cell::new(0), } }; - let bccx = &mut bccx; - visit::walk_crate(bccx, krate, ()); + visit::walk_crate(&mut bccx, krate, ()); if tcx.sess.borrowck_stats() { println!("--- borrowck stats ---"); println!("paths requiring guarantees: {}", bccx.stats.guaranteed_paths.get()); println!("paths requiring loans : {}", - make_stat(bccx, bccx.stats.loaned_paths_same.get())); + make_stat(&bccx, bccx.stats.loaned_paths_same.get())); println!("paths requiring imm loans : {}", - make_stat(bccx, bccx.stats.loaned_paths_imm.get())); + make_stat(&bccx, bccx.stats.loaned_paths_imm.get())); println!("stable paths : {}", - make_stat(bccx, bccx.stats.stable_paths.get())); + make_stat(&bccx, bccx.stats.stable_paths.get())); } - return bccx.root_map; + return bccx.root_map.unwrap(); - fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str { + fn make_stat(bccx: &BorrowckCtxt, stat: uint) -> ~str { let stat_f = stat as f64; let total = bccx.stats.guaranteed_paths.get() as f64; - format!("{} ({:.0f}%)", stat , stat_f * 100.0 / total) + format!("{} ({:.0f}%)", stat, stat_f * 100.0 / total) } } @@ -175,7 +174,7 @@ pub struct BorrowckCtxt<'a> { moves_map: &'a NodeSet, moved_variables_set: &'a NodeSet, capture_map: &'a moves::CaptureMap, - root_map: root_map, + root_map: RefCell, // Statistics: stats: @BorrowStats @@ -375,11 +374,7 @@ pub struct RootInfo { pub scope: ast::NodeId, } -pub type root_map = @RefCell>; - -pub fn root_map() -> root_map { - return @RefCell::new(HashMap::new()); -} +pub type root_map = HashMap; /////////////////////////////////////////////////////////////////////////// // Errors diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 6d6031ed050..eb52aa18de8 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -45,7 +45,7 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item, _is_const: bool) { match it.node { ItemStatic(_, _, ex) => { v.visit_expr(ex, true); - check_item_recursion(&v.tcx.sess, &v.tcx.map, v.tcx.def_map, it); + check_item_recursion(&v.tcx.sess, &v.tcx.map, &v.tcx.def_map, it); } ItemEnum(ref enum_definition, _) => { for var in (*enum_definition).variants.iter() { @@ -178,14 +178,14 @@ struct CheckItemRecursionVisitor<'a> { root_it: &'a Item, sess: &'a Session, ast_map: &'a ast_map::Map, - def_map: resolve::DefMap, + def_map: &'a resolve::DefMap, idstack: Vec } // Make sure a const item doesn't recursively refer to itself // FIXME: Should use the dependency graph when it's available (#1356) pub fn check_item_recursion<'a>(sess: &'a Session, ast_map: &'a ast_map::Map, - def_map: resolve::DefMap, + def_map: &'a resolve::DefMap, it: &'a Item) { let mut visitor = CheckItemRecursionVisitor { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 12d83aa4135..2ef009e36e4 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -934,7 +934,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, has_guard: bool, pats: &[@Pat]) { let tcx = cx.tcx; - let def_map = tcx.def_map; + let def_map = &tcx.def_map; let mut by_ref_span = None; let mut any_by_move = false; for pat in pats.iter() { diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f72555de988..cd3ab100e55 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -127,7 +127,7 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt, None => {} } let maps = astencode::Maps { - root_map: @RefCell::new(HashMap::new()), + root_map: HashMap::new(), capture_map: RefCell::new(NodeMap::new()) }; let e = match csearch::maybe_get_item_ast(tcx, enum_def, @@ -166,7 +166,7 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId) None => {} } let maps = astencode::Maps { - root_map: @RefCell::new(HashMap::new()), + root_map: HashMap::new(), capture_map: RefCell::new(NodeMap::new()) }; let e = match csearch::maybe_get_item_ast(tcx, def_id, diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index e74bef9e95c..94d3cab1ef6 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -339,7 +339,7 @@ impl<'a> DeadVisitor<'a> { let def_id = local_def(id); match self.tcx.inherent_impls.borrow().find(&def_id) { None => (), - Some(ref impl_list) => { + Some(impl_list) => { for impl_ in impl_list.borrow().iter() { for method in impl_.methods.iter() { if self.live_symbols.contains(&method.def_id.node) { diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index d6adb19419b..1f7b6ea733b 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -32,13 +32,13 @@ pub struct freevar_entry { pub type freevar_info = @Vec<@freevar_entry> ; pub type freevar_map = NodeMap; -struct CollectFreevarsVisitor { +struct CollectFreevarsVisitor<'a> { seen: NodeSet, - refs: Vec<@freevar_entry> , - def_map: resolve::DefMap, + refs: Vec<@freevar_entry>, + def_map: &'a resolve::DefMap, } -impl Visitor for CollectFreevarsVisitor { +impl<'a> Visitor for CollectFreevarsVisitor<'a> { fn visit_item(&mut self, _: &ast::Item, _: int) { // ignore_item @@ -87,30 +87,23 @@ impl Visitor for CollectFreevarsVisitor { // Since we want to be able to collect upvars in some arbitrary piece // of the AST, we take a walker function that we invoke with a visitor // in order to start the search. -fn collect_freevars(def_map: resolve::DefMap, blk: &ast::Block) -> freevar_info { - let seen = NodeSet::new(); - let refs = Vec::new(); - +fn collect_freevars(def_map: &resolve::DefMap, blk: &ast::Block) -> freevar_info { let mut v = CollectFreevarsVisitor { - seen: seen, - refs: refs, + seen: NodeSet::new(), + refs: Vec::new(), def_map: def_map, }; v.visit_block(blk, 1); - let CollectFreevarsVisitor { - refs, - .. - } = v; - return @refs; + @v.refs } -struct AnnotateFreevarsVisitor { - def_map: resolve::DefMap, +struct AnnotateFreevarsVisitor<'a> { + def_map: &'a resolve::DefMap, freevars: freevar_map, } -impl Visitor<()> for AnnotateFreevarsVisitor { +impl<'a> Visitor<()> for AnnotateFreevarsVisitor<'a> { fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl, blk: &ast::Block, s: Span, nid: ast::NodeId, _: ()) { let vars = collect_freevars(self.def_map, blk); @@ -124,7 +117,7 @@ impl Visitor<()> for AnnotateFreevarsVisitor { // efficient as it fully recomputes the free variables at every // node of interest rather than building up the free variables in // one pass. This could be improved upon if it turns out to matter. -pub fn annotate_freevars(def_map: resolve::DefMap, krate: &ast::Crate) -> +pub fn annotate_freevars(def_map: &resolve::DefMap, krate: &ast::Crate) -> freevar_map { let mut visitor = AnnotateFreevarsVisitor { def_map: def_map, @@ -132,11 +125,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, krate: &ast::Crate) -> }; visit::walk_crate(&mut visitor, krate, ()); - let AnnotateFreevarsVisitor { - freevars, - .. - } = visitor; - freevars + visitor.freevars } pub fn get_freevars(tcx: &ty::ctxt, fid: ast::NodeId) -> freevar_info { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index d7f879bc40d..a35b862eb9c 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -1337,7 +1337,7 @@ fn check_unsafe_block(cx: &Context, e: &ast::Expr) { fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) { match p.node { ast::PatIdent(ast::BindByValue(ast::MutMutable), - ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> { + ref path, _) if pat_util::pat_is_binding(&cx.tcx.def_map, p) => { // `let mut _a = 1;` doesn't need a warning. let initial_underscore = if path.segments.len() == 1 { token::get_ident(path.segments diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 32d2a8f9c8f..4be9992367d 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -368,7 +368,7 @@ fn visit_fn(ir: &mut IrMaps, } for arg in decl.inputs.iter() { - pat_util::pat_bindings(ir.tcx.def_map, + pat_util::pat_bindings(&ir.tcx.def_map, arg.pat, |_bm, arg_id, _x, path| { debug!("adding argument {}", arg_id); @@ -402,7 +402,7 @@ fn visit_fn(ir: &mut IrMaps, } fn visit_local(ir: &mut IrMaps, local: &Local) { - pat_util::pat_bindings(ir.tcx.def_map, local.pat, |bm, p_id, sp, path| { + pat_util::pat_bindings(&ir.tcx.def_map, local.pat, |bm, p_id, sp, path| { debug!("adding local variable {}", p_id); let name = ast_util::path_to_ident(path); ir.add_live_node_for_node(p_id, VarDefNode(sp)); @@ -426,7 +426,7 @@ fn visit_local(ir: &mut IrMaps, local: &Local) { fn visit_arm(ir: &mut IrMaps, arm: &Arm) { for pat in arm.pats.iter() { - pat_util::pat_bindings(ir.tcx.def_map, *pat, |bm, p_id, sp, path| { + pat_util::pat_bindings(&ir.tcx.def_map, *pat, |bm, p_id, sp, path| { debug!("adding local variable {} from match with bm {:?}", p_id, bm); let name = ast_util::path_to_ident(path); @@ -596,7 +596,7 @@ impl<'a> Liveness<'a> { fn pat_bindings(&mut self, pat: &Pat, f: |&mut Liveness<'a>, LiveNode, Variable, Span, NodeId|) { - pat_util::pat_bindings(self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| { + pat_util::pat_bindings(&self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); let var = self.variable(p_id, sp); f(self, ln, var, sp, p_id); @@ -1524,7 +1524,7 @@ impl<'a> Liveness<'a> { fn warn_about_unused_args(&self, decl: &FnDecl, entry_ln: LiveNode) { for arg in decl.inputs.iter() { - pat_util::pat_bindings(self.ir.tcx.def_map, + pat_util::pat_bindings(&self.ir.tcx.def_map, arg.pat, |_bm, p_id, sp, path| { let var = self.variable(p_id, sp); diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index fc9e3d02ae7..eedcaa89e3c 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -605,7 +605,7 @@ impl<'a> VisitContext<'a> { * into itself or not based on its type and annotation. */ - pat_bindings(self.tcx.def_map, pat, |bm, id, _span, path| { + pat_bindings(&self.tcx.def_map, pat, |bm, id, _span, path| { let binding_moves = match bm { BindByRef(_) => false, BindByValue(_) => { diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 2d50d2e0f77..842d3bae6a7 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -20,7 +20,7 @@ pub type PatIdMap = HashMap; // This is used because same-named variables in alternative patterns need to // use the NodeId of their namesake in the first pattern. -pub fn pat_id_map(dm: resolve::DefMap, pat: &Pat) -> PatIdMap { +pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap { let mut map = HashMap::new(); pat_bindings(dm, pat, |_bm, p_id, _s, n| { map.insert(path_to_ident(n), p_id); @@ -28,7 +28,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: &Pat) -> PatIdMap { map } -pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { match dm.borrow().find(&pat.id) { @@ -40,7 +40,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_const(dm: resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatIdent(_, _, None) | PatEnum(..) => { match dm.borrow().find(&pat.id) { @@ -52,7 +52,7 @@ pub fn pat_is_const(dm: resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_binding(dm: resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatIdent(..) => { !pat_is_variant_or_struct(dm, pat) && @@ -62,7 +62,7 @@ pub fn pat_is_binding(dm: resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatIdent(..) => pat_is_binding(dm, pat), PatWild | PatWildMulti => true, @@ -72,7 +72,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: &Pat) -> bool { /// Call `it` on every "binding" in a pattern, e.g., on `a` in /// `match foo() { Some(a) => (), None => () }` -pub fn pat_bindings(dm: resolve::DefMap, +pub fn pat_bindings(dm: &resolve::DefMap, pat: &Pat, it: |BindingMode, NodeId, Span, &Path|) { walk_pat(pat, |p| { @@ -88,7 +88,7 @@ pub fn pat_bindings(dm: resolve::DefMap, /// Checks if the pattern contains any patterns that bind something to /// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`. -pub fn pat_contains_bindings(dm: resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &Pat) -> bool { let mut contains_bindings = false; walk_pat(pat, |p| { if pat_is_binding(dm, p) { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 5e1f854f6a4..ff90e58d184 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -16,7 +16,7 @@ use metadata::decoder::{DefLike, DlDef, DlField, DlImpl}; use middle::lang_items::LanguageItems; use middle::lint::{UnnecessaryQualification, UnusedImports}; use middle::pat_util::pat_bindings; -use util::nodemap::{NodeMap, DefIdSet}; +use util::nodemap::{NodeMap, DefIdSet, FnvHashSet}; use syntax::ast::*; use syntax::ast; @@ -38,7 +38,7 @@ use std::strbuf::StrBuf; use std::uint; // Definition mapping -pub type DefMap = @RefCell>; +pub type DefMap = RefCell>; struct binding_info { span: Span, @@ -53,7 +53,7 @@ pub type TraitMap = NodeMap >; // This is the replacement export map. It maps a module to all of the exports // within. -pub type ExportMap2 = @RefCell >>; +pub type ExportMap2 = RefCell >>; pub struct Export2 { pub name: ~str, // The name of the target. @@ -821,15 +821,15 @@ fn Resolver<'a>(session: &'a Session, graph_root: graph_root, - method_map: @RefCell::new(HashMap::new()), + method_set: RefCell::new(FnvHashSet::new()), structs: HashSet::new(), unresolved_imports: 0, current_module: current_module, - value_ribs: @RefCell::new(Vec::new()), - type_ribs: @RefCell::new(Vec::new()), - label_ribs: @RefCell::new(Vec::new()), + value_ribs: RefCell::new(Vec::new()), + type_ribs: RefCell::new(Vec::new()), + label_ribs: RefCell::new(Vec::new()), current_trait_refs: None, @@ -840,8 +840,8 @@ fn Resolver<'a>(session: &'a Session, namespaces: vec!(TypeNS, ValueNS), - def_map: @RefCell::new(NodeMap::new()), - export_map2: @RefCell::new(NodeMap::new()), + def_map: RefCell::new(NodeMap::new()), + export_map2: RefCell::new(NodeMap::new()), trait_map: NodeMap::new(), used_imports: HashSet::new(), external_exports: DefIdSet::new(), @@ -860,7 +860,7 @@ struct Resolver<'a> { graph_root: @NameBindings, - method_map: @RefCell>>, + method_set: RefCell>, structs: HashSet, // The number of imports that are currently unresolved. @@ -871,13 +871,13 @@ struct Resolver<'a> { // The current set of local scopes, for values. // FIXME #4948: Reuse ribs to avoid allocation. - value_ribs: @RefCell >, + value_ribs: RefCell>, // The current set of local scopes, for types. - type_ribs: @RefCell >, + type_ribs: RefCell>, // The current set of local scopes, for labels. - label_ribs: @RefCell >, + label_ribs: RefCell>, // The trait that the current context can refer to. current_trait_refs: Option >, @@ -1003,13 +1003,13 @@ impl<'a> Resolver<'a> { * If this node does not have a module definition and we are not inside * a block, fails. */ - fn add_child(&mut self, - name: Ident, - reduced_graph_parent: ReducedGraphParent, - duplicate_checking_mode: DuplicateCheckingMode, - // For printing errors - sp: Span) - -> (@NameBindings, ReducedGraphParent) { + fn add_child(&self, + name: Ident, + reduced_graph_parent: ReducedGraphParent, + duplicate_checking_mode: DuplicateCheckingMode, + // For printing errors + sp: Span) + -> (@NameBindings, ReducedGraphParent) { // If this is the immediate descendant of a module, then we add the // child name directly. Otherwise, we create or reuse an anonymous // module and add the child to that. @@ -1358,8 +1358,9 @@ impl<'a> Resolver<'a> { let module_parent = ModuleReducedGraphParent(name_bindings. get_module()); + let def_id = local_def(item.id); + // Add the names of all the methods to the trait info. - let mut method_names = HashMap::new(); for method in methods.iter() { let ty_m = trait_method_to_ty_method(method); @@ -1388,23 +1389,8 @@ impl<'a> Resolver<'a> { method_name_bindings.define_value(def, ty_m.span, true); // Add it to the trait info if not static. - match ty_m.explicit_self.node { - SelfStatic => {} - _ => { - method_names.insert(ident.name, ()); - } - } - } - - let def_id = local_def(item.id); - for (name, _) in method_names.iter() { - let mut method_map = self.method_map.borrow_mut(); - if !method_map.contains_key(name) { - method_map.insert(*name, HashSet::new()); - } - match method_map.find_mut(name) { - Some(s) => { s.insert(def_id); }, - _ => fail!("can't happen"), + if ty_m.explicit_self.node != SelfStatic { + self.method_set.borrow_mut().insert((ident.name, def_id)); } } @@ -1685,7 +1671,6 @@ impl<'a> Resolver<'a> { let method_def_ids = csearch::get_trait_method_def_ids(&self.session.cstore, def_id); - let mut interned_method_names = HashSet::new(); for &method_def_id in method_def_ids.iter() { let (method_name, explicit_self) = csearch::get_method_name_and_explicit_self(&self.session.cstore, @@ -1698,22 +1683,12 @@ impl<'a> Resolver<'a> { // Add it to the trait info if not static. if explicit_self != SelfStatic { - interned_method_names.insert(method_name.name); + self.method_set.borrow_mut().insert((method_name.name, def_id)); } if is_exported { self.external_exports.insert(method_def_id); } } - for name in interned_method_names.iter() { - let mut method_map = self.method_map.borrow_mut(); - if !method_map.contains_key(name) { - method_map.insert(*name, HashSet::new()); - } - match method_map.find_mut(name) { - Some(s) => { s.insert(def_id); }, - _ => fail!("can't happen"), - } - } child_name_bindings.define_type(def, DUMMY_SP, is_public); @@ -3444,12 +3419,12 @@ impl<'a> Resolver<'a> { /// Wraps the given definition in the appropriate number of `def_upvar` /// wrappers. - fn upvarify(&mut self, - ribs: &mut Vec<@Rib> , - rib_index: uint, - def_like: DefLike, - span: Span) - -> Option { + fn upvarify(&self, + ribs: &[@Rib], + rib_index: uint, + def_like: DefLike, + span: Span) + -> Option { let mut def; let is_ty_param; @@ -3470,7 +3445,7 @@ impl<'a> Resolver<'a> { let mut rib_index = rib_index + 1; while rib_index < ribs.len() { - match ribs.get(rib_index).kind { + match ribs[rib_index].kind { NormalRibKind => { // Nothing to do. Continue. } @@ -3560,18 +3535,18 @@ impl<'a> Resolver<'a> { return Some(DlDef(def)); } - fn search_ribs(&mut self, - ribs: &mut Vec<@Rib> , - name: Name, - span: Span) - -> Option { + fn search_ribs(&self, + ribs: &[@Rib], + name: Name, + span: Span) + -> Option { // FIXME #4950: This should not use a while loop. // FIXME #4950: Try caching? let mut i = ribs.len(); while i != 0 { i -= 1; - let binding_opt = ribs.get(i).bindings.borrow().find_copy(&name); + let binding_opt = ribs[i].bindings.borrow().find_copy(&name); match binding_opt { Some(def_like) => { return self.upvarify(ribs, i, def_like, span); @@ -4095,7 +4070,7 @@ impl<'a> Resolver<'a> { // user and one 'x' came from the macro. fn binding_mode_map(&mut self, pat: @Pat) -> BindingMap { let mut result = HashMap::new(); - pat_bindings(self.def_map, pat, |binding_mode, _id, sp, path| { + pat_bindings(&self.def_map, pat, |binding_mode, _id, sp, path| { let name = mtwt::resolve(path_to_ident(path)); result.insert(name, binding_info {span: sp, @@ -4786,22 +4761,17 @@ impl<'a> Resolver<'a> { }; match containing_module.kind.get() { TraitModuleKind | ImplModuleKind => { - match self.method_map.borrow().find(&ident.name) { - Some(s) => { - match containing_module.def_id.get() { - Some(def_id) if s.contains(&def_id) => { - debug!("containing module was a trait or impl \ - and name was a method -> not resolved"); - return None; - }, - _ => (), - } + match containing_module.def_id.get() { + Some(def_id) if self.method_set.borrow().contains(&(ident.name, def_id)) => { + debug!("containing module was a trait or impl \ + and name was a method -> not resolved"); + return None; }, - None => (), + _ => (), } }, _ => (), - }; + } return Some(def); } @@ -4865,12 +4835,12 @@ impl<'a> Resolver<'a> { let search_result = match namespace { ValueNS => { let renamed = mtwt::resolve(ident); - self.search_ribs(&mut *self.value_ribs.borrow_mut(), + self.search_ribs(self.value_ribs.borrow().as_slice(), renamed, span) } TypeNS => { let name = ident.name; - self.search_ribs(&mut *self.type_ribs.borrow_mut(), name, span) + self.search_ribs(self.type_ribs.borrow().as_slice(), name, span) } }; @@ -4936,7 +4906,7 @@ impl<'a> Resolver<'a> { rs } - fn resolve_error(&mut self, span: Span, s: &str) { + fn resolve_error(&self, span: Span, s: &str) { if self.emit_errors { self.session.span_err(span, s); } @@ -5115,9 +5085,9 @@ impl<'a> Resolver<'a> { ExprForLoop(..) => fail!("non-desugared expr_for_loop"), ExprBreak(Some(label)) | ExprAgain(Some(label)) => { - let mut label_ribs = self.label_ribs.borrow_mut(); let renamed = mtwt::resolve(label); - match self.search_ribs(&mut *label_ribs, renamed, expr.span) { + match self.search_ribs(self.label_ribs.borrow().as_slice(), + renamed, expr.span) { None => self.resolve_error(expr.span, format!("use of undeclared label `{}`", @@ -5147,14 +5117,14 @@ impl<'a> Resolver<'a> { // field, we need to add any trait methods we find that match // the field name so that we can do some nice error reporting // later on in typeck. - let traits = self.search_for_traits_containing_method(ident); + let traits = self.search_for_traits_containing_method(ident.name); self.trait_map.insert(expr.id, traits); } ExprMethodCall(ident, _, _) => { debug!("(recording candidate traits for expr) recording \ traits for {}", expr.id); - let traits = self.search_for_traits_containing_method(ident); + let traits = self.search_for_traits_containing_method(ident.name); self.trait_map.insert(expr.id, traits); } _ => { @@ -5163,33 +5133,43 @@ impl<'a> Resolver<'a> { } } - fn search_for_traits_containing_method(&mut self, name: Ident) -> Vec { + fn search_for_traits_containing_method(&mut self, name: Name) -> Vec { debug!("(searching for traits containing method) looking for '{}'", - token::get_ident(name)); + token::get_name(name)); + + fn add_trait_info(found_traits: &mut Vec, + trait_def_id: DefId, + name: Name) { + debug!("(adding trait info) found trait {}:{} for method '{}'", + trait_def_id.krate, + trait_def_id.node, + token::get_name(name)); + found_traits.push(trait_def_id); + } let mut found_traits = Vec::new(); let mut search_module = self.current_module; - match self.method_map.borrow().find(&name.name) { - Some(candidate_traits) => loop { - // Look for the current trait. - match self.current_trait_refs { - Some(ref trait_def_ids) => { - for trait_def_id in trait_def_ids.iter() { - if candidate_traits.contains(trait_def_id) { - self.add_trait_info(&mut found_traits, - *trait_def_id, - name); - } + loop { + // Look for the current trait. + match self.current_trait_refs { + Some(ref trait_def_ids) => { + let method_set = self.method_set.borrow(); + for &trait_def_id in trait_def_ids.iter() { + if method_set.contains(&(name, trait_def_id)) { + add_trait_info(&mut found_traits, trait_def_id, name); } } - None => { - // Nothing to do. - } } + None => { + // Nothing to do. + } + } - // Look for trait children. - self.populate_module_if_necessary(search_module); + // Look for trait children. + self.populate_module_if_necessary(search_module); + { + let method_set = self.method_set.borrow(); for (_, &child_names) in search_module.children.borrow().iter() { let def = match child_names.def_for_namespace(TypeNS) { Some(def) => def, @@ -5199,52 +5179,39 @@ impl<'a> Resolver<'a> { DefTrait(trait_def_id) => trait_def_id, _ => continue, }; - if candidate_traits.contains(&trait_def_id) { - self.add_trait_info(&mut found_traits, trait_def_id, - name); + if method_set.contains(&(name, trait_def_id)) { + add_trait_info(&mut found_traits, trait_def_id, name); } } + } - // Look for imports. - let import_resolutions = search_module.import_resolutions - .borrow(); - for (_, &import) in import_resolutions.iter() { - let target = match import.target_for_namespace(TypeNS) { - None => continue, - Some(target) => target, - }; - let did = match target.bindings.def_for_namespace(TypeNS) { - Some(DefTrait(trait_def_id)) => trait_def_id, - Some(..) | None => continue, - }; - if candidate_traits.contains(&did) { - self.add_trait_info(&mut found_traits, did, name); - self.used_imports.insert((import.type_id.get(), TypeNS)); - } + // Look for imports. + let import_resolutions = search_module.import_resolutions + .borrow(); + for (_, &import) in import_resolutions.iter() { + let target = match import.target_for_namespace(TypeNS) { + None => continue, + Some(target) => target, + }; + let did = match target.bindings.def_for_namespace(TypeNS) { + Some(DefTrait(trait_def_id)) => trait_def_id, + Some(..) | None => continue, + }; + if self.method_set.borrow().contains(&(name, did)) { + add_trait_info(&mut found_traits, did, name); + self.used_imports.insert((import.type_id.get(), TypeNS)); } + } - match search_module.parent_link { - NoParentLink | ModuleParentLink(..) => break, - BlockParentLink(parent_module, _) => { - search_module = parent_module; - } + match search_module.parent_link { + NoParentLink | ModuleParentLink(..) => break, + BlockParentLink(parent_module, _) => { + search_module = parent_module; } - }, - _ => () + } } - return found_traits; - } - - fn add_trait_info(&self, - found_traits: &mut Vec , - trait_def_id: DefId, - name: Ident) { - debug!("(adding trait info) found trait {}:{} for method '{}'", - trait_def_id.krate, - trait_def_id.node, - token::get_ident(name)); - found_traits.push(trait_def_id); + found_traits } fn record_def(&mut self, node_id: NodeId, (def, lp): (Def, LastPrivate)) { diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index bab7a227572..3a1d6cab018 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -496,7 +496,7 @@ fn expand_nested_bindings<'r,'b>( } fn assert_is_binding_or_wild(bcx: &Block, p: @ast::Pat) { - if !pat_is_binding_or_wild(bcx.tcx().def_map, p) { + if !pat_is_binding_or_wild(&bcx.tcx().def_map, p) { bcx.sess().span_bug( p.span, format!("expected an identifier pattern but found p: {}", @@ -508,7 +508,7 @@ type enter_pat<'a> = |@ast::Pat|: 'a -> Option>; fn enter_match<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef, @@ -556,7 +556,7 @@ fn enter_match<'r,'b>( fn enter_default<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef, @@ -657,10 +657,10 @@ fn enter_opt<'r,'b>( // "column" of arm patterns and the algorithm will converge. let guarded = m.iter().any(|x| x.data.arm.guard.is_some()); let multi_pats = m.len() > 0 && m[0].pats.len() > 1; - enter_match(bcx, tcx.def_map, m, col, val, |p| { + enter_match(bcx, &tcx.def_map, m, col, val, |p| { let answer = match p.node { ast::PatEnum(..) | - ast::PatIdent(_, _, None) if pat_is_const(tcx.def_map, p) => { + ast::PatIdent(_, _, None) if pat_is_const(&tcx.def_map, p) => { let const_def = tcx.def_map.borrow().get_copy(&p.id); let const_def_id = ast_util::def_id_of_def(const_def); let konst = lit(ConstLit(const_def_id)); @@ -684,7 +684,7 @@ fn enter_opt<'r,'b>( } } ast::PatIdent(_, _, None) - if pat_is_variant_or_struct(tcx.def_map, p) => { + if pat_is_variant_or_struct(&tcx.def_map, p) => { if opt_eq(tcx, &variant_opt(bcx, p.id), opt) { Some(Vec::new()) } else { @@ -801,7 +801,7 @@ fn enter_opt<'r,'b>( fn enter_rec_or_struct<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, fields: &[ast::Ident], @@ -837,7 +837,7 @@ fn enter_rec_or_struct<'r,'b>( fn enter_tup<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef, @@ -870,7 +870,7 @@ fn enter_tup<'r,'b>( fn enter_tuple_struct<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef, @@ -899,7 +899,7 @@ fn enter_tuple_struct<'r,'b>( fn enter_uniq<'r,'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef) @@ -928,7 +928,7 @@ fn enter_uniq<'r,'b>( fn enter_region<'r, 'b>( bcx: &'b Block<'b>, - dm: DefMap, + dm: &DefMap, m: &[Match<'r,'b>], col: uint, val: ValueRef) @@ -1170,7 +1170,7 @@ fn pats_require_rooting(bcx: &Block, m: &[Match], col: uint) -> bool { m.iter().any(|br| { let pat_id = br.pats.get(col).id; let key = root_map_key {id: pat_id, derefs: 0u }; - bcx.ccx().maps.root_map.borrow().contains_key(&key) + bcx.ccx().maps.root_map.contains_key(&key) }) } @@ -1551,7 +1551,7 @@ fn compile_submatch_continue<'r, val: ValueRef) { let fcx = bcx.fcx; let tcx = bcx.tcx(); - let dm = tcx.def_map; + let dm = &tcx.def_map; let vals_left = Vec::from_slice(vals.slice(0u, col)).append(vals.slice(col + 1u, vals.len())); let ccx = bcx.fcx.ccx; @@ -1885,7 +1885,7 @@ fn create_bindings_map(bcx: &Block, pat: @ast::Pat) -> BindingsMap { let ccx = bcx.ccx(); let tcx = bcx.tcx(); let mut bindings_map = HashMap::new(); - pat_bindings(tcx.def_map, pat, |bm, p_id, span, path| { + pat_bindings(&tcx.def_map, pat, |bm, p_id, span, path| { let ident = path_to_ident(path); let variable_ty = node_id_type(bcx, p_id); let llvariable_ty = type_of::type_of(ccx, variable_ty); @@ -2066,7 +2066,7 @@ pub fn store_local<'a>(bcx: &'a Block<'a>, // create dummy memory for the variables if we have no // value to store into them immediately let tcx = bcx.tcx(); - pat_bindings(tcx.def_map, pat, |_, p_id, _, path| { + pat_bindings(&tcx.def_map, pat, |_, p_id, _, path| { let scope = cleanup::var_scope(tcx, p_id); bcx = mk_binding_alloca( bcx, p_id, path, BindLocal, scope, (), @@ -2199,7 +2199,7 @@ fn bind_irrefutable_pat<'a>( let ccx = bcx.ccx(); match pat.node { ast::PatIdent(pat_binding_mode, ref path, inner) => { - if pat_is_binding(tcx.def_map, pat) { + if pat_is_binding(&tcx.def_map, pat) { // Allocate the stack slot where the value of this // binding will live and place it into the appropriate // map. diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 92a6bb73c8e..9d995ca5ef7 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2056,17 +2056,13 @@ pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef { pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::EncodeInlinedItem<'r>) -> encoder::EncodeParams<'r> { - - let diag = cx.sess().diagnostic(); - let item_symbols = &cx.item_symbols; - let link_meta = &cx.link_meta; encoder::EncodeParams { - diag: diag, + diag: cx.sess().diagnostic(), tcx: cx.tcx(), - reexports2: cx.exp_map2, - item_symbols: item_symbols, + reexports2: &cx.exp_map2, + item_symbols: &cx.item_symbols, non_inlineable_statics: &cx.non_inlineable_statics, - link_meta: link_meta, + link_meta: &cx.link_meta, cstore: &cx.sess().cstore, encode_inlined_item: ie, } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index c5739960a19..35fef462735 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -369,7 +369,7 @@ pub fn create_local_var_metadata(bcx: &Block, local: &ast::Local) { } let cx = bcx.ccx(); - let def_map = cx.tcx.def_map; + let def_map = &cx.tcx.def_map; pat_util::pat_bindings(def_map, local.pat, |_, node_id, span, path_ref| { let var_ident = ast_util::path_to_ident(path_ref); @@ -509,7 +509,7 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) { let fcx = bcx.fcx; let cx = fcx.ccx; - let def_map = cx.tcx.def_map; + let def_map = &cx.tcx.def_map; let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata; pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| { @@ -2381,7 +2381,7 @@ fn populate_scope_map(cx: &CrateContext, fn_entry_block: &ast::Block, fn_metadata: DISubprogram, scope_map: &mut HashMap) { - let def_map = cx.tcx.def_map; + let def_map = &cx.tcx.def_map; struct ScopeStackEntry { scope_metadata: DIScope, @@ -2494,7 +2494,7 @@ fn populate_scope_map(cx: &CrateContext, scope_stack: &mut Vec , scope_map: &mut HashMap) { - let def_map = cx.tcx.def_map; + let def_map = &cx.tcx.def_map; // Unfortunately, we cannot just use pat_util::pat_bindings() or ast_util::walk_pat() here // because we have to visit *all* nodes in order to put them into the scope map. The above diff --git a/src/librustc/middle/trans/write_guard.rs b/src/librustc/middle/trans/write_guard.rs index 565805446f7..8f114827bfd 100644 --- a/src/librustc/middle/trans/write_guard.rs +++ b/src/librustc/middle/trans/write_guard.rs @@ -34,7 +34,7 @@ pub fn root_and_write_guard<'a, K:KindOps>(datum: &Datum, // // (Note: root'd values are always boxes) let ccx = bcx.ccx(); - match ccx.maps.root_map.borrow().find(&key) { + match ccx.maps.root_map.find(&key) { None => bcx, Some(&root_info) => root(datum, bcx, span, key, root_info) } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b28fd06f9ad..ced81b8e671 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -320,12 +320,12 @@ pub struct ctxt { pub destructors: RefCell, // Maps a trait onto a list of impls of that trait. - pub trait_impls: RefCell >>>, + pub trait_impls: RefCell>>>, // Maps a def_id of a type to a list of its inherent impls. // Contains implementations of methods that are inherent to a type. // Methods in these implementations don't need to be exported. - pub inherent_impls: RefCell >>>, + pub inherent_impls: RefCell>>>, // Maps a def_id of an impl to an Impl structure. // Note that this contains all of the impls that we know about, @@ -4386,22 +4386,17 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> @ItemVariances { } /// Records a trait-to-implementation mapping. -fn record_trait_implementation(tcx: &ctxt, - trait_def_id: DefId, - implementation: @Impl) { - let implementation_list; - let mut trait_impls = tcx.trait_impls.borrow_mut(); - match trait_impls.find(&trait_def_id) { - None => { - implementation_list = @RefCell::new(Vec::new()); - trait_impls.insert(trait_def_id, implementation_list); - } - Some(&existing_implementation_list) => { - implementation_list = existing_implementation_list +pub fn record_trait_implementation(tcx: &ctxt, + trait_def_id: DefId, + implementation: @Impl) { + match tcx.trait_impls.borrow().find(&trait_def_id) { + Some(impls_for_trait) => { + impls_for_trait.borrow_mut().push(implementation); + return; } + None => {} } - - implementation_list.borrow_mut().push(implementation); + tcx.trait_impls.borrow_mut().insert(trait_def_id, @RefCell::new(vec!(implementation))); } /// Populates the type context with all the implementations for the given type @@ -4437,24 +4432,20 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt, } } - // If this is an inherent implementation, record it. - if associated_traits.is_none() { - let implementation_list; - let mut inherent_impls = tcx.inherent_impls.borrow_mut(); - match inherent_impls.find(&type_id) { - None => { - implementation_list = @RefCell::new(Vec::new()); - inherent_impls.insert(type_id, implementation_list); - } - Some(&existing_implementation_list) => { - implementation_list = existing_implementation_list; - } - } - implementation_list.borrow_mut().push(implementation); - } - // Store the implementation info. tcx.impls.borrow_mut().insert(implementation_def_id, implementation); + + // If this is an inherent implementation, record it. + if associated_traits.is_none() { + match tcx.inherent_impls.borrow().find(&type_id) { + Some(implementation_list) => { + implementation_list.borrow_mut().push(implementation); + return; + } + None => {} + } + tcx.inherent_impls.borrow_mut().insert(type_id, @RefCell::new(vec!(implementation))); + } }); tcx.populated_external_types.borrow_mut().insert(type_id); diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 286c8d17751..9ceb3132509 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -40,7 +40,7 @@ pub fn check_match(fcx: &FnCtxt, for arm in arms.iter() { let mut pcx = pat_ctxt { fcx: fcx, - map: pat_id_map(tcx.def_map, *arm.pats.get(0)), + map: pat_id_map(&tcx.def_map, *arm.pats.get(0)), }; for p in arm.pats.iter() { check_pat(&mut pcx, *p, discrim_ty);} @@ -467,14 +467,14 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { fcx.write_ty(pat.id, b_ty); } ast::PatEnum(..) | - ast::PatIdent(..) if pat_is_const(tcx.def_map, pat) => { + ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => { let const_did = ast_util::def_id_of_def(tcx.def_map.borrow() .get_copy(&pat.id)); let const_tpt = ty::lookup_item_type(tcx, const_did); demand::suptype(fcx, pat.span, expected, const_tpt.ty); fcx.write_ty(pat.id, const_tpt.ty); } - ast::PatIdent(bm, ref name, sub) if pat_is_binding(tcx.def_map, pat) => { + ast::PatIdent(bm, ref name, sub) if pat_is_binding(&tcx.def_map, pat) => { let typ = fcx.local_ty(pat.span, pat.id); match bm { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 45d6434431b..57f6eb72516 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -155,7 +155,7 @@ pub mod method; /// share the inherited fields. pub struct Inherited<'a> { infcx: infer::InferCtxt<'a>, - locals: @RefCell>, + locals: RefCell>, param_env: ty::ParameterEnvironment, // Temporary tables: @@ -260,7 +260,7 @@ impl<'a> Inherited<'a> { -> Inherited<'a> { Inherited { infcx: infer::new_infer_ctxt(tcx), - locals: @RefCell::new(NodeMap::new()), + locals: RefCell::new(NodeMap::new()), param_env: param_env, node_types: RefCell::new(NodeMap::new()), node_type_substs: RefCell::new(NodeMap::new()), @@ -387,7 +387,7 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> { fn visit_pat(&mut self, p: &ast::Pat, _: ()) { match p.node { ast::PatIdent(_, ref path, _) - if pat_util::pat_is_binding(self.fcx.ccx.tcx.def_map, p) => { + if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map, p) => { self.assign(p.id, None); debug!("Pattern binding {} is assigned to {}", token::get_ident(path.segments.get(0).identifier), @@ -469,7 +469,7 @@ fn check_fn<'a>(ccx: &'a CrateCtxt<'a>, // Add formal parameters. for (arg_ty, input) in arg_tys.iter().zip(decl.inputs.iter()) { // Create type variables for each argument. - pat_util::pat_bindings(tcx.def_map, + pat_util::pat_bindings(&tcx.def_map, input.pat, |_bm, pat_id, _sp, _path| { visit.assign(pat_id, None); @@ -478,7 +478,7 @@ fn check_fn<'a>(ccx: &'a CrateCtxt<'a>, // Check the pattern. let pcx = pat_ctxt { fcx: &fcx, - map: pat_id_map(tcx.def_map, input.pat), + map: pat_id_map(&tcx.def_map, input.pat), }; _match::check_pat(&pcx, input.pat, *arg_ty); } @@ -3266,7 +3266,7 @@ pub fn check_decl_local(fcx: &FnCtxt, local: &ast::Local) { let pcx = pat_ctxt { fcx: fcx, - map: pat_id_map(tcx.def_map, local.pat), + map: pat_id_map(&tcx.def_map, local.pat), }; _match::check_pat(&pcx, local.pat, t); let pat_ty = fcx.node_ty(local.pat.id); diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 50ba1421458..abbd5b81660 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -361,7 +361,7 @@ fn visit_local(rcx: &mut Rcx, l: &ast::Local) { fn constrain_bindings_in_pat(pat: &ast::Pat, rcx: &mut Rcx) { let tcx = rcx.fcx.tcx(); debug!("regionck::visit_pat(pat={})", pat.repr(tcx)); - pat_util::pat_bindings(tcx.def_map, pat, |_, id, span, _| { + pat_util::pat_bindings(&tcx.def_map, pat, |_, id, span, _| { // If we have a variable that contains region'd data, that // data will be accessible from anywhere that the variable is // accessed. We must be wary of loops like this: diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index cdee230e52d..1ab4578f6ce 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -28,7 +28,6 @@ use util::ppaux; use util::ppaux::Repr; use collections::HashSet; -use std::cell::RefCell; use syntax::ast; use syntax::ast_util; use syntax::codemap::Span; @@ -319,10 +318,12 @@ fn search_for_vtable(vcx: &VtableContext, ty::populate_implementations_for_trait_if_necessary(tcx, trait_ref.def_id); - // FIXME: this is a bad way to do this, since we do - // pointless allocations. - let impls = tcx.trait_impls.borrow().find(&trait_ref.def_id) - .map_or(@RefCell::new(Vec::new()), |x| *x); + let impls = match tcx.trait_impls.borrow().find_copy(&trait_ref.def_id) { + Some(impls) => impls, + None => { + return None; + } + }; // impls is the list of all impls in scope for trait_ref. for im in impls.borrow().iter() { // im is one specific impl of trait_ref. diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index dedab59cce7..3843c38fd18 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -380,7 +380,7 @@ pub fn resolve_type_vars_in_fn(fcx: &FnCtxt, decl: &ast::FnDecl, for arg in decl.inputs.iter() { wbcx.visit_pat(arg.pat, ()); // Privacy needs the type for the whole pattern, not just each binding - if !pat_util::pat_is_binding(fcx.tcx().def_map, arg.pat) { + if !pat_util::pat_is_binding(&fcx.tcx().def_map, arg.pat) { resolve_type_vars_for_node(wbcx, arg.pat.span, arg.pat.id); } } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index c0fd73f4a36..df79a448030 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -366,40 +366,23 @@ impl<'a> CoherenceChecker<'a> { } } - fn add_inherent_impl(&self, base_def_id: DefId, - implementation: @Impl) { + fn add_inherent_impl(&self, base_def_id: DefId, implementation: @Impl) { let tcx = self.crate_context.tcx; - let implementation_list; - let mut inherent_impls = tcx.inherent_impls.borrow_mut(); - match inherent_impls.find(&base_def_id) { - None => { - implementation_list = @RefCell::new(Vec::new()); - inherent_impls.insert(base_def_id, implementation_list); - } - Some(&existing_implementation_list) => { - implementation_list = existing_implementation_list; + match tcx.inherent_impls.borrow().find(&base_def_id) { + Some(implementation_list) => { + implementation_list.borrow_mut().push(implementation); + return; } + None => {} } - implementation_list.borrow_mut().push(implementation); + tcx.inherent_impls.borrow_mut().insert(base_def_id, @RefCell::new(vec!(implementation))); } - fn add_trait_impl(&self, base_def_id: DefId, - implementation: @Impl) { - let tcx = self.crate_context.tcx; - let implementation_list; - let mut trait_impls = tcx.trait_impls.borrow_mut(); - match trait_impls.find(&base_def_id) { - None => { - implementation_list = @RefCell::new(Vec::new()); - trait_impls.insert(base_def_id, implementation_list); - } - Some(&existing_implementation_list) => { - implementation_list = existing_implementation_list; - } - } - - implementation_list.borrow_mut().push(implementation); + fn add_trait_impl(&self, base_def_id: DefId, implementation: @Impl) { + ty::record_trait_implementation(self.crate_context.tcx, + base_def_id, + implementation); } fn check_implementation_coherence(&self) { @@ -538,7 +521,7 @@ impl<'a> CoherenceChecker<'a> { } fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId { - let def_map = self.crate_context.tcx.def_map; + let def_map = &self.crate_context.tcx.def_map; let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id); let trait_id = def_id_of_def(trait_def); return trait_id; @@ -680,13 +663,10 @@ impl<'a> CoherenceChecker<'a> { Some(id) => id, None => { return } }; - let trait_impls = tcx.trait_impls.borrow(); - let impls_opt = trait_impls.find(&drop_trait); - let impls; - match impls_opt { + let impls = match tcx.trait_impls.borrow().find_copy(&drop_trait) { None => return, // No types with (new-style) dtors present. - Some(found_impls) => impls = found_impls - } + Some(found_impls) => found_impls + }; for impl_info in impls.borrow().iter() { if impl_info.methods.len() < 1 { diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index ac4db178a00..7d7d5d16d74 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -16,12 +16,13 @@ use std::io; use syntax::ast; pub type FnvHashMap = HashMap; +pub type FnvHashSet = HashSet; pub type NodeMap = FnvHashMap; pub type DefIdMap = FnvHashMap; -pub type NodeSet = HashSet; -pub type DefIdSet = HashSet; +pub type NodeSet = FnvHashSet; +pub type DefIdSet = FnvHashSet; // Hacks to get good names pub mod FnvHashMap { @@ -31,6 +32,13 @@ pub mod FnvHashMap { HashMap::with_hasher(super::FnvHasher) } } +pub mod FnvHashSet { + use std::hash::Hash; + use collections::HashSet; + pub fn new + TotalEq>() -> super::FnvHashSet { + HashSet::with_hasher(super::FnvHasher) + } +} pub mod NodeMap { pub fn new() -> super::NodeMap { super::FnvHashMap::new() @@ -42,15 +50,13 @@ pub mod DefIdMap { } } pub mod NodeSet { - use collections::HashSet; pub fn new() -> super::NodeSet { - HashSet::with_hasher(super::FnvHasher) + super::FnvHashSet::new() } } pub mod DefIdSet { - use collections::HashSet; pub fn new() -> super::DefIdSet { - HashSet::with_hasher(super::FnvHasher) + super::FnvHashSet::new() } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1d98cc143de..3038dc8259f 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -9,7 +9,6 @@ // except according to those terms. -use metadata::encoder; use middle::ty::{ReSkolemized, ReVar}; use middle::ty::{BoundRegion, BrAnon, BrNamed}; use middle::ty::{BrFresh, ctxt}; @@ -469,7 +468,7 @@ pub fn parameterized(cx: &ctxt, } pub fn ty_to_short_str(cx: &ctxt, typ: t) -> ~str { - let mut s = encoder::encoded_ty(cx, typ); + let mut s = typ.repr(cx); if s.len() >= 32u { s = s.slice(0u, 32u).to_owned(); } return s; }