auto merge of #5523 : alexcrichton/rust/less-oldmap, r=thestinger

I started out just removing a few instances of `HashMap` throughout rustc, but it ended up snowballing to remove the entire thing. Most uses translated to just using `@mut LinearMap` instead of `HashMap`, although I tried where possible to drop the `@mut` modifier. This ended up working out some of the time, but definitely not in the major use cases.

Things got kinda weird in some cases like:

* https://github.com/alexcrichton/rust/compare/mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L39R1587
* https://github.com/alexcrichton/rust/compare/mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L61R3760
* https://github.com/alexcrichton/rust/compare/mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L71R917
* https://github.com/alexcrichton/rust/compare/mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L91R127

I tried to tag them all with bugs which I thought would make them less weird, but I may have the wrong bug in a few places. These cases only came up when I tried to pass around `&mut LinearMap` instead of an `@mut LinearMap`.

I also ran into a few bugs when migrating to `LinearMap`, one of which is #5521. There's another set of bugs which a00d779042fb8753c716e07b4f1aac0d5ab7bf66 addresses (all marked with `XXX`). I have a feeling they're all the same bug, but all I've been able is to reproduce them. I tried to whittle down the test cases and try to get some input which causes a failure, but I've been unable to do so. All I know is that it's vaguely related to `*T` pointers being used as `&*T` (return value of `find`). I'm not able to open a very descriptive issue, but I'll do so if there seems no other better route.

I realize this is a very large pull request, so if it'd be better to split this up into multiple segments I'd be more than willing to do so. So far the tests all pass locally, although I'm sure bors will turn something up. I also don't mind keeping this up to date with rebasing. This maybe should wait until after 0.6 because it is a fairly large change...
This commit is contained in:
bors 2013-03-26 16:21:59 -07:00
commit fa82b9af2a
106 changed files with 1225 additions and 1635 deletions

View file

@ -441,11 +441,11 @@ expression context, the final namespace qualifier is omitted.
Two examples of paths with type arguments:
~~~~
# use std::oldmap;
# use core::hashmap::linear::LinearMap;
# fn f() {
# fn id<T:Copy>(t: T) -> T { t }
type t = oldmap::HashMap<int,~str>; // Type arguments used in a type expression
let x = id::<int>(10); // Type arguments used in a call expression
type t = LinearMap<int,~str>; // Type arguments used in a type expression
let x = id::<int>(10); // Type arguments used in a call expression
# }
~~~~

View file

