Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove oldmap::HashMap #5523

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# }
~~~~

Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

//! Logging

use libc;

pub mod rustrt {
use libc;

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/libcore/rt/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/libcore/rt/uv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/rt/uvll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ 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};
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.
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down
63 changes: 27 additions & 36 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -46,111 +46,102 @@ 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: ~[],
intr: intr
};
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Loading