@ -1829,8 +1829,8 @@ illegal to copy and pass by value.
Generic `type`, `struct`, and `enum` declarations follow the same pattern:
~~~~
# use std::oldmap::HashMap;
type Set<T> = HashMap<T, ()>;
# use core::hashmap::linear::LinearMap;
type Set<T> = LinearMap<T, ()>;
struct Stack<T> {
elements: ~[T]

View file

@ -17,10 +17,10 @@ Simple compression
use libc;
use libc::{c_void, size_t, c_int};
use ptr;
use rand::RngUtil;
use vec;
#[cfg(test)] use rand;
#[cfg(test)] use rand::RngUtil;
pub mod rustrt {
use libc::{c_int, c_void, size_t};

View file

@ -656,6 +656,11 @@ pub mod linear {
fn reserve_at_least(&mut self, n: uint) {
self.map.reserve_at_least(n)
}
/// Consumes all of the elements in the set, emptying it out
fn consume(&mut self, f: &fn(T)) {
self.map.consume(|k, _| f(k))
}
}
#[test]

View file

@ -10,8 +10,6 @@
//! Logging
use libc;
pub mod rustrt {
use libc;
@ -49,6 +47,7 @@ pub fn console_off() {
pub fn log_type<T>(level: u32, object: &T) {
use cast::transmute;
use io;
use libc;
use repr;
use vec;

View file

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use option::*;
use comm::{GenericPort, GenericChan};
pub mod file;
// FIXME #5370 Strongly want this to be StreamError(&mut Stream)

View file

@ -42,7 +42,6 @@ use ptr;
use libc::{c_void, c_int, size_t, malloc, free, ssize_t};
use cast::{transmute, transmute_mut_region};
use ptr::null;
use sys::size_of;
use super::uvll;
use super::uvll::*;
use unstable::finally::Finally;

View file

@ -32,7 +32,6 @@
use libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t};
use libc::{malloc, free};
use prelude::*;
use ptr::to_unsafe_ptr;
pub struct uv_err_t {
code: c_int,

View file

@ -642,7 +642,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
match ccx.type_hashcodes.find(&t) {
Some(h) => h,
Some(&h) => h,
None => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
ccx.type_hashcodes.insert(t, hash);

View file

@ -246,7 +246,7 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
// These next two const passes can probably be merged
time(time_passes, ~"const marking", ||
middle::const_eval::process_crate(crate, def_map, ty_cx));
middle::const_eval::process_crate(crate, ty_cx));
time(time_passes, ~"const checking", ||
middle::check_const::check_crate(sess, crate, ast_map, def_map,
@ -546,11 +546,11 @@ pub fn build_session_options(+binary: ~str,
let flags = vec::append(getopts::opt_strs(matches, level_short),
getopts::opt_strs(matches, level_name));
for flags.each |lint_name| {
let lint_name = @str::replace(*lint_name, ~"-", ~"_");
let lint_name = str::replace(*lint_name, ~"-", ~"_");
match lint_dict.find(&lint_name) {
None => {
early_error(demitter, fmt!("unknown %s flag: %s",
level_name, *lint_name));
level_name, lint_name));
}
Some(lint) => {
lint_opts.push((lint.lint, *level));

View file

@ -10,12 +10,12 @@
use core::prelude::*;
use core::hashmap::linear::LinearMap;
use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
use core::option;
use core::ptr;
use core::str;
use core::vec;
use std::oldmap::HashMap;
pub type Opcode = u32;
pub type Bool = c_uint;
@ -1467,8 +1467,8 @@ pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
/* Memory-managed object interface to type handles. */
pub struct TypeNames {
type_names: HashMap<TypeRef, @str>,
named_types: HashMap<@str, TypeRef>
type_names: @mut LinearMap<TypeRef, @str>,
named_types: @mut LinearMap<@str, TypeRef>
}
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
@ -1477,17 +1477,17 @@ pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
}
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
return tn.type_names.find(&t);
return tn.type_names.find(&t).map_consume(|x| *x);
}
pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
return tn.named_types.find(&s);
return tn.named_types.find(&s).map_consume(|x| *x);
}
pub fn mk_type_names() -> @TypeNames {
@TypeNames {
type_names: HashMap(),
named_types: HashMap()
type_names: @mut LinearMap::new(),
named_types: @mut LinearMap::new()
}
}

View file

@ -19,6 +19,7 @@ use metadata::filesearch::FileSearch;
use metadata::loader;
use core::either;
use core::hashmap::linear::LinearMap;
use core::vec;
use syntax::attr;
use syntax::codemap::{span, dummy_sp};
@ -26,7 +27,6 @@ use syntax::diagnostic::span_handler;
use syntax::parse::token::ident_interner;
use syntax::visit;
use syntax::{ast, ast_util};
use std::oldmap::HashMap;
// Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc.
@ -307,7 +307,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
debug!("resolving deps of external crate");
// The map from crate numbers in the crate we're resolving to local crate
// numbers
let cnum_map = HashMap();
let mut cnum_map = LinearMap::new();
for decoder::get_crate_deps(e.intr, cdata).each |dep| {
let extrn_cnum = dep.cnum;
let cname = dep.name;
@ -334,7 +334,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
}
}
}
return cnum_map;
return @mut cnum_map;
}
// Local Variables:

View file

@ -17,8 +17,8 @@ use core::prelude::*;
use metadata::cstore;
use metadata::decoder;
use core::hashmap::linear::LinearMap;
use core::vec;
use std::oldmap;
use std;
use syntax::{ast, attr};
use syntax::parse::token::ident_interner;
@ -27,7 +27,7 @@ use syntax::parse::token::ident_interner;
// 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 = oldmap::HashMap<ast::crate_num, ast::crate_num>;
pub type cnum_map = @mut LinearMap<ast::crate_num, ast::crate_num>;
pub struct crate_metadata {
name: @~str,
@ -37,7 +37,7 @@ pub struct crate_metadata {
}
pub struct CStore {
priv metas: oldmap::HashMap<ast::crate_num, @crate_metadata>,
priv metas: LinearMap <ast::crate_num, @crate_metadata>,
priv extern_mod_crate_map: extern_mod_crate_map,
priv used_crate_files: ~[Path],
priv used_libraries: ~[~str],
@ -46,14 +46,12 @@ pub struct CStore {
}
// Map from node_id's of local extern mod statements to crate numbers
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
type extern_mod_crate_map = LinearMap<ast::node_id, ast::crate_num>;
pub fn mk_cstore(intr: @ident_interner) -> CStore {
let meta_cache = oldmap::HashMap();
let crate_map = oldmap::HashMap();
return CStore {
metas: meta_cache,
extern_mod_crate_map: crate_map,
metas: LinearMap::new(),
extern_mod_crate_map: LinearMap::new(),
used_crate_files: ~[],
used_libraries: ~[],
used_link_args: ~[],
@ -61,96 +59,89 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore {
};
}
pub fn get_crate_data(cstore: @mut CStore, cnum: ast::crate_num)
pub fn get_crate_data(cstore: &CStore, cnum: ast::crate_num)
-> @crate_metadata {
return cstore.metas.get(&cnum);
return *cstore.metas.get(&cnum);
}
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
pub fn get_crate_hash(cstore: &CStore, cnum: ast::crate_num) -> @~str {
let cdata = get_crate_data(cstore, cnum);
decoder::get_crate_hash(cdata.data)
}
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
pub fn get_crate_vers(cstore: &CStore, cnum: ast::crate_num) -> @~str {
let cdata = get_crate_data(cstore, cnum);
decoder::get_crate_vers(cdata.data)
}
pub fn set_crate_data(cstore: @mut CStore,
pub fn set_crate_data(cstore: &mut CStore,
cnum: ast::crate_num,
data: @crate_metadata) {
let metas = cstore.metas;
metas.insert(cnum, data);
cstore.metas.insert(cnum, data);
}
pub fn have_crate_data(cstore: @mut CStore, cnum: ast::crate_num) -> bool {
pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
cstore.metas.contains_key(&cnum)
}
pub fn iter_crate_data(cstore: @mut CStore,
pub fn iter_crate_data(cstore: &CStore,
i: &fn(ast::crate_num, @crate_metadata)) {
let metas = cstore.metas;
for metas.each |&k, &v| {
for cstore.metas.each |&(&k, &v)| {
i(k, v);
}
}
pub fn add_used_crate_file(cstore: @mut CStore, lib: &Path) {
let cstore = &mut *cstore;
pub fn add_used_crate_file(cstore: &mut CStore, lib: &Path) {
if !vec::contains(cstore.used_crate_files, lib) {
cstore.used_crate_files.push(copy *lib);
}
}
pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
pub fn get_used_crate_files(cstore: &CStore) -> ~[Path] {
return /*bad*/copy cstore.used_crate_files;
}
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
pub fn add_used_library(cstore: &mut CStore, lib: @~str) -> bool {
fail_unless!(*lib != ~"");
let cstore = &mut *cstore;
if cstore.used_libraries.contains(&*lib) { return false; }
cstore.used_libraries.push(/*bad*/ copy *lib);
true
}
pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] {
pub fn get_used_libraries(cstore: &CStore) -> ~[~str] {
/*bad*/copy cstore.used_libraries
}
pub fn add_used_link_args(cstore: @mut CStore, args: &str) {
pub fn add_used_link_args(cstore: &mut CStore, args: &str) {
for args.each_split_char(' ') |s| {
cstore.used_link_args.push(s.to_owned());
}
}
pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
pub fn get_used_link_args(cstore: &CStore) -> ~[~str] {
/*bad*/copy cstore.used_link_args
}
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
emod_id: ast::node_id,
cnum: ast::crate_num) {
let extern_mod_crate_map = cstore.extern_mod_crate_map;
extern_mod_crate_map.insert(emod_id, cnum);
cstore.extern_mod_crate_map.insert(emod_id, cnum);
}
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
emod_id: ast::node_id)
-> Option<ast::crate_num> {
let extern_mod_crate_map = cstore.extern_mod_crate_map;
extern_mod_crate_map.find(&emod_id)
cstore.extern_mod_crate_map.find(&emod_id).map_consume(|x| *x)
}
// returns hashes of crates directly used by this crate. Hashes are sorted by
// (crate name, crate version, crate hash) in lexicographic order (not semver)
pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
pub fn get_dep_hashes(cstore: &CStore) -> ~[~str] {
struct crate_hash { name: @~str, vers: @~str, hash: @~str }
let mut result = ~[];
let extern_mod_crate_map = cstore.extern_mod_crate_map;
for extern_mod_crate_map.each_value |&cnum| {
for cstore.extern_mod_crate_map.each_value |&cnum| {
let cdata = cstore::get_crate_data(cstore, cnum);
let hash = decoder::get_crate_hash(cdata.data);
let vers = decoder::get_crate_vers(cdata.data);

View file

@ -1132,7 +1132,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
}
match cdata.cnum_map.find(&did.crate) {
option::Some(n) => ast::def_id { crate: n, node: did.node },
option::Some(&n) => ast::def_id { crate: n, node: did.node },
option::None => fail!(~"didn't find a crate in the cnum_map")
}
}

View file

@ -17,6 +17,7 @@ use metadata::common::*;
use metadata::cstore;
use metadata::decoder;
use metadata::tyencode;
use middle::trans::reachable;
use middle::ty::node_id_to_type;
use middle::ty;
use middle;
@ -24,6 +25,7 @@ use util::ppaux::ty_to_str;
use core::flate;
use core::hash::{Hash, HashUtil};
use core::hashmap::linear::{LinearMap, LinearSet};
use core::int;
use core::io::{Writer, WriterUtil};
use core::io;
@ -31,9 +33,7 @@ use core::str;
use core::to_bytes::IterBytes;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use std::serialize::Encodable;
use std::{ebml, oldmap};
use std;
use syntax::ast::*;
use syntax::ast;
@ -49,7 +49,7 @@ use syntax;
use writer = std::ebml::writer;
// used by astencode:
type abbrev_map = oldmap::HashMap<ty::t, tyencode::ty_abbrev>;
type abbrev_map = @mut LinearMap<ty::t, tyencode::ty_abbrev>;
pub type encode_inlined_item = @fn(ecx: @EncodeContext,
ebml_w: writer::Encoder,
@ -59,10 +59,10 @@ pub type encode_inlined_item = @fn(ecx: @EncodeContext,
pub struct EncodeParams {
diag: @span_handler,
tcx: ty::ctxt,
reachable: HashMap<ast::node_id, ()>,
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: HashMap<ast::node_id, ~str>,
discrim_symbols: HashMap<ast::node_id, ~str>,
item_symbols: @mut LinearMap<ast::node_id, ~str>,
discrim_symbols: @mut LinearMap<ast::node_id, ~str>,
link_meta: LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item
@ -86,10 +86,10 @@ pub struct EncodeContext {
diag: @span_handler,
tcx: ty::ctxt,
stats: @mut Stats,
reachable: HashMap<ast::node_id, ()>,
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: HashMap<ast::node_id, ~str>,
discrim_symbols: HashMap<ast::node_id, ~str>,
item_symbols: @mut LinearMap<ast::node_id, ~str>,
discrim_symbols: @mut LinearMap<ast::node_id, ~str>,
link_meta: LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item,
@ -97,7 +97,7 @@ pub struct EncodeContext {
}
pub fn reachable(ecx: @EncodeContext, id: node_id) -> bool {
ecx.reachable.contains_key(&id)
ecx.reachable.contains(&id)
}
fn encode_name(ecx: @EncodeContext, ebml_w: writer::Encoder, name: ident) {
@ -188,7 +188,7 @@ fn encode_type_param_bounds(ebml_w: writer::Encoder,
ecx: @EncodeContext,
params: &OptVec<TyParam>) {
let ty_param_bounds =
@params.map_to_vec(|param| ecx.tcx.ty_param_bounds.get(&param.id));
@params.map_to_vec(|param| *ecx.tcx.ty_param_bounds.get(&param.id));
encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds);
}
@ -229,7 +229,7 @@ fn encode_type(ecx: @EncodeContext, ebml_w: writer::Encoder, typ: ty::t) {
fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
match ecx.item_symbols.find(&id) {
Some(ref x) => {
Some(x) => {
debug!("encode_symbol(id=%?, str=%s)", id, *x);
ebml_w.writer.write(str::to_bytes(*x));
}
@ -244,7 +244,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
fn encode_discriminant(ecx: @EncodeContext, ebml_w: writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(&id)));
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get(&id)));
ebml_w.end_tag();
}
@ -1026,7 +1026,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
let ebml_w = copy ebml_w;
|i, cx, v| {
visit::visit_item(i, cx, v);
match ecx.tcx.items.get(&i.id) {
match *ecx.tcx.items.get(&i.id) {
ast_map::node_item(_, pt) => {
encode_info_for_item(ecx, ebml_w, i,
index, *pt);
@ -1039,7 +1039,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
let ebml_w = copy ebml_w;
|ni, cx, v| {
visit::visit_foreign_item(ni, cx, v);
match ecx.tcx.items.get(&ni.id) {
match *ecx.tcx.items.get(&ni.id) {
ast_map::node_foreign_item(_, abi, _, pt) => {
encode_info_for_foreign_item(ecx, ebml_w, ni,
index, /*bad*/copy *pt,
@ -1320,7 +1320,7 @@ pub static metadata_encoding_version : &'static [u8] =
0x74, //'t' as u8,
0, 0, 0, 1 ];
pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
pub fn encode_metadata(+parms: EncodeParams, crate: &crate) -> ~[u8] {
let wr = @io::BytesWriter();
let mut stats = Stats {
inline_bytes: 0,
@ -1334,18 +1334,21 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
total_bytes: 0,
n_inlines: 0
};
let EncodeParams{item_symbols, diag, tcx, reachable, reexports2,
discrim_symbols, cstore, encode_inlined_item,
link_meta, _} = parms;
let ecx = @EncodeContext {
diag: parms.diag,
tcx: parms.tcx,
diag: diag,
tcx: tcx,
stats: @mut stats,
reachable: parms.reachable,
reexports2: parms.reexports2,
item_symbols: parms.item_symbols,
discrim_symbols: parms.discrim_symbols,
link_meta: /*bad*/copy parms.link_meta,
cstore: parms.cstore,
encode_inlined_item: parms.encode_inlined_item,
type_abbrevs: ty::new_ty_hash()
reachable: reachable,
reexports2: reexports2,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
link_meta: link_meta,
cstore: cstore,
encode_inlined_item: encode_inlined_item,
type_abbrevs: @mut LinearMap::new()
};
let ebml_w = writer::Encoder(wr as @io::Writer);
@ -1385,7 +1388,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
ecx.stats.total_bytes = wr.pos;
if (parms.tcx.sess.meta_stats()) {
if (tcx.sess.meta_stats()) {
do wr.bytes.each |e| {
if *e == 0 {

View file

@ -337,7 +337,7 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
pos: pos,
len: len };
match st.tcx.rcache.find(&key) {
Some(tt) => return tt,
Some(&tt) => return tt,
None => {
let ps = @mut PState {pos: pos ,.. copy *st};
let tt = parse_ty(ps, conv);

View file

@ -16,11 +16,11 @@ use core::prelude::*;
use middle::ty::{Vid, param_ty};
use middle::ty;
use core::hashmap::linear::LinearMap;
use core::io::WriterUtil;
use core::io;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::*;
use syntax::diagnostic::span_handler;
use syntax::print::pprust::*;
@ -47,7 +47,7 @@ pub struct ty_abbrev {
pub enum abbrev_ctxt {
ac_no_abbrevs,
ac_use_abbrevs(HashMap<ty::t, ty_abbrev>),
ac_use_abbrevs(@mut LinearMap<ty::t, ty_abbrev>),
}
fn cx_uses_abbrevs(cx: @ctxt) -> bool {
@ -61,7 +61,7 @@ pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
match cx.abbrevs {
ac_no_abbrevs => {
let result_str = match cx.tcx.short_names_cache.find(&t) {
Some(s) => /*bad*/copy *s,
Some(&s) => /*bad*/copy *s,
None => {
let s = do io::with_str_writer |wr| {
enc_sty(wr, cx, /*bad*/copy ty::get(t).sty);

View file

@ -856,12 +856,14 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
do ebml_w.tag(c::tag_table_node_type_subst) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
ebml_w.emit_tys(ecx, /*bad*/copy *tys)
// FIXME(#5562): removing this copy causes a segfault
// before stage2
ebml_w.emit_tys(ecx, /*bad*/copy **tys)
}
}
}
for tcx.freevars.find(&id).each |fv| {
for tcx.freevars.find(&id).each |&fv| {
do ebml_w.tag(c::tag_table_freevars) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -873,7 +875,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
}
let lid = ast::def_id { crate: ast::local_crate, node: id };
for tcx.tcache.find(&lid).each |tpbt| {
for tcx.tcache.find(&lid).each |&tpbt| {
do ebml_w.tag(c::tag_table_tcache) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -882,7 +884,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
}
}
for tcx.ty_param_bounds.find(&id).each |pbs| {
for tcx.ty_param_bounds.find(&id).each |&pbs| {
do ebml_w.tag(c::tag_table_param_bounds) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -905,7 +907,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
// }
//}
if maps.mutbl_map.contains_key(&id) {
if maps.mutbl_map.contains(&id) {
do ebml_w.tag(c::tag_table_mutbl) {
ebml_w.id(id);
}
@ -915,14 +917,14 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
do ebml_w.tag(c::tag_table_last_use) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec(/*bad*/ copy *m) |id| {
do ebml_w.emit_from_vec(/*bad*/ copy **m) |id| {
id.encode(&ebml_w);
}
}
}
}
for maps.method_map.find(&id).each |mme| {
for maps.method_map.find(&id).each |&mme| {
do ebml_w.tag(c::tag_table_method_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -931,7 +933,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
}
}
for maps.vtable_map.find(&id).each |dr| {
for maps.vtable_map.find(&id).each |&dr| {
do ebml_w.tag(c::tag_table_vtable_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -949,13 +951,13 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
}
}
for maps.moves_map.find(&id).each |_| {
if maps.moves_map.contains(&id) {
do ebml_w.tag(c::tag_table_moves_map) {
ebml_w.id(id);
}
}
for maps.capture_map.find(&id).each |cap_vars| {
for maps.capture_map.find(&id).each |&cap_vars| {
do ebml_w.tag(c::tag_table_capture_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -1097,9 +1099,9 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
tag, id, id0);
if tag == (c::tag_table_mutbl as uint) {
dcx.maps.mutbl_map.insert(id, ());
dcx.maps.mutbl_map.insert(id);
} else if tag == (c::tag_table_moves_map as uint) {
dcx.maps.moves_map.insert(id, ());
dcx.maps.moves_map.insert(id);
} else {
let val_doc = entry_doc[c::tag_table_val as uint];
let val_dsr = &reader::Decoder(val_doc);

View file

@ -31,8 +31,8 @@ use middle::mem_categorization::{lp_comp, lp_deref, lp_local};
use middle::ty;
use util::ppaux::ty_to_str;
use core::hashmap::linear::LinearSet;
use core::uint;
use std::oldmap::HashMap;
use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast;
use syntax::ast_util;
@ -44,7 +44,7 @@ struct CheckLoanCtxt {
bccx: @BorrowckCtxt,
req_maps: ReqMaps,
reported: HashMap<ast::node_id, ()>,
reported: LinearSet<ast::node_id>,
declared_purity: @mut ast::purity,
fn_args: @mut @~[ast::node_id]
@ -63,12 +63,12 @@ enum purity_cause {
}
pub fn check_loans(bccx: @BorrowckCtxt,
req_maps: ReqMaps,
+req_maps: ReqMaps,
crate: @ast::crate) {
let clcx = @mut CheckLoanCtxt {
bccx: bccx,
req_maps: req_maps,
reported: HashMap(),
reported: LinearSet::new(),
declared_purity: @mut ast::impure_fn,
fn_args: @mut @~[]
};
@ -104,9 +104,9 @@ pub impl assignment_type {
}
pub impl CheckLoanCtxt {
fn tcx(@mut self) -> ty::ctxt { self.bccx.tcx }
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
fn purity(@mut self, scope_id: ast::node_id) -> Option<purity_cause> {
fn purity(&mut self, scope_id: ast::node_id) -> Option<purity_cause> {
let default_purity = match *self.declared_purity {
// an unsafe declaration overrides all
ast::unsafe_fn => return None,
@ -122,43 +122,38 @@ pub impl CheckLoanCtxt {
// purity. if so, that overrides the declaration.
let mut scope_id = scope_id;
let region_map = self.tcx().region_map;
let pure_map = self.req_maps.pure_map;
loop {
match pure_map.find(&scope_id) {
match self.req_maps.pure_map.find(&scope_id) {
None => (),
Some(ref e) => return Some(pc_cmt((*e)))
Some(e) => return Some(pc_cmt(*e))
}
match region_map.find(&scope_id) {
match self.tcx().region_map.find(&scope_id) {
None => return default_purity,
Some(next_scope_id) => scope_id = next_scope_id
Some(&next_scope_id) => scope_id = next_scope_id
}
}
}
fn walk_loans(@mut self,
scope_id: ast::node_id,
fn walk_loans(&self,
mut scope_id: ast::node_id,
f: &fn(v: &Loan) -> bool) {
let mut scope_id = scope_id;
let region_map = self.tcx().region_map;
let req_loan_map = self.req_maps.req_loan_map;
loop {
for req_loan_map.find(&scope_id).each |loans| {
for self.req_maps.req_loan_map.find(&scope_id).each |loans| {
for loans.each |loan| {
if !f(loan) { return; }
}
}
match region_map.find(&scope_id) {
match self.tcx().region_map.find(&scope_id) {
None => return,
Some(next_scope_id) => scope_id = next_scope_id,
Some(&next_scope_id) => scope_id = next_scope_id,
}
}
}
fn walk_loans_of(@mut self,
fn walk_loans_of(&mut self,
scope_id: ast::node_id,
lp: @loan_path,
f: &fn(v: &Loan) -> bool) {
@ -175,7 +170,7 @@ pub impl CheckLoanCtxt {
// note: we take opt_expr and expr_id separately because for
// overloaded operators the callee has an id but no expr.
// annoying.
fn check_pure_callee_or_arg(@mut self,
fn check_pure_callee_or_arg(&mut self,
pc: purity_cause,
opt_expr: Option<@ast::expr>,
callee_id: ast::node_id,
@ -202,7 +197,7 @@ pub impl CheckLoanCtxt {
Some(expr) => {
match expr.node {
ast::expr_path(_) if pc == pc_pure_fn => {
let def = self.tcx().def_map.get(&expr.id);
let def = *self.tcx().def_map.get(&expr.id);
let did = ast_util::def_id_of_def(def);
let is_fn_arg =
did.crate == ast::local_crate &&
@ -242,7 +237,7 @@ pub impl CheckLoanCtxt {
// True if the expression with the given `id` is a stack closure.
// The expression must be an expr_fn_block(*)
fn is_stack_closure(@mut self, id: ast::node_id) -> bool {
fn is_stack_closure(&mut self, id: ast::node_id) -> bool {
let fn_ty = ty::node_id_to_type(self.tcx(), id);
match ty::get(fn_ty).sty {
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
@ -251,10 +246,10 @@ pub impl CheckLoanCtxt {
}
}
fn is_allowed_pure_arg(@mut self, expr: @ast::expr) -> bool {
fn is_allowed_pure_arg(&mut self, expr: @ast::expr) -> bool {
return match expr.node {
ast::expr_path(_) => {
let def = self.tcx().def_map.get(&expr.id);
let def = *self.tcx().def_map.get(&expr.id);
let did = ast_util::def_id_of_def(def);
did.crate == ast::local_crate &&
(*self.fn_args).contains(&(did.node))
@ -264,18 +259,18 @@ pub impl CheckLoanCtxt {
};
}
fn check_for_conflicting_loans(@mut self, scope_id: ast::node_id) {
fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) {
debug!("check_for_conflicting_loans(scope_id=%?)", scope_id);
let new_loans = match self.req_maps.req_loan_map.find(&scope_id) {
None => return,
Some(loans) => loans
Some(&loans) => loans
};
let new_loans: &mut ~[Loan] = new_loans;
debug!("new_loans has length %?", new_loans.len());
let par_scope_id = self.tcx().region_map.get(&scope_id);
let par_scope_id = *self.tcx().region_map.get(&scope_id);
for self.walk_loans(par_scope_id) |old_loan| {
debug!("old_loan=%?", self.bccx.loan_to_repr(old_loan));
@ -294,7 +289,7 @@ pub impl CheckLoanCtxt {
}
}
fn report_error_if_loans_conflict(@mut self,
fn report_error_if_loans_conflict(&self,
old_loan: &Loan,
new_loan: &Loan) {
if old_loan.lp != new_loan.lp {
@ -330,19 +325,19 @@ pub impl CheckLoanCtxt {
}
}
fn is_local_variable(@mut self, cmt: cmt) -> bool {
fn is_local_variable(&self, cmt: cmt) -> bool {
match cmt.cat {
cat_local(_) => true,
_ => false
}
}
fn check_assignment(@mut self, at: assignment_type, ex: @ast::expr) {
fn check_assignment(&mut self, at: assignment_type, ex: @ast::expr) {
// We don't use cat_expr() here because we don't want to treat
// auto-ref'd parameters in overloaded operators as rvalues.
let cmt = match self.bccx.tcx.adjustments.find(&ex.id) {
None => self.bccx.cat_expr_unadjusted(ex),
Some(adj) => self.bccx.cat_expr_autoderefd(ex, adj)
Some(&adj) => self.bccx.cat_expr_autoderefd(ex, adj)
};
debug!("check_assignment(cmt=%s)",
@ -369,6 +364,7 @@ pub impl CheckLoanCtxt {
match self.purity(ex.id) {
None => (),
Some(pc_cmt(_)) => {
let purity = self.purity(ex.id).get();
// Subtle: Issue #3162. If we are enforcing purity
// because there is a reference to aliasable, mutable data
// that we require to be immutable, we can't allow writes
@ -376,7 +372,7 @@ pub impl CheckLoanCtxt {
// because that aliasable data might have been located on
// the current stack frame, we don't know.
self.report_purity_error(
self.purity(ex.id).get(),
purity,
ex.span,
at.ing_form(self.bccx.cmt_to_str(cmt)));
}
@ -404,7 +400,7 @@ pub impl CheckLoanCtxt {
self.add_write_guards_if_necessary(cmt);
}
fn add_write_guards_if_necessary(@mut self, cmt: cmt) {
fn add_write_guards_if_necessary(&mut self, cmt: cmt) {
match cmt.cat {
cat_deref(base, deref_count, ptr_kind) => {
self.add_write_guards_if_necessary(base);
@ -415,7 +411,7 @@ pub impl CheckLoanCtxt {
id: base.id,
derefs: deref_count
};
self.bccx.write_guard_map.insert(key, ());
self.bccx.write_guard_map.insert(key);
}
_ => {}
}
@ -427,7 +423,7 @@ pub impl CheckLoanCtxt {
}
}
fn check_for_loan_conflicting_with_assignment(@mut self,
fn check_for_loan_conflicting_with_assignment(&mut self,
at: assignment_type,
ex: @ast::expr,
cmt: cmt,
@ -466,7 +462,7 @@ pub impl CheckLoanCtxt {
}
}
fn report_purity_error(@mut self, pc: purity_cause, sp: span, msg: ~str) {
fn report_purity_error(&mut self, pc: purity_cause, sp: span, msg: ~str) {
match pc {
pc_pure_fn => {
self.tcx().sess.span_err(
@ -474,8 +470,7 @@ pub impl CheckLoanCtxt {
fmt!("%s prohibited in pure context", msg));
}
pc_cmt(ref e) => {
let reported = self.reported;
if reported.insert((*e).cmt.id, ()) {
if self.reported.insert((*e).cmt.id) {
self.tcx().sess.span_err(
(*e).cmt.span,
fmt!("illegal borrow unless pure: %s",
@ -522,7 +517,7 @@ pub impl CheckLoanCtxt {
}
}
fn analyze_move_out_from_cmt(@mut self, cmt: cmt) -> MoveError {
fn analyze_move_out_from_cmt(&mut self, cmt: cmt) -> MoveError {
debug!("check_move_out_from_cmt(cmt=%s)",
self.bccx.cmt_to_repr(cmt));
@ -555,7 +550,7 @@ pub impl CheckLoanCtxt {
return MoveOk;
}
fn check_call(@mut self,
fn check_call(&mut self,
expr: @ast::expr,
callee: Option<@ast::expr>,
callee_id: ast::node_id,
@ -695,7 +690,7 @@ fn check_loans_in_expr(expr: @ast::expr,
self.check_for_conflicting_loans(expr.id);
if self.bccx.moves_map.contains_key(&expr.id) {
if self.bccx.moves_map.contains(&expr.id) {
self.check_move_out_from_expr(expr);
}

View file

@ -32,9 +32,8 @@ use middle::ty;
use util::common::indenter;
use util::ppaux::{expr_repr, region_to_str};
use core::hashmap::linear::LinearSet;
use core::hashmap::linear::{LinearSet, LinearMap};
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast;
use syntax::codemap::span;
@ -80,7 +79,8 @@ struct GatherLoanCtxt {
pub fn gather_loans(bccx: @BorrowckCtxt, crate: @ast::crate) -> ReqMaps {
let glcx = @mut GatherLoanCtxt {
bccx: bccx,
req_maps: ReqMaps { req_loan_map: HashMap(), pure_map: HashMap() },
req_maps: ReqMaps { req_loan_map: LinearMap::new(),
pure_map: LinearMap::new() },
item_ub: 0,
root_ub: 0,
ignore_adjustments: LinearSet::new()
@ -90,7 +90,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt, crate: @ast::crate) -> ReqMaps {
visit_stmt: add_stmt_to_map,
.. *visit::default_visitor()});
visit::visit_crate(*crate, glcx, v);
return glcx.req_maps;
let @GatherLoanCtxt{req_maps, _} = glcx;
return req_maps;
}
fn req_loans_in_fn(fk: &visit::fn_kind,
@ -132,7 +133,7 @@ fn req_loans_in_expr(ex: @ast::expr,
{
let mut this = &mut *self;
if !this.ignore_adjustments.contains(&ex.id) {
for tcx.adjustments.find(&ex.id).each |adjustments| {
for tcx.adjustments.find(&ex.id).each |&adjustments| {
this.guarantee_adjustments(ex, *adjustments);
}
}
@ -257,7 +258,7 @@ fn req_loans_in_expr(ex: @ast::expr,
// (if used like `a.b(...)`), the call where it's an argument
// (if used like `x(a.b)`), or the block (if used like `let x
// = a.b`).
let scope_r = ty::re_scope(self.tcx().region_map.get(&ex.id));
let scope_r = ty::re_scope(*self.tcx().region_map.get(&ex.id));
let rcvr_cmt = self.bccx.cat_expr(rcvr);
self.guarantee_valid(rcvr_cmt, m_imm, scope_r);
visit::visit_expr(ex, self, vt);
@ -429,8 +430,7 @@ pub impl GatherLoanCtxt {
// if the scope is some block/expr in the
// fn, then just require that this scope
// be pure
let pure_map = self.req_maps.pure_map;
pure_map.insert(pure_id, *e);
self.req_maps.pure_map.insert(pure_id, *e);
self.bccx.stats.req_pure_paths += 1;
debug!("requiring purity for scope %?",
@ -575,12 +575,11 @@ pub impl GatherLoanCtxt {
match self.req_maps.req_loan_map.find(&scope_id) {
Some(req_loans) => {
req_loans.push_all(loans);
return;
}
None => {
let req_loan_map = self.req_maps.req_loan_map;
req_loan_map.insert(scope_id, @mut loans);
}
None => {}
}
self.req_maps.req_loan_map.insert(scope_id, @mut loans);
}
fn gather_pat(@mut self,
@ -683,7 +682,7 @@ fn add_stmt_to_map(stmt: @ast::stmt,
vt: visit::vt<@mut GatherLoanCtxt>) {
match stmt.node {
ast::stmt_expr(_, id) | ast::stmt_semi(_, id) => {
self.bccx.stmt_map.insert(id, ());
self.bccx.stmt_map.insert(id);
}
_ => ()
}

View file

@ -130,7 +130,7 @@ pub impl LoanContext {
}
cat_local(local_id) | cat_arg(local_id) | cat_self(local_id) => {
// FIXME(#4903)
let local_scope_id = self.bccx.tcx.region_map.get(&local_id);
let local_scope_id = *self.bccx.tcx.region_map.get(&local_id);
self.issue_loan(cmt, ty::re_scope(local_scope_id), loan_kind,
owns_lent_data)
}

View file

@ -234,10 +234,10 @@ use middle::moves;
use util::common::{indenter, stmt_set};
use util::ppaux::note_and_explain_region;
use core::hashmap::linear::{LinearSet, LinearMap};
use core::io;
use core::result::{Result, Ok, Err};
use core::to_bytes;
use std::oldmap::{HashMap, Set};
use syntax::ast::{mutability, m_mutbl, m_imm, m_const};
use syntax::ast;
use syntax::codemap::span;
@ -260,9 +260,9 @@ pub fn check_crate(
moves_map: moves_map,
capture_map: capture_map,
root_map: root_map(),
mutbl_map: HashMap(),
write_guard_map: HashMap(),
stmt_map: HashMap(),
mutbl_map: @mut LinearSet::new(),
write_guard_map: @mut LinearSet::new(),
stmt_map: @mut LinearSet::new(),
stats: @mut BorrowStats {
loaned_paths_same: 0,
loaned_paths_imm: 0,
@ -333,7 +333,7 @@ pub struct RootInfo {
// a map mapping id's of expressions of gc'd type (@T, @[], etc) where
// the box needs to be kept live to the id of the scope for which they
// must stay live.
pub type root_map = HashMap<root_map_key, RootInfo>;
pub type root_map = @mut LinearMap<root_map_key, RootInfo>;
// the keys to the root map combine the `id` of the expression with
// the number of types that it is autodereferenced. So, for example,
@ -348,11 +348,11 @@ pub struct root_map_key {
// set of ids of local vars / formal arguments that are modified / moved.
// this is used in trans for optimization purposes.
pub type mutbl_map = HashMap<ast::node_id, ()>;
pub type mutbl_map = @mut LinearSet<ast::node_id>;
// A set containing IDs of expressions of gc'd type that need to have a write
// guard.
pub type write_guard_map = HashMap<root_map_key, ()>;
pub type write_guard_map = @mut LinearSet<root_map_key>;
// Errors that can occur
#[deriving(Eq)]
@ -405,8 +405,8 @@ pub struct Loan {
/// - `pure_map`: map from block/expr that must be pure to the error message
/// that should be reported if they are not pure
pub struct ReqMaps {
req_loan_map: HashMap<ast::node_id, @mut ~[Loan]>,
pure_map: HashMap<ast::node_id, bckerr>
req_loan_map: LinearMap<ast::node_id, @mut ~[Loan]>,
pure_map: LinearMap<ast::node_id, bckerr>
}
pub fn save_and_restore<T:Copy,U>(save_and_restore_t: &mut T,
@ -450,7 +450,7 @@ impl to_bytes::IterBytes for root_map_key {
}
pub fn root_map() -> root_map {
return HashMap();
return @mut LinearMap::new();
}
// ___________________________________________________________________________
@ -541,7 +541,7 @@ pub impl BorrowckCtxt {
fn add_to_mutbl_map(&self, cmt: cmt) {
match cmt.cat {
cat_local(id) | cat_arg(id) => {
self.mutbl_map.insert(id, ());
self.mutbl_map.insert(id);
}
cat_stack_upvar(cmt) => {
self.add_to_mutbl_map(cmt);

View file

@ -108,7 +108,7 @@ pub impl<'self> PreserveCtxt<'self> {
// Maybe if we pass in the parent instead here,
// we can prevent the "scope not found" error
debug!("scope_region thing: %? ", cmt.id);
ty::re_scope(self.tcx().region_map.get(&cmt.id))
ty::re_scope(*self.tcx().region_map.get(&cmt.id))
};
self.compare_scope(cmt, scope_region)
@ -128,14 +128,14 @@ pub impl<'self> PreserveCtxt<'self> {
cmt.span,
~"preserve() called with local and !root_managed_data");
}
let local_scope_id = self.tcx().region_map.get(&local_id);
let local_scope_id = *self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_binding(local_id) => {
// Bindings are these kind of weird implicit pointers (cc
// #2329). We require (in gather_loans) that they be
// rooted in an immutable location.
let local_scope_id = self.tcx().region_map.get(&local_id);
let local_scope_id = *self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_arg(local_id) => {
@ -143,11 +143,11 @@ pub impl<'self> PreserveCtxt<'self> {
// modes). In that case, the caller guarantees stability
// for at least the scope of the fn. This is basically a
// deref of a region ptr.
let local_scope_id = self.tcx().region_map.get(&local_id);
let local_scope_id = *self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_self(local_id) => {
let local_scope_id = self.tcx().region_map.get(&local_id);
let local_scope_id = *self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_comp(cmt_base, comp_field(*)) |
@ -371,7 +371,7 @@ pub impl<'self> PreserveCtxt<'self> {
// scope_id;`. Though that would potentially re-introduce
// the ICE. See #3511 for more details.
let scope_to_use = if
self.bccx.stmt_map.contains_key(&scope_id) {
self.bccx.stmt_map.contains(&scope_id) {
// Root it in its parent scope, b/c
// trans won't introduce a new scope for the
// stmt

View file

@ -124,12 +124,12 @@ pub fn check_expr(sess: Session,
items without type parameters");
}
match def_map.find(&e.id) {
Some(def_const(_)) |
Some(def_fn(_, _)) |
Some(def_variant(_, _)) |
Some(def_struct(_)) => { }
Some(&def_const(_)) |
Some(&def_fn(_, _)) |
Some(&def_variant(_, _)) |
Some(&def_struct(_)) => { }
Some(def) => {
Some(&def) => {
debug!("(checking const) found bad def: %?", def);
sess.span_err(
e.span,
@ -143,8 +143,8 @@ pub fn check_expr(sess: Session,
}
expr_call(callee, _, NoSugar) => {
match def_map.find(&callee.id) {
Some(def_struct(*)) => {} // OK.
Some(def_variant(*)) => {} // OK.
Some(&def_struct(*)) => {} // OK.
Some(&def_variant(*)) => {} // OK.
_ => {
sess.span_err(
e.span,
@ -238,9 +238,9 @@ pub fn check_item_recursion(sess: Session,
match e.node {
expr_path(*) => {
match env.def_map.find(&e.id) {
Some(def_const(def_id)) => {
Some(&def_const(def_id)) => {
if ast_util::is_local(def_id) {
match env.ast_map.get(&def_id.node) {
match *env.ast_map.get(&def_id.node) {
ast_map::node_item(it, _) => {
(v.visit_item)(it, env, v);
}

View file

@ -55,7 +55,7 @@ pub fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
return false;
}
!cx.moves_map.contains_key(&expr.id)
!cx.moves_map.contains(&expr.id)
}
pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
@ -303,8 +303,8 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
pat_wild => { None }
pat_ident(_, _, _) | pat_enum(_, _) => {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, id)) => Some(variant(id)),
Some(def_const(did)) => {
Some(&def_variant(_, id)) => Some(variant(id)),
Some(&def_const(did)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).get();
Some(val(eval_const_expr(cx.tcx, const_expr)))
}
@ -317,7 +317,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
}
pat_struct(*) => {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, id)) => Some(variant(id)),
Some(&def_variant(_, id)) => Some(variant(id)),
_ => Some(single)
}
}
@ -339,7 +339,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
pat_wild => { true }
pat_ident(_, _, _) => {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, _)) | Some(def_const(*)) => { false }
Some(&def_variant(_, _)) | Some(&def_const(*)) => { false }
_ => { true }
}
}
@ -490,14 +490,14 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
pat_ident(_, _, _) => {
match cx.tcx.def_map.find(&pat_id) {
Some(def_variant(_, id)) => {
Some(&def_variant(_, id)) => {
if variant(id) == ctor_id {
Some(vec::from_slice(r.tail()))
} else {
None
}
}
Some(def_const(did)) => {
Some(&def_const(did)) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).get();
let e_v = eval_const_expr(cx.tcx, const_expr);
@ -527,7 +527,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
}
pat_enum(_, args) => {
match cx.tcx.def_map.get(&pat_id) {
match *cx.tcx.def_map.get(&pat_id) {
def_const(did) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).get();
@ -569,7 +569,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
pat_struct(_, ref flds, _) => {
// Is this a struct or an enum variant?
match cx.tcx.def_map.get(&pat_id) {
match *cx.tcx.def_map.get(&pat_id) {
def_variant(_, variant_id) => {
if variant(variant_id) == ctor_id {
// FIXME #4731: Is this right? --pcw
@ -714,12 +714,12 @@ pub fn check_fn(cx: @MatchCheckCtxt,
pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(enum_id, _)) => {
Some(&def_variant(enum_id, _)) => {
if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u {
return true;
}
}
Some(def_const(*)) => return true,
Some(&def_const(*)) => return true,
_ => ()
}
@ -766,7 +766,7 @@ pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
by_ref_span = Some(span);
}
bind_infer => {
if cx.moves_map.contains_key(&id) {
if cx.moves_map.contains(&id) {
any_by_move = true;
}
}
@ -806,7 +806,7 @@ pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
if pat_is_binding(def_map, p) {
match p.node {
pat_ident(_, _, sub) => {
if cx.moves_map.contains_key(&p.id) {
if cx.moves_map.contains(&p.id) {
check_move(p, sub);
}
}
@ -832,7 +832,7 @@ pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
behind_bad_pointer);
if behind_bad_pointer &&
cx.moves_map.contains_key(&pat.id)
cx.moves_map.contains(&pat.id)
{
cx.tcx.sess.span_err(
pat.span,

View file

@ -12,7 +12,6 @@ use core::prelude::*;
use metadata::csearch;
use middle::astencode;
use middle::resolve;
use middle::ty;
use middle;
@ -21,7 +20,7 @@ use core::vec;
use syntax::{ast, ast_map, ast_util, visit};
use syntax::ast::*;
use std::oldmap::HashMap;
use core::hashmap::linear::{LinearMap, LinearSet};
//
// This pass classifies expressions by their constant-ness.
@ -77,12 +76,11 @@ pub fn join_all(cs: &[constness]) -> constness {
}
pub fn classify(e: @expr,
def_map: resolve::DefMap,
tcx: ty::ctxt)
-> constness {
let did = ast_util::local_def(e.id);
match tcx.ccache.find(&did) {
Some(x) => x,
Some(&x) => x,
None => {
let cn =
match e.node {
@ -97,23 +95,23 @@ pub fn classify(e: @expr,
ast::expr_copy(inner) |
ast::expr_unary(_, inner) |
ast::expr_paren(inner) => {
classify(inner, def_map, tcx)
classify(inner, tcx)
}
ast::expr_binary(_, a, b) => {
join(classify(a, def_map, tcx),
classify(b, def_map, tcx))
join(classify(a, tcx),
classify(b, tcx))
}
ast::expr_tup(ref es) |
ast::expr_vec(ref es, ast::m_imm) => {
join_all(vec::map(*es, |e| classify(*e, def_map, tcx)))
join_all(vec::map(*es, |e| classify(*e, tcx)))
}
ast::expr_vstore(e, vstore) => {
match vstore {
ast::expr_vstore_fixed(_) |
ast::expr_vstore_slice => classify(e, def_map, tcx),
ast::expr_vstore_slice => classify(e, tcx),
ast::expr_vstore_uniq |
ast::expr_vstore_box |
ast::expr_vstore_mut_box |
@ -124,7 +122,7 @@ pub fn classify(e: @expr,
ast::expr_struct(_, ref fs, None) => {
let cs = do vec::map((*fs)) |f| {
if f.node.mutbl == ast::m_imm {
classify(f.node.expr, def_map, tcx)
classify(f.node.expr, tcx)
} else {
non_const
}
@ -134,7 +132,7 @@ pub fn classify(e: @expr,
ast::expr_cast(base, _) => {
let ty = ty::expr_ty(tcx, e);
let base = classify(base, def_map, tcx);
let base = classify(base, tcx);
if ty::type_is_integral(ty) {
join(integral_const, base)
} else if ty::type_is_fp(ty) {
@ -145,16 +143,16 @@ pub fn classify(e: @expr,
}
ast::expr_field(base, _, _) => {
classify(base, def_map, tcx)
classify(base, tcx)
}
ast::expr_index(base, idx) => {
join(classify(base, def_map, tcx),
classify(idx, def_map, tcx))
join(classify(base, tcx),
classify(idx, tcx))
}
ast::expr_addr_of(ast::m_imm, base) => {
classify(base, def_map, tcx)
classify(base, tcx)
}
// FIXME: (#3728) we can probably do something CCI-ish
@ -173,7 +171,7 @@ pub fn classify(e: @expr,
pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> {
match tcx.def_map.find(&e.id) {
Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id),
Some(&ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id),
_ => None
}
}
@ -184,7 +182,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
if ast_util::is_local(def_id) {
match tcx.items.find(&def_id.node) {
None => None,
Some(ast_map::node_item(it, _)) => match it.node {
Some(&ast_map::node_item(it, _)) => match it.node {
item_const(_, const_expr) => Some(const_expr),
_ => None
},
@ -192,14 +190,14 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
}
} else {
let maps = astencode::Maps {
mutbl_map: HashMap(),
root_map: HashMap(),
last_use_map: HashMap(),
method_map: HashMap(),
vtable_map: HashMap(),
write_guard_map: HashMap(),
moves_map: HashMap(),
capture_map: HashMap()
mutbl_map: @mut LinearSet::new(),
root_map: @mut LinearMap::new(),
last_use_map: @mut LinearMap::new(),
method_map: @mut LinearMap::new(),
vtable_map: @mut LinearMap::new(),
write_guard_map: @mut LinearSet::new(),
moves_map: @mut LinearSet::new(),
capture_map: @mut LinearMap::new()
};
match csearch::maybe_get_item_ast(tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
@ -227,10 +225,9 @@ pub fn lookup_constness(tcx: ty::ctxt, e: @expr) -> constness {
}
pub fn process_crate(crate: @ast::crate,
def_map: resolve::DefMap,
tcx: ty::ctxt) {
let v = visit::mk_simple_visitor(@visit::SimpleVisitor {
visit_expr_post: |e| { classify(e, def_map, tcx); },
visit_expr_post: |e| { classify(e, tcx); },
.. *visit::default_simple_visitor()
});
visit::visit_crate(*crate, (), v);

View file

@ -12,13 +12,12 @@
// A pass that annotates for each loops and functions with the free
// variables that they contain.
use core::prelude::*;
use middle::resolve;
use middle::ty;
use core::int;
use core::option::*;
use core::vec;
use std::oldmap::*;
use core::hashmap::linear::LinearMap;
use syntax::codemap::span;
use syntax::{ast, ast_util, visit};
@ -31,7 +30,7 @@ pub struct freevar_entry {
span: span //< First span where it is accessed (there can be multiple)
}
pub type freevar_info = @~[@freevar_entry];
pub type freevar_map = HashMap<ast::node_id, freevar_info>;
pub type freevar_map = @mut LinearMap<ast::node_id, freevar_info>;
// Searches through part of the AST for all references to locals or
// upvars in this frame and returns the list of definition IDs thus found.
@ -40,7 +39,7 @@ pub type freevar_map = HashMap<ast::node_id, freevar_info>;
// in order to start the search.
fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
-> freevar_info {
let seen = HashMap();
let seen = @mut LinearMap::new();
let refs = @mut ~[];
fn ignore_item(_i: @ast::item, &&_depth: int, _v: visit::vt<int>) { }
@ -53,7 +52,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
let mut i = 0;
match def_map.find(&expr.id) {
None => fail!(~"path not found"),
Some(df) => {
Some(&df) => {
let mut def = df;
while i < depth {
match def {
@ -93,7 +92,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
// one pass. This could be improved upon if it turns out to matter.
pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
freevar_map {
let freevars = HashMap();
let freevars = @mut LinearMap::new();
let walk_fn: @fn(&visit::fn_kind,
&ast::fn_decl,
@ -116,7 +115,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
match tcx.freevars.find(&fid) {
None => fail!(~"get_freevars: "+int::to_str(fid)+~" has no freevars"),
Some(d) => return d
Some(&d) => return d
}
}

View file

@ -18,9 +18,6 @@ use middle::ty;
use middle::typeck;
use util::ppaux::{ty_to_str, tys_to_str};
use core::str;
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::*;
use syntax::attr::attrs_contains_name;
use syntax::codemap::{span, spanned};
@ -58,8 +55,6 @@ use syntax::{visit, ast_util};
pub static try_adding: &'static str = "Try adding a move";
pub type rval_map = HashMap<node_id, ()>;
pub struct Context {
tcx: ty::ctxt,
method_map: typeck::method_map,
@ -133,13 +128,13 @@ fn check_item(item: @item, cx: Context, visitor: visit::vt<Context>) {
item_impl(_, Some(trait_ref), self_type, _) => {
match cx.tcx.def_map.find(&trait_ref.ref_id) {
None => cx.tcx.sess.bug(~"trait ref not in def map!"),
Some(trait_def) => {
Some(&trait_def) => {
let trait_def_id = ast_util::def_id_of_def(trait_def);
if cx.tcx.lang_items.drop_trait() == trait_def_id {
// Yes, it's a destructor.
match self_type.node {
ty_path(_, path_node_id) => {
let struct_def = cx.tcx.def_map.get(
let struct_def = *cx.tcx.def_map.get(
&path_node_id);
let struct_did =
ast_util::def_id_of_def(struct_def);
@ -279,9 +274,11 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
_ => e.id
};
for cx.tcx.node_type_substs.find(&type_parameter_id).each |ts| {
// FIXME(#5562): removing this copy causes a segfault before stage2
let ts = /*bad*/ copy **ts;
let bounds = match e.node {
expr_path(_) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id));
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&e.id));
ty::lookup_item_type(cx.tcx, did).bounds
}
_ => {
@ -294,15 +291,15 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
~"non path/method call expr has type substs??")
}
};
if vec::len(*ts) != vec::len(*bounds) {
if ts.len() != bounds.len() {
// Fail earlier to make debugging easier
fail!(fmt!("internal error: in kind::check_expr, length \
mismatch between actual and declared bounds: actual = \
%s (%u tys), declared = %? (%u tys)",
tys_to_str(cx.tcx, *ts), ts.len(),
*bounds, (*bounds).len()));
tys_to_str(cx.tcx, ts), ts.len(),
*bounds, bounds.len()));
}
for vec::each2(*ts, *bounds) |ty, bound| {
for vec::each2(ts, *bounds) |ty, bound| {
check_bounds(cx, type_parameter_id, e.span, *ty, *bound)
}
}
@ -340,9 +337,11 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
match aty.node {
ty_path(_, id) => {
for cx.tcx.node_type_substs.find(&id).each |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id));
// FIXME(#5562): removing this copy causes a segfault before stage2
let ts = /*bad*/ copy **ts;
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&id));
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
for vec::each2(*ts, *bounds) |ty, bound| {
for vec::each2(ts, *bounds) |ty, bound| {
check_bounds(cx, aty.id, aty.span, *ty, *bound)
}
}
@ -405,7 +404,7 @@ pub fn check_bounds(cx: Context,
fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
match ex.node {
expr_path(_) => {
match cx.tcx.def_map.get(&ex.id) {
match *cx.tcx.def_map.get(&ex.id) {
def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}

View file

@ -31,8 +31,8 @@ use syntax::ast_util::{local_def};
use syntax::visit::{default_simple_visitor, mk_simple_visitor, SimpleVisitor};
use syntax::visit::{visit_crate, visit_item};
use core::hashmap::linear::LinearMap;
use core::ptr;
use std::oldmap::HashMap;
pub enum LangItem {
ConstTraitLangItem, // 0
@ -259,7 +259,7 @@ fn LanguageItemCollector<'r>(crate: @crate,
session: Session,
items: &'r mut LanguageItems)
-> LanguageItemCollector<'r> {
let item_refs = HashMap();
let mut item_refs = LinearMap::new();
item_refs.insert(@~"const", ConstTraitLangItem as uint);
item_refs.insert(@~"copy", CopyTraitLangItem as uint);
@ -317,7 +317,7 @@ struct LanguageItemCollector {
crate: @crate,
session: Session,
item_refs: HashMap<@~str, uint>,
item_refs: LinearMap<@~str, uint>,
}
pub impl<'self> LanguageItemCollector<'self> {
@ -362,7 +362,7 @@ pub impl<'self> LanguageItemCollector<'self> {
None => {
// Didn't match.
}
Some(item_index) => {
Some(&item_index) => {
self.collect_item(item_index, item_def_id)
}
}
@ -397,7 +397,7 @@ pub impl<'self> LanguageItemCollector<'self> {
}
fn check_completeness(&self) {
for self.item_refs.each |&key, &item_ref| {
for self.item_refs.each |&(&key, &item_ref)| {
match self.items.items[item_ref] {
None => {
self.session.err(fmt!("no item found for `%s`", *key));

View file

@ -15,6 +15,7 @@ use driver::session;
use middle::ty;
use util::ppaux::{ty_to_str};
use core::hashmap::linear::LinearMap;
use core::char;
use core::cmp;
use core::either;
@ -30,8 +31,6 @@ use core::u32;
use core::u64;
use core::uint;
use core::vec;
use std::oldmap::{Map, HashMap};
use std::oldmap;
use std::smallintmap::SmallIntMap;
use syntax::attr;
use syntax::codemap::span;
@ -110,7 +109,7 @@ struct LintSpec {
default: level
}
pub type LintDict = HashMap<@~str, @LintSpec>;
pub type LintDict = @LinearMap<~str, LintSpec>;
/*
Pass names should not contain a '-', as the compiler normalizes
@ -118,142 +117,142 @@ pub type LintDict = HashMap<@~str, @LintSpec>;
*/
pub fn get_lint_dict() -> LintDict {
let v = ~[
(@~"ctypes",
@LintSpec {
(~"ctypes",
LintSpec {
lint: ctypes,
desc: "proper use of core::libc types in foreign modules",
default: warn
}),
(@~"unused_imports",
@LintSpec {
(~"unused_imports",
LintSpec {
lint: unused_imports,
desc: "imports that are never used",
default: warn
}),
(@~"while_true",
@LintSpec {
(~"while_true",
LintSpec {
lint: while_true,
desc: "suggest using loop { } instead of while(true) { }",
default: warn
}),
(@~"path_statement",
@LintSpec {
(~"path_statement",
LintSpec {
lint: path_statement,
desc: "path statements with no effect",
default: warn
}),
(@~"unrecognized_lint",
@LintSpec {
(~"unrecognized_lint",
LintSpec {
lint: unrecognized_lint,
desc: "unrecognized lint attribute",
default: warn
}),
(@~"non_implicitly_copyable_typarams",
@LintSpec {
(~"non_implicitly_copyable_typarams",
LintSpec {
lint: non_implicitly_copyable_typarams,
desc: "passing non implicitly copyable types as copy type params",
default: warn
}),
(@~"vecs_implicitly_copyable",
@LintSpec {
(~"vecs_implicitly_copyable",
LintSpec {
lint: vecs_implicitly_copyable,
desc: "make vecs and strs not implicitly copyable \
(only checked at top level)",
default: warn
}),
(@~"implicit_copies",
@LintSpec {
(~"implicit_copies",
LintSpec {
lint: implicit_copies,
desc: "implicit copies of non implicitly copyable data",
default: warn
}),
(@~"deprecated_mode",
@LintSpec {
(~"deprecated_mode",
LintSpec {
lint: deprecated_mode,
desc: "warn about deprecated uses of modes",
default: warn
}),
(@~"foreign_mode",
@LintSpec {
(~"foreign_mode",
LintSpec {
lint: foreign_mode,
desc: "warn about deprecated uses of modes in foreign fns",
default: warn
}),
(@~"deprecated_pattern",
@LintSpec {
(~"deprecated_pattern",
LintSpec {
lint: deprecated_pattern,
desc: "warn about deprecated uses of pattern bindings",
default: allow
}),
(@~"non_camel_case_types",
@LintSpec {
(~"non_camel_case_types",
LintSpec {
lint: non_camel_case_types,
desc: "types, variants and traits should have camel case names",
default: allow
}),
(@~"managed_heap_memory",
@LintSpec {
(~"managed_heap_memory",
LintSpec {
lint: managed_heap_memory,
desc: "use of managed (@ type) heap memory",
default: allow
}),
(@~"owned_heap_memory",
@LintSpec {
(~"owned_heap_memory",
LintSpec {
lint: owned_heap_memory,
desc: "use of owned (~ type) heap memory",
default: allow
}),
(@~"heap_memory",
@LintSpec {
(~"heap_memory",
LintSpec {
lint: heap_memory,
desc: "use of any (~ type or @ type) heap memory",
default: allow
}),
(@~"legacy modes",
@LintSpec {
(~"legacy modes",
LintSpec {
lint: legacy_modes,
desc: "allow legacy modes",
default: forbid
}),
(@~"type_limits",
@LintSpec {
(~"type_limits",
LintSpec {
lint: type_limits,
desc: "comparisons made useless by limits of the types involved",
default: warn
}),
(@~"default_methods",
@LintSpec {
(~"default_methods",
LintSpec {
lint: default_methods,
desc: "allow default methods",
default: deny
}),
(@~"deprecated_mutable_fields",
@LintSpec {
(~"deprecated_mutable_fields",
LintSpec {
lint: deprecated_mutable_fields,
desc: "deprecated mutable fields in structures",
default: deny
}),
(@~"deprecated_drop",
@LintSpec {
(~"deprecated_drop",
LintSpec {
lint: deprecated_drop,
desc: "deprecated \"drop\" notation for the destructor",
default: deny
@ -275,12 +274,16 @@ pub fn get_lint_dict() -> LintDict {
}),
*/
];
oldmap::hash_from_vec(v)
let mut map = LinearMap::new();
do vec::consume(v) |_, (k, v)| {
map.insert(k, v);
}
return @map;
}
// This is a highly not-optimal set of data structure decisions.
type LintModes = @mut SmallIntMap<level>;
type LintModeMap = HashMap<ast::node_id, LintModes>;
type LintModeMap = @mut LinearMap<ast::node_id, LintModes>;
// settings_map maps node ids of items with non-default lint settings
// to their settings; default_settings contains the settings for everything
@ -293,7 +296,7 @@ pub struct LintSettings {
pub fn mk_lint_settings() -> LintSettings {
LintSettings {
default_settings: @mut SmallIntMap::new(),
settings_map: HashMap()
settings_map: @mut LinearMap::new()
}
}
@ -310,7 +313,7 @@ pub fn get_lint_settings_level(settings: LintSettings,
item_id: ast::node_id)
-> level {
match settings.settings_map.find(&item_id) {
Some(modes) => get_lint_level(modes, lint_mode),
Some(&modes) => get_lint_level(modes, lint_mode),
None => get_lint_level(settings.default_settings, lint_mode)
}
}
@ -392,7 +395,7 @@ pub impl Context {
(ref meta, level, lintname) => (meta, level, lintname)
};
match self.dict.find(&lintname) {
match self.dict.find(lintname) {
None => {
self.span_lint(
new_ctxt.get_level(unrecognized_lint),
@ -735,7 +738,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node {
ast::ty_path(_, id) => {
match cx.def_map.get(&id) {
match *cx.def_map.get(&id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.sess.span_lint(
ctypes, id, fn_id,

View file

@ -112,13 +112,13 @@ use middle::moves;
use util::ppaux::ty_to_str;
use core::cmp;
use core::hashmap::linear::LinearMap;
use core::io::WriterUtil;
use core::io;
use core::ptr;
use core::to_str;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::*;
use syntax::codemap::span;
use syntax::parse::token::special_idents;
@ -135,7 +135,7 @@ use syntax::{visit, ast_util};
//
// Very subtle (#2633): borrowck will remove entries from this table
// if it detects an outstanding loan (that is, the addr is taken).
pub type last_use_map = HashMap<node_id, @mut ~[node_id]>;
pub type last_use_map = @mut LinearMap<node_id, @mut ~[node_id]>;
struct Variable(uint);
struct LiveNode(uint);
@ -212,7 +212,7 @@ pub fn check_crate(tcx: ty::ctxt,
.. *visit::default_visitor()
});
let last_use_map = HashMap();
let last_use_map = @mut LinearMap::new();
let initial_maps = @mut IrMaps(tcx,
method_map,
variable_moves_map,
@ -304,9 +304,9 @@ struct IrMaps {
num_live_nodes: uint,
num_vars: uint,
live_node_map: HashMap<node_id, LiveNode>,
variable_map: HashMap<node_id, Variable>,
capture_info_map: HashMap<node_id, @~[CaptureInfo]>,
live_node_map: LinearMap<node_id, LiveNode>,
variable_map: LinearMap<node_id, Variable>,
capture_info_map: LinearMap<node_id, @~[CaptureInfo]>,
var_kinds: ~[VarKind],
lnks: ~[LiveNodeKind],
}
@ -325,9 +325,9 @@ fn IrMaps(tcx: ty::ctxt,
last_use_map: last_use_map,
num_live_nodes: 0,
num_vars: 0,
live_node_map: HashMap(),
variable_map: HashMap(),
capture_info_map: HashMap(),
live_node_map: LinearMap::new(),
variable_map: LinearMap::new(),
capture_info_map: LinearMap::new(),
var_kinds: ~[],
lnks: ~[]
}
@ -374,7 +374,7 @@ pub impl IrMaps {
fn variable(&mut self, node_id: node_id, span: span) -> Variable {
match self.variable_map.find(&node_id) {
Some(var) => var,
Some(&var) => var,
None => {
self.tcx.sess.span_bug(
span, fmt!("No variable registered for id %d", node_id));
@ -396,7 +396,7 @@ pub impl IrMaps {
fn captures(&mut self, expr: @expr) -> @~[CaptureInfo] {
match self.capture_info_map.find(&expr.id) {
Some(caps) => caps,
Some(&caps) => caps,
None => {
self.tcx.sess.span_bug(expr.span, ~"no registered caps");
}
@ -416,7 +416,7 @@ pub impl IrMaps {
Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) |
Local(LocalInfo {id: id, kind: FromMatch(_), _}) => {
let v = match self.last_use_map.find(&expr_id) {
Some(v) => v,
Some(&v) => v,
None => {
let v = @mut ~[];
self.last_use_map.insert(expr_id, v);
@ -562,7 +562,7 @@ fn visit_expr(expr: @expr, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) {
match expr.node {
// live nodes required for uses or definitions of variables:
expr_path(_) => {
let def = self.tcx.def_map.get(&expr.id);
let def = *self.tcx.def_map.get(&expr.id);
debug!("expr %d: path that leads to %?", expr.id, def);
if relevant_def(def).is_some() {
self.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -657,7 +657,7 @@ static ACC_READ: uint = 1u;
static ACC_WRITE: uint = 2u;
static ACC_USE: uint = 4u;
type LiveNodeMap = HashMap<node_id, LiveNode>;
type LiveNodeMap = @mut LinearMap<node_id, LiveNode>;
struct Liveness {
tcx: ty::ctxt,
@ -684,15 +684,16 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
users: @mut vec::from_elem(ir.num_live_nodes * ir.num_vars,
invalid_users()),
loop_scope: @mut ~[],
break_ln: HashMap(),
cont_ln: HashMap()
break_ln: @mut LinearMap::new(),
cont_ln: @mut LinearMap::new()
}
}
pub impl Liveness {
fn live_node(&self, node_id: node_id, span: span) -> LiveNode {
match self.ir.live_node_map.find(&node_id) {
Some(ln) => ln,
let ir: &mut IrMaps = self.ir;
match ir.live_node_map.find(&node_id) {
Some(&ln) => ln,
None => {
// This must be a mismatch between the ir_map construction
// above and the propagation code below; the two sets of
@ -708,7 +709,7 @@ pub impl Liveness {
fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
match expr.node {
expr_path(_) => {
let def = self.tcx.def_map.get(&expr.id);
let def = *self.tcx.def_map.get(&expr.id);
relevant_def(def).map(
|rdef| self.variable(*rdef, expr.span)
)
@ -724,7 +725,7 @@ pub impl Liveness {
fn variable_from_def_map(&self, node_id: node_id,
span: span) -> Option<Variable> {
match self.tcx.def_map.find(&node_id) {
Some(def) => {
Some(&def) => {
relevant_def(def).map(
|rdef| self.variable(*rdef, span)
)
@ -845,7 +846,7 @@ pub impl Liveness {
Some(_) => // Refers to a labeled loop. Use the results of resolve
// to find with one
match self.tcx.def_map.find(&id) {
Some(def_label(loop_id)) => loop_id,
Some(&def_label(loop_id)) => loop_id,
_ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \
doesn't refer to a loop")
},
@ -1226,7 +1227,7 @@ pub impl Liveness {
// look it up in the break loop nodes table
match self.break_ln.find(&sc) {
Some(b) => b,
Some(&b) => b,
None => self.tcx.sess.span_bug(expr.span,
~"Break to unknown label")
}
@ -1240,7 +1241,7 @@ pub impl Liveness {
// look it up in the continue loop nodes table
match self.cont_ln.find(&sc) {
Some(b) => b,
Some(&b) => b,
None => self.tcx.sess.span_bug(expr.span,
~"Loop to unknown label")
}
@ -1448,7 +1449,7 @@ pub impl Liveness {
fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
-> LiveNode {
let def = self.tcx.def_map.get(&expr.id);
let def = *self.tcx.def_map.get(&expr.id);
match relevant_def(def) {
Some(nid) => {
let ln = self.live_node(expr.id, expr.span);
@ -1587,7 +1588,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
match self.ir.variable_moves_map.find(&expr.id) {
None => {}
Some(entire_expr) => {
Some(&entire_expr) => {
debug!("(checking expr) is a move: `%s`",
expr_to_str(expr, self.tcx.sess.intr()));
self.check_move_from_var(ln, *var, entire_expr);
@ -1723,7 +1724,7 @@ pub impl Liveness {
fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) {
match expr.node {
expr_path(_) => {
match self.tcx.def_map.get(&expr.id) {
match *self.tcx.def_map.get(&expr.id) {
def_local(nid, false) => {
// Assignment to an immutable variable or argument:
// only legal if there is no later assignment.

View file

@ -359,7 +359,7 @@ pub impl mem_categorization_ctxt {
self.cat_expr_unadjusted(expr)
}
Some(@ty::AutoAddEnv(*)) => {
Some(&@ty::AutoAddEnv(*)) => {
// Convert a bare fn to a closure by adding NULL env.
// Result is an rvalue.
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
@ -367,7 +367,7 @@ pub impl mem_categorization_ctxt {
}
Some(
@ty::AutoDerefRef(
&@ty::AutoDerefRef(
ty::AutoDerefRef {
autoref: Some(_), _})) => {
// Equivalent to &*expr or something similar.
@ -377,7 +377,7 @@ pub impl mem_categorization_ctxt {
}
Some(
@ty::AutoDerefRef(
&@ty::AutoDerefRef(
ty::AutoDerefRef {
autoref: None, autoderefs: autoderefs})) => {
// Equivalent to *expr or something similar.
@ -431,7 +431,7 @@ pub impl mem_categorization_ctxt {
}
ast::expr_path(_) => {
let def = self.tcx.def_map.get(&expr.id);
let def = *self.tcx.def_map.get(&expr.id);
self.cat_def(expr.id, expr.span, expr_ty, def)
}
@ -902,21 +902,21 @@ pub impl mem_categorization_ctxt {
}
ast::pat_enum(_, Some(ref subpats)) => {
match self.tcx.def_map.find(&pat.id) {
Some(ast::def_variant(enum_did, _)) => {
Some(&ast::def_variant(enum_did, _)) => {
// variant(x, y, z)
for subpats.each |subpat| {
let subcmt = self.cat_variant(*subpat, enum_did, cmt);
self.cat_pattern(subcmt, *subpat, op);
}
}
Some(ast::def_struct(*)) => {
Some(&ast::def_struct(*)) => {
for subpats.each |subpat| {
let cmt_field = self.cat_anon_struct_field(*subpat,
cmt);
self.cat_pattern(cmt_field, *subpat, op);
}
}
Some(ast::def_const(*)) => {
Some(&ast::def_const(*)) => {
for subpats.each |subpat| {
self.cat_pattern(cmt, *subpat, op);
}
@ -1124,7 +1124,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
}
}
ty::ty_enum(*) => {
match tcx.def_map.get(&node_id) {
match *tcx.def_map.get(&node_id) {
ast::def_variant(_, variant_id) => {
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
if fld.ident == f_name {

View file

@ -216,8 +216,8 @@ use middle::typeck::check::{DerefArgs, DoDerefArgs, DontDerefArgs};
use util::ppaux;
use util::common::indenter;
use core::hashmap::linear::{LinearSet, LinearMap};
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::*;
use syntax::ast_util;
use syntax::visit;
@ -242,14 +242,14 @@ pub struct CaptureVar {
mode: CaptureMode // How variable is being accessed
}
pub type CaptureMap = HashMap<node_id, @[CaptureVar]>;
pub type CaptureMap = @mut LinearMap<node_id, @[CaptureVar]>;
pub type MovesMap = HashMap<node_id, ()>;
pub type MovesMap = @mut LinearSet<node_id>;
/**
* For each variable which will be moved, links to the
* expression */
pub type VariableMovesMap = HashMap<node_id, @expr>;
pub type VariableMovesMap = @mut LinearMap<node_id, @expr>;
/** See the section Output on the module comment for explanation. */
pub struct MoveMaps {
@ -260,7 +260,7 @@ pub struct MoveMaps {
struct VisitContext {
tcx: ty::ctxt,
method_map: HashMap<node_id,method_map_entry>,
method_map: method_map,
move_maps: MoveMaps
}
@ -282,9 +282,9 @@ pub fn compute_moves(tcx: ty::ctxt,
tcx: tcx,
method_map: method_map,
move_maps: MoveMaps {
moves_map: HashMap(),
variable_moves_map: HashMap(),
capture_map: HashMap()
moves_map: @mut LinearSet::new(),
variable_moves_map: @mut LinearMap::new(),
capture_map: @mut LinearMap::new()
}
};
visit::visit_crate(*crate, visit_cx, visitor);
@ -402,7 +402,7 @@ pub impl VisitContext {
expr_mode);
match expr_mode {
MoveInWhole => { self.move_maps.moves_map.insert(expr.id, ()); }
MoveInWhole => { self.move_maps.moves_map.insert(expr.id); }
MoveInPart(_) | Read => {}
}
@ -410,7 +410,7 @@ pub impl VisitContext {
// those adjustments is to take a reference, then it's only
// reading the underlying expression, not moving it.
let comp_mode = match self.tcx.adjustments.find(&expr.id) {
Some(@ty::AutoDerefRef(
Some(&@ty::AutoDerefRef(
ty::AutoDerefRef {
autoref: Some(_), _})) => Read,
_ => expr_mode.component_mode(expr)
@ -725,7 +725,7 @@ pub impl VisitContext {
};
match mode {
MoveInWhole => { self.move_maps.moves_map.insert(id, ()); }
MoveInWhole => { self.move_maps.moves_map.insert(id); }
MoveInPart(_) | Read => {}
}
}
@ -795,7 +795,7 @@ pub impl VisitContext {
for arm.pats.each |pat| {
let mut found = false;
do pat_bindings(self.tcx.def_map, *pat) |_, node_id, _, _| {
if moves_map.contains_key(&node_id) {
if moves_map.contains(&node_id) {
found = true;
}
}

View file

@ -12,17 +12,17 @@ use core::prelude::*;
use middle::resolve;
use core::hashmap::linear::LinearMap;
use syntax::ast::*;
use syntax::ast_util::{path_to_ident, walk_pat};
use syntax::codemap::{span, respan};
use std::oldmap::HashMap;
pub type PatIdMap = HashMap<ident, node_id>;
pub type PatIdMap = LinearMap<ident, node_id>;
// This is used because same-named variables in alternative patterns need to
// use the node_id of their namesake in the first pattern.
pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap {
let map = HashMap();
let mut map = LinearMap::new();
do pat_bindings(dm, pat) |_bm, p_id, _s, n| {
map.insert(path_to_ident(n), p_id);
};
@ -33,7 +33,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
match pat.node {
pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => {
match dm.find(&pat.id) {
Some(def_variant(*)) | Some(def_struct(*)) => true,
Some(&def_variant(*)) | Some(&def_struct(*)) => true,
_ => false
}
}
@ -45,7 +45,7 @@ pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
match pat.node {
pat_ident(_, _, None) | pat_enum(*) => {
match dm.find(&pat.id) {
Some(def_const(*)) => true,
Some(&def_const(*)) => true,
_ => false
}
}

View file

@ -113,8 +113,8 @@ pub fn check_crate(tcx: ty::ctxt,
@fn(span: span, method_id: node_id) -> def_id =
|span, method_id| {
match tcx.items.find(&method_id) {
Some(node_method(_, impl_id, _)) => impl_id,
Some(node_trait_method(_, trait_id, _)) => trait_id,
Some(&node_method(_, impl_id, _)) => impl_id,
Some(&node_trait_method(_, trait_id, _)) => trait_id,
Some(_) => {
tcx.sess.span_bug(span,
fmt!("method was a %s?!",
@ -148,7 +148,7 @@ pub fn check_crate(tcx: ty::ctxt,
}
match tcx.items.find(&container_id.node) {
Some(node_item(item, _)) => {
Some(&node_item(item, _)) => {
match item.node {
item_impl(_, None, _, _)
if item.vis != public => {
@ -170,10 +170,10 @@ pub fn check_crate(tcx: ty::ctxt,
};
match tcx.items.find(&method_id) {
Some(node_method(method, impl_id, _)) => {
Some(&node_method(method, impl_id, _)) => {
check(method.vis, impl_id)
}
Some(node_trait_method(trait_method, trait_id, _)) => {
Some(&node_trait_method(trait_method, trait_id, _)) => {
match *trait_method {
required(_) => check(public, trait_id),
provided(method) => check(method.vis, trait_id),
@ -200,16 +200,16 @@ pub fn check_crate(tcx: ty::ctxt,
let mut f: &fn(node_id) -> bool = |_| false;
f = |item_id| {
match tcx.items.find(&item_id) {
Some(node_item(item, _)) => item.vis != public,
Some(node_foreign_item(_, _, vis, _)) => vis != public,
Some(node_method(method, impl_did, _)) => {
Some(&node_item(item, _)) => item.vis != public,
Some(&node_foreign_item(_, _, vis, _)) => vis != public,
Some(&node_method(method, impl_did, _)) => {
match method.vis {
private => true,
public => false,
inherited => f(impl_did.node)
}
}
Some(node_trait_method(_, trait_did, _)) => f(trait_did.node),
Some(&node_trait_method(_, trait_did, _)) => f(trait_did.node),
Some(_) => {
tcx.sess.span_bug(span,
fmt!("local_item_is_private: item was \
@ -332,7 +332,7 @@ pub fn check_crate(tcx: ty::ctxt,
method_super(trait_id, method_num) => {
if trait_id.crate == local_crate {
match tcx.items.find(&trait_id.node) {
Some(node_item(item, _)) => {
Some(&node_item(item, _)) => {
match item.node {
item_trait(_, _, ref methods) => {
if method_num >= (*methods).len() {
@ -484,7 +484,7 @@ pub fn check_crate(tcx: ty::ctxt,
}
}
expr_path(path) => {
check_path(expr.span, tcx.def_map.get(&expr.id), path);
check_path(expr.span, *tcx.def_map.get(&expr.id), path);
}
expr_struct(_, ref fields, _) => {
match ty::get(ty::expr_ty(tcx, expr)).sty {
@ -502,7 +502,7 @@ pub fn check_crate(tcx: ty::ctxt,
ty_enum(id, _) => {
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) {
match tcx.def_map.get(&expr.id) {
match *tcx.def_map.get(&expr.id) {
def_variant(_, variant_id) => {
for (*fields).each |field| {
debug!("(privacy checking) \
@ -570,7 +570,7 @@ pub fn check_crate(tcx: ty::ctxt,
!privileged_items.contains(
&enum_id.node) {
match tcx.def_map.find(&pattern.id) {
Some(def_variant(_, variant_id)) => {
Some(&def_variant(_, variant_id)) => {
for fields.each |field| {
debug!("(privacy checking) \
checking field in \

View file

@ -26,8 +26,8 @@ use middle::ty::{region_variance, rv_covariant, rv_invariant};
use middle::ty::{rv_contravariant};
use middle::ty;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::vec;
use std::oldmap::HashMap;
use syntax::ast_map;
use syntax::codemap::span;
use syntax::print::pprust;
@ -46,7 +46,7 @@ Encodes the bounding lifetime for a given AST node:
- Variables and bindings are mapped to the block in which they are declared.
*/
pub type region_map = HashMap<ast::node_id, ast::node_id>;
pub type region_map = @mut LinearMap<ast::node_id, ast::node_id>;
pub struct ctxt {
sess: Session,
@ -62,7 +62,7 @@ pub struct ctxt {
// the condition in a while loop is always a parent. In those
// cases, we add the node id of such an expression to this set so
// that when we visit it we can view it as a parent.
root_exprs: HashMap<ast::node_id, ()>,
root_exprs: @mut LinearSet<ast::node_id>,
// The parent scope is the innermost block, statement, call, or match
// expression during the execution of which the current expression
@ -106,7 +106,7 @@ pub fn scope_contains(region_map: region_map, superscope: ast::node_id,
while superscope != subscope {
match region_map.find(&subscope) {
None => return false,
Some(scope) => subscope = scope
Some(&scope) => subscope = scope
}
}
return true;
@ -150,7 +150,7 @@ pub fn nearest_common_ancestor(region_map: region_map,
loop {
match region_map.find(&scope) {
None => return result,
Some(superscope) => {
Some(&superscope) => {
result.push(superscope);
scope = superscope;
}
@ -228,7 +228,7 @@ pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
ast::pat_ident(*) => {
let defn_opt = cx.def_map.find(&pat.id);
match defn_opt {
Some(ast::def_variant(_,_)) => {
Some(&ast::def_variant(_,_)) => {
/* Nothing to do; this names a variant. */
}
_ => {
@ -280,12 +280,12 @@ pub fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
new_cx.parent = Some(expr.id);
}
ast::expr_while(cond, _) => {
new_cx.root_exprs.insert(cond.id, ());
new_cx.root_exprs.insert(cond.id);
}
_ => {}
};
if new_cx.root_exprs.contains_key(&expr.id) {
if new_cx.root_exprs.contains(&expr.id) {
new_cx.parent = Some(expr.id);
}
@ -350,8 +350,8 @@ pub fn resolve_crate(sess: Session,
-> region_map {
let cx: ctxt = ctxt {sess: sess,
def_map: def_map,
region_map: HashMap(),
root_exprs: HashMap(),
region_map: @mut LinearMap::new(),
root_exprs: @mut LinearSet::new(),
parent: None};
let visitor = visit::mk_vt(@visit::Visitor {
visit_block: resolve_block,
@ -387,7 +387,7 @@ pub fn resolve_crate(sess: Session,
// a worklist. We can then process the worklist, propagating indirect
// dependencies until a fixed point is reached.
pub type region_paramd_items = HashMap<ast::node_id, region_variance>;
pub type region_paramd_items = @mut LinearMap<ast::node_id, region_variance>;
#[deriving(Eq)]
pub struct region_dep {
@ -395,7 +395,7 @@ pub struct region_dep {
id: ast::node_id
}
pub type dep_map = HashMap<ast::node_id, @mut ~[region_dep]>;
pub type dep_map = @mut LinearMap<ast::node_id, @mut ~[region_dep]>;
pub struct DetermineRpCtxt {
sess: Session,
@ -464,7 +464,8 @@ pub impl DetermineRpCtxt {
/// the new variance is joined with the old variance.
fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
fail_unless!(id != 0);
let old_variance = self.region_paramd_items.find(&id);
let old_variance = self.region_paramd_items.find(&id).
map_consume(|x| *x);
let joined_variance = match old_variance {
None => variance,
Some(v) => join_variance(v, variance)
@ -496,7 +497,7 @@ pub impl DetermineRpCtxt {
self.sess.parse_sess.interner),
copy self.ambient_variance);
let vec = match self.dep_map.find(&from) {
Some(vec) => vec,
Some(&vec) => vec,
None => {
let vec = @mut ~[];
let dep_map = self.dep_map;
@ -689,7 +690,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
match ty.node {
ast::ty_path(path, id) => {
match cx.def_map.find(&id) {
Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => {
Some(&ast::def_ty(did)) | Some(&ast::def_struct(did)) => {
if did.crate == ast::local_crate {
if cx.region_is_relevant(path.rp) {
cx.add_dep(did.node);
@ -782,15 +783,15 @@ pub fn determine_rp_in_struct_field(
pub fn determine_rp_in_crate(sess: Session,
ast_map: ast_map::map,
def_map: resolve::DefMap,
+def_map: resolve::DefMap,
crate: @ast::crate)
-> region_paramd_items {
let cx = @mut DetermineRpCtxt {
sess: sess,
ast_map: ast_map,
def_map: def_map,
region_paramd_items: HashMap(),
dep_map: HashMap(),
region_paramd_items: @mut LinearMap::new(),
dep_map: @mut LinearMap::new(),
worklist: ~[],
item_id: 0,
anon_implies_rp: false,
@ -822,7 +823,7 @@ pub fn determine_rp_in_crate(sess: Session,
let cx = &mut *cx;
while cx.worklist.len() != 0 {
let c_id = cx.worklist.pop();
let c_variance = cx.region_paramd_items.get(&c_id);
let c_variance = *cx.region_paramd_items.get(&c_id);
debug!("popped %d from worklist", c_id);
match cx.dep_map.find(&c_id) {
None => {}
@ -839,7 +840,7 @@ pub fn determine_rp_in_crate(sess: Session,
debug!("%s", {
debug!("Region variance results:");
let region_paramd_items = cx.region_paramd_items;
for region_paramd_items.each |&key, &value| {
for region_paramd_items.each |&(&key, &value)| {
debug!("item %? (%s) is parameterized with variance %?",
key,
ast_map::node_id_to_str(ast_map, key,

View file

@ -77,11 +77,10 @@ use syntax::opt_vec::OptVec;
use core::option::{Some, get, is_some, is_none};
use core::str::{connect, each_split_str};
use core::hashmap::linear::LinearMap;
use std::oldmap::HashMap;
use core::hashmap::linear::{LinearMap, LinearSet};
// Definition mapping
pub type DefMap = HashMap<node_id,def>;
pub type DefMap = @mut LinearMap<node_id,def>;
pub struct binding_info {
span: span,
@ -89,7 +88,7 @@ pub struct binding_info {
}
// Map from the name in a pattern to its binding mode.
pub type BindingMap = HashMap<ident,binding_info>;
pub type BindingMap = LinearMap<ident,binding_info>;
// Implementation resolution
//
@ -110,11 +109,11 @@ pub struct Impl {
}
// Trait method resolution
pub type TraitMap = @HashMap<node_id,@mut ~[def_id]>;
pub type TraitMap = LinearMap<node_id,@mut ~[def_id]>;
// This is the replacement export map. It maps a module to all of the exports
// within.
pub type ExportMap2 = HashMap<node_id, ~[Export2]>;
pub type ExportMap2 = @mut LinearMap<node_id, ~[Export2]>;
pub struct Export2 {
name: @~str, // The name of the target.
@ -335,13 +334,13 @@ pub fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode)
/// One local scope.
pub struct Rib {
bindings: HashMap<ident,def_like>,
bindings: @mut LinearMap<ident,def_like>,
kind: RibKind,
}
pub fn Rib(kind: RibKind) -> Rib {
Rib {
bindings: HashMap(),
bindings: @mut LinearMap::new(),
kind: kind
}
}
@ -475,7 +474,7 @@ pub struct Module {
// There will be an anonymous module created around `g` with the ID of the
// entry block for `f`.
anonymous_children: @HashMap<node_id,@mut Module>,
anonymous_children: @mut LinearMap<node_id,@mut Module>,
// The status of resolving each import in this module.
import_resolutions: @mut LinearMap<ident, @mut ImportResolution>,
@ -497,7 +496,7 @@ pub fn Module(parent_link: ParentLink,
kind: kind,
children: @mut LinearMap::new(),
imports: @mut ~[],
anonymous_children: @HashMap(),
anonymous_children: @mut LinearMap::new(),
import_resolutions: @mut LinearMap::new(),
glob_count: 0,
resolved_import_count: 0
@ -709,11 +708,11 @@ pub fn NameBindings() -> NameBindings {
/// Interns the names of the primitive types.
pub struct PrimitiveTypeTable {
primitive_types: HashMap<ident,prim_ty>,
primitive_types: LinearMap<ident,prim_ty>,
}
pub impl PrimitiveTypeTable {
fn intern(&self, intr: @ident_interner, string: @~str,
fn intern(&mut self, intr: @ident_interner, string: @~str,
primitive_type: prim_ty) {
let ident = intr.intern(string);
self.primitive_types.insert(ident, primitive_type);
@ -721,8 +720,8 @@ pub impl PrimitiveTypeTable {
}
pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
let table = PrimitiveTypeTable {
primitive_types: HashMap()
let mut table = PrimitiveTypeTable {
primitive_types: LinearMap::new()
};
table.intern(intr, @~"bool", ty_bool);
@ -777,8 +776,8 @@ pub fn Resolver(session: Session,
graph_root: graph_root,
trait_info: @HashMap(),
structs: @HashMap(),
trait_info: LinearMap::new(),
structs: LinearSet::new(),
unresolved_imports: 0,
@ -801,9 +800,9 @@ pub fn Resolver(session: Session,
attr_main_fn: None,
main_fns: ~[],
def_map: @HashMap(),
export_map2: @HashMap(),
trait_map: @HashMap(),
def_map: @mut LinearMap::new(),
export_map2: @mut LinearMap::new(),
trait_map: LinearMap::new(),
intr: session.intr()
};
@ -821,8 +820,8 @@ pub struct Resolver {
graph_root: @mut NameBindings,
trait_info: @HashMap<def_id,@HashMap<ident,()>>,
structs: @HashMap<def_id,()>,
trait_info: LinearMap<def_id, LinearSet<ident>>,
structs: LinearSet<def_id>,
// The number of imports that are currently unresolved.
unresolved_imports: uint,
@ -863,8 +862,8 @@ pub struct Resolver {
// The functions named 'main'
main_fns: ~[Option<(node_id, span)>],
def_map: @DefMap,
export_map2: @ExportMap2,
def_map: DefMap,
export_map2: ExportMap2,
trait_map: TraitMap,
}
@ -1192,7 +1191,7 @@ pub impl Resolver {
}
// Record the def ID of this struct.
self.structs.insert(local_def(item.id), ());
self.structs.insert(local_def(item.id));
visit_item(item, new_parent, visitor);
}
@ -1305,8 +1304,8 @@ pub impl Resolver {
}
// Add the names of all the methods to the trait info.
let method_names = @HashMap();
for (*methods).each |method| {
let mut method_names = LinearSet::new();
for methods.each |method| {
let ty_m = trait_method_to_ty_method(method);
let ident = ty_m.ident;
@ -1329,7 +1328,7 @@ pub impl Resolver {
ty_m.span);
}
_ => {
method_names.insert(ident, ());
method_names.insert(ident);
}
}
}
@ -1378,7 +1377,7 @@ pub impl Resolver {
def_variant(item_id,
local_def(variant.node.id)),
variant.span);
self.structs.insert(local_def(variant.node.id), ());
self.structs.insert(local_def(variant.node.id));
}
enum_variant_kind(ref enum_definition) => {
child.define_type(privacy,
@ -1565,7 +1564,7 @@ pub impl Resolver {
fn handle_external_def(@mut self,
def: def,
modules: HashMap<def_id, @mut Module>,
modules: &mut LinearMap<def_id, @mut Module>,
child_name_bindings: @mut NameBindings,
final_ident: &str,
ident: ident,
@ -1585,8 +1584,8 @@ pub impl Resolver {
%s", final_ident);
let parent_link = self.get_parent_link(new_parent, ident);
match modules.find(&def_id) {
None => {
// FIXME (#5074): this should be a match on find
if !modules.contains_key(&def_id) {
child_name_bindings.define_module(Public,
parent_link,
Some(def_id),
@ -1594,8 +1593,8 @@ pub impl Resolver {
dummy_sp());
modules.insert(def_id,
child_name_bindings.get_module());
}
Some(existing_module) => {
} else {
let existing_module = *modules.get(&def_id);
// Create an import resolution to
// avoid creating cycles in the
// module graph.
@ -1623,7 +1622,6 @@ pub impl Resolver {
... creating import resolution");
new_parent.import_resolutions.insert(ident, resolution);
}
}
}
}
@ -1646,7 +1644,7 @@ pub impl Resolver {
// Nothing to do.
}
Some(method_names) => {
let interned_method_names = @HashMap();
let mut interned_method_names = LinearSet::new();
for method_names.each |method_data| {
let (method_name, self_ty) = *method_data;
debug!("(building reduced graph for \
@ -1656,7 +1654,7 @@ pub impl Resolver {
// Add it to the trait info if not static.
if self_ty != sty_static {
interned_method_names.insert(method_name, ());
interned_method_names.insert(method_name);
}
}
self.trait_info.insert(def_id, interned_method_names);
@ -1670,7 +1668,7 @@ pub impl Resolver {
crate) building type %s",
final_ident);
child_name_bindings.define_type(Public, def, dummy_sp());
self.structs.insert(def_id, ());
self.structs.insert(def_id);
}
def_self(*) | def_arg(*) | def_local(*) |
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
@ -1686,7 +1684,7 @@ pub impl Resolver {
* crate.
*/
fn build_reduced_graph_for_external_crate(@mut self, root: @mut Module) {
let modules = HashMap();
let mut modules = LinearMap::new();
// Create all the items reachable by paths.
for each_path(self.session.cstore, root.def_id.get().crate)
@ -1758,7 +1756,7 @@ pub impl Resolver {
dummy_sp());
self.handle_external_def(def,
modules,
&mut modules,
child_name_bindings,
*self.session.str_of(
final_ident),
@ -3338,8 +3336,9 @@ pub impl Resolver {
// If the def is a ty param, and came from the parent
// item, it's ok
match def {
def_ty_param(did, _) if self.def_map.find(&did.node)
== Some(def_typaram_binder(item_id)) => {
def_ty_param(did, _)
if self.def_map.find(&did.node).map_consume(|x| *x)
== Some(def_typaram_binder(item_id)) => {
// ok
}
_ => {
@ -3412,7 +3411,7 @@ pub impl Resolver {
while i != 0 {
i -= 1;
match ribs[i].bindings.find(&name) {
Some(def_like) => {
Some(&def_like) => {
return self.upvarify(ribs, i, def_like, span,
allow_capturing_self);
}
@ -3995,8 +3994,8 @@ pub impl Resolver {
}
fn binding_mode_map(@mut self, pat: @pat) -> BindingMap {
let result = HashMap();
do pat_bindings(*self.def_map, pat) |binding_mode, _id, sp, path| {
let mut result = LinearMap::new();
do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| {
let ident = path_to_ident(path);
result.insert(ident,
binding_info {span: sp,
@ -4011,7 +4010,7 @@ pub impl Resolver {
for arm.pats.eachi() |i, p| {
let map_i = self.binding_mode_map(*p);
for map_0.each |&key, &binding_0| {
for map_0.each |&(&key, &binding_0)| {
match map_i.find(&key) {
None => {
self.session.span_err(
@ -4032,7 +4031,7 @@ pub impl Resolver {
}
}
for map_i.each |&key, &binding| {
for map_i.each |&(&key, &binding)| {
if !map_0.contains_key(&key) {
self.session.span_err(
binding.span,
@ -4047,7 +4046,7 @@ pub impl Resolver {
fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) {
self.value_ribs.push(@Rib(NormalRibKind));
let bindings_list = HashMap();
let bindings_list = @mut LinearMap::new();
for arm.pats.each |pattern| {
self.resolve_pattern(*pattern, RefutableMode, Immutable,
Some(bindings_list), visitor);
@ -4071,7 +4070,7 @@ pub impl Resolver {
let orig_module = self.current_module;
match self.current_module.anonymous_children.find(&block.node.id) {
None => { /* Nothing to do. */ }
Some(anonymous_module) => {
Some(&anonymous_module) => {
debug!("(resolving block) found anonymous module, moving \
down");
self.current_module = anonymous_module;
@ -4106,7 +4105,7 @@ pub impl Resolver {
.primitive_types
.find(&name) {
Some(primitive_type) => {
Some(&primitive_type) => {
result_def =
Some(def_prim_ty(primitive_type));
}
@ -4167,7 +4166,7 @@ pub impl Resolver {
mutability: Mutability,
// Maps idents to the node ID for the (outermost)
// pattern that binds them
bindings_list: Option<HashMap<ident,node_id>>,
bindings_list: Option<@mut LinearMap<ident,node_id>>,
visitor: ResolveVisitor) {
let pat_id = pattern.id;
do walk_pat(pattern) |pattern| {
@ -4271,7 +4270,7 @@ pub impl Resolver {
bindings_list.insert(ident, pat_id);
}
Some(b) => {
if b.find(&ident) == Some(pat_id) {
if b.find(&ident) == Some(&pat_id) {
// Then this is a duplicate variable
// in the same disjunct, which is an
// error
@ -4371,21 +4370,19 @@ pub impl Resolver {
}
pat_struct(path, _, _) => {
let structs: &mut LinearSet<def_id> = &mut self.structs;
match self.resolve_path(path, TypeNS, false, visitor) {
Some(def_ty(class_id))
if self.structs.contains_key(&class_id)
=> {
if structs.contains(&class_id) => {
let class_def = def_struct(class_id);
self.record_def(pattern.id, class_def);
}
Some(definition @ def_struct(class_id))
if self.structs.contains_key(&class_id)
=> {
if structs.contains(&class_id) => {
self.record_def(pattern.id, definition);
}
Some(definition @ def_variant(_, variant_id))
if self.structs.contains_key(&variant_id)
=> {
if structs.contains(&variant_id) => {
self.record_def(pattern.id, definition);
}
result => {
@ -4869,14 +4866,15 @@ pub impl Resolver {
expr_struct(path, _, _) => {
// Resolve the path to the structure it goes to.
let structs: &mut LinearSet<def_id> = &mut self.structs;
match self.resolve_path(path, TypeNS, false, visitor) {
Some(def_ty(class_id)) | Some(def_struct(class_id))
if self.structs.contains_key(&class_id) => {
if structs.contains(&class_id) => {
let class_def = def_struct(class_id);
self.record_def(expr.id, class_def);
}
Some(definition @ def_variant(_, class_id))
if self.structs.contains_key(&class_id) => {
if structs.contains(&class_id) => {
self.record_def(expr.id, definition);
}
_ => {
@ -5095,7 +5093,7 @@ pub impl Resolver {
return found_traits;
}
fn add_trait_info_if_containing_method(@mut self,
fn add_trait_info_if_containing_method(&self,
found_traits: &mut ~[def_id],
trait_def_id: def_id,
name: ident)
@ -5107,7 +5105,7 @@ pub impl Resolver {
*self.session.str_of(name));
match self.trait_info.find(&trait_def_id) {
Some(trait_info) if trait_info.contains_key(&name) => {
Some(trait_info) if trait_info.contains(&name) => {
debug!("(adding trait info if containing method) found trait \
%d:%d for method '%s'",
trait_def_id.crate,
@ -5351,10 +5349,11 @@ pub fn resolve_crate(session: Session,
-> CrateMap {
let resolver = @mut Resolver(session, lang_items, crate);
resolver.resolve();
let @Resolver{def_map, export_map2, trait_map, _} = resolver;
CrateMap {
def_map: *resolver.def_map,
exp_map2: *resolver.export_map2,
trait_map: resolver.trait_map
def_map: def_map,
exp_map2: export_map2,
trait_map: trait_map
}
}

View file

@ -167,7 +167,7 @@ use middle::trans::type_of;
use middle::ty;
use util::common::indenter;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use syntax::ast;
use syntax::ast::ident;
use syntax::ast_util::path_to_ident;
@ -282,7 +282,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result {
pub fn variant_opt(bcx: block, pat_id: ast::node_id)
-> Opt {
let ccx = bcx.ccx();
match ccx.tcx.def_map.get(&pat_id) {
match *ccx.tcx.def_map.get(&pat_id) {
ast::def_variant(enum_id, var_id) => {
let variants = ty::enum_variants(ccx.tcx, enum_id);
for vec::each(*variants) |v| {
@ -323,7 +323,7 @@ pub struct BindingInfo {
ty: ty::t,
}
pub type BindingsMap = HashMap<ident, BindingInfo>;
pub type BindingsMap = LinearMap<ident, BindingInfo>;
pub struct ArmData {
bodycx: block,
@ -517,7 +517,7 @@ pub fn enter_opt<'r>(bcx: block,
match p.node {
ast::pat_enum(*) |
ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
let const_def = tcx.def_map.get(&p.id);
let const_def = *tcx.def_map.get(&p.id);
let const_def_id = ast_util::def_id_of_def(const_def);
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
Some(~[])
@ -553,7 +553,7 @@ pub fn enter_opt<'r>(bcx: block,
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
// Look up the struct variant ID.
let struct_id;
match tcx.def_map.get(&p.id) {
match *tcx.def_map.get(&p.id) {
ast::def_variant(_, found_struct_id) => {
struct_id = found_struct_id;
}
@ -801,15 +801,15 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
// This is one of: an enum variant, a unit-like struct, or a
// variable binding.
match ccx.tcx.def_map.find(&cur.id) {
Some(ast::def_variant(*)) => {
Some(&ast::def_variant(*)) => {
add_to_set(ccx.tcx, &mut found,
variant_opt(bcx, cur.id));
}
Some(ast::def_struct(*)) => {
Some(&ast::def_struct(*)) => {
add_to_set(ccx.tcx, &mut found,
lit(UnitLikeStructLit(cur.id)));
}
Some(ast::def_const(const_did)) => {
Some(&ast::def_const(const_did)) => {
add_to_set(ccx.tcx, &mut found,
lit(ConstLit(const_did)));
}
@ -820,11 +820,11 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
// This could be one of: a tuple-like enum variant, a
// struct-like enum variant, or a struct.
match ccx.tcx.def_map.find(&cur.id) {
Some(ast::def_variant(*)) => {
Some(&ast::def_variant(*)) => {
add_to_set(ccx.tcx, &mut found,
variant_opt(bcx, cur.id));
}
Some(ast::def_const(const_did)) => {
Some(&ast::def_const(const_did)) => {
add_to_set(ccx.tcx, &mut found,
lit(ConstLit(const_did)));
}
@ -959,7 +959,7 @@ pub fn root_pats_as_necessary(bcx: block,
let key = root_map_key {id: pat_id, derefs: 0u };
match bcx.ccx().maps.root_map.find(&key) {
None => (),
Some(root_info) => {
Some(&root_info) => {
// Note: the scope_id will always be the id of the match. See
// the extended comment in rustc::middle::borrowck::preserve()
// for details (look for the case covering cat_discr).
@ -1013,7 +1013,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
match pat.node {
ast::pat_enum(_, Some(_)) => {
match bcx.tcx().def_map.find(&pat.id) {
Some(ast::def_struct(*)) => true,
Some(&ast::def_struct(*)) => true,
_ => false
}
}
@ -1620,7 +1620,7 @@ pub fn trans_match_inner(scope_cx: block,
// to an alloca() that will be the value for that local variable.
// Note that we use the names because each binding will have many ids
// from the various alternatives.
let bindings_map = HashMap();
let mut bindings_map = LinearMap::new();
do pat_bindings(tcx.def_map, arm.pats[0]) |bm, p_id, _s, path| {
let ident = path_to_ident(path);
let variable_ty = node_id_type(bcx, p_id);
@ -1633,7 +1633,7 @@ pub fn trans_match_inner(scope_cx: block,
// but during matching we need to store a *T as explained
// above
let is_move =
scope_cx.ccx().maps.moves_map.contains_key(&p_id);
scope_cx.ccx().maps.moves_map.contains(&p_id);
llmatch = alloca(bcx, T_ptr(llvariable_ty));
trmode = TrByValue(is_move, alloca(bcx, llvariable_ty));
}
@ -1765,7 +1765,7 @@ pub fn bind_irrefutable_pat(bcx: block,
}
ast::pat_enum(_, ref sub_pats) => {
match bcx.tcx().def_map.find(&pat.id) {
Some(ast::def_variant(enum_id, var_id)) => {
Some(&ast::def_variant(enum_id, var_id)) => {
let repr = adt::represent_node(bcx, pat.id);
let vinfo = ty::enum_variant_with_id(ccx.tcx,
enum_id,
@ -1784,7 +1784,7 @@ pub fn bind_irrefutable_pat(bcx: block,
}
}
}
Some(ast::def_struct(*)) => {
Some(&ast::def_struct(*)) => {
match *sub_pats {
None => {
// This is a unit-like struct. Nothing to do here.
@ -1804,7 +1804,7 @@ pub fn bind_irrefutable_pat(bcx: block,
}
}
}
Some(ast::def_const(*)) => {
Some(&ast::def_const(*)) => {
bcx = bind_irrefutable_pat(bcx, pat, val, make_copy, binding_mode);
}
_ => {

View file

@ -67,13 +67,12 @@ use util::ppaux::{ty_to_str, ty_to_short_str};
use util::ppaux;
use core::hash;
use core::hashmap::linear::LinearMap;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::int;
use core::io;
use core::libc::{c_uint, c_ulonglong};
use core::uint;
use std::oldmap::HashMap;
use std::{oldmap, time, list};
use std::{time, list};
use syntax::ast::ident;
use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name};
use syntax::ast_util::{def_id_of_def, local_def, path_to_ident};
@ -170,7 +169,10 @@ pub fn get_extern_fn(externs: ExternMap,
name: @str,
cc: lib::llvm::CallConv,
ty: TypeRef) -> ValueRef {
if externs.contains_key(&name) { return externs.get(&name); }
match externs.find(&name) {
Some(n) => return copy *n,
None => ()
}
let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f);
return f;
@ -178,8 +180,11 @@ pub fn get_extern_fn(externs: ExternMap,
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
name: @str, ty: TypeRef) -> ValueRef {
match externs.find(&name) {
Some(n) => return copy *n,
None => ()
}
unsafe {
if externs.contains_key(&name) { return externs.get(&name); }
let c = str::as_c_str(name, |buf| {
llvm::LLVMAddGlobal(llmod, ty, buf)
});
@ -383,7 +388,7 @@ pub fn get_tydesc_simple(ccx: @CrateContext, t: ty::t) -> ValueRef {
pub fn get_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
match ccx.tydescs.find(&t) {
Some(inf) => inf,
Some(&inf) => inf,
_ => {
ccx.stats.n_static_tydescs += 1u;
let inf = glue::declare_tydesc(ccx, t);
@ -467,10 +472,12 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
// Double-check that we never ask LLVM to declare the same symbol twice. It
// silently mangles such symbols, breaking our linkage model.
pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) {
if ccx.all_llvm_symbols.contains_key(&sym) {
// XXX: this should not be necessary
use core::container::Set;
if ccx.all_llvm_symbols.contains(&sym) {
ccx.sess.bug(~"duplicate LLVM symbol: " + sym);
}
ccx.all_llvm_symbols.insert(sym, ());
ccx.all_llvm_symbols.insert(sym);
}
@ -1100,7 +1107,7 @@ pub fn init_local(bcx: block, local: @ast::local) -> block {
}
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
Some(local_mem(v)) => v,
Some(&local_mem(v)) => v,
_ => { bcx.tcx().sess.span_bug(local.span,
~"init_local: Someone forgot to document why it's\
safe to assume local.node.init must be local_mem!");
@ -1453,7 +1460,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
| session::arch_mips => ~"llvm.memcpy.p0i8.p0i8.i32",
session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64"
};
let memcpy = ccx.intrinsics.get(&key);
let memcpy = *ccx.intrinsics.get(&key);
let src_ptr = PointerCast(cx, src, T_ptr(T_i8()));
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
let size = IntCast(cx, n_bytes, ccx.int_type);
@ -1502,7 +1509,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
}
}
let llintrinsicfn = ccx.intrinsics.get(&intrinsic_key);
let llintrinsicfn = *ccx.intrinsics.get(&intrinsic_key);
let llptr = PointerCast(cx, llptr, T_ptr(T_i8()));
let llzeroval = C_u8(0);
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
@ -1601,9 +1608,9 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
llself: None,
personality: None,
loop_ret: None,
llargs: @HashMap(),
lllocals: @HashMap(),
llupvars: @HashMap(),
llargs: @mut LinearMap::new(),
lllocals: @mut LinearMap::new(),
llupvars: @mut LinearMap::new(),
id: id,
impl_id: impl_id,
param_substs: param_substs,
@ -1905,7 +1912,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
// this function as an opaque blob due to the way that type_of()
// works. So we have to cast to the destination's view of the type.
let llarg = match fcx.llargs.find(&va.id) {
Some(local_mem(x)) => x,
Some(&local_mem(x)) => x,
_ => fail!(~"trans_enum_variant: how do we know this works?"),
};
let arg_ty = arg_tys[i].ty;
@ -1969,7 +1976,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
for fields.eachi |i, field| {
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr, 0, i);
let llarg = match fcx.llargs.get(&field.node.id) {
let llarg = match *fcx.llargs.get(&field.node.id) {
local_mem(x) => x,
_ => {
ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \
@ -2058,7 +2065,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
pub fn trans_item(ccx: @CrateContext, item: ast::item) {
let _icx = ccx.insn_ctxt("trans_item");
let path = match ccx.tcx.items.get(&item.id) {
let path = match *ccx.tcx.items.get(&item.id) {
ast_map::node_item(_, p) => p,
// tjc: ?
_ => fail!(~"trans_item"),
@ -2329,13 +2336,12 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
}
pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
vec::append(
/*bad*/copy *match ccx.tcx.items.get(&i.id) {
ast_map::node_item(_, p) => p,
// separate map for paths?
_ => fail!(~"item_path")
},
~[path_name(i.ident)])
let base = match *ccx.tcx.items.get(&i.id) {
ast_map::node_item(_, p) => p,
// separate map for paths?
_ => fail!(~"item_path")
};
vec::append(/*bad*/copy *base, ~[path_name(i.ident)])
}
/* If there's already a symbol for the dtor with <id> and substs <substs>,
@ -2347,7 +2353,7 @@ pub fn get_dtor_symbol(ccx: @CrateContext,
-> ~str {
let t = ty::node_id_to_type(ccx.tcx, id);
match ccx.item_symbols.find(&id) {
Some(ref s) => (/*bad*/copy *s),
Some(s) => (/*bad*/copy *s),
None if substs.is_none() => {
let s = mangle_exported_name(
ccx,
@ -2382,11 +2388,11 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
debug!("get_item_val(id=`%?`)", id);
let tcx = ccx.tcx;
match ccx.item_vals.find(&id) {
Some(v) => v,
Some(&v) => v,
None => {
let mut exprt = false;
let val = match ccx.tcx.items.get(&id) {
let val = match *ccx.tcx.items.get(&id) {
ast_map::node_item(i, pth) => {
let my_path = vec::append(/*bad*/copy *pth,
~[path_name(i.ident)]);
@ -2538,7 +2544,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
ccx.sess.bug(~"get_item_val(): unexpected variant")
}
};
if !(exprt || ccx.reachable.contains_key(&id)) {
if !(exprt || ccx.reachable.contains(&id)) {
lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage);
}
ccx.item_vals.insert(id, val);
@ -2617,7 +2623,7 @@ pub fn p2i(ccx: @CrateContext, v: ValueRef) -> ValueRef {
}
}
pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> {
pub fn declare_intrinsics(llmod: ModuleRef) -> LinearMap<~str, ValueRef> {
let T_memcpy32_args: ~[TypeRef] =
~[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
let T_memcpy64_args: ~[TypeRef] =
@ -2750,7 +2756,7 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> {
let bswap64 = decl_cdecl_fn(llmod, ~"llvm.bswap.i64",
T_fn(~[T_i64()], T_i64()));
let intrinsics = HashMap();
let mut intrinsics = LinearMap::new();
intrinsics.insert(~"llvm.gcroot", gcroot);
intrinsics.insert(~"llvm.gcread", gcread);
intrinsics.insert(~"llvm.memcpy.p0i8.p0i8.i32", memcpy32);
@ -2811,7 +2817,7 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> {
}
pub fn declare_dbg_intrinsics(llmod: ModuleRef,
intrinsics: HashMap<~str, ValueRef>) {
intrinsics: &mut LinearMap<~str, ValueRef>) {
let declare =
decl_cdecl_fn(llmod, ~"llvm.dbg.declare",
T_fn(~[T_metadata(), T_metadata()], T_void()));
@ -2826,7 +2832,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef,
pub fn trap(bcx: block) {
let v: ~[ValueRef] = ~[];
match bcx.ccx().intrinsics.find(&~"llvm.trap") {
Some(x) => { Call(bcx, x, v); },
Some(&x) => { Call(bcx, x, v); },
_ => bcx.sess().bug(~"unbound llvm.trap in trap")
}
}
@ -2861,8 +2867,8 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
}
let mut elts: ~[ValueRef] = ~[];
for ccx.module_data.each |&key, &val| {
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy key)),
for ccx.module_data.each |&(key, &val)| {
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)),
p2i(ccx, val)]);
elts.push(elt);
}
@ -3036,9 +3042,9 @@ pub fn trans_crate(sess: session::Session,
let targ_cfg = sess.targ_cfg;
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
let tn = mk_type_names();
let intrinsics = declare_intrinsics(llmod);
let mut intrinsics = declare_intrinsics(llmod);
if sess.opts.extra_debuginfo {
declare_dbg_intrinsics(llmod, intrinsics);
declare_dbg_intrinsics(llmod, &mut intrinsics);
}
let int_type = T_int(targ_cfg);
let float_type = T_float(targ_cfg);
@ -3059,36 +3065,36 @@ pub fn trans_crate(sess: session::Session,
llmod: llmod,
td: td,
tn: tn,
externs: HashMap(),
externs: @mut LinearMap::new(),
intrinsics: intrinsics,
item_vals: HashMap(),
item_vals: @mut LinearMap::new(),
exp_map2: emap2,
reachable: reachable,
item_symbols: HashMap(),
item_symbols: @mut LinearMap::new(),
link_meta: link_meta,
enum_sizes: ty::new_ty_hash(),
discrims: HashMap(),
discrim_symbols: HashMap(),
tydescs: ty::new_ty_hash(),
enum_sizes: @mut LinearMap::new(),
discrims: @mut LinearMap::new(),
discrim_symbols: @mut LinearMap::new(),
tydescs: @mut LinearMap::new(),
finished_tydescs: @mut false,
external: HashMap(),
monomorphized: HashMap(),
monomorphizing: HashMap(),
type_use_cache: HashMap(),
vtables: oldmap::HashMap(),
const_cstr_cache: HashMap(),
const_globals: HashMap(),
const_values: HashMap(),
module_data: HashMap(),
lltypes: ty::new_ty_hash(),
llsizingtypes: ty::new_ty_hash(),
external: @mut LinearMap::new(),
monomorphized: @mut LinearMap::new(),
monomorphizing: @mut LinearMap::new(),
type_use_cache: @mut LinearMap::new(),
vtables: @mut LinearMap::new(),
const_cstr_cache: @mut LinearMap::new(),
const_globals: @mut LinearMap::new(),
const_values: @mut LinearMap::new(),
module_data: @mut LinearMap::new(),
lltypes: @mut LinearMap::new(),
llsizingtypes: @mut LinearMap::new(),
adt_reprs: @mut LinearMap::new(),
names: new_namegen(sess.parse_sess.interner),
next_addrspace: new_addrspace_gen(),
symbol_hasher: symbol_hasher,
type_hashcodes: ty::new_ty_hash(),
type_short_names: ty::new_ty_hash(),
all_llvm_symbols: HashMap(),
type_hashcodes: @mut LinearMap::new(),
type_short_names: @mut LinearMap::new(),
all_llvm_symbols: @mut LinearSet::new(),
tcx: tcx,
maps: maps,
stats: @mut Stats {
@ -3101,7 +3107,7 @@ pub fn trans_crate(sess: session::Session,
n_inlines: 0u,
n_closures: 0u,
llvm_insn_ctxt: @mut ~[],
llvm_insns: HashMap(),
llvm_insns: @mut LinearMap::new(),
fn_times: @mut ~[]
},
upcalls: upcall::declare_upcalls(targ_cfg, llmod),
@ -3151,7 +3157,7 @@ pub fn trans_crate(sess: session::Session,
}
if ccx.sess.count_llvm_insns() {
for ccx.stats.llvm_insns.each |&k, &v| {
for ccx.stats.llvm_insns.each |&(&k, &v)| {
io::println(fmt!("%-7u %s", v, k));
}
}

View file

@ -18,13 +18,13 @@ use syntax::codemap::span;
use core::prelude::*;
use core::cast;
use core::hashmap::linear::LinearMap;
use core::libc::{c_uint, c_int, c_ulonglong, c_char};
use core::libc;
use core::option::Some;
use core::ptr;
use core::str;
use core::vec;
use std::oldmap::HashMap;
pub fn terminate(cx: block, _: &str) {
unsafe {
@ -55,7 +55,7 @@ pub fn count_insn(cx: block, category: &str) {
// Build version of path with cycles removed.
// Pass 1: scan table mapping str -> rightmost pos.
let mm = HashMap();
let mut mm = LinearMap::new();
let len = vec::len(*v);
let mut i = 0u;
while i < len {
@ -70,7 +70,7 @@ pub fn count_insn(cx: block, category: &str) {
let mut s = ~".";
i = 0u;
while i < len {
i = mm.get(&v[i]);
i = *mm.get(&v[i]);
s += ~"/";
s += v[i];
i += 1u;
@ -80,7 +80,7 @@ pub fn count_insn(cx: block, category: &str) {
s += category;
let n = match h.find(&s) {
Some(n) => n,
Some(&n) => n,
_ => 0u
};
h.insert(s, n+1u);

View file

@ -82,9 +82,12 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
}
ast::expr_field(base, _, _) => {
match bcx.ccx().maps.method_map.find(&expr.id) {
Some(ref origin) => { // An impl method
Some(origin) => { // An impl method
// FIXME(#5562): removing this copy causes a segfault
// before stage2
let origin = /*bad*/ copy *origin;
return meth::trans_method_callee(bcx, expr.id,
base, (*origin));
base, origin);
}
None => {} // not a method, just a field
}
@ -265,7 +268,7 @@ pub fn trans_fn_ref_with_vtables(
ccx.tcx.items.find(&def_id.node),
|| fmt!("local item should be in ast map"));
match map_node {
match *map_node {
ast_map::node_foreign_item(_,
ast::foreign_abi_rust_intrinsic,
_,
@ -343,11 +346,14 @@ pub fn trans_method_call(in_cx: block,
expr_ty(in_cx, call_ex),
|cx| {
match cx.ccx().maps.method_map.find(&call_ex.id) {
Some(ref origin) => {
Some(origin) => {
// FIXME(#5562): removing this copy causes a segfault
// before stage2
let origin = /*bad*/ copy *origin;
meth::trans_method_callee(cx,
call_ex.callee_id,
rcvr,
(*origin))
origin)
}
None => {
cx.tcx().sess.span_bug(call_ex.span,
@ -700,7 +706,7 @@ pub fn trans_arg_expr(bcx: block,
match autoref_arg {
DoAutorefArg => {
fail_unless!(!
bcx.ccx().maps.moves_map.contains_key(&arg_expr.id));
bcx.ccx().maps.moves_map.contains(&arg_expr.id));
val = arg_datum.to_ref_llval(bcx);
}
DontAutorefArg => {

View file

@ -411,7 +411,7 @@ pub fn trans_expr_fn(bcx: block,
let Result {bcx: bcx, val: closure} = match sigil {
ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => {
let cap_vars = ccx.maps.capture_map.get(&user_id);
let cap_vars = *ccx.maps.capture_map.get(&user_id);
let ret_handle = match is_loop_body {Some(x) => x,
None => None};
let ClosureResult {llbox, cdata_ty, bcx}

View file

@ -45,14 +45,13 @@ use util::ppaux::{expr_repr, ty_to_str};
use core::cast;
use core::hash;
use core::hashmap::linear::LinearMap;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::libc::{c_uint, c_longlong, c_ulonglong};
use core::ptr;
use core::str;
use core::to_bytes;
use core::vec::raw::to_ptr;
use core::vec;
use std::oldmap::{HashMap, Set};
use syntax::ast::ident;
use syntax::ast_map::{path, path_elt};
use syntax::codemap::span;
@ -134,7 +133,7 @@ pub struct Stats {
n_inlines: uint,
n_closures: uint,
llvm_insn_ctxt: @mut ~[~str],
llvm_insns: HashMap<~str, uint>,
llvm_insns: @mut LinearMap<~str, uint>,
fn_times: @mut ~[(~str, int)] // (ident, time)
}
@ -156,7 +155,7 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
}
}
pub type ExternMap = HashMap<@str, ValueRef>;
pub type ExternMap = @mut LinearMap<@str, ValueRef>;
// Crate context. Every crate we compile has one of these.
pub struct CrateContext {
@ -165,30 +164,30 @@ pub struct CrateContext {
td: TargetData,
tn: @TypeNames,
externs: ExternMap,
intrinsics: HashMap<~str, ValueRef>,
item_vals: HashMap<ast::node_id, ValueRef>,
intrinsics: LinearMap<~str, ValueRef>,
item_vals: @mut LinearMap<ast::node_id, ValueRef>,
exp_map2: resolve::ExportMap2,
reachable: reachable::map,
item_symbols: HashMap<ast::node_id, ~str>,
item_symbols: @mut LinearMap<ast::node_id, ~str>,
link_meta: LinkMeta,
enum_sizes: HashMap<ty::t, uint>,
discrims: HashMap<ast::def_id, ValueRef>,
discrim_symbols: HashMap<ast::node_id, ~str>,
tydescs: HashMap<ty::t, @mut tydesc_info>,
enum_sizes: @mut LinearMap<ty::t, uint>,
discrims: @mut LinearMap<ast::def_id, ValueRef>,
discrim_symbols: @mut LinearMap<ast::node_id, ~str>,
tydescs: @mut LinearMap<ty::t, @mut tydesc_info>,
// Set when running emit_tydescs to enforce that no more tydescs are
// created.
finished_tydescs: @mut bool,
// Track mapping of external ids to local items imported for inlining
external: HashMap<ast::def_id, Option<ast::node_id>>,
external: @mut LinearMap<ast::def_id, Option<ast::node_id>>,
// Cache instances of monomorphized functions
monomorphized: HashMap<mono_id, ValueRef>,
monomorphizing: HashMap<ast::def_id, uint>,
monomorphized: @mut LinearMap<mono_id, ValueRef>,
monomorphizing: @mut LinearMap<ast::def_id, uint>,
// Cache computed type parameter uses (see type_use.rs)
type_use_cache: HashMap<ast::def_id, ~[type_use::type_uses]>,
type_use_cache: @mut LinearMap<ast::def_id, ~[type_use::type_uses]>,
// Cache generated vtables
vtables: HashMap<mono_id, ValueRef>,
vtables: @mut LinearMap<mono_id, ValueRef>,
// Cache of constant strings,
const_cstr_cache: HashMap<@~str, ValueRef>,
const_cstr_cache: @mut LinearMap<@~str, ValueRef>,
// Reverse-direction for const ptrs cast from globals.
// Key is an int, cast from a ValueRef holding a *T,
@ -198,20 +197,20 @@ pub struct CrateContext {
// when we ptrcast, and we have to ptrcast during translation
// of a [T] const because we form a slice, a [*T,int] pair, not
// a pointer to an LLVM array type.
const_globals: HashMap<int, ValueRef>,
const_globals: @mut LinearMap<int, ValueRef>,
// Cache of emitted const values
const_values: HashMap<ast::node_id, ValueRef>,
module_data: HashMap<~str, ValueRef>,
lltypes: HashMap<ty::t, TypeRef>,
llsizingtypes: HashMap<ty::t, TypeRef>,
const_values: @mut LinearMap<ast::node_id, ValueRef>,
module_data: @mut LinearMap<~str, ValueRef>,
lltypes: @mut LinearMap<ty::t, TypeRef>,
llsizingtypes: @mut LinearMap<ty::t, TypeRef>,
adt_reprs: @mut LinearMap<ty::t, @adt::Repr>,
names: namegen,
next_addrspace: addrspace_gen,
symbol_hasher: @hash::State,
type_hashcodes: HashMap<ty::t, @str>,
type_short_names: HashMap<ty::t, ~str>,
all_llvm_symbols: Set<~str>,
type_hashcodes: @mut LinearMap<ty::t, @str>,
type_short_names: @mut LinearMap<ty::t, ~str>,
all_llvm_symbols: @mut LinearSet<~str>,
tcx: ty::ctxt,
maps: astencode::Maps,
stats: @mut Stats,
@ -310,12 +309,12 @@ pub struct fn_ctxt_ {
loop_ret: Option<(ValueRef, ValueRef)>,
// Maps arguments to allocas created for them in llallocas.
llargs: @HashMap<ast::node_id, local_val>,
llargs: @mut LinearMap<ast::node_id, local_val>,
// Maps the def_ids for local variables to the allocas created for
// them in llallocas.
lllocals: @HashMap<ast::node_id, local_val>,
lllocals: @mut LinearMap<ast::node_id, local_val>,
// Same as above, but for closure upvars
llupvars: @HashMap<ast::node_id, ValueRef>,
llupvars: @mut LinearMap<ast::node_id, ValueRef>,
// The node_id of the function, or -1 if it doesn't correspond to
// a user-defined function.
@ -712,7 +711,7 @@ pub impl block_ {
fn def(@mut self, nid: ast::node_id) -> ast::def {
match self.tcx().def_map.find(&nid) {
Some(v) => v,
Some(&v) => v,
None => {
self.tcx().sess.bug(fmt!(
"No def associated with node id %?", nid));
@ -1132,7 +1131,7 @@ pub fn C_u8(i: uint) -> ValueRef {
pub fn C_cstr(cx: @CrateContext, s: @~str) -> ValueRef {
unsafe {
match cx.const_cstr_cache.find(&s) {
Some(llval) => return llval,
Some(&llval) => return llval,
None => ()
}
@ -1400,7 +1399,7 @@ pub fn node_vtables(bcx: block, id: ast::node_id)
-> Option<typeck::vtable_res> {
let raw_vtables = bcx.ccx().maps.vtable_map.find(&id);
raw_vtables.map(
|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
|&vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
}
pub fn resolve_vtables_in_fn_ctxt(fcx: fn_ctxt, vts: typeck::vtable_res)

View file

@ -110,7 +110,7 @@ fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
fn const_deref_ptr(cx: @CrateContext, v: ValueRef) -> ValueRef {
let v = match cx.const_globals.find(&(v as int)) {
Some(v) => v,
Some(&v) => v,
None => v
};
unsafe {
@ -158,7 +158,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
if !ast_util::is_local(def_id) {
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
}
match cx.tcx.items.get(&def_id.node) {
match *cx.tcx.items.get(&def_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_const(_, subexpr), _
}, _) => {
@ -167,7 +167,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
_ => cx.tcx.sess.bug(~"expected a const to be an item")
}
}
cx.const_values.get(&def_id.node)
*cx.const_values.get(&def_id.node)
}
pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
@ -175,14 +175,14 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
let ety = ty::expr_ty(cx.tcx, e);
match cx.tcx.adjustments.find(&e.id) {
None => { }
Some(@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
Some(&@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
llconst = C_struct(~[llconst, C_null(T_opaque_box_ptr(cx))])
}
Some(@ty::AutoAddEnv(ref r, ref s)) => {
Some(&@ty::AutoAddEnv(ref r, ref s)) => {
cx.sess.span_bug(e.span, fmt!("unexpected static function: \
region %? sigil %?", *r, *s))
}
Some(@ty::AutoDerefRef(ref adj)) => {
Some(&@ty::AutoDerefRef(ref adj)) => {
let mut ty = ety;
let mut maybe_ptr = None;
for adj.autoderefs.times {
@ -496,7 +496,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
ast::expr_path(pth) => {
fail_unless!(pth.types.len() == 0);
match cx.tcx.def_map.find(&e.id) {
Some(ast::def_fn(def_id, _purity)) => {
Some(&ast::def_fn(def_id, _purity)) => {
if !ast_util::is_local(def_id) {
let ty = csearch::get_type(cx.tcx, def_id).ty;
base::trans_external_path(cx, def_id, ty)
@ -505,10 +505,10 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
base::get_item_val(cx, def_id.node)
}
}
Some(ast::def_const(def_id)) => {
Some(&ast::def_const(def_id)) => {
get_const_val(cx, def_id)
}
Some(ast::def_variant(enum_did, variant_did)) => {
Some(&ast::def_variant(enum_did, variant_did)) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
let vinfo = ty::enum_variant_with_id(cx.tcx,
@ -516,7 +516,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
variant_did);
adt::trans_const(cx, repr, vinfo.disr_val, [])
}
Some(ast::def_struct(_)) => {
Some(&ast::def_struct(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let llty = type_of::type_of(cx, ety);
C_null(llty)
@ -529,13 +529,13 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
ast::expr_call(callee, ref args, _) => {
match cx.tcx.def_map.find(&callee.id) {
Some(ast::def_struct(_)) => {
Some(&ast::def_struct(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
adt::trans_const(cx, repr, 0,
args.map(|a| const_expr(cx, *a)))
}
Some(ast::def_variant(enum_did, variant_did)) => {
Some(&ast::def_variant(enum_did, variant_did)) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
let vinfo = ty::enum_variant_with_id(cx.tcx,
@ -561,7 +561,7 @@ pub fn trans_const(ccx: @CrateContext, _e: @ast::expr, id: ast::node_id) {
let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type.
let v = ccx.const_values.get(&id);
let v = *ccx.const_values.get(&id);
llvm::LLVMSetInitializer(g, v);
llvm::LLVMSetGlobalConstant(g, True);
}

View file

@ -196,7 +196,7 @@ pub fn trans_log(log_ex: @ast::expr,
};
let global = if ccx.module_data.contains_key(&modname) {
ccx.module_data.get(&modname)
*ccx.module_data.get(&modname)
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, ~"loglevel");

View file

@ -105,6 +105,7 @@ use util::common::indenter;
use util::ppaux::ty_to_str;
use core::cmp;
use core::container::Set; // XXX: this should not be necessary
use core::to_bytes;
use core::uint;
use syntax::ast;
@ -230,7 +231,7 @@ pub impl Datum {
* `id` is located in the move table, but copies otherwise.
*/
if bcx.ccx().maps.moves_map.contains_key(&id) {
if bcx.ccx().maps.moves_map.contains(&id) {
self.move_to(bcx, action, dst)
} else {
self.copy_to(bcx, action, dst)
@ -646,16 +647,15 @@ pub impl Datum {
let key = root_map_key { id: expr_id, derefs: derefs };
let bcx = match ccx.maps.root_map.find(&key) {
None => bcx,
Some(root_info) => self.root(bcx, root_info)
Some(&root_info) => self.root(bcx, root_info)
};
// Perform the write guard, if necessary.
//
// (Note: write-guarded values are always boxes)
let bcx = match ccx.maps.write_guard_map.find(&key) {
None => bcx,
Some(_) => self.perform_write_guard(bcx)
};
let bcx = if ccx.maps.write_guard_map.contains(&key) {
self.perform_write_guard(bcx)
} else { bcx };
match ty::get(self.ty).sty {
ty::ty_box(_) | ty::ty_uniq(_) => {

View file

@ -20,11 +20,10 @@ use middle::trans;
use middle::ty;
use util::ppaux::ty_to_str;
use core::hashmap::linear::LinearMap;
use core::libc;
use core::option;
use core::sys;
use std::oldmap::HashMap;
use std::oldmap;
use syntax::codemap::{span, CharPos};
use syntax::parse::token::ident_interner;
use syntax::{ast, codemap, ast_util, ast_map};
@ -107,19 +106,18 @@ pub struct DebugContext {
pub fn mk_ctxt(+crate: ~str, intr: @ident_interner) -> DebugContext {
DebugContext {
llmetadata: oldmap::HashMap(),
llmetadata: @mut LinearMap::new(),
names: new_namegen(intr),
crate_file: crate
}
}
fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) {
let existing = if cache.contains_key(&mdtag) {
cache.get(&mdtag)
} else {
~[]
let mut existing = match cache.pop(&mdtag) {
Some(arr) => arr, None => ~[]
};
cache.insert(mdtag, vec::append_one(existing, val));
existing.push(val);
cache.insert(mdtag, existing);
}
struct Metadata<T> {
@ -153,7 +151,7 @@ struct RetvalMetadata {
id: ast::node_id
}
type metadata_cache = HashMap<int, ~[debug_metadata]>;
type metadata_cache = @mut LinearMap<int, ~[debug_metadata]>;
enum debug_metadata {
file_metadata(@Metadata<FileMetadata>),
@ -318,7 +316,7 @@ fn create_block(cx: block) -> @Metadata<BlockMetadata> {
};
let file_node = create_file(cx.ccx(), fname);
let unique_id = match cache.find(&LexicalBlockTag) {
option::Some(v) => vec::len(v) as int,
option::Some(v) => v.len() as int,
option::None => 0
};
let lldata = ~[lltag(tg),
@ -746,13 +744,13 @@ pub fn create_local_var(bcx: block, local: @ast::local)
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
option::Some(local_mem(v)) => v,
option::Some(&local_mem(v)) => v,
option::Some(_) => {
bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
something weird");
}
option::None => {
match bcx.fcx.lllocals.get(&local.node.pat.id) {
match *bcx.fcx.lllocals.get(&local.node.pat.id) {
local_imm(v) => v,
_ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
something weird")
@ -760,7 +758,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
}
};
let declargs = ~[llmdnode(~[llptr]), mdnode];
trans::build::Call(bcx, cx.intrinsics.get(&~"llvm.dbg.declare"),
trans::build::Call(bcx, *cx.intrinsics.get(&~"llvm.dbg.declare"),
declargs);
return mdval;
}
@ -807,12 +805,12 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
};
update_cache(cache, tg, argument_metadata(mdval));
let llptr = match fcx.llargs.get(&arg.id) {
let llptr = match *fcx.llargs.get(&arg.id) {
local_mem(v) | local_imm(v) => v,
};
let declargs = ~[llmdnode(~[llptr]), mdnode];
trans::build::Call(bcx,
cx.intrinsics.get(&~"llvm.dbg.declare"),
*cx.intrinsics.get(&~"llvm.dbg.declare"),
declargs);
return Some(mdval);
}
@ -851,7 +849,7 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
let sp = fcx.span.get();
debug!("%s", cx.sess.codemap.span_to_str(sp));
let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) {
let (ident, ret_ty, id) = match *cx.tcx.items.get(&fcx.id) {
ast_map::node_item(item, _) => {
match item.node {
ast::item_fn(ref decl, _, _, _) => {

View file

@ -150,7 +150,7 @@ use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
use util::common::indenter;
use util::ppaux::ty_to_str;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use syntax::print::pprust::{expr_to_str};
use syntax::ast;
use syntax::codemap;
@ -198,14 +198,14 @@ pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock {
None => {
trans_to_datum_unadjusted(bcx, expr)
}
Some(@AutoAddEnv(*)) => {
Some(&@AutoAddEnv(*)) => {
let mut bcx = bcx;
let mut datum = unpack_datum!(bcx, {
trans_to_datum_unadjusted(bcx, expr)
});
add_env(bcx, expr, datum)
}
Some(@AutoDerefRef(ref adj)) => {
Some(&@AutoDerefRef(ref adj)) => {
let mut bcx = bcx;
let mut datum = unpack_datum!(bcx, {
trans_to_datum_unadjusted(bcx, expr)
@ -925,7 +925,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
// at the end of the scope with id `scope_id`:
let root_key = root_map_key { id: expr.id, derefs: 0u };
for bcx.ccx().maps.root_map.find(&root_key).each |&root_info| {
bcx = unrooted_datum.root(bcx, root_info);
bcx = unrooted_datum.root(bcx, *root_info);
}
return DatumBlock {bcx: bcx, datum: unrooted_datum};
@ -1131,7 +1131,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
// Can't move upvars, so this is never a ZeroMemLastUse.
let local_ty = node_id_type(bcx, nid);
match bcx.fcx.llupvars.find(&nid) {
Some(val) => {
Some(&val) => {
Datum {
val: val,
ty: local_ty,
@ -1146,10 +1146,10 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
}
}
ast::def_arg(nid, _, _) => {
take_local(bcx, *bcx.fcx.llargs, nid)
take_local(bcx, bcx.fcx.llargs, nid)
}
ast::def_local(nid, _) | ast::def_binding(nid, _) => {
take_local(bcx, *bcx.fcx.lllocals, nid)
take_local(bcx, bcx.fcx.lllocals, nid)
}
ast::def_self(nid, _) => {
let self_info: ValSelfData = match bcx.fcx.llself {
@ -1181,11 +1181,11 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
};
fn take_local(bcx: block,
table: HashMap<ast::node_id, local_val>,
table: &LinearMap<ast::node_id, local_val>,
nid: ast::node_id) -> Datum {
let (v, mode) = match table.find(&nid) {
Some(local_mem(v)) => (v, ByRef),
Some(local_imm(v)) => (v, ByValue),
Some(&local_mem(v)) => (v, ByRef),
Some(&local_imm(v)) => (v, ByValue),
None => {
bcx.sess().bug(fmt!(
"trans_local_var: no llval for local/arg %? found", nid));
@ -1227,7 +1227,7 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
ty_to_str(tcx, ty)));
}
Some(node_id) => {
match tcx.def_map.get(&node_id) {
match *tcx.def_map.get(&node_id) {
ast::def_variant(enum_id, variant_id) => {
let variant_info = ty::enum_variant_with_id(
tcx, enum_id, variant_id);
@ -1647,7 +1647,7 @@ fn trans_overloaded_op(bcx: block,
dest: Dest,
+autoref_arg: AutorefArg) -> block
{
let origin = bcx.ccx().maps.method_map.get(&expr.id);
let origin = *bcx.ccx().maps.method_map.get(&expr.id);
let fty = node_id_type(bcx, expr.callee_id);
return callee::trans_call_inner(
bcx, expr.info(), fty,

View file

@ -567,7 +567,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty),
out_sz = machine::llbitsize_of_real(ccx, llout_ty);
if tp_sz != out_sz {
let sp = match ccx.tcx.items.get(&ref_id.get()) {
let sp = match *ccx.tcx.items.get(&ref_id.get()) {
ast_map::node_expr(e) => e.span,
_ => fail!(~"reinterpret_cast or forget has non-expr arg")
};
@ -605,7 +605,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
abi::tydesc_field_visit_glue, None);
}
~"frame_address" => {
let frameaddress = ccx.intrinsics.get(&~"llvm.frameaddress");
let frameaddress = *ccx.intrinsics.get(&~"llvm.frameaddress");
let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]);
let star_u8 = ty::mk_imm_ptr(
bcx.tcx(),
@ -644,7 +644,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get(
let llfn = *bcx.ccx().intrinsics.get(
&~"llvm.memmove.p0i8.p0i8.i32");
Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]);
}
@ -654,249 +654,249 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get(
let llfn = *bcx.ccx().intrinsics.get(
&~"llvm.memmove.p0i8.p0i8.i64");
Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]);
}
~"sqrtf32" => {
let x = get_param(decl, first_real_arg);
let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f32");
let sqrtf = *ccx.intrinsics.get(&~"llvm.sqrt.f32");
Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr);
}
~"sqrtf64" => {
let x = get_param(decl, first_real_arg);
let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f64");
let sqrtf = *ccx.intrinsics.get(&~"llvm.sqrt.f64");
Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr);
}
~"powif32" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powif = ccx.intrinsics.get(&~"llvm.powi.f32");
let powif = *ccx.intrinsics.get(&~"llvm.powi.f32");
Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr);
}
~"powif64" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powif = ccx.intrinsics.get(&~"llvm.powi.f64");
let powif = *ccx.intrinsics.get(&~"llvm.powi.f64");
Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr);
}
~"sinf32" => {
let x = get_param(decl, first_real_arg);
let sinf = ccx.intrinsics.get(&~"llvm.sin.f32");
let sinf = *ccx.intrinsics.get(&~"llvm.sin.f32");
Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr);
}
~"sinf64" => {
let x = get_param(decl, first_real_arg);
let sinf = ccx.intrinsics.get(&~"llvm.sin.f64");
let sinf = *ccx.intrinsics.get(&~"llvm.sin.f64");
Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr);
}
~"cosf32" => {
let x = get_param(decl, first_real_arg);
let cosf = ccx.intrinsics.get(&~"llvm.cos.f32");
let cosf = *ccx.intrinsics.get(&~"llvm.cos.f32");
Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr);
}
~"cosf64" => {
let x = get_param(decl, first_real_arg);
let cosf = ccx.intrinsics.get(&~"llvm.cos.f64");
let cosf = *ccx.intrinsics.get(&~"llvm.cos.f64");
Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr);
}
~"powf32" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powf = ccx.intrinsics.get(&~"llvm.pow.f32");
let powf = *ccx.intrinsics.get(&~"llvm.pow.f32");
Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr);
}
~"powf64" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powf = ccx.intrinsics.get(&~"llvm.pow.f64");
let powf = *ccx.intrinsics.get(&~"llvm.pow.f64");
Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr);
}
~"expf32" => {
let x = get_param(decl, first_real_arg);
let expf = ccx.intrinsics.get(&~"llvm.exp.f32");
let expf = *ccx.intrinsics.get(&~"llvm.exp.f32");
Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr);
}
~"expf64" => {
let x = get_param(decl, first_real_arg);
let expf = ccx.intrinsics.get(&~"llvm.exp.f64");
let expf = *ccx.intrinsics.get(&~"llvm.exp.f64");
Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr);
}
~"exp2f32" => {
let x = get_param(decl, first_real_arg);
let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f32");
let exp2f = *ccx.intrinsics.get(&~"llvm.exp2.f32");
Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr);
}
~"exp2f64" => {
let x = get_param(decl, first_real_arg);
let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f64");
let exp2f = *ccx.intrinsics.get(&~"llvm.exp2.f64");
Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr);
}
~"logf32" => {
let x = get_param(decl, first_real_arg);
let logf = ccx.intrinsics.get(&~"llvm.log.f32");
let logf = *ccx.intrinsics.get(&~"llvm.log.f32");
Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr);
}
~"logf64" => {
let x = get_param(decl, first_real_arg);
let logf = ccx.intrinsics.get(&~"llvm.log.f64");
let logf = *ccx.intrinsics.get(&~"llvm.log.f64");
Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr);
}
~"log10f32" => {
let x = get_param(decl, first_real_arg);
let log10f = ccx.intrinsics.get(&~"llvm.log10.f32");
let log10f = *ccx.intrinsics.get(&~"llvm.log10.f32");
Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr);
}
~"log10f64" => {
let x = get_param(decl, first_real_arg);
let log10f = ccx.intrinsics.get(&~"llvm.log10.f64");
let log10f = *ccx.intrinsics.get(&~"llvm.log10.f64");
Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr);
}
~"log2f32" => {
let x = get_param(decl, first_real_arg);
let log2f = ccx.intrinsics.get(&~"llvm.log2.f32");
let log2f = *ccx.intrinsics.get(&~"llvm.log2.f32");
Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr);
}
~"log2f64" => {
let x = get_param(decl, first_real_arg);
let log2f = ccx.intrinsics.get(&~"llvm.log2.f64");
let log2f = *ccx.intrinsics.get(&~"llvm.log2.f64");
Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr);
}
~"fmaf32" => {
let a = get_param(decl, first_real_arg);
let b = get_param(decl, first_real_arg + 1u);
let c = get_param(decl, first_real_arg + 2u);
let fmaf = ccx.intrinsics.get(&~"llvm.fma.f32");
let fmaf = *ccx.intrinsics.get(&~"llvm.fma.f32");
Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr);
}
~"fmaf64" => {
let a = get_param(decl, first_real_arg);
let b = get_param(decl, first_real_arg + 1u);
let c = get_param(decl, first_real_arg + 2u);
let fmaf = ccx.intrinsics.get(&~"llvm.fma.f64");
let fmaf = *ccx.intrinsics.get(&~"llvm.fma.f64");
Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr);
}
~"fabsf32" => {
let x = get_param(decl, first_real_arg);
let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f32");
let fabsf = *ccx.intrinsics.get(&~"llvm.fabs.f32");
Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr);
}
~"fabsf64" => {
let x = get_param(decl, first_real_arg);
let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f64");
let fabsf = *ccx.intrinsics.get(&~"llvm.fabs.f64");
Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr);
}
~"floorf32" => {
let x = get_param(decl, first_real_arg);
let floorf = ccx.intrinsics.get(&~"llvm.floor.f32");
let floorf = *ccx.intrinsics.get(&~"llvm.floor.f32");
Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr);
}
~"floorf64" => {
let x = get_param(decl, first_real_arg);
let floorf = ccx.intrinsics.get(&~"llvm.floor.f64");
let floorf = *ccx.intrinsics.get(&~"llvm.floor.f64");
Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr);
}
~"ceilf32" => {
let x = get_param(decl, first_real_arg);
let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f32");
let ceilf = *ccx.intrinsics.get(&~"llvm.ceil.f32");
Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr);
}
~"ceilf64" => {
let x = get_param(decl, first_real_arg);
let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f64");
let ceilf = *ccx.intrinsics.get(&~"llvm.ceil.f64");
Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr);
}
~"truncf32" => {
let x = get_param(decl, first_real_arg);
let truncf = ccx.intrinsics.get(&~"llvm.trunc.f32");
let truncf = *ccx.intrinsics.get(&~"llvm.trunc.f32");
Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr);
}
~"truncf64" => {
let x = get_param(decl, first_real_arg);
let truncf = ccx.intrinsics.get(&~"llvm.trunc.f64");
let truncf = *ccx.intrinsics.get(&~"llvm.trunc.f64");
Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr);
}
~"ctpop8" => {
let x = get_param(decl, first_real_arg);
let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i8");
let ctpop = *ccx.intrinsics.get(&~"llvm.ctpop.i8");
Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr)
}
~"ctpop16" => {
let x = get_param(decl, first_real_arg);
let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i16");
let ctpop = *ccx.intrinsics.get(&~"llvm.ctpop.i16");
Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr)
}
~"ctpop32" => {
let x = get_param(decl, first_real_arg);
let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i32");
let ctpop = *ccx.intrinsics.get(&~"llvm.ctpop.i32");
Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr)
}
~"ctpop64" => {
let x = get_param(decl, first_real_arg);
let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i64");
let ctpop = *ccx.intrinsics.get(&~"llvm.ctpop.i64");
Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr)
}
~"ctlz8" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8");
let ctlz = *ccx.intrinsics.get(&~"llvm.ctlz.i8");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz16" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16");
let ctlz = *ccx.intrinsics.get(&~"llvm.ctlz.i16");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz32" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32");
let ctlz = *ccx.intrinsics.get(&~"llvm.ctlz.i32");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz64" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64");
let ctlz = *ccx.intrinsics.get(&~"llvm.ctlz.i64");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"cttz8" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8");
let cttz = *ccx.intrinsics.get(&~"llvm.cttz.i8");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz16" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16");
let cttz = *ccx.intrinsics.get(&~"llvm.cttz.i16");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz32" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32");
let cttz = *ccx.intrinsics.get(&~"llvm.cttz.i32");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz64" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64");
let cttz = *ccx.intrinsics.get(&~"llvm.cttz.i64");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"bswap16" => {
let x = get_param(decl, first_real_arg);
let cttz = ccx.intrinsics.get(&~"llvm.bswap.i16");
let cttz = *ccx.intrinsics.get(&~"llvm.bswap.i16");
Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr)
}
~"bswap32" => {
let x = get_param(decl, first_real_arg);
let cttz = ccx.intrinsics.get(&~"llvm.bswap.i32");
let cttz = *ccx.intrinsics.get(&~"llvm.bswap.i32");
Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr)
}
~"bswap64" => {
let x = get_param(decl, first_real_arg);
let cttz = ccx.intrinsics.get(&~"llvm.bswap.i64");
let cttz = *ccx.intrinsics.get(&~"llvm.bswap.i64");
Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr)
}
_ => {
@ -1082,7 +1082,7 @@ pub fn register_foreign_fn(ccx: @CrateContext,
fn abi_of_foreign_fn(ccx: @CrateContext, i: @ast::foreign_item)
-> ast::foreign_abi {
match attr::first_attr_value_str_by_name(i.attrs, ~"abi") {
None => match ccx.tcx.items.get(&i.id) {
None => match *ccx.tcx.items.get(&i.id) {
ast_map::node_foreign_item(_, abi, _, _) => abi,
// ??
_ => fail!(~"abi_of_foreign_fn: not foreign")

View file

@ -402,7 +402,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) {
let mut bcx = bcx;
let ty_visitor_name = special_idents::ty_visitor;
fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&ty_visitor_name));
let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name);
let (trait_id, ty) = *bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name);
let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty)));
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id);
build_return(bcx);

View file

@ -32,13 +32,13 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
-> ast::def_id {
let _icx = ccx.insn_ctxt("maybe_instantiate_inline");
match ccx.external.find(&fn_id) {
Some(Some(node_id)) => {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline(%s): already inline as node id %d",
ty::item_path_str(ccx.tcx, fn_id), node_id);
local_def(node_id)
}
Some(None) => fn_id, // Not inlinable
Some(&None) => fn_id, // Not inlinable
None => { // Not seen yet
match csearch::maybe_get_item_ast(
ccx.tcx, fn_id,

View file

@ -10,6 +10,7 @@
// Information concerning the machine representation of various types.
use core::prelude::*;
use lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
use lib::llvm::{True, False, Bool};
@ -119,7 +120,7 @@ pub fn llalign_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
// Computes the size of the data part of an enum.
pub fn static_size_of_enum(cx: @CrateContext, t: ty::t) -> uint {
if cx.enum_sizes.contains_key(&t) {
return cx.enum_sizes.get(&t);
return *cx.enum_sizes.get(&t);
}
debug!("static_size_of_enum %s", ty_to_str(cx.tcx, t));

View file

@ -306,7 +306,7 @@ pub fn trans_static_method_callee(bcx: block,
};
let mname = if method_id.crate == ast::local_crate {
match bcx.tcx().items.get(&method_id.node) {
match *bcx.tcx().items.get(&method_id.node) {
ast_map::node_trait_method(trait_method, _, _) => {
ast_util::trait_method_to_ty_method(trait_method).ident
}
@ -323,7 +323,7 @@ pub fn trans_static_method_callee(bcx: block,
name=%s", method_id, callee_id, *ccx.sess.str_of(mname));
let vtbls = resolve_vtables_in_fn_ctxt(
bcx.fcx, ccx.maps.vtable_map.get(&callee_id));
bcx.fcx, *ccx.maps.vtable_map.get(&callee_id));
match vtbls[bound_index] {
typeck::vtable_static(impl_did, ref rcvr_substs, rcvr_origins) => {
@ -361,7 +361,7 @@ pub fn method_from_methods(ms: &[@ast::method], name: ast::ident)
pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
name: ast::ident) -> ast::def_id {
if impl_id.crate == ast::local_crate {
match ccx.tcx.items.get(&impl_id.node) {
match *ccx.tcx.items.get(&impl_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_impl(_, _, _, ref ms),
_
@ -378,7 +378,7 @@ pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
pub fn method_with_name_or_default(ccx: @CrateContext, impl_id: ast::def_id,
name: ast::ident) -> ast::def_id {
if impl_id.crate == ast::local_crate {
match ccx.tcx.items.get(&impl_id.node) {
match *ccx.tcx.items.get(&impl_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_impl(_, _, _, ref ms), _
}, _) => {
@ -414,7 +414,7 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id,
debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
if m_id.crate == ast::local_crate {
match ccx.tcx.items.find(&m_id.node) {
Some(ast_map::node_method(m, _, _)) => m.generics.ty_params.len(),
Some(&ast_map::node_method(m, _, _)) => m.generics.ty_params.len(),
None => {
match ccx.tcx.provided_method_sources.find(&m_id) {
Some(source) => {
@ -424,7 +424,7 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id,
None => fail!()
}
}
Some(ast_map::node_trait_method(@ast::provided(@ref m),
Some(&ast_map::node_trait_method(@ast::provided(@ref m),
_, _)) => {
m.generics.ty_params.len()
}
@ -764,7 +764,7 @@ pub fn get_vtable(ccx: @CrateContext,
// XXX: Bad copy.
let hash_id = vtable_id(ccx, copy origin);
match ccx.vtables.find(&hash_id) {
Some(val) => val,
Some(&val) => val,
None => match origin {
typeck::vtable_static(id, substs, sub_vtables) => {
make_impl_vtable(ccx, id, substs, sub_vtables)

View file

@ -77,7 +77,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id);
match ccx.monomorphized.find(&hash_id) {
Some(val) => {
Some(&val) => {
debug!("leaving monomorphic fn %s",
ty::item_path_str(ccx.tcx, fn_id));
return (val, must_cast);
@ -93,7 +93,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
(may have attempted to monomorphize an item defined in a different \
crate?)", fn_id));
// Get the path so that we can create a symbol
let (pt, name, span) = match map_node {
let (pt, name, span) = match *map_node {
ast_map::node_item(i, pt) => (pt, i.ident, i.span),
ast_map::node_variant(ref v, enm, pt) => (pt, (*v).node.name, enm.span),
ast_map::node_method(m, _, pt) => (pt, m.ident, m.span),
@ -142,7 +142,9 @@ pub fn monomorphic_fn(ccx: @CrateContext,
ccx.stats.n_monos += 1;
let depth = option::get_or_default(ccx.monomorphizing.find(&fn_id), 0u);
let depth = match ccx.monomorphizing.find(&fn_id) {
Some(&d) => d, None => 0
};
// Random cut-off -- code that needs to instantiate the same function
// recursively more than thirty times can probably safely be assumed to be
// causing an infinite expansion.
@ -170,7 +172,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
self_ty: impl_ty_opt
});
let lldecl = match map_node {
let lldecl = match *map_node {
ast_map::node_item(i@@ast::item {
// XXX: Bad copy.
node: ast::item_fn(ref decl, _, _, ref body),

View file

@ -21,7 +21,7 @@ use middle::ty;
use middle::typeck;
use core::prelude::*;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearSet;
use syntax::ast;
use syntax::ast::*;
use syntax::ast_util::def_id_of_def;
@ -30,27 +30,29 @@ use syntax::codemap;
use syntax::print::pprust::expr_to_str;
use syntax::{visit, ast_util, ast_map};
pub type map = HashMap<node_id, ()>;
pub type map = @LinearSet<node_id>;
struct ctx {
exp_map2: resolve::ExportMap2,
tcx: ty::ctxt,
method_map: typeck::method_map,
rmap: map
rmap: &'self mut LinearSet<node_id>,
}
pub fn find_reachable(crate_mod: &_mod, exp_map2: resolve::ExportMap2,
tcx: ty::ctxt, method_map: typeck::method_map) -> map {
let rmap = HashMap();
let cx = ctx {
exp_map2: exp_map2,
tcx: tcx,
method_map: method_map,
rmap: rmap
};
traverse_public_mod(cx, ast::crate_node_id, crate_mod);
traverse_all_resources_and_impls(cx, crate_mod);
rmap
let mut rmap = LinearSet::new();
{
let cx = ctx {
exp_map2: exp_map2,
tcx: tcx,
method_map: method_map,
rmap: &mut rmap
};
traverse_public_mod(cx, ast::crate_node_id, crate_mod);
traverse_all_resources_and_impls(cx, crate_mod);
}
return @rmap;
}
fn traverse_exports(cx: ctx, mod_id: node_id) -> bool {
@ -69,20 +71,17 @@ fn traverse_exports(cx: ctx, mod_id: node_id) -> bool {
fn traverse_def_id(cx: ctx, did: def_id) {
if did.crate != local_crate { return; }
let n = match cx.tcx.items.find(&did.node) {
None => return, // This can happen for self, for example
Some(ref n) => (/*bad*/copy *n)
};
match n {
ast_map::node_item(item, _) => traverse_public_item(cx, item),
ast_map::node_method(_, impl_id, _) => traverse_def_id(cx, impl_id),
ast_map::node_foreign_item(item, _, _, _) => {
cx.rmap.insert(item.id, ());
}
ast_map::node_variant(ref v, _, _) => {
cx.rmap.insert((*v).node.id, ());
}
_ => ()
match cx.tcx.items.find(&did.node) {
None => (), // This can happen for self, for example
Some(&ast_map::node_item(item, _)) => traverse_public_item(cx, item),
Some(&ast_map::node_method(_, impl_id, _)) => traverse_def_id(cx, impl_id),
Some(&ast_map::node_foreign_item(item, _, _, _)) => {
cx.rmap.insert(item.id);
}
Some(&ast_map::node_variant(ref v, _, _)) => {
cx.rmap.insert(v.node.id);
}
_ => ()
}
}
@ -96,14 +95,16 @@ fn traverse_public_mod(cx: ctx, mod_id: node_id, m: &_mod) {
}
fn traverse_public_item(cx: ctx, item: @item) {
if cx.rmap.contains_key(&item.id) { return; }
cx.rmap.insert(item.id, ());
// XXX: it shouldn't be necessary to do this
let rmap: &mut LinearSet<node_id> = cx.rmap;
if rmap.contains(&item.id) { return; }
rmap.insert(item.id);
match item.node {
item_mod(ref m) => traverse_public_mod(cx, item.id, m),
item_foreign_mod(ref nm) => {
if !traverse_exports(cx, item.id) {
for nm.items.each |item| {
cx.rmap.insert(item.id, ());
cx.rmap.insert(item.id);
}
}
}
@ -119,17 +120,17 @@ fn traverse_public_item(cx: ctx, item: @item) {
m.generics.ty_params.len() > 0u ||
attr::find_inline_attr(m.attrs) != attr::ia_none
{
cx.rmap.insert(m.id, ());
cx.rmap.insert(m.id);
traverse_inline_body(cx, &m.body);
}
}
}
item_struct(ref struct_def, ref generics) => {
for struct_def.ctor_id.each |&ctor_id| {
cx.rmap.insert(ctor_id, ());
cx.rmap.insert(ctor_id);
}
for struct_def.dtor.each |dtor| {
cx.rmap.insert(dtor.node.id, ());
cx.rmap.insert(dtor.node.id);
if generics.ty_params.len() > 0u ||
attr::find_inline_attr(dtor.node.attrs) != attr::ia_none
{
@ -151,17 +152,19 @@ fn mk_ty_visitor() -> visit::vt<ctx> {
..*visit::default_visitor()})
}
fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt<ctx>) {
if cx.rmap.contains_key(&ty.id) { return; }
cx.rmap.insert(ty.id, ());
fn traverse_ty(ty: @Ty, cx: ctx<'a>, v: visit::vt<ctx<'a>>) {
// XXX: it shouldn't be necessary to do this
let rmap: &mut LinearSet<node_id> = cx.rmap;
if rmap.contains(&ty.id) { return; }
rmap.insert(ty.id);
match ty.node {
ty_path(p, p_id) => {
match cx.tcx.def_map.find(&p_id) {
// Kind of a hack to check this here, but I'm not sure what else
// to do
Some(def_prim_ty(_)) => { /* do nothing */ }
Some(d) => traverse_def_id(cx, def_id_of_def(d)),
Some(&def_prim_ty(_)) => { /* do nothing */ }
Some(&d) => traverse_def_id(cx, def_id_of_def(d)),
None => { /* do nothing -- but should we fail here? */ }
}
for p.types.each |t| {
@ -173,11 +176,11 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt<ctx>) {
}
fn traverse_inline_body(cx: ctx, body: &blk) {
fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
fn traverse_expr(e: @expr, cx: ctx<'a>, v: visit::vt<ctx<'a>>) {
match e.node {
expr_path(_) => {
match cx.tcx.def_map.find(&e.id) {
Some(d) => {
Some(&d) => {
traverse_def_id(cx, def_id_of_def(d));
}
None => cx.tcx.sess.span_bug(e.span, fmt!("Unbound node \
@ -187,7 +190,7 @@ fn traverse_inline_body(cx: ctx, body: &blk) {
}
expr_field(_, _, _) => {
match cx.method_map.find(&e.id) {
Some(typeck::method_map_entry {
Some(&typeck::method_map_entry {
origin: typeck::method_static(did),
_
}) => {
@ -198,7 +201,7 @@ fn traverse_inline_body(cx: ctx, body: &blk) {
}
expr_method_call(*) => {
match cx.method_map.find(&e.id) {
Some(typeck::method_map_entry {
Some(&typeck::method_map_entry {
origin: typeck::method_static(did),
_
}) => {

View file

@ -337,7 +337,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block,
use syntax::parse::token::special_idents::tydesc;
let final = sub_block(bcx, ~"final");
fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc));
let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
let (_, tydesc_ty) = *bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
let mut r = Reflector {
visitor_val: visitor_val,

View file

@ -28,7 +28,6 @@ use util::common::indenter;
use util::ppaux::ty_to_str;
use core::option::None;
use core::uint;
use core::vec;
use syntax::ast;
use syntax::codemap;

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::prelude::*;
use lib::llvm::llvm;
use lib::llvm::{TypeRef};
@ -100,8 +101,10 @@ pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
// behavior.
pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
if cx.llsizingtypes.contains_key(&t) {
return cx.llsizingtypes.get(&t);
match cx.llsizingtypes.find(&t) {
// FIXME(#5562): removing this copy causes a segfault in stage1 core
Some(t) => return /*bad*/ copy *t,
None => ()
}
let llsizingty = match ty::get(t).sty {
@ -160,7 +163,11 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
debug!("type_of %?: %?", t, ty::get(t));
// Check the cache.
if cx.lltypes.contains_key(&t) { return cx.lltypes.get(&t); }
match cx.lltypes.find(&t) {
// FIXME(#5562): removing this copy causes a segfault in stage1 core
Some(t) => return /*bad*/ copy *t,
None => ()
}
// Replace any typedef'd types with their equivalent non-typedef
// type. This ensures that all LLVM nominal types that contain

View file

@ -27,6 +27,7 @@
// much information, but have the disadvantage of being very
// invasive.)
use core::prelude::*;
use middle::freevars;
use middle::trans::common::*;
@ -59,7 +60,7 @@ pub struct Context {
pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
-> ~[type_uses] {
match ccx.type_use_cache.find(&fn_id) {
Some(uses) => return uses,
Some(uses) => return /*bad*/ copy *uses,
None => ()
}
@ -97,7 +98,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
return uses;
}
let map_node = match ccx.tcx.items.find(&fn_id_loc.node) {
Some(ref x) => (/*bad*/copy *x),
Some(x) => (/*bad*/copy *x),
None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?",
fn_id_loc))
};
@ -249,8 +250,11 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
match mth.origin {
typeck::method_static(did) => {
for cx.ccx.tcx.node_type_substs.find(&callee_id).each |ts| {
// FIXME(#5562): removing this copy causes a segfault
// before stage2
let ts = /*bad*/ copy **ts;
let type_uses = type_uses_for(cx.ccx, did, ts.len());
for vec::each2(type_uses, *ts) |uses, subst| {
for vec::each2(type_uses, ts) |uses, subst| {
type_needs(cx, *uses, *subst)
}
}
@ -295,9 +299,11 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
}
expr_path(_) => {
for cx.ccx.tcx.node_type_substs.find(&e.id).each |ts| {
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(&e.id));
// FIXME(#5562): removing this copy causes a segfault before stage2
let ts = copy **ts;
let id = ast_util::def_id_of_def(*cx.ccx.tcx.def_map.get(&e.id));
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
for vec::each2(uses_for_ts, *ts) |uses, subst| {
for vec::each2(uses_for_ts, ts) |uses, subst| {
type_needs(cx, *uses, *subst)
}
}

View file

@ -37,9 +37,7 @@ use core::result;
use core::to_bytes;
use core::uint;
use core::vec;
use core::hashmap::linear::LinearMap;
use std::oldmap::HashMap;
use std::oldmap;
use core::hashmap::linear::{LinearMap, LinearSet};
use std::smallintmap::SmallIntMap;
use syntax::ast::*;
use syntax::ast_util::{is_local, local_def};
@ -118,7 +116,7 @@ pub struct creader_cache_key {
len: uint
}
type creader_cache = HashMap<creader_cache_key, t>;
type creader_cache = @mut LinearMap<creader_cache_key, t>;
impl to_bytes::IterBytes for creader_cache_key {
fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
@ -222,7 +220,7 @@ pub enum AutoRefKind {
// This is a map from ID of each implementation to the method info and trait
// method ID of each of the default methods belonging to the trait that that
// implementation implements.
pub type ProvidedMethodsMap = HashMap<def_id,@mut ~[@ProvidedMethodInfo]>;
pub type ProvidedMethodsMap = @mut LinearMap<def_id,@mut ~[@ProvidedMethodInfo]>;
// Stores the method info and definition ID of the associated trait method for
// each instantiation of each provided method.
@ -245,7 +243,7 @@ pub type ctxt = @ctxt_;
struct ctxt_ {
diag: @syntax::diagnostic::span_handler,
interner: HashMap<intern_key, t_box>,
interner: @mut LinearMap<intern_key, t_box>,
next_id: @mut uint,
vecs_implicitly_copyable: bool,
legacy_modes: bool,
@ -265,43 +263,43 @@ struct ctxt_ {
// of this node. This only applies to nodes that refer to entities
// parameterized by type parameters, such as generic fns, types, or
// other items.
node_type_substs: HashMap<node_id, ~[t]>,
node_type_substs: @mut LinearMap<node_id, ~[t]>,
items: ast_map::map,
intrinsic_defs: HashMap<ast::ident, (ast::def_id, t)>,
intrinsic_defs: @mut LinearMap<ast::ident, (ast::def_id, t)>,
freevars: freevars::freevar_map,
tcache: type_cache,
rcache: creader_cache,
ccache: constness_cache,
short_names_cache: HashMap<t, @~str>,
needs_unwind_cleanup_cache: HashMap<t, bool>,
short_names_cache: @mut LinearMap<t, @~str>,
needs_unwind_cleanup_cache: @mut LinearMap<t, bool>,
tc_cache: @mut LinearMap<uint, TypeContents>,
ast_ty_to_ty_cache: HashMap<node_id, ast_ty_to_ty_cache_entry>,
enum_var_cache: HashMap<def_id, @~[VariantInfo]>,
trait_method_cache: HashMap<def_id, @~[method]>,
ty_param_bounds: HashMap<ast::node_id, param_bounds>,
inferred_modes: HashMap<ast::node_id, ast::mode>,
adjustments: HashMap<ast::node_id, @AutoAdjustment>,
normalized_cache: HashMap<t, t>,
ast_ty_to_ty_cache: @mut LinearMap<node_id, ast_ty_to_ty_cache_entry>,
enum_var_cache: @mut LinearMap<def_id, @~[VariantInfo]>,
trait_method_cache: @mut LinearMap<def_id, @~[method]>,
ty_param_bounds: @mut LinearMap<ast::node_id, param_bounds>,
inferred_modes: @mut LinearMap<ast::node_id, ast::mode>,
adjustments: @mut LinearMap<ast::node_id, @AutoAdjustment>,
normalized_cache: @mut LinearMap<t, t>,
lang_items: middle::lang_items::LanguageItems,
// A mapping from an implementation ID to the method info and trait
// method ID of the provided (a.k.a. default) methods in the traits that
// that implementation implements.
provided_methods: ProvidedMethodsMap,
provided_method_sources: HashMap<ast::def_id, ProvidedMethodSource>,
supertraits: HashMap<ast::def_id, @~[InstantiatedTraitRef]>,
provided_method_sources: @mut LinearMap<ast::def_id, ProvidedMethodSource>,
supertraits: @mut LinearMap<ast::def_id, @~[InstantiatedTraitRef]>,
// A mapping from the def ID of an enum or struct type to the def ID
// of the method that implements its destructor. If the type is not
// present in this map, it does not have a destructor. This map is
// populated during the coherence phase of typechecking.
destructor_for_type: HashMap<ast::def_id, ast::def_id>,
destructor_for_type: @mut LinearMap<ast::def_id, ast::def_id>,
// A method will be in this list if and only if it is a destructor.
destructors: HashMap<ast::def_id, ()>,
destructors: @mut LinearSet<ast::def_id>,
// Maps a trait onto a mapping from self-ty to impl
trait_impls: HashMap<ast::def_id, HashMap<t, @Impl>>
trait_impls: @mut LinearMap<ast::def_id, @mut LinearMap<t, @Impl>>
}
enum tbox_flag {
@ -778,18 +776,18 @@ pub struct ty_param_substs_and_ty {
ty: ty::t
}
type type_cache = HashMap<ast::def_id, ty_param_bounds_and_ty>;
type type_cache = @mut LinearMap<ast::def_id, ty_param_bounds_and_ty>;
type constness_cache = HashMap<ast::def_id, const_eval::constness>;
type constness_cache = @mut LinearMap<ast::def_id, const_eval::constness>;
pub type node_type_table = @mut SmallIntMap<t>;
fn mk_rcache() -> creader_cache {
return oldmap::HashMap();
return @mut LinearMap::new();
}
pub fn new_ty_hash<V:Copy>() -> oldmap::HashMap<t, V> {
oldmap::HashMap()
pub fn new_ty_hash<V:Copy>() -> @mut LinearMap<t, V> {
@mut LinearMap::new()
}
pub fn mk_ctxt(s: session::Session,
@ -811,13 +809,12 @@ pub fn mk_ctxt(s: session::Session,
}
}
let interner = oldmap::HashMap();
let vecs_implicitly_copyable =
get_lint_level(s.lint_settings.default_settings,
lint::vecs_implicitly_copyable) == allow;
@ctxt_ {
diag: s.diagnostic(),
interner: interner,
interner: @mut LinearMap::new(),
next_id: @mut 0,
vecs_implicitly_copyable: vecs_implicitly_copyable,
legacy_modes: legacy_modes,
@ -827,30 +824,30 @@ pub fn mk_ctxt(s: session::Session,
region_map: region_map,
region_paramd_items: region_paramd_items,
node_types: @mut SmallIntMap::new(),
node_type_substs: oldmap::HashMap(),
node_type_substs: @mut LinearMap::new(),
items: amap,
intrinsic_defs: oldmap::HashMap(),
intrinsic_defs: @mut LinearMap::new(),
freevars: freevars,
tcache: HashMap(),
tcache: @mut LinearMap::new(),
rcache: mk_rcache(),
ccache: HashMap(),
ccache: @mut LinearMap::new(),
short_names_cache: new_ty_hash(),
needs_unwind_cleanup_cache: new_ty_hash(),
tc_cache: @mut LinearMap::new(),
ast_ty_to_ty_cache: HashMap(),
enum_var_cache: HashMap(),
trait_method_cache: HashMap(),
ty_param_bounds: HashMap(),
inferred_modes: HashMap(),
adjustments: HashMap(),
ast_ty_to_ty_cache: @mut LinearMap::new(),
enum_var_cache: @mut LinearMap::new(),
trait_method_cache: @mut LinearMap::new(),
ty_param_bounds: @mut LinearMap::new(),
inferred_modes: @mut LinearMap::new(),
adjustments: @mut LinearMap::new(),
normalized_cache: new_ty_hash(),
lang_items: lang_items,
provided_methods: HashMap(),
provided_method_sources: HashMap(),
supertraits: HashMap(),
destructor_for_type: HashMap(),
destructors: HashMap(),
trait_impls: HashMap()
provided_methods: @mut LinearMap::new(),
provided_method_sources: @mut LinearMap::new(),
supertraits: @mut LinearMap::new(),
destructor_for_type: @mut LinearMap::new(),
destructors: @mut LinearSet::new(),
trait_impls: @mut LinearMap::new()
}
}
@ -863,7 +860,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) }
fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
let key = intern_key { sty: to_unsafe_ptr(&st), o_def_id: o_def_id };
match cx.interner.find(&key) {
Some(t) => unsafe { return cast::reinterpret_cast(&t); },
Some(&t) => unsafe { return cast::reinterpret_cast(&t); },
_ => ()
}
@ -1161,7 +1158,7 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode {
// with id `id`.
pub fn encl_region(cx: ctxt, id: ast::node_id) -> ty::Region {
match cx.region_map.find(&id) {
Some(encl_scope) => ty::re_scope(encl_scope),
Some(&encl_scope) => ty::re_scope(encl_scope),
None => ty::re_static
}
}
@ -1622,25 +1619,24 @@ pub fn type_needs_drop(cx: ctxt, ty: t) -> bool {
// cleanups.
pub fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool {
match cx.needs_unwind_cleanup_cache.find(&ty) {
Some(result) => return result,
Some(&result) => return result,
None => ()
}
let tycache = new_ty_hash();
let mut tycache = LinearSet::new();
let needs_unwind_cleanup =
type_needs_unwind_cleanup_(cx, ty, tycache, false);
type_needs_unwind_cleanup_(cx, ty, &mut tycache, false);
cx.needs_unwind_cleanup_cache.insert(ty, needs_unwind_cleanup);
return needs_unwind_cleanup;
}
fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
tycache: oldmap::HashMap<t, ()>,
tycache: &mut LinearSet<t>,
encountered_box: bool) -> bool {
// Prevent infinite recursion
match tycache.find(&ty) {
Some(_) => return false,
None => { tycache.insert(ty, ()); }
if !tycache.insert(ty) {
return false;
}
let mut encountered_box = encountered_box;
@ -2016,7 +2012,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
fail_unless!(p.def_id.crate == ast::local_crate);
param_bounds_to_contents(
cx, cx.ty_param_bounds.get(&p.def_id.node))
cx, *cx.ty_param_bounds.get(&p.def_id.node))
}
ty_self(_) => {
@ -2711,10 +2707,6 @@ impl to_bytes::IterBytes for sty {
}
}
pub fn br_hashmap<V:Copy>() -> HashMap<bound_region, V> {
oldmap::HashMap()
}
pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
//io::println(fmt!("%?/%?", id, cx.node_types.len()));
match cx.node_types.find(&(id as uint)) {
@ -2729,7 +2721,7 @@ pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
pub fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] {
match cx.node_type_substs.find(&id) {
None => return ~[],
Some(ts) => return ts
Some(ts) => return /*bad*/ copy *ts
}
}
@ -2882,7 +2874,7 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t {
return match cx.adjustments.find(&expr.id) {
None => unadjusted_ty,
Some(@AutoAddEnv(r, s)) => {
Some(&@AutoAddEnv(r, s)) => {
match ty::get(unadjusted_ty).sty {
ty::ty_bare_fn(ref b) => {
ty::mk_closure(
@ -2900,7 +2892,7 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t {
}
}
Some(@AutoDerefRef(ref adj)) => {
Some(&@AutoDerefRef(ref adj)) => {
let mut adjusted_ty = unadjusted_ty;
for uint::range(0, adj.autoderefs) |i| {
@ -3037,7 +3029,7 @@ pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
pub fn resolve_expr(tcx: ctxt, expr: @ast::expr) -> ast::def {
match tcx.def_map.find(&expr.id) {
Some(def) => def,
Some(&def) => def,
None => {
tcx.sess.span_bug(expr.span, fmt!(
"No def-map entry for expr %?", expr.id));
@ -3270,19 +3262,20 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) {
// Maintains a little union-set tree for inferred modes. `canon()` returns
// the current head value for `m0`.
fn canon<T:Copy + cmp::Eq>(tbl: HashMap<ast::node_id, ast::inferable<T>>,
fn canon<T:Copy + cmp::Eq>(tbl: &mut LinearMap<ast::node_id, ast::inferable<T>>,
+m0: ast::inferable<T>) -> ast::inferable<T> {
match m0 {
ast::infer(id) => match tbl.find(&id) {
None => m0,
Some(ref m1) => {
let cm1 = canon(tbl, (*m1));
ast::infer(id) => {
let m1 = match tbl.find(&id) {
None => return m0,
Some(&m1) => m1
};
let cm1 = canon(tbl, m1);
// path compression:
if cm1 != (*m1) { tbl.insert(id, cm1); }
if cm1 != m1 { tbl.insert(id, cm1); }
cm1
}
},
_ => m0
},
_ => m0
}
}
@ -3545,7 +3538,7 @@ pub fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
if is_local(id) {
match cx.items.find(&id.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: item_trait(_, _, ref ms),
_
}, _)) =>
@ -3565,7 +3558,7 @@ pub fn trait_supertraits(cx: ctxt,
-> @~[InstantiatedTraitRef] {
// Check the cache.
match cx.supertraits.find(&id) {
Some(instantiated_trait_info) => { return instantiated_trait_info; }
Some(&instantiated_trait_info) => { return instantiated_trait_info; }
None => {} // Continue.
}
@ -3598,7 +3591,7 @@ pub fn trait_supertraits(cx: ctxt,
pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
match cx.trait_method_cache.find(&id) {
// Local traits are supposed to have been added explicitly.
Some(ms) => ms,
Some(&ms) => ms,
_ => {
// If the lookup in trait_method_cache fails, assume that the trait
// method we're trying to look up is in a different crate, and look
@ -3634,7 +3627,7 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, store: TraitStore) -> ~[t] {
if id.crate == ast::local_crate {
debug!("(impl_traits) searching for trait impl %?", id);
match cx.items.find(&id.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_impl(_, opt_trait, _, _),
_},
_)) => {
@ -3670,7 +3663,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option<ast::def_id> {
}
match cx.items.find(&struct_did.node) {
Some(ast_map::node_item(item, _)) => {
Some(&ast_map::node_item(item, _)) => {
match item.node {
ast::item_struct(struct_def, _) => {
struct_def.ctor_id.map(|ctor_id|
@ -3736,13 +3729,13 @@ pub impl DtorKind {
Otherwise return none. */
pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
match cx.destructor_for_type.find(&struct_id) {
Some(method_def_id) => return TraitDtor(method_def_id),
Some(&method_def_id) => return TraitDtor(method_def_id),
None => {} // Continue.
}
if is_local(struct_id) {
match cx.items.find(&struct_id.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor),
_ },
_),
@ -3769,8 +3762,12 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
if id.crate != ast::local_crate {
csearch::get_item_path(cx, id)
} else {
let node = cx.items.get(&id.node);
match node {
// FIXME (#5521): uncomment this code and don't have a catch-all at the
// end of the match statement. Favor explicitly listing
// each variant.
// let node = cx.items.get(&id.node);
// match *node {
match *cx.items.get(&id.node) {
ast_map::node_item(item, path) => {
let item_elt = match item.node {
item_mod(_) | item_foreign_mod(_) => {
@ -3812,9 +3809,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
vec::append_one(/*bad*/copy *path, ast_map::path_name(item.ident))
}
ast_map::node_stmt(*) | ast_map::node_expr(*) |
ast_map::node_arg(*) | ast_map::node_local(*) |
ast_map::node_block(*) => {
ref node => {
cx.sess.bug(fmt!("cannot find item_path for node %?", node));
}
}
@ -3834,7 +3829,7 @@ pub fn type_is_empty(cx: ctxt, t: t) -> bool {
pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
match cx.enum_var_cache.find(&id) {
Some(variants) => return variants,
Some(&variants) => return variants,
_ => { /* fallthrough */ }
}
@ -3846,7 +3841,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
call eval_const_expr, it should never get called twice for the same
expr, since check_enum_variants also updates the enum_var_cache
*/
match cx.items.get(&id.node) {
match *cx.items.get(&id.node) {
ast_map::node_item(@ast::item {
node: ast::item_enum(ref enum_definition, _),
_
@ -3920,7 +3915,7 @@ pub fn lookup_item_type(cx: ctxt,
did: ast::def_id)
-> ty_param_bounds_and_ty {
match cx.tcache.find(&did) {
Some(tpt) => {
Some(&tpt) => {
// The item is in this crate. The caller should have added it to the
// type cache already
return tpt;
@ -3962,7 +3957,7 @@ pub fn lookup_field_type(tcx: ctxt,
pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
if did.crate == ast::local_crate {
match cx.items.find(&did.node) {
Some(ast_map::node_item(i,_)) => {
Some(&ast_map::node_item(i,_)) => {
match i.node {
ast::item_struct(struct_def, _) => {
struct_field_tys(struct_def.fields)
@ -3970,7 +3965,7 @@ pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
_ => cx.sess.bug(~"struct ID bound to non-struct")
}
}
Some(ast_map::node_variant(ref variant, _, _)) => {
Some(&ast_map::node_variant(ref variant, _, _)) => {
match (*variant).node.kind {
ast::struct_variant_kind(struct_def) => {
struct_field_tys(struct_def.fields)
@ -4168,7 +4163,7 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
}
match cx.normalized_cache.find(&t) {
Some(t) => return t,
Some(&t) => return t,
None => ()
}
@ -4299,7 +4294,7 @@ pub fn iter_bound_traits_and_supertraits(tcx: ctxt,
}
};
let mut supertrait_map = HashMap();
let mut supertrait_map = LinearMap::new();
let mut seen_def_ids = ~[];
let mut i = 0;
let trait_ty_id = ty_to_def_id(bound_trait_ty).expect(

View file

@ -60,7 +60,6 @@ use middle::ty::{ty_param_substs_and_ty};
use middle::ty;
use middle::typeck::rscope::{in_binding_rscope};
use middle::typeck::rscope::{region_scope, type_rscope, RegionError};
use middle::typeck::{CrateCtxt};
use core::result;
use core::vec;
@ -236,11 +235,11 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
}
ast::ty_path(path, id) if a_seq_ty.mutbl == ast::m_imm => {
match tcx.def_map.find(&id) {
Some(ast::def_prim_ty(ast::ty_str)) => {
Some(&ast::def_prim_ty(ast::ty_str)) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
return ty::mk_estr(tcx, vst);
}
Some(ast::def_ty(type_def_id)) => {
Some(&ast::def_ty(type_def_id)) => {
let result = ast_path_to_substs_and_ty(
self, rscope,
type_def_id, path);
@ -304,8 +303,8 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
let tcx = self.tcx();
match tcx.ast_ty_to_ty_cache.find(&ast_ty.id) {
Some(ty::atttce_resolved(ty)) => return ty,
Some(ty::atttce_unresolved) => {
Some(&ty::atttce_resolved(ty)) => return ty,
Some(&ty::atttce_unresolved) => {
tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \
insert an enum in the cycle, \
if this is desired");
@ -360,7 +359,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
None => tcx.sess.span_fatal(
ast_ty.span, fmt!("unbound path %s",
path_to_str(path, tcx.sess.intr()))),
Some(d) => d
Some(&d) => d
};
match a_def {
ast::def_ty(did) | ast::def_struct(did) => {

View file

@ -18,8 +18,8 @@ use middle::typeck::check::{instantiate_path, lookup_def};
use middle::typeck::check::{structure_of, valid_range_bounds};
use middle::typeck::require_same_types;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::vec;
use std::oldmap::HashMap;
use syntax::ast;
use syntax::ast_util;
use syntax::codemap::span;
@ -228,7 +228,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
/// `class_fields` describes the type of each field of the struct.
/// `class_id` is the ID of the struct.
/// `substitutions` are the type substitutions applied to this struct type
/// (e.g. K,V in HashMap<K,V>).
/// (e.g. K,V in LinearMap<K,V>).
/// `etc` is true if the pattern said '...' and false otherwise.
pub fn check_struct_pat_fields(pcx: pat_ctxt,
span: span,
@ -241,23 +241,23 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt,
let tcx = pcx.fcx.ccx.tcx;
// Index the class fields.
let field_map = HashMap();
let mut field_map = LinearMap::new();
for class_fields.eachi |i, class_field| {
field_map.insert(class_field.ident, i);
}
// Typecheck each field.
let found_fields = HashMap();
let mut found_fields = LinearSet::new();
for fields.each |field| {
match field_map.find(&field.ident) {
Some(index) => {
Some(&index) => {
let class_field = class_fields[index];
let field_type = ty::lookup_field_type(tcx,
class_id,
class_field.id,
substitutions);
check_pat(pcx, field.pat, field_type);
found_fields.insert(index, ());
found_fields.insert(index);
}
None => {
let name = pprust::path_to_str(path, tcx.sess.intr());
@ -272,7 +272,7 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt,
// Report an error if not all the fields were specified.
if !etc {
for class_fields.eachi |i, field| {
if found_fields.contains_key(&i) {
if found_fields.contains(&i) {
loop;
}
tcx.sess.span_err(span,
@ -293,11 +293,11 @@ pub fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span,
// Check to ensure that the struct is the one specified.
match tcx.def_map.find(&pat_id) {
Some(ast::def_struct(supplied_def_id))
Some(&ast::def_struct(supplied_def_id))
if supplied_def_id == class_id => {
// OK.
}
Some(ast::def_struct(*)) | Some(ast::def_variant(*)) => {
Some(&ast::def_struct(*)) | Some(&ast::def_variant(*)) => {
let name = pprust::path_to_str(path, tcx.sess.intr());
tcx.sess.span_err(span,
fmt!("mismatched types: expected `%s` but \
@ -334,7 +334,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt,
// Find the variant that was specified.
match tcx.def_map.find(&pat_id) {
Some(ast::def_variant(found_enum_id, variant_id))
Some(&ast::def_variant(found_enum_id, variant_id))
if found_enum_id == enum_id => {
// Get the struct fields from this struct-like enum variant.
let class_fields = ty::lookup_struct_fields(tcx, variant_id);
@ -342,7 +342,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt,
check_struct_pat_fields(pcx, span, path, fields, class_fields,
variant_id, substitutions, etc);
}
Some(ast::def_struct(*)) | Some(ast::def_variant(*)) => {
Some(&ast::def_struct(*)) | Some(&ast::def_variant(*)) => {
let name = pprust::path_to_str(path, tcx.sess.intr());
tcx.sess.span_err(span,
fmt!("mismatched types: expected `%s` but \
@ -394,7 +394,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
}
ast::pat_enum(*) |
ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => {
let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id));
let const_did = ast_util::def_id_of_def(*tcx.def_map.get(&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);
@ -421,7 +421,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
}
}
let canon_id = pcx.map.get(&ast_util::path_to_ident(name));
let canon_id = *pcx.map.get(&ast_util::path_to_ident(name));
if canon_id != pat.id {
let ct = fcx.local_ty(pat.span, canon_id);
demand::eqtype(fcx, pat.span, ct, typ);

View file

@ -95,10 +95,10 @@ use middle::typeck::{method_self, method_static, method_trait, method_super};
use util::common::indenter;
use util::ppaux::expr_repr;
use core::hashmap::linear::LinearSet;
use core::result;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use syntax::ast::{def_id, sty_by_ref, sty_value, sty_region, sty_box};
use syntax::ast::{sty_uniq, sty_static, node_id, by_copy, by_ref};
use syntax::ast::{m_const, m_mutbl, m_imm};
@ -131,6 +131,7 @@ pub fn lookup(
check_traits: CheckTraitsFlag, // Whether we check traits only.
autoderef_receiver: AutoderefReceiverFlag)
-> Option<method_map_entry> {
let mut impl_dups = LinearSet::new();
let lcx = LookupContext {
fcx: fcx,
expr: expr,
@ -138,7 +139,7 @@ pub fn lookup(
callee_id: callee_id,
m_name: m_name,
supplied_tps: supplied_tps,
impl_dups: HashMap(),
impl_dups: &mut impl_dups,
inherent_candidates: @mut ~[],
extension_candidates: @mut ~[],
deref_args: deref_args,
@ -158,7 +159,7 @@ pub struct LookupContext {
callee_id: node_id,
m_name: ast::ident,
supplied_tps: &'self [ty::t],
impl_dups: HashMap<def_id, ()>,
impl_dups: &'self mut LinearSet<def_id>,
inherent_candidates: @mut ~[Candidate],
extension_candidates: @mut ~[Candidate],
deref_args: check::DerefArgs,
@ -344,8 +345,8 @@ pub impl<'self> LookupContext<'self> {
// If the method being called is associated with a trait, then
// find all the impls of that trait. Each of those are
// candidates.
let opt_applicable_traits = self.fcx.ccx.trait_map.find(
&self.expr.id);
let trait_map: &mut resolve::TraitMap = &mut self.fcx.ccx.trait_map;
let opt_applicable_traits = trait_map.find(&self.expr.id);
for opt_applicable_traits.each |applicable_traits| {
for applicable_traits.each |trait_did| {
let coherence_info = self.fcx.ccx.coherence_info;
@ -362,7 +363,7 @@ pub impl<'self> LookupContext<'self> {
// Look for default methods.
match self.tcx().provided_methods.find(trait_did) {
Some(methods) => {
Some(&methods) => {
self.push_candidates_from_provided_methods(
self.extension_candidates, self_ty, *trait_did,
methods);
@ -384,7 +385,7 @@ pub impl<'self> LookupContext<'self> {
let mut next_bound_idx = 0; // count only trait bounds
let bounds = tcx.ty_param_bounds.get(&param_ty.def_id.node);
for vec::each(*bounds) |bound| {
for bounds.each |bound| {
let bound_trait_ty = match *bound {
ty::bound_trait(bound_t) => bound_t,
@ -639,7 +640,7 @@ pub impl<'self> LookupContext<'self> {
fn push_candidates_from_impl(&self, candidates: &mut ~[Candidate],
impl_info: &resolve::Impl) {
if !self.impl_dups.insert(impl_info.did, ()) {
if !self.impl_dups.insert(impl_info.did) {
return; // already visited
}
@ -1195,7 +1196,7 @@ pub impl<'self> LookupContext<'self> {
match candidate.origin {
method_static(method_id) | method_self(method_id, _)
| method_super(method_id, _) => {
bad = self.tcx().destructors.contains_key(&method_id);
bad = self.tcx().destructors.contains(&method_id);
}
method_param(method_param { trait_id: trait_id, _ }) |
method_trait(trait_id, _, _) => {
@ -1256,7 +1257,7 @@ pub impl<'self> LookupContext<'self> {
fn report_static_candidate(&self, idx: uint, did: def_id) {
let span = if did.crate == ast::local_crate {
match self.tcx().items.find(&did.node) {
Some(ast_map::node_method(m, _, _)) => m.span,
Some(&ast_map::node_method(m, _, _)) => m.span,
_ => fail!(fmt!("report_static_candidate: bad item %?", did))
}
} else {

View file

@ -112,6 +112,7 @@ use util::ppaux::{bound_region_to_str, expr_repr, pat_repr};
use util::ppaux;
use core::either;
use core::hashmap::linear::LinearMap;
use core::option;
use core::ptr;
use core::result::{Result, Ok, Err};
@ -119,8 +120,6 @@ use core::result;
use core::str;
use core::vec;
use std::list::Nil;
use std::oldmap::HashMap;
use std::oldmap;
use syntax::ast::{provided, required, ty_i};
use syntax::ast;
use syntax::ast_map;
@ -160,12 +159,12 @@ pub struct SelfInfo {
/// share the inherited fields.
pub struct inherited {
infcx: @mut infer::InferCtxt,
locals: HashMap<ast::node_id, ty::t>,
locals: @mut LinearMap<ast::node_id, ty::t>,
// Temporary tables:
node_types: HashMap<ast::node_id, ty::t>,
node_type_substs: HashMap<ast::node_id, ty::substs>,
adjustments: HashMap<ast::node_id, @ty::AutoAdjustment>,
node_types: @mut LinearMap<ast::node_id, ty::t>,
node_type_substs: @mut LinearMap<ast::node_id, ty::substs>,
adjustments: @mut LinearMap<ast::node_id, @ty::AutoAdjustment>,
method_map: method_map,
vtable_map: vtable_map,
}
@ -222,12 +221,12 @@ pub struct FnCtxt {
pub fn blank_inherited(ccx: @mut CrateCtxt) -> @inherited {
@inherited {
infcx: infer::new_infer_ctxt(ccx.tcx),
locals: HashMap(),
node_types: oldmap::HashMap(),
node_type_substs: oldmap::HashMap(),
adjustments: oldmap::HashMap(),
method_map: oldmap::HashMap(),
vtable_map: oldmap::HashMap(),
locals: @mut LinearMap::new(),
node_types: @mut LinearMap::new(),
node_type_substs: @mut LinearMap::new(),
adjustments: @mut LinearMap::new(),
method_map: @mut LinearMap::new(),
vtable_map: @mut LinearMap::new(),
}
}
@ -399,7 +398,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
assign(self_info.self_id, Some(self_info.self_ty));
debug!("self is assigned to %s",
fcx.infcx().ty_to_str(
fcx.inh.locals.get(&self_info.self_id)));
*fcx.inh.locals.get(&self_info.self_id)));
}
// Add formal parameters.
@ -432,7 +431,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
debug!("Local variable %s is assigned type %s",
fcx.pat_to_str(local.node.pat),
fcx.infcx().ty_to_str(
fcx.inh.locals.get(&local.node.id)));
*fcx.inh.locals.get(&local.node.id)));
visit::visit_local(local, e, v);
};
@ -445,7 +444,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
debug!("Pattern binding %s is assigned to %s",
*tcx.sess.str_of(path.idents[0]),
fcx.infcx().ty_to_str(
fcx.inh.locals.get(&p.id)));
*fcx.inh.locals.get(&p.id)));
}
_ => {}
}
@ -506,11 +505,12 @@ pub fn check_method(ccx: @mut CrateCtxt,
pub fn check_no_duplicate_fields(tcx: ty::ctxt,
fields: ~[(ast::ident, span)]) {
let field_names = HashMap();
let mut field_names = LinearMap::new();
for fields.each |p| {
let (id, sp) = *p;
match field_names.find(&id) {
let orig_sp = field_names.find(&id).map_consume(|x| *x);
match orig_sp {
Some(orig_sp) => {
tcx.sess.span_err(sp, fmt!("Duplicate field \
name %s in record type declaration",
@ -572,7 +572,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
check_bare_fn(ccx, decl, body, it.id, None);
}
ast::item_impl(_, _, ty, ref ms) => {
let rp = ccx.tcx.region_paramd_items.find(&it.id);
let rp = ccx.tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
debug!("item_impl %s with id %d rp %?",
*ccx.tcx.sess.str_of(it.ident), it.id, rp);
let self_ty = ccx.to_ty(&rscope::type_rscope(rp), ty);
@ -679,7 +679,7 @@ pub impl FnCtxt {
fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t {
match self.inh.locals.find(&nid) {
Some(t) => t,
Some(&t) => t,
None => {
self.tcx().sess.span_bug(
span,
@ -766,7 +766,7 @@ pub impl FnCtxt {
fn expr_ty(&self, ex: @ast::expr) -> ty::t {
match self.inh.node_types.find(&ex.id) {
Some(t) => t,
Some(&t) => t,
None => {
self.tcx().sess.bug(
fmt!("no type for %s in fcx %s",
@ -776,7 +776,7 @@ pub impl FnCtxt {
}
fn node_ty(&self, id: ast::node_id) -> ty::t {
match self.inh.node_types.find(&id) {
Some(t) => t,
Some(&t) => t,
None => {
self.tcx().sess.bug(
fmt!("no type for node %d: %s in fcx %s",
@ -789,7 +789,7 @@ pub impl FnCtxt {
}
fn node_ty_substs(&self, id: ast::node_id) -> ty::substs {
match self.inh.node_type_substs.find(&id) {
Some(ref ts) => (/*bad*/copy *ts),
Some(ts) => (/*bad*/copy *ts),
None => {
self.tcx().sess.bug(
fmt!("no type substs for node %d: %s in fcx %s",
@ -800,10 +800,14 @@ pub impl FnCtxt {
}
}
}
fn opt_node_ty_substs(&self, id: ast::node_id) -> Option<ty::substs> {
self.inh.node_type_substs.find(&id)
}
fn opt_node_ty_substs(&self, id: ast::node_id,
f: &fn(&ty::substs) -> bool) {
match self.inh.node_type_substs.find(&id) {
Some(s) => { f(s); }
None => ()
}
}
fn mk_subty(&self,
a_is_expected: bool,
@ -1059,9 +1063,10 @@ pub fn impl_self_ty(vcx: &VtableContext,
let tcx = vcx.tcx();
let (n_tps, region_param, raw_ty) = if did.crate == ast::local_crate {
let region_param = tcx.region_paramd_items.find(&did.node);
let region_param = tcx.region_paramd_items.find(&did.node).
map_consume(|x| *x);
match tcx.items.find(&did.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_impl(ref ts, _, st, _),
_
}, _)) => {
@ -1069,7 +1074,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
region_param,
vcx.ccx.to_ty(&rscope::type_rscope(region_param), st))
}
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_struct(_, ref ts),
id: class_id,
_
@ -1328,7 +1333,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
sugar: ast::CallSugar) {
// Index expressions need to be handled separately, to inform them
// that they appear in call position.
let mut bot = check_expr(fcx, f);
let mut _bot = check_expr(fcx, f);
check_call_or_method(fcx,
sp,
call_expr_id,
@ -1769,7 +1774,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
check_completeness: bool) {
let tcx = fcx.ccx.tcx;
let class_field_map = HashMap();
let mut class_field_map = LinearMap::new();
let mut fields_found = 0;
for field_types.each |field| {
// XXX: Check visibility here.
@ -1782,7 +1787,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
for ast_fields.each |field| {
let mut expected_field_type = ty::mk_err(tcx);
match class_field_map.find(&field.node.ident) {
let pair = class_field_map.find(&field.node.ident).
map_consume(|x| *x);
match pair {
None => {
tcx.sess.span_err(
field.span,
@ -1825,7 +1832,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let mut missing_fields = ~[];
for field_types.each |class_field| {
let name = class_field.ident;
let (_, seen) = class_field_map.get(&name);
let (_, seen) = *class_field_map.get(&name);
if !seen {
missing_fields.push(
~"`" + *tcx.sess.str_of(name) + ~"`");
@ -1862,9 +1869,10 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let type_parameter_count, region_parameterized, raw_type;
if class_id.crate == ast::local_crate {
region_parameterized =
tcx.region_paramd_items.find(&class_id.node);
tcx.region_paramd_items.find(&class_id.node).
map_consume(|x| *x);
match tcx.items.find(&class_id.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_struct(_, ref generics),
_
}, _)) => {
@ -1950,9 +1958,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let type_parameter_count, region_parameterized, raw_type;
if enum_id.crate == ast::local_crate {
region_parameterized =
tcx.region_paramd_items.find(&enum_id.node);
tcx.region_paramd_items.find(&enum_id.node).map_consume(|x| *x);
match tcx.items.find(&enum_id.node) {
Some(ast_map::node_item(@ast::item {
Some(&ast_map::node_item(@ast::item {
node: ast::item_enum(_, ref generics),
_
}, _)) => {
@ -2730,11 +2738,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
ast::expr_struct(path, ref fields, base_expr) => {
// Resolve the path.
match tcx.def_map.find(&id) {
Some(ast::def_struct(type_def_id)) => {
Some(&ast::def_struct(type_def_id)) => {
check_struct_constructor(fcx, id, expr.span, type_def_id,
*fields, base_expr);
}
Some(ast::def_variant(enum_id, variant_id)) => {
Some(&ast::def_variant(enum_id, variant_id)) => {
check_struct_enum_variant(fcx, id, expr.span, enum_id,
variant_id, *fields);
}
@ -2834,7 +2842,7 @@ pub fn check_decl_local(fcx: @mut FnCtxt, local: @ast::local) {
}
let region =
ty::re_scope(tcx.region_map.get(&local.node.id));
ty::re_scope(*tcx.region_map.get(&local.node.id));
let pcx = pat_ctxt {
fcx: fcx,
map: pat_id_map(tcx.def_map, local.node.pat),
@ -3350,7 +3358,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: &ast::blk) -> bool {
match e.node {
ast::expr_break(Some(_)) =>
match cx.def_map.find(&e.id) {
Some(ast::def_label(loop_id)) if id == loop_id => true,
Some(&ast::def_label(loop_id)) if id == loop_id => true,
_ => false,
},
_ => false
@ -3445,8 +3453,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
let ty_visitor_name = tcx.sess.ident_of(~"TyVisitor");
fail_unless!(tcx.intrinsic_defs.contains_key(&tydesc_name));
fail_unless!(ccx.tcx.intrinsic_defs.contains_key(&ty_visitor_name));
let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name);
let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name);
let (_, tydesc_ty) = *tcx.intrinsic_defs.get(&tydesc_name);
let (_, visitor_trait) = *tcx.intrinsic_defs.get(&ty_visitor_name);
let visitor_trait = match ty::get(visitor_trait).sty {
ty::ty_trait(trait_def_id, ref trait_substs, _) => {

View file

@ -180,7 +180,7 @@ pub fn visit_block(b: &ast::blk, &&rcx: @mut Rcx, v: rvt) {
pub fn visit_expr(expr: @ast::expr, &&rcx: @mut Rcx, v: rvt) {
debug!("visit_expr(e=%s)", rcx.fcx.expr_to_str(expr));
for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| {
for rcx.fcx.inh.adjustments.find(&expr.id).each |&adjustment| {
match *adjustment {
@ty::AutoDerefRef(
ty::AutoDerefRef {
@ -331,7 +331,7 @@ pub fn constrain_auto_ref(rcx: @mut Rcx, expr: @ast::expr) {
let adjustment = rcx.fcx.inh.adjustments.find(&expr.id);
let region = match adjustment {
Some(@ty::AutoDerefRef(
Some(&@ty::AutoDerefRef(
ty::AutoDerefRef {
autoref: Some(ref auto_ref), _})) => {
auto_ref.region
@ -727,7 +727,7 @@ pub mod guarantor {
debug!("before adjustments, cat=%?", expr_ct.cat);
match rcx.fcx.inh.adjustments.find(&expr.id) {
Some(@ty::AutoAddEnv(*)) => {
Some(&@ty::AutoAddEnv(*)) => {
// This is basically an rvalue, not a pointer, no regions
// involved.
expr_ct.cat = ExprCategorization {
@ -736,7 +736,7 @@ pub mod guarantor {
};
}
Some(@ty::AutoDerefRef(ref adjustment)) => {
Some(&@ty::AutoDerefRef(ref adjustment)) => {
debug!("adjustment=%?", adjustment);
expr_ct = apply_autoderefs(

View file

@ -192,7 +192,7 @@ pub fn lookup_vtable(vcx: &VtableContext,
match ty::get(ty).sty {
ty::ty_param(param_ty {idx: n, def_id: did}) => {
let mut n_bound = 0;
let bounds = tcx.ty_param_bounds.get(&did.node);
let bounds = *tcx.ty_param_bounds.get(&did.node);
for ty::iter_bound_traits_and_supertraits(
tcx, bounds) |ity| {
debug!("checking bounds trait %?",
@ -511,9 +511,8 @@ pub fn early_resolve_expr(ex: @ast::expr,
let cx = fcx.ccx;
match ex.node {
ast::expr_path(*) => {
match fcx.opt_node_ty_substs(ex.id) {
Some(ref substs) => {
let def = cx.tcx.def_map.get(&ex.id);
for fcx.opt_node_ty_substs(ex.id) |substs| {
let def = *cx.tcx.def_map.get(&ex.id);
let did = ast_util::def_id_of_def(def);
let item_ty = ty::lookup_item_type(cx.tcx, did);
debug!("early resolve expr: def %? %?, %?, %?", ex.id, did, def,
@ -531,8 +530,6 @@ pub fn early_resolve_expr(ex: @ast::expr,
insert_vtables(fcx, ex.id, vtbls);
}
}
}
_ => ()
}
}

View file

@ -66,7 +66,7 @@ fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) {
// Resolve any method map entry
match fcx.inh.method_map.find(&id) {
None => {}
Some(ref mme) => {
Some(mme) => {
for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| {
let method_map = fcx.ccx.method_map;
let new_entry = method_map_entry {
@ -119,7 +119,7 @@ fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
match fcx.inh.adjustments.find(&id) {
None => (),
Some(@ty::AutoAddEnv(r, s)) => {
Some(&@ty::AutoAddEnv(r, s)) => {
match resolve_region(fcx.infcx(), r, resolve_all | force_all) {
Err(e) => {
// This should not, I think, happen:
@ -135,7 +135,7 @@ fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
}
}
Some(@ty::AutoDerefRef(adj)) => {
Some(&@ty::AutoDerefRef(adj)) => {
let resolved_autoref = match adj.autoref {
Some(ref autoref) => {
match resolve_region(fcx.infcx(), autoref.region,
@ -176,18 +176,15 @@ fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
debug!("resolve_type_vars_for_node(id=%d, n_ty=%s, t=%s)",
id, ppaux::ty_to_str(tcx, n_ty), ppaux::ty_to_str(tcx, t));
write_ty_to_tcx(tcx, id, t);
match fcx.opt_node_ty_substs(id) {
Some(ref substs) => {
let mut new_tps = ~[];
for (*substs).tps.each |subst| {
match resolve_type_vars_in_type(fcx, sp, *subst) {
Some(t) => new_tps.push(t),
None => { wbcx.success = false; return None; }
}
}
write_substs_to_tcx(tcx, id, new_tps);
for fcx.opt_node_ty_substs(id) |substs| {
let mut new_tps = ~[];
for substs.tps.each |subst| {
match resolve_type_vars_in_type(fcx, sp, *subst) {
Some(t) => new_tps.push(t),
None => { wbcx.success = false; return None; }
}
}
None => ()
write_substs_to_tcx(tcx, id, new_tps);
}
return Some(t);
}

View file

@ -58,7 +58,6 @@ use util::ppaux::ty_to_str;
use core::result::Ok;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::uint;
use std::oldmap::HashMap;
pub struct UniversalQuantificationResult {
monotype: t,
@ -187,7 +186,7 @@ pub fn CoherenceChecker(crate_context: @mut CrateCtxt) -> CoherenceChecker {
crate_context: crate_context,
inference_context: new_infer_ctxt(crate_context.tcx),
base_type_def_ids: HashMap()
base_type_def_ids: @mut LinearMap::new(),
}
}
@ -198,7 +197,7 @@ pub struct CoherenceChecker {
// A mapping from implementations to the corresponding base type
// definition ID.
base_type_def_ids: HashMap<def_id,def_id>,
base_type_def_ids: @mut LinearMap<def_id,def_id>,
}
pub impl CoherenceChecker {
@ -475,7 +474,7 @@ pub impl CoherenceChecker {
ty_to_str(self.crate_context.tcx, self_t));
match self.crate_context.tcx.trait_impls.find(&trait_t) {
None => {
let m = HashMap();
let m = @mut LinearMap::new();
m.insert(self_t, the_impl);
self.crate_context.tcx.trait_impls.insert(trait_t, m);
}
@ -505,14 +504,14 @@ pub impl CoherenceChecker {
f: &fn(x: &ty::method) -> bool) {
// Make a list of all the names of the provided methods.
// XXX: This is horrible.
let provided_method_idents = HashMap();
let mut provided_method_idents = LinearSet::new();
let tcx = self.crate_context.tcx;
for ty::provided_trait_methods(tcx, trait_did).each |ident| {
provided_method_idents.insert(*ident, ());
provided_method_idents.insert(*ident);
}
for ty::trait_methods(tcx, trait_did).each |method| {
if provided_method_idents.contains_key(&method.ident) {
if provided_method_idents.contains(&method.ident) {
if !f(method) {
break;
}
@ -622,7 +621,7 @@ pub impl CoherenceChecker {
fn get_self_type_for_implementation(&self, implementation: @Impl)
-> ty_param_bounds_and_ty {
return self.crate_context.tcx.tcache.get(&implementation.did);
return *self.crate_context.tcx.tcache.get(&implementation.did);
}
// Privileged scope checking
@ -694,7 +693,7 @@ pub impl CoherenceChecker {
fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
let def_map = self.crate_context.tcx.def_map;
let trait_def = def_map.get(&trait_ref.ref_id);
let trait_def = *def_map.get(&trait_ref.ref_id);
let trait_id = def_id_of_def(trait_def);
return trait_id;
}
@ -773,7 +772,7 @@ pub impl CoherenceChecker {
has no provided methods", trait_did.node);
/* fall through */
}
Some(all_provided) => {
Some(&all_provided) => {
debug!("(creating impl) trait with node_id `%d` \
has provided methods", trait_did.node);
// Add all provided methods.
@ -802,7 +801,7 @@ pub impl CoherenceChecker {
fn span_of_impl(&self, implementation: @Impl) -> span {
fail_unless!(implementation.did.crate == local_crate);
match self.crate_context.tcx.items.find(&implementation.did.node) {
Some(node_item(item, _)) => {
Some(&node_item(item, _)) => {
return item.span;
}
_ => {
@ -815,7 +814,7 @@ pub impl CoherenceChecker {
// External crate handling
fn add_impls_for_module(&self, impls_seen: HashMap<def_id,()>,
fn add_impls_for_module(&self, impls_seen: &mut LinearSet<def_id>,
crate_store: @mut CStore,
module_def_id: def_id) {
let implementations = get_impls_for_mod(crate_store,
@ -828,16 +827,11 @@ pub impl CoherenceChecker {
// Make sure we don't visit the same implementation
// multiple times.
match impls_seen.find(&implementation.did) {
None => {
// Good. Continue.
impls_seen.insert(implementation.did, ());
}
Some(_) => {
// Skip this one.
loop;
}
if !impls_seen.insert(implementation.did) {
// Skip this one.
loop;
}
// Good. Continue.
let self_type = lookup_item_type(self.crate_context.tcx,
implementation.did);
@ -939,11 +933,11 @@ pub impl CoherenceChecker {
// Adds implementations and traits from external crates to the coherence
// info.
fn add_external_crates(&self) {
let impls_seen = HashMap();
let mut impls_seen = LinearSet::new();
let crate_store = self.crate_context.tcx.sess.cstore;
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
self.add_impls_for_module(impls_seen,
self.add_impls_for_module(&mut impls_seen,
crate_store,
def_id { crate: crate_number,
node: 0 });
@ -951,7 +945,7 @@ pub impl CoherenceChecker {
for each_path(crate_store, crate_number) |_p, def_like| {
match def_like {
dl_def(def_mod(def_id)) => {
self.add_impls_for_module(impls_seen,
self.add_impls_for_module(&mut impls_seen,
crate_store,
def_id);
}
@ -1003,13 +997,13 @@ pub impl CoherenceChecker {
ty::ty_struct(type_def_id, _) => {
tcx.destructor_for_type.insert(type_def_id,
method_def_id);
tcx.destructors.insert(method_def_id, ());
tcx.destructors.insert(method_def_id);
}
_ => {
// Destructors only work on nominal types.
if impl_info.did.crate == ast::local_crate {
match tcx.items.find(&impl_info.did.node) {
Some(ast_map::node_item(@ref item, _)) => {
Some(&ast_map::node_item(@ref item, _)) => {
tcx.sess.span_err((*item).span,
~"the Drop trait may only \
be implemented on \

View file

@ -137,10 +137,10 @@ impl AstConv for CrateCtxt {
csearch::get_type(self.tcx, id)
} else {
match self.tcx.items.find(&id.node) {
Some(ast_map::node_item(item, _)) => {
Some(&ast_map::node_item(item, _)) => {
ty_of_item(self, item)
}
Some(ast_map::node_foreign_item(foreign_item, _, _, _)) => {
Some(&ast_map::node_foreign_item(foreign_item, _, _, _)) => {
ty_of_foreign_item(self, foreign_item)
}
ref x => {
@ -280,8 +280,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
let tcx = ccx.tcx;
let region_paramd = tcx.region_paramd_items.find(&id);
match tcx.items.get(&id) {
let region_paramd = tcx.region_paramd_items.find(&id).map_consume(|x| *x);
match *tcx.items.get(&id) {
ast_map::node_item(@ast::item {
node: ast::item_trait(ref generics, _, ref ms),
_
@ -516,7 +516,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt,
// the methods within the trait with bogus results. (See issue #3903.)
match tcx.items.find(&did.node) {
Some(ast_map::node_item(item, _)) => {
Some(&ast_map::node_item(item, _)) => {
let tpt = ty_of_item(ccx, item);
ensure_trait_methods(ccx, did.node, tpt.ty);
}
@ -615,7 +615,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
pub fn convert(ccx: &CrateCtxt, it: @ast::item) {
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.find(&it.id);
let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
debug!("convert: item %s with id %d rp %?",
*tcx.sess.str_of(it.ident), it.id, rp);
match it.node {
@ -828,10 +828,10 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
let def_id = local_def(it.id);
let tcx = ccx.tcx;
match tcx.tcache.find(&def_id) {
Some(tpt) => return tpt,
Some(&tpt) => return tpt,
_ => {}
}
let rp = tcx.region_paramd_items.find(&it.id);
let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
match it.node {
ast::item_const(t, _) => {
let typ = ccx.to_ty(&empty_rscope, t);
@ -857,11 +857,11 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
}
ast::item_ty(t, ref generics) => {
match tcx.tcache.find(&local_def(it.id)) {
Some(tpt) => return tpt,
Some(&tpt) => return tpt,
None => { }
}
let rp = tcx.region_paramd_items.find(&it.id);
let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
let tpt = {
let ty = {
let t0 = ccx.to_ty(&type_rscope(rp), t);
@ -991,7 +991,7 @@ pub fn ty_param_bounds(ccx: &CrateCtxt,
-> @~[ty::param_bounds] {
@do generics.ty_params.map_to_vec |param| {
match ccx.tcx.ty_param_bounds.find(&param.id) {
Some(bs) => bs,
Some(&bs) => bs,
None => {
let bounds = compute_bounds(ccx, param.bounds);
ccx.tcx.ty_param_bounds.insert(param.id, bounds);

View file

@ -549,11 +549,11 @@ use util::ppaux::note_and_explain_region;
use core::cell::{Cell, empty_cell};
use core::cmp;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::result::{Err, Ok, Result};
use core::to_bytes;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use syntax::codemap::span;
enum Constraint {
@ -619,15 +619,19 @@ enum UndoLogEntry {
Snapshot,
AddVar(RegionVid),
AddConstraint(Constraint),
AddCombination(CombineMap, TwoRegions)
AddCombination(CombineMapType, TwoRegions)
}
type CombineMap = HashMap<TwoRegions, RegionVid>;
enum CombineMapType {
Lub, Glb
}
type CombineMap = LinearMap<TwoRegions, RegionVid>;
pub struct RegionVarBindings {
tcx: ty::ctxt,
var_spans: ~[span],
constraints: HashMap<Constraint, span>,
constraints: LinearMap<Constraint, span>,
lubs: CombineMap,
glbs: CombineMap,
skolemization_count: uint,
@ -654,22 +658,15 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
tcx: tcx,
var_spans: ~[],
values: empty_cell(),
constraints: HashMap(),
lubs: CombineMap(),
glbs: CombineMap(),
constraints: LinearMap::new(),
lubs: LinearMap::new(),
glbs: LinearMap::new(),
skolemization_count: 0,
bound_count: 0,
undo_log: ~[]
}
}
// Note: takes two regions but doesn't care which is `a` and which is
// `b`! Not obvious that this is the most efficient way to go about
// it.
fn CombineMap() -> CombineMap {
return HashMap();
}
pub impl RegionVarBindings {
fn in_snapshot(&mut self) -> bool {
self.undo_log.len() > 0
@ -706,8 +703,11 @@ pub impl RegionVarBindings {
AddConstraint(ref constraint) => {
self.constraints.remove(constraint);
}
AddCombination(map, ref regions) => {
map.remove(regions);
AddCombination(Glb, ref regions) => {
self.glbs.remove(regions);
}
AddCombination(Lub, ref regions) => {
self.lubs.remove(regions);
}
}
}
@ -825,7 +825,7 @@ pub impl RegionVarBindings {
(re_infer(ReVar(*)), _) | (_, re_infer(ReVar(*))) => {
self.combine_vars(
self.lubs, a, b, span,
Lub, a, b, span,
|this, old_r, new_r| this.make_subregion(span, old_r, new_r))
}
@ -852,7 +852,7 @@ pub impl RegionVarBindings {
(re_infer(ReVar(*)), _) | (_, re_infer(ReVar(*))) => {
self.combine_vars(
self.glbs, a, b, span,
Glb, a, b, span,
|this, old_r, new_r| this.make_subregion(span, new_r, old_r))
}
@ -905,7 +905,7 @@ pub impl RegionVarBindings {
}
fn combine_vars(&mut self,
combines: CombineMap,
t: CombineMapType,
a: Region,
b: Region,
span: span,
@ -914,21 +914,35 @@ pub impl RegionVarBindings {
new_r: Region) -> cres<()>)
-> cres<Region> {
let vars = TwoRegions { a: a, b: b };
match combines.find(&vars) {
Some(c) => Ok(re_infer(ReVar(c))),
None => {
let c = self.new_region_var(span);
combines.insert(vars, c);
if self.in_snapshot() {
self.undo_log.push(AddCombination(combines, vars));
}
do relate(self, a, re_infer(ReVar(c))).then {
do relate(self, b, re_infer(ReVar(c))).then {
debug!("combine_vars() c=%?", c);
Ok(re_infer(ReVar(c)))
let c;
{
// FIXME (#3850): shouldn't need a scope, nor should this need to be
// done twice to get the maps out
{
let combines = match t {
Glb => &self.glbs, Lub => &self.lubs
};
match combines.find(&vars) {
Some(&c) => return Ok(re_infer(ReVar(c))),
None => ()
}
}
}
c = self.new_region_var(span);
{
let combines = match t {
Glb => &mut self.glbs, Lub => &mut self.lubs
};
combines.insert(vars, c);
}
}
if self.in_snapshot() {
self.undo_log.push(AddCombination(t, vars));
}
do relate(self, a, re_infer(ReVar(c))).then {
do relate(self, b, re_infer(ReVar(c))).then {
debug!("combine_vars() c=%?", c);
Ok(re_infer(ReVar(c)))
}
}
}
@ -1206,11 +1220,7 @@ struct SpannedRegion {
span: span,
}
type TwoRegionsMap = HashMap<TwoRegions, ()>;
fn TwoRegionsMap() -> TwoRegionsMap {
return HashMap();
}
type TwoRegionsMap = LinearSet<TwoRegions>;
pub impl RegionVarBindings {
fn infer_variable_values(&mut self) -> ~[GraphNodeValue] {
@ -1239,7 +1249,7 @@ pub impl RegionVarBindings {
// It would be nice to write this using map():
let mut edges = vec::with_capacity(num_edges);
for self.constraints.each |constraint, span| {
for self.constraints.each |&(constraint, span)| {
edges.push(GraphEdge {
next_edge: [uint::max_value, uint::max_value],
constraint: *constraint,
@ -1439,7 +1449,7 @@ pub impl RegionVarBindings {
&mut self,
graph: &Graph) -> ~[GraphNodeValue]
{
let dup_map = TwoRegionsMap();
let mut dup_map = LinearSet::new();
graph.nodes.mapi(|idx, node| {
match node.value {
Value(_) => {
@ -1478,11 +1488,11 @@ pub impl RegionVarBindings {
match node.classification {
Expanding => {
self.report_error_for_expanding_node(
graph, dup_map, node_vid);
graph, &mut dup_map, node_vid);
}
Contracting => {
self.report_error_for_contracting_node(
graph, dup_map, node_vid);
graph, &mut dup_map, node_vid);
}
}
}
@ -1494,17 +1504,17 @@ pub impl RegionVarBindings {
// Used to suppress reporting the same basic error over and over
fn is_reported(&mut self,
dup_map: TwoRegionsMap,
dup_map: &mut TwoRegionsMap,
r_a: Region,
r_b: Region)
-> bool {
let key = TwoRegions { a: r_a, b: r_b };
!dup_map.insert(key, ())
!dup_map.insert(key)
}
fn report_error_for_expanding_node(&mut self,
graph: &Graph,
dup_map: TwoRegionsMap,
dup_map: &mut TwoRegionsMap,
node_idx: RegionVid) {
// Errors in expanding nodes result from a lower-bound that is
// not contained by an upper-bound.
@ -1557,7 +1567,7 @@ pub impl RegionVarBindings {
fn report_error_for_contracting_node(&mut self,
graph: &Graph,
dup_map: TwoRegionsMap,
dup_map: &mut TwoRegionsMap,
node_idx: RegionVid) {
// Errors in contracting nodes result from two upper-bounds
// that have no intersection.
@ -1614,9 +1624,9 @@ pub impl RegionVarBindings {
orig_node_idx: RegionVid,
dir: Direction)
-> ~[SpannedRegion] {
let set = HashMap();
let mut set = LinearSet::new();
let mut stack = ~[orig_node_idx];
set.insert(orig_node_idx.to_uint(), ());
set.insert(orig_node_idx.to_uint());
let mut result = ~[];
while !vec::is_empty(stack) {
let node_idx = stack.pop();
@ -1627,7 +1637,7 @@ pub impl RegionVarBindings {
Incoming => from_vid,
Outgoing => to_vid
};
if set.insert(vid.to_uint(), ()) {
if set.insert(vid.to_uint()) {
stack.push(vid);
}
}

View file

@ -55,12 +55,11 @@ use middle::ty;
use util::common::time;
use util::ppaux;
use core::hashmap::linear::LinearMap;
use core::result;
use core::vec;
use std::list::{List, Nil, Cons};
use std::list;
use std::oldmap::HashMap;
use std::oldmap;
use syntax::codemap::{span, spanned, respan};
use syntax::print::pprust::*;
use syntax::{ast, ast_util, ast_map};
@ -130,7 +129,7 @@ pub struct method_map_entry {
// maps from an expression id that corresponds to a method call to the details
// of the method to be invoked
pub type method_map = HashMap<ast::node_id, method_map_entry>;
pub type method_map = @mut LinearMap<ast::node_id, method_map_entry>;
// Resolutions for bounds of all parameters, left to right, for a given path.
pub type vtable_res = @~[vtable_origin];
@ -171,7 +170,7 @@ pub impl vtable_origin {
}
}
pub type vtable_map = HashMap<ast::node_id, vtable_res>;
pub type vtable_map = @mut LinearMap<ast::node_id, vtable_res>;
pub struct CrateCtxt {
// A mapping from method call sites to traits that have that method.
@ -209,7 +208,7 @@ pub fn write_tpt_to_tcx(tcx: ty::ctxt,
pub fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
match tcx.def_map.find(&id) {
Some(x) => x,
Some(&x) => x,
_ => {
tcx.sess.span_fatal(sp, ~"internal error looking up a definition")
}
@ -292,7 +291,7 @@ fn check_main_fn_ty(ccx: @mut CrateCtxt,
match ty::get(main_t).sty {
ty::ty_bare_fn(ref fn_ty) => {
match tcx.items.find(&main_id) {
Some(ast_map::node_item(it,_)) => {
Some(&ast_map::node_item(it,_)) => {
match it.node {
ast::item_fn(_, _, ref ps, _)
if ps.is_parameterized() => {
@ -337,14 +336,14 @@ fn check_for_main_fn(ccx: @mut CrateCtxt) {
}
pub fn check_crate(tcx: ty::ctxt,
trait_map: resolve::TraitMap,
+trait_map: resolve::TraitMap,
crate: @ast::crate)
-> (method_map, vtable_map) {
let time_passes = tcx.sess.time_passes();
let ccx = @mut CrateCtxt {
trait_map: trait_map,
method_map: oldmap::HashMap(),
vtable_map: oldmap::HashMap(),
method_map: @mut LinearMap::new(),
vtable_map: @mut LinearMap::new(),
coherence_info: @coherence::CoherenceInfo(),
tcx: tcx
};

View file

@ -123,6 +123,8 @@ pub mod lib {
pub mod llvm;
}
use core::prelude::*;
use driver::driver::{host_triple, optgroups, early_error};
use driver::driver::{str_input, file_input, build_session_options};
use driver::driver::{build_session, build_configuration, parse_pretty};
@ -166,7 +168,7 @@ Available lint options:
let lint_dict = lint::get_lint_dict();
let mut max_key = 0;
for lint_dict.each_key |&k| { max_key = uint::max(k.len(), max_key); }
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
fn padded(max: uint, s: &str) -> ~str {
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
}
@ -175,7 +177,7 @@ Available lint options:
padded(max_key, ~"name"), ~"default", ~"meaning"));
io::println(fmt!(" %s %7.7s %s\n",
padded(max_key, ~"----"), ~"-------", ~"-------"));
for lint_dict.each |&k, &v| {
for lint_dict.each |&(k, v)| {
let k = str::replace(*k, ~"_", ~"-");
io::println(fmt!(" %s %7.7s %s",
padded(max_key, k),

View file

@ -14,8 +14,8 @@ use syntax::ast;
use syntax::codemap::{span};
use syntax::visit;
use core::hashmap::linear::LinearSet;
use core::str;
use std::oldmap::HashMap;
use std;
pub fn time<T>(do_it: bool, what: ~str, thunk: &fn() -> T) -> T {
@ -55,8 +55,6 @@ pub fn indenter() -> _indenter {
_indenter(())
}
pub type flag = HashMap<~str, ()>;
pub fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; }
pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
@ -116,7 +114,7 @@ pub fn pluralize(n: uint, +s: ~str) -> ~str {
}
// A set of node IDs (used to keep track of which node IDs are for statements)
pub type stmt_set = HashMap<ast::node_id, ()>;
pub type stmt_set = @mut LinearSet<ast::node_id>;
//
// Local Variables:

View file

@ -64,10 +64,10 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
return match region {
re_scope(node_id) => {
match cx.items.find(&node_id) {
Some(ast_map::node_block(ref blk)) => {
Some(&ast_map::node_block(ref blk)) => {
explain_span(cx, "block", blk.span)
}
Some(ast_map::node_expr(expr)) => {
Some(&ast_map::node_expr(expr)) => {
match expr.node {
ast::expr_call(*) => explain_span(cx, "call", expr.span),
ast::expr_method_call(*) => {
@ -77,10 +77,10 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
_ => explain_span(cx, "expression", expr.span)
}
}
Some(ast_map::node_stmt(stmt)) => {
Some(&ast_map::node_stmt(stmt)) => {
explain_span(cx, "statement", stmt.span)
}
Some(ast_map::node_item(it, _)) if (match it.node {
Some(&ast_map::node_item(it, _)) if (match it.node {
ast::item_fn(*) => true, _ => false}) => {
explain_span(cx, "function body", it.span)
}
@ -102,7 +102,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
};
match cx.items.find(&id) {
Some(ast_map::node_block(ref blk)) => {
Some(&ast_map::node_block(ref blk)) => {
let (msg, opt_span) = explain_span(cx, "block", blk.span);
(fmt!("%s %s", prefix, msg), opt_span)
}
@ -152,11 +152,11 @@ pub fn bound_region_to_str_space(cx: ctxt,
pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
match cx.items.find(&node_id) {
Some(ast_map::node_block(ref blk)) => {
Some(&ast_map::node_block(ref blk)) => {
fmt!("<block at %s>",
cx.sess.codemap.span_to_str(blk.span))
}
Some(ast_map::node_expr(expr)) => {
Some(&ast_map::node_expr(expr)) => {
match expr.node {
ast::expr_call(*) => {
fmt!("<call at %s>",

View file

@ -114,7 +114,7 @@ fn parse_item_attrs<T:Owned>(
id: doc::AstId,
parse_attrs: ~fn(a: ~[ast::attribute]) -> T) -> T {
do astsrv::exec(srv) |ctxt| {
let attrs = match ctxt.ast_map.get(&id) {
let attrs = match *ctxt.ast_map.get(&id) {
ast_map::node_item(item, _) => copy item.attrs,
ast_map::node_foreign_item(item, _, _, _) => copy item.attrs,
_ => fail!(~"parse_item_attrs: not an item")
@ -162,7 +162,7 @@ fn fold_enum(
let desc = {
let variant = copy variant;
do astsrv::exec(srv.clone()) |ctxt| {
match ctxt.ast_map.get(&doc_id) {
match *ctxt.ast_map.get(&doc_id) {
ast_map::node_item(@ast::item {
node: ast::item_enum(ref enum_definition, _), _
}, _) => {
@ -226,7 +226,7 @@ fn merge_method_attrs(
// Create an assoc list from method name to attributes
let attrs: ~[(~str, Option<~str>)] = do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&item_id) {
match *ctxt.ast_map.get(&item_id) {
ast_map::node_item(@ast::item {
node: ast::item_trait(_, _, ref methods), _
}, _) => {

View file

@ -53,7 +53,7 @@ fn is_hidden(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
let id = doc.id;
do astsrv::exec(srv) |ctxt| {
let attrs = match ctxt.ast_map.get(&id) {
let attrs = match *ctxt.ast_map.get(&id) {
ast_map::node_item(item, _) => copy item.attrs,
_ => ~[]
};

View file

@ -57,7 +57,7 @@ fn fold_impl(
let doc = fold::default_seq_fold_impl(fold, doc);
do astsrv::exec(fold.ctxt.clone()) |ctxt| {
match ctxt.ast_map.get(&doc.item.id) {
match *ctxt.ast_map.get(&doc.item.id) {
ast_map::node_item(item, _) => {
match item.node {
ast::item_impl(_, None, _, ref methods) => {
@ -136,7 +136,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
let id = doc.id;
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&id) {
match *ctxt.ast_map.get(&id) {
ast_map::node_item(item, _) => {
match &item.node {
&ast::item_impl(*) => {

View file

@ -66,7 +66,7 @@ fn fold_fn(
fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> {
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&fn_id) {
match *ctxt.ast_map.get(&fn_id) {
ast_map::node_item(@ast::item {
ident: ident,
node: ast::item_fn(ref decl, purity, ref tys, _), _
@ -106,7 +106,7 @@ fn fold_const(
sig: Some({
let doc = copy doc;
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&doc.id()) {
match *ctxt.ast_map.get(&doc.id()) {
ast_map::node_item(@ast::item {
node: ast::item_const(ty, _), _
}, _) => {
@ -137,7 +137,7 @@ fn fold_enum(
let sig = {
let variant = copy *variant;
do astsrv::exec(srv.clone()) |ctxt| {
match ctxt.ast_map.get(&doc_id) {
match *ctxt.ast_map.get(&doc_id) {
ast_map::node_item(@ast::item {
node: ast::item_enum(ref enum_definition, _), _
}, _) => {
@ -199,7 +199,7 @@ fn get_method_sig(
method_name: ~str
) -> Option<~str> {
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&item_id) {
match *ctxt.ast_map.get(&item_id) {
ast_map::node_item(@ast::item {
node: ast::item_trait(_, _, ref methods), _
}, _) => {
@ -277,7 +277,7 @@ fn fold_impl(
let (bounds, trait_types, self_ty) = {
let doc = copy doc;
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&doc.id()) {
match *ctxt.ast_map.get(&doc.id()) {
ast_map::node_item(@ast::item {
node: ast::item_impl(ref generics, opt_trait_type, self_ty, _), _
}, _) => {
@ -347,7 +347,7 @@ fn fold_type(
sig: {
let doc = copy doc;
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&doc.id()) {
match *ctxt.ast_map.get(&doc.id()) {
ast_map::node_item(@ast::item {
ident: ident,
node: ast::item_ty(ty, ref params), _
@ -385,7 +385,7 @@ fn fold_struct(
sig: {
let doc = copy doc;
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get(&doc.id()) {
match *ctxt.ast_map.get(&doc.id()) {
ast_map::node_item(item, _) => {
let item = strip_struct_extra_stuff(item);
Some(pprust::item_to_str(item,

View file

@ -1202,7 +1202,6 @@ mod tests {
use core::result;
use core::hashmap::linear::LinearMap;
use core::cmp;
fn mk_object(items: &[(~str, Json)]) -> Json {

View file

@ -1,388 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! A deprecated compatibility layer on top of `core::hashmap`
use core::prelude::*;
use core::hash::Hash;
use core::prelude::*;
use core::to_bytes::IterBytes;
use core::vec;
/// A convenience type to treat a hashmap as a set
pub type Set<K> = HashMap<K, ()>;
pub type HashMap<K, V> = chained::T<K, V>;
pub mod chained {
use core::ops;
use core::prelude::*;
use core::hashmap::linear::LinearMap;
struct HashMap_<K, V> {
priv map: LinearMap<K, V>
}
pub type T<K, V> = @mut HashMap_<K, V>;
pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
fn clear(&mut self) {
self.map.clear()
}
}
impl<K:Eq + IterBytes + Hash,V> Container for HashMap_<K, V> {
fn len(&const self) -> uint { self.map.len() }
fn is_empty(&const self) -> bool { self.map.is_empty() }
}
pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
fn contains_key(&self, k: &K) -> bool {
self.map.contains_key(k)
}
fn insert(&mut self, k: K, v: V) -> bool {
self.map.insert(k, v)
}
fn remove(&mut self, k: &K) -> bool {
self.map.remove(k)
}
fn each(&self, blk: &fn(key: &K, value: &V) -> bool) {
do self.map.each |&(k, v)| { blk(k, v) }
}
fn each_key(&self, blk: &fn(key: &K) -> bool) {
self.map.each_key(blk)
}
fn each_value(&self, blk: &fn(value: &V) -> bool) {
self.map.each_value(blk)
}
}
pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> HashMap_<K, V> {
fn find(&self, k: &K) -> Option<V> {
self.map.find(k).map(|&x| copy *x)
}
fn update(&mut self, key: K, newval: V, ff: &fn(V, V) -> V) -> bool {
match self.find(&key) {
None => self.insert(key, newval),
Some(orig) => self.insert(key, ff(orig, newval))
}
}
fn get(&self, k: &K) -> V {
copy *self.map.get(k)
}
}
impl<K:Eq + IterBytes + Hash + Copy,V:Copy> ops::Index<K, V>
for HashMap_<K, V> {
fn index(&self, k: K) -> V {
self.get(&k)
}
}
pub fn mk<K:Eq + IterBytes + Hash,V:Copy>() -> T<K,V> {
@mut HashMap_{map: LinearMap::new()}
}
}
/*
Function: hashmap
Construct a hashmap.
*/
pub fn HashMap<K:Eq + IterBytes + Hash + Const,V:Copy>()
-> HashMap<K, V> {
chained::mk()
}
/// Convenience function for adding keys to a hashmap with nil type keys
pub fn set_add<K:Eq + IterBytes + Hash + Const + Copy>(set: Set<K>, key: K)
-> bool {
set.insert(key, ())
}
/// Convert a set into a vector.
pub fn vec_from_set<T:Eq + IterBytes + Hash + Copy>(s: Set<T>) -> ~[T] {
do vec::build_sized(s.len()) |push| {
for s.each_key() |&k| {
push(k);
}
}
}
/// Construct a hashmap from a vector
pub fn hash_from_vec<K:Eq + IterBytes + Hash + Const + Copy,V:Copy>(
items: &[(K, V)]) -> HashMap<K, V> {
let map = HashMap();
for vec::each(items) |item| {
match *item {
(copy key, copy value) => {
map.insert(key, value);
}
}
}
map
}
#[cfg(test)]
mod tests {
use core::uint;
use super::*;
#[test]
fn test_simple() {
debug!("*** starting test_simple");
fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
fn uint_id(x: &uint) -> uint { *x }
debug!("uint -> uint");
let hm_uu: HashMap<uint, uint> =
HashMap::<uint, uint>();
fail_unless!((hm_uu.insert(10u, 12u)));
fail_unless!((hm_uu.insert(11u, 13u)));
fail_unless!((hm_uu.insert(12u, 14u)));
fail_unless!((hm_uu.get(&11) == 13u));
fail_unless!((hm_uu.get(&12) == 14u));
fail_unless!((hm_uu.get(&10) == 12u));
fail_unless!((!hm_uu.insert(12u, 14u)));
fail_unless!((hm_uu.get(&12) == 14u));
fail_unless!((!hm_uu.insert(12u, 12u)));
fail_unless!((hm_uu.get(&12) == 12u));
let ten: ~str = ~"ten";
let eleven: ~str = ~"eleven";
let twelve: ~str = ~"twelve";
debug!("str -> uint");
let hm_su: HashMap<~str, uint> =
HashMap::<~str, uint>();
fail_unless!((hm_su.insert(~"ten", 12u)));
fail_unless!((hm_su.insert(eleven, 13u)));
fail_unless!((hm_su.insert(~"twelve", 14u)));
fail_unless!((hm_su.get(&eleven) == 13u));
fail_unless!((hm_su.get(&~"eleven") == 13u));
fail_unless!((hm_su.get(&~"twelve") == 14u));
fail_unless!((hm_su.get(&~"ten") == 12u));
fail_unless!((!hm_su.insert(~"twelve", 14u)));
fail_unless!((hm_su.get(&~"twelve") == 14u));
fail_unless!((!hm_su.insert(~"twelve", 12u)));
fail_unless!((hm_su.get(&~"twelve") == 12u));
debug!("uint -> str");
let hm_us: HashMap<uint, ~str> =
HashMap::<uint, ~str>();
fail_unless!((hm_us.insert(10u, ~"twelve")));
fail_unless!((hm_us.insert(11u, ~"thirteen")));
fail_unless!((hm_us.insert(12u, ~"fourteen")));
fail_unless!(hm_us.get(&11) == ~"thirteen");
fail_unless!(hm_us.get(&12) == ~"fourteen");
fail_unless!(hm_us.get(&10) == ~"twelve");
fail_unless!((!hm_us.insert(12u, ~"fourteen")));
fail_unless!(hm_us.get(&12) == ~"fourteen");
fail_unless!((!hm_us.insert(12u, ~"twelve")));
fail_unless!(hm_us.get(&12) == ~"twelve");
debug!("str -> str");
let hm_ss: HashMap<~str, ~str> =
HashMap::<~str, ~str>();
fail_unless!((hm_ss.insert(ten, ~"twelve")));
fail_unless!((hm_ss.insert(eleven, ~"thirteen")));
fail_unless!((hm_ss.insert(twelve, ~"fourteen")));
fail_unless!(hm_ss.get(&~"eleven") == ~"thirteen");
fail_unless!(hm_ss.get(&~"twelve") == ~"fourteen");
fail_unless!(hm_ss.get(&~"ten") == ~"twelve");
fail_unless!((!hm_ss.insert(~"twelve", ~"fourteen")));
fail_unless!(hm_ss.get(&~"twelve") == ~"fourteen");
fail_unless!((!hm_ss.insert(~"twelve", ~"twelve")));
fail_unless!(hm_ss.get(&~"twelve") == ~"twelve");
debug!("*** finished test_simple");
}
/**
* Force map growth
*/
#[test]
fn test_growth() {
debug!("*** starting test_growth");
let num_to_insert: uint = 64u;
fn eq_uint(x: &uint, y: &uint) -> bool { *x == *y }
fn uint_id(x: &uint) -> uint { *x }
debug!("uint -> uint");
let hm_uu: HashMap<uint, uint> =
HashMap::<uint, uint>();
let mut i: uint = 0u;
while i < num_to_insert {
fail_unless!((hm_uu.insert(i, i * i)));
debug!("inserting %u -> %u", i, i*i);
i += 1u;
}
debug!("-----");
i = 0u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm_uu.get(&i));
fail_unless!((hm_uu.get(&i) == i * i));
i += 1u;
}
fail_unless!((hm_uu.insert(num_to_insert, 17u)));
fail_unless!((hm_uu.get(&num_to_insert) == 17u));
debug!("-----");
i = 0u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm_uu.get(&i));
fail_unless!((hm_uu.get(&i) == i * i));
i += 1u;
}
debug!("str -> str");
let hm_ss: HashMap<~str, ~str> =
HashMap::<~str, ~str>();
i = 0u;
while i < num_to_insert {
fail_unless!(hm_ss.insert(uint::to_str_radix(i, 2u),
uint::to_str_radix(i * i, 2u)));
debug!("inserting \"%s\" -> \"%s\"",
uint::to_str_radix(i, 2u),
uint::to_str_radix(i*i, 2u));
i += 1u;
}
debug!("-----");
i = 0u;
while i < num_to_insert {
debug!("get(\"%s\") = \"%s\"",
uint::to_str_radix(i, 2u),
hm_ss.get(&uint::to_str_radix(i, 2u)));
fail_unless!(hm_ss.get(&uint::to_str_radix(i, 2u)) ==
uint::to_str_radix(i * i, 2u));
i += 1u;
}
fail_unless!(hm_ss.insert(uint::to_str_radix(num_to_insert, 2u),
uint::to_str_radix(17u, 2u)));
fail_unless!(hm_ss.get(&uint::to_str_radix(num_to_insert, 2u)) ==
uint::to_str_radix(17u, 2u));
debug!("-----");
i = 0u;
while i < num_to_insert {
debug!("get(\"%s\") = \"%s\"",
uint::to_str_radix(i, 2u),
hm_ss.get(&uint::to_str_radix(i, 2u)));
fail_unless!(hm_ss.get(&uint::to_str_radix(i, 2u)) ==
uint::to_str_radix(i * i, 2u));
i += 1u;
}
debug!("*** finished test_growth");
}
#[test]
fn test_removal() {
debug!("*** starting test_removal");
let num_to_insert: uint = 64u;
let hm: HashMap<uint, uint> =
HashMap::<uint, uint>();
let mut i: uint = 0u;
while i < num_to_insert {
fail_unless!((hm.insert(i, i * i)));
debug!("inserting %u -> %u", i, i*i);
i += 1u;
}
fail_unless!((hm.len() == num_to_insert));
debug!("-----");
debug!("removing evens");
i = 0u;
while i < num_to_insert {
let v = hm.remove(&i);
fail_unless!(v);
i += 2u;
}
fail_unless!((hm.len() == num_to_insert / 2u));
debug!("-----");
i = 1u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm.get(&i));
fail_unless!((hm.get(&i) == i * i));
i += 2u;
}
debug!("-----");
i = 1u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm.get(&i));
fail_unless!((hm.get(&i) == i * i));
i += 2u;
}
debug!("-----");
i = 0u;
while i < num_to_insert {
fail_unless!((hm.insert(i, i * i)));
debug!("inserting %u -> %u", i, i*i);
i += 2u;
}
fail_unless!((hm.len() == num_to_insert));
debug!("-----");
i = 0u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm.get(&i));
fail_unless!((hm.get(&i) == i * i));
i += 1u;
}
debug!("-----");
fail_unless!((hm.len() == num_to_insert));
i = 0u;
while i < num_to_insert {
debug!("get(%u) = %u", i, hm.get(&i));
fail_unless!((hm.get(&i) == i * i));
i += 1u;
}
debug!("*** finished test_removal");
}
#[test]
fn test_contains_key() {
let key = ~"k";
let map = HashMap::<~str, ~str>();
fail_unless!((!map.contains_key(&key)));
map.insert(key, ~"val");
fail_unless!((map.contains_key(&key)));
}
#[test]
fn test_find() {
let key = ~"k";
let map = HashMap::<~str, ~str>();
fail_unless!(map.find(&key).is_none());
map.insert(key, ~"val");
fail_unless!(map.find(&key).get() == ~"val");
}
#[test]
fn test_clear() {
let key = ~"k";
let mut map = HashMap::<~str, ~str>();
map.insert(key, ~"val");
fail_unless!((map.len() == 1));
fail_unless!((map.contains_key(&key)));
map.clear();
fail_unless!((map.len() == 0));
fail_unless!((!map.contains_key(&key)));
}
#[test]
fn test_hash_from_vec() {
let map = hash_from_vec(~[
(~"a", 1),
(~"b", 2),
(~"c", 3)
]);
fail_unless!(map.len() == 3u);
fail_unless!(map.get(&~"a") == 1);
fail_unless!(map.get(&~"b") == 2);
fail_unless!(map.get(&~"c") == 3);
}
}

View file

@ -725,8 +725,6 @@ fn copy_vec<T:Copy>(dest: &mut [T], s1: uint,
#[cfg(test)]
mod test_qsort3 {
use core::prelude::*;
use sort::*;
use core::vec;
@ -770,8 +768,6 @@ mod test_qsort3 {
#[cfg(test)]
mod test_qsort {
use core::prelude::*;
use sort::*;
use core::int;

View file

@ -71,7 +71,6 @@ pub mod bitv;
pub mod deque;
pub mod fun_treemap;
pub mod list;
pub mod oldmap;
pub mod priority_queue;
pub mod rope;
pub mod smallintmap;

View file

@ -23,9 +23,9 @@ use print::pprust;
use visit;
use core::cmp;
use core::hashmap::linear::LinearMap;
use core::str;
use core::vec;
use std;
pub enum path_elt {
path_mod(ident),
@ -104,10 +104,10 @@ pub enum ast_node {
node_struct_ctor(@struct_def, @item, @path),
}
pub type map = std::oldmap::HashMap<node_id, ast_node>;
pub type map = @mut LinearMap<node_id, ast_node>;
pub struct Ctx {
map: @map,
map: map,
path: path,
local_id: uint,
diag: @span_handler,
@ -134,13 +134,13 @@ pub fn mk_ast_map_visitor() -> vt {
pub fn map_crate(diag: @span_handler, c: crate) -> map {
let cx = @mut Ctx {
map: @std::oldmap::HashMap(),
map: @mut LinearMap::new(),
path: ~[],
local_id: 0u,
diag: diag,
};
visit::visit_crate(c, cx, mk_ast_map_visitor());
*cx.map
cx.map
}
// Used for items loaded from external crate that are being inlined into this
@ -157,7 +157,7 @@ pub fn map_decoded_item(diag: @span_handler,
// even if we did I think it only needs an ordering between local
// variables that are simultaneously in scope).
let cx = @mut Ctx {
map: @map,
map: map,
path: copy path,
local_id: 0,
diag: diag,
@ -374,7 +374,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
None => {
fmt!("unknown node (id=%d)", id)
}
Some(node_item(item, path)) => {
Some(&node_item(item, path)) => {
let path_str = path_ident_to_str(*path, item.ident, itr);
let item_str = match item.node {
item_const(*) => ~"const",
@ -390,43 +390,43 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
};
fmt!("%s %s (id=%?)", item_str, path_str, id)
}
Some(node_foreign_item(item, abi, _, path)) => {
Some(&node_foreign_item(item, abi, _, path)) => {
fmt!("foreign item %s with abi %? (id=%?)",
path_ident_to_str(*path, item.ident, itr), abi, id)
}
Some(node_method(m, _, path)) => {
Some(&node_method(m, _, path)) => {
fmt!("method %s in %s (id=%?)",
*itr.get(m.ident), path_to_str(*path, itr), id)
}
Some(node_trait_method(ref tm, _, path)) => {
Some(&node_trait_method(ref tm, _, path)) => {
let m = ast_util::trait_method_to_ty_method(&**tm);
fmt!("method %s in %s (id=%?)",
*itr.get(m.ident), path_to_str(*path, itr), id)
}
Some(node_variant(ref variant, _, path)) => {
Some(&node_variant(ref variant, _, path)) => {
fmt!("variant %s in %s (id=%?)",
*itr.get(variant.node.name), path_to_str(*path, itr), id)
}
Some(node_expr(expr)) => {
Some(&node_expr(expr)) => {
fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id)
}
Some(node_stmt(stmt)) => {
Some(&node_stmt(stmt)) => {
fmt!("stmt %s (id=%?)",
pprust::stmt_to_str(*stmt, itr), id)
}
Some(node_arg(_, _)) => { // add more info here
Some(&node_arg(_, _)) => { // add more info here
fmt!("arg (id=%?)", id)
}
Some(node_local(_)) => { // add more info here
Some(&node_local(_)) => { // add more info here
fmt!("local (id=%?)", id)
}
Some(node_dtor(*)) => { // add more info here
Some(&node_dtor(*)) => { // add more info here
fmt!("node_dtor (id=%?)", id)
}
Some(node_block(_)) => {
Some(&node_block(_)) => {
fmt!("block")
}
Some(node_struct_ctor(*)) => {
Some(&node_struct_ctor(*)) => {
fmt!("struct_ctor")
}
}
@ -436,7 +436,7 @@ pub fn node_item_query<Result>(items: map, id: node_id,
query: &fn(@item) -> Result,
+error_msg: ~str) -> Result {
match items.find(&id) {
Some(node_item(it, _)) => query(it),
Some(&node_item(it, _)) => query(it),
_ => fail!(error_msg)
}
}

View file

@ -19,11 +19,8 @@ use parse::parser::Parser;
use parse::token::{Token, EOF, to_str, nonterminal};
use parse::token;
use core::option::{Option, Some, None};
use core::str;
use core::uint;
use core::vec;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use core::prelude::*;
/* This is an Earley-like parser, without support for in-grammar nonterminals,
only by calling out to the main rust parser for named nonterminals (which it
@ -189,9 +186,9 @@ pub enum named_match {
pub type earley_item = ~MatcherPos;
pub fn nameize(p_s: @mut ParseSess, ms: ~[matcher], res: ~[@named_match])
-> HashMap<ident,@named_match> {
-> LinearMap<ident,@named_match> {
fn n_rec(p_s: @mut ParseSess, m: matcher, res: ~[@named_match],
ret_val: HashMap<ident, @named_match>) {
ret_val: &mut LinearMap<ident, @named_match>) {
match m {
codemap::spanned {node: match_tok(_), _} => (),
codemap::spanned {node: match_seq(ref more_ms, _, _, _, _), _} => {
@ -210,13 +207,13 @@ pub fn nameize(p_s: @mut ParseSess, ms: ~[matcher], res: ~[@named_match])
}
}
}
let ret_val = HashMap();
for ms.each() |m| { n_rec(p_s, *m, res, ret_val) }
let mut ret_val = LinearMap::new();
for ms.each() |m| { n_rec(p_s, *m, res, &mut ret_val) }
return ret_val;
}
pub enum parse_result {
success(HashMap<ident, @named_match>),
success(LinearMap<ident, @named_match>),
failure(codemap::span, ~str),
error(codemap::span, ~str)
}
@ -226,11 +223,11 @@ pub fn parse_or_else(
+cfg: ast::crate_cfg,
rdr: @reader,
ms: ~[matcher]
) -> HashMap<ident, @named_match> {
) -> LinearMap<ident, @named_match> {
match parse(sess, cfg, rdr, ms) {
success(m) => m,
failure(sp, ref str) => sess.span_diagnostic.span_fatal(sp, (*str)),
error(sp, ref str) => sess.span_diagnostic.span_fatal(sp, (*str))
failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str),
error(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
}
}

View file

@ -63,12 +63,12 @@ pub fn add_new_extension(cx: @ext_ctxt,
argument_gram);
// Extract the arguments:
let lhses = match argument_map.get(&lhs_nm) {
let lhses = match *argument_map.get(&lhs_nm) {
@matched_seq(ref s, _) => /* FIXME (#2543) */ copy *s,
_ => cx.span_bug(sp, ~"wrong-structured lhs")
};
let rhses = match argument_map.get(&rhs_nm) {
let rhses = match *argument_map.get(&rhs_nm) {
@matched_seq(ref s, _) => /* FIXME (#2543) */ copy *s,
_ => cx.span_bug(sp, ~"wrong-structured rhs")
};

View file

@ -18,9 +18,9 @@ use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal};
use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident, ident_interner};
use parse::lexer::TokenAndSpan;
use core::hashmap::linear::LinearMap;
use core::option;
use core::vec;
use std;
/* FIXME #2811: figure out how to have a uniquely linked stack, and change to
`~` */
@ -39,7 +39,7 @@ pub struct TtReader {
// the unzipped tree:
cur: @mut TtFrame,
/* for MBE-style macro transcription */
interpolations: std::oldmap::HashMap<ident, @named_match>,
interpolations: LinearMap<ident, @named_match>,
repeat_idx: ~[uint],
repeat_len: ~[uint],
/* cached: */
@ -52,7 +52,7 @@ pub struct TtReader {
* should) be none. */
pub fn new_tt_reader(sp_diag: @span_handler,
itr: @ident_interner,
interp: Option<std::oldmap::HashMap<ident,@named_match>>,
interp: Option<LinearMap<ident,@named_match>>,
+src: ~[ast::token_tree])
-> @mut TtReader {
let r = @mut TtReader {
@ -66,7 +66,7 @@ pub fn new_tt_reader(sp_diag: @span_handler,
up: option::None
},
interpolations: match interp { /* just a convienience */
None => std::oldmap::HashMap(),
None => LinearMap::new(),
Some(x) => x
},
repeat_idx: ~[],
@ -124,7 +124,10 @@ fn lookup_cur_matched_by_matched(r: &mut TtReader,
}
fn lookup_cur_matched(r: &mut TtReader, name: ident) -> @named_match {
lookup_cur_matched_by_matched(r, r.interpolations.get(&name))
// FIXME (#3850): this looks a bit silly with an extra scope.
let start;
{ start = *r.interpolations.get(&name); }
return lookup_cur_matched_by_matched(r, start);
}
enum lis {
lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str)

View file

@ -129,7 +129,7 @@ pub impl Parser {
// A sanity check that the word we are asking for is a known keyword
fn require_keyword(&self, word: &~str) {
if !self.keywords.contains_key(word) {
if !self.keywords.contains(word) {
self.bug(fmt!("unknown keyword: %s", *word));
}
}
@ -153,7 +153,7 @@ pub impl Parser {
fn is_any_keyword(&self, tok: &token::Token) -> bool {
match *tok {
token::IDENT(sid, false) => {
self.keywords.contains_key(self.id_to_str(sid))
self.keywords.contains(self.id_to_str(sid))
}
_ => false
}
@ -183,7 +183,7 @@ pub impl Parser {
}
fn is_strict_keyword(&self, word: &~str) -> bool {
self.strict_keywords.contains_key(word)
self.strict_keywords.contains(word)
}
fn check_strict_keywords(&self) {
@ -203,7 +203,7 @@ pub impl Parser {
}
fn is_reserved_keyword(&self, word: &~str) -> bool {
self.reserved_keywords.contains_key(word)
self.reserved_keywords.contains(word)
}
fn check_reserved_keywords(&self) {

View file

@ -225,9 +225,9 @@ pub impl Parser {
desc: &str) {
self.span_err(sp, fmt!("obsolete syntax: %s", kind_str));
if !self.obsolete_set.contains_key(&kind) {
if !self.obsolete_set.contains(&kind) {
self.sess.span_diagnostic.handler().note(fmt!("%s", desc));
self.obsolete_set.insert(kind, ());
self.obsolete_set.insert(kind);
}
}

View file

@ -92,8 +92,8 @@ use opt_vec::OptVec;
use core::either::{Either, Left, Right};
use core::either;
use core::hashmap::linear::LinearSet;
use core::vec;
use std::oldmap::HashMap;
#[deriving(Eq)]
enum restriction {
@ -240,7 +240,7 @@ pub fn Parser(sess: @mut ParseSess,
keywords: token::keyword_table(),
strict_keywords: token::strict_keyword_table(),
reserved_keywords: token::reserved_keyword_table(),
obsolete_set: HashMap(),
obsolete_set: @mut LinearSet::new(),
mod_path_stack: @mut ~[],
}
}
@ -259,12 +259,12 @@ pub struct Parser {
quote_depth: @mut uint, // not (yet) related to the quasiquoter
reader: @reader,
interner: @token::ident_interner,
keywords: HashMap<~str, ()>,
strict_keywords: HashMap<~str, ()>,
reserved_keywords: HashMap<~str, ()>,
keywords: LinearSet<~str>,
strict_keywords: LinearSet<~str>,
reserved_keywords: LinearSet<~str>,
/// The set of seen errors about obsolete syntax. Used to suppress
/// extra detail when the same error is seen twice
obsolete_set: HashMap<ObsoleteSyntax, ()>,
obsolete_set: @mut LinearSet<ObsoleteSyntax>,
/// Used to determine the path to externally loaded source files
mod_path_stack: @mut ~[~str],

View file

@ -18,9 +18,9 @@ use util::interner;
use core::cast;
use core::char;
use core::hashmap::linear::LinearSet;
use core::str;
use core::task;
use std::oldmap::HashMap;
#[auto_encode]
#[auto_decode]
@ -458,35 +458,33 @@ pub fn mk_fake_ident_interner() -> @ident_interner {
* appear as identifiers at all. Reserved keywords are not used anywhere in
* the language and may not appear as identifiers.
*/
pub fn keyword_table() -> HashMap<~str, ()> {
let keywords = HashMap();
for temporary_keyword_table().each_key |&word| {
keywords.insert(word, ());
}
for strict_keyword_table().each_key |&word| {
keywords.insert(word, ());
}
for reserved_keyword_table().each_key |&word| {
keywords.insert(word, ());
}
keywords
pub fn keyword_table() -> LinearSet<~str> {
let mut keywords = LinearSet::new();
let mut tmp = temporary_keyword_table();
let mut strict = strict_keyword_table();
let mut reserved = reserved_keyword_table();
do tmp.consume |word| { keywords.insert(word); }
do strict.consume |word| { keywords.insert(word); }
do reserved.consume |word| { keywords.insert(word); }
return keywords;
}
/// Keywords that may be used as identifiers
pub fn temporary_keyword_table() -> HashMap<~str, ()> {
let words = HashMap();
pub fn temporary_keyword_table() -> LinearSet<~str> {
let mut words = LinearSet::new();
let keys = ~[
~"self", ~"static",
];
for keys.each |word| {
words.insert(copy *word, ());
do vec::consume(keys) |_, s| {
words.insert(s);
}
words
return words;
}
/// Full keywords. May not appear anywhere else.
pub fn strict_keyword_table() -> HashMap<~str, ()> {
let words = HashMap();
pub fn strict_keyword_table() -> LinearSet<~str> {
let mut words = LinearSet::new();
let keys = ~[
~"as",
~"break",
@ -505,21 +503,21 @@ pub fn strict_keyword_table() -> HashMap<~str, ()> {
~"unsafe", ~"use",
~"while"
];
for keys.each |word| {
words.insert(copy *word, ());
do vec::consume(keys) |_, w| {
words.insert(w);
}
words
return words;
}
pub fn reserved_keyword_table() -> HashMap<~str, ()> {
let words = HashMap();
pub fn reserved_keyword_table() -> LinearSet<~str> {
let mut words = LinearSet::new();
let keys = ~[
~"be"
];
for keys.each |word| {
words.insert(copy *word, ());
do vec::consume(keys) |_, s| {
words.insert(s);
}
words
return words;
}

View file

@ -13,11 +13,11 @@
extern mod std;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
pub type header_map = HashMap<~str, @mut ~[@~str]>;
pub type header_map = LinearMap<~str, @mut ~[@~str]>;
// the unused ty param is necessary so this gets monomorphized
pub fn request<T:Copy>(req: header_map) {
let _x = copy *(copy *req.get(&~"METHOD"))[0u];
pub fn request<T:Copy>(req: &header_map) {
let _x = copy *(copy **req.get(&~"METHOD"))[0u];
}

View file

@ -13,8 +13,6 @@
extern mod std;
use std::time::precise_time_s;
use std::oldmap;
use std::oldmap::{Map, HashMap};
use core::io::{Reader, ReaderUtil};
use core::rand::RngUtil;
@ -29,7 +27,6 @@ fn main() {
bench!(shift_push);
bench!(read_line);
bench!(str_set);
bench!(vec_plus);
bench!(vec_append);
bench!(vec_push_all);
@ -73,24 +70,6 @@ fn read_line() {
}
}
fn str_set() {
let r = rand::Rng();
let s = oldmap::HashMap();
for int::range(0, 1000) |_i| {
oldmap::set_add(s, r.gen_str(10));
}
let mut found = 0;
for int::range(0, 1000) |_i| {
match s.find(&r.gen_str(10)) {
Some(_) => { found += 1; }
None => { }
}
}
}
fn vec_plus() {
let r = rand::Rng();

View file

@ -22,11 +22,9 @@ An implementation of the Graph500 Breadth First Search problem in Rust.
extern mod std;
use std::arc;
use std::time;
use std::oldmap;
use std::oldmap::Map;
use std::oldmap::HashMap;
use std::deque::Deque;
use std::par;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::io::WriterUtil;
use core::int::abs;
use core::rand::RngUtil;
@ -82,27 +80,31 @@ fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
}
fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
let graph = do vec::from_fn(N) |_i| {
oldmap::HashMap::<node_id, ()>()
let mut graph = do vec::from_fn(N) |_i| {
LinearSet::new()
};
do vec::each(edges) |e| {
match *e {
(i, j) => {
oldmap::set_add(graph[i], j);
oldmap::set_add(graph[j], i);
graph[i].insert(j);
graph[j].insert(i);
}
}
true
}
do graph.map() |v| {
oldmap::vec_from_set(*v)
do vec::map_consume(graph) |mut v| {
let mut vec = ~[];
do v.consume |i| {
vec.push(i);
}
vec
}
}
fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
let keys = oldmap::HashMap::<node_id, ()>();
let mut keys = LinearSet::new();
let r = rand::Rng();
while keys.len() < n {
@ -111,10 +113,14 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
if graph[k].len() > 0u && vec::any(graph[k], |i| {
*i != k as node_id
}) {
oldmap::set_add(keys, k as node_id);
keys.insert(k as node_id);
}
}
oldmap::vec_from_set(keys)
let mut vec = ~[];
do keys.consume |i| {
vec.push(i);
}
return vec;
}
/**

View file

@ -11,8 +11,6 @@
// chameneos
extern mod std;
use std::oldmap;
use std::oldmap::HashMap;
use std::sort;
use core::cell::Cell;
use core::comm::*;

View file

@ -14,15 +14,14 @@
#[legacy_modes];
extern mod std;
use std::oldmap;
use std::oldmap::HashMap;
use std::sort;
use core::hashmap::linear::LinearMap;
use core::io::ReaderUtil;
use core::comm::{stream, Port, Chan};
use core::cmp::Ord;
// given a map, print a sorted version of it
fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
fn sort_and_fmt(mm: &LinearMap<~[u8], uint>, total: uint) -> ~str {
fn pct(xx: uint, yy: uint) -> float {
return (xx as float) * 100f / (yy as float);
}
@ -49,7 +48,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
let mut pairs = ~[];
// map -> [(k,%)]
for mm.each |&key, &val| {
for mm.each |&(&key, &val)| {
pairs.push((key, pct(val, total)));
}
@ -68,17 +67,21 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
}
// given a map, search for the frequency of a pattern
fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint {
fn find(mm: &LinearMap<~[u8], uint>, key: ~str) -> uint {
match mm.find(&str::to_bytes(str::to_lower(key))) {
option::None => { return 0u; }
option::Some(num) => { return num; }
option::Some(&num) => { return num; }
}
}
// given a map, increment the counter for a key
fn update_freq(mm: HashMap<~[u8], uint>, key: &[u8]) {
fn update_freq(mm: &mut LinearMap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len()).to_vec();
mm.update(key, 1, |v,v1| { v+v1 });
let newval = match mm.pop(&key) {
Some(v) => v + 1,
None => 1
};
mm.insert(key, newval);
}
// given a ~[u8], for each window call a function
@ -100,7 +103,7 @@ fn windows_with_carry(bb: &[u8], nn: uint,
fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
to_parent: comm::Chan<~str>) {
let freqs: HashMap<~[u8], uint> = oldmap::HashMap();
let mut freqs: LinearMap<~[u8], uint> = LinearMap::new();
let mut carry: ~[u8] = ~[];
let mut total: uint = 0u;
@ -112,19 +115,19 @@ fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
if line == ~[] { break; }
carry = windows_with_carry(carry + line, sz, |window| {
update_freq(freqs, window);
update_freq(&mut freqs, window);
total += 1u;
});
}
let buffer = match sz {
1u => { sort_and_fmt(freqs, total) }
2u => { sort_and_fmt(freqs, total) }
3u => { fmt!("%u\t%s", find(freqs, ~"GGT"), ~"GGT") }
4u => { fmt!("%u\t%s", find(freqs, ~"GGTA"), ~"GGTA") }
6u => { fmt!("%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT") }
12u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
18u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
1u => { sort_and_fmt(&freqs, total) }
2u => { sort_and_fmt(&freqs, total) }
3u => { fmt!("%u\t%s", find(&freqs, ~"GGT"), ~"GGT") }
4u => { fmt!("%u\t%s", find(&freqs, ~"GGTA"), ~"GGTA") }
6u => { fmt!("%u\t%s", find(&freqs, ~"GGTATT"), ~"GGTATT") }
12u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
18u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
_ => { ~"" }
};

View file

@ -9,12 +9,12 @@
// except according to those terms.
//buggy.rs
extern mod std;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
fn main() {
let buggy_map :HashMap<uint, &uint> =
HashMap::<uint, &uint>();
let mut buggy_map :LinearMap<uint, &uint> =
LinearMap::new::<uint, &uint>();
buggy_map.insert(42, &*~1); //~ ERROR illegal borrow
// but it is ok if we use a temporary

View file

@ -10,11 +10,11 @@
// error-pattern: mismatched types
extern mod std;
use std::oldmap::HashMap;
use std::bitv;
use core::hashmap::linear::LinearMap;
struct FnInfo {
vars: HashMap<uint, VarInfo>
vars: LinearMap<uint, VarInfo>
}
struct VarInfo {
@ -27,7 +27,7 @@ fn bitv_to_str(enclosing: FnInfo, v: ~bitv::Bitv) -> str {
// error is that the value type in the hash map is var_info, not a box
for enclosing.vars.each_value |val| {
if v.get(val) { s += "foo"; }
if *v.get(val) { s += "foo"; }
}
return s;
}

View file

@ -11,7 +11,7 @@
// except according to those terms.
extern mod std;
use std::oldmap::HashMap;
use std::json::Object;
pub fn main() {
io::println("Hello world!");

View file

@ -16,17 +16,10 @@
This originally came from the word-count benchmark.
*/
extern mod std;
use std::oldmap;
use std::oldmap::HashMap;
use core::comm::*;
pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }
mod map_reduce {
use std::oldmap;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use core::comm::*;
pub type putter = @fn(~str, ~str);
@ -44,23 +37,20 @@ mod map_reduce {
}
fn map_task(ctrl: SharedChan<ctrl_proto>, input: ~str) {
let intermediates = oldmap::HashMap();
let intermediates = @mut LinearMap::new();
fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
val: ~str) {
let mut c;
match im.find(&key) {
Some(_c) => { c = _c }
None => {
let (pp, cc) = stream();
error!("sending find_reducer");
ctrl.send(find_reducer(str::to_bytes(key), cc));
error!("receiving");
c = pp.recv();
error!(c);
im.insert(key, c);
}
fn emit(im: &mut LinearMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
_val: ~str) {
if im.contains_key(&key) {
return;
}
let (pp, cc) = stream();
error!("sending find_reducer");
ctrl.send(find_reducer(str::to_bytes(key), cc));
error!("receiving");
let c = pp.recv();
error!(c);
im.insert(key, c);
}
let ctrl_clone = ctrl.clone();
@ -75,9 +65,9 @@ mod map_reduce {
// This task becomes the master control task. It spawns others
// to do the rest.
let mut reducers: oldmap::HashMap<~str, int>;
let mut reducers: LinearMap<~str, int>;
reducers = oldmap::HashMap();
reducers = LinearMap::new();
start_mappers(ctrl_chan, inputs.clone());
@ -89,7 +79,7 @@ mod map_reduce {
find_reducer(k, cc) => {
let mut c;
match reducers.find(&str::from_bytes(k)) {
Some(_c) => { c = _c; }
Some(&_c) => { c = _c; }
None => { c = 0; }
}
cc.send(c);

View file

@ -10,11 +10,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
pub fn main() {
let m = HashMap();
let mut m = LinearMap::new();
m.insert(str::to_bytes(~"foo"), str::to_bytes(~"bar"));
error!(m);
}

Some files were not shown because too many files have changed in this diff Show more