Skip to content

Commit fa82b9a

Browse files
committed
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: * alexcrichton/rust@mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L39R1587 * alexcrichton/rust@mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L61R3760 * alexcrichton/rust@mozilla:a56ec8c1342453a88be79e192a11501844375d40...alexcrichton:621b63300358cacad088ddd7f78180f29c40e66e#L71R917 * alexcrichton/rust@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...
2 parents 3d588c5 + d69108d commit fa82b9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1226
-1636
lines changed

doc/rust.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ expression context, the final namespace qualifier is omitted.
441441
Two examples of paths with type arguments:
442442

443443
~~~~
444-
# use std::oldmap;
444+
# use core::hashmap::linear::LinearMap;
445445
# fn f() {
446446
# fn id<T:Copy>(t: T) -> T { t }
447-
type t = oldmap::HashMap<int,~str>; // Type arguments used in a type expression
448-
let x = id::<int>(10); // Type arguments used in a call expression
447+
type t = LinearMap<int,~str>; // Type arguments used in a type expression
448+
let x = id::<int>(10); // Type arguments used in a call expression
449449
# }
450450
~~~~
451451

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,8 @@ illegal to copy and pass by value.
18291829
Generic `type`, `struct`, and `enum` declarations follow the same pattern:
18301830

18311831
~~~~
1832-
# use std::oldmap::HashMap;
1833-
type Set<T> = HashMap<T, ()>;
1832+
# use core::hashmap::linear::LinearMap;
1833+
type Set<T> = LinearMap<T, ()>;
18341834
18351835
struct Stack<T> {
18361836
elements: ~[T]

src/libcore/flate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Simple compression
1717
use libc;
1818
use libc::{c_void, size_t, c_int};
1919
use ptr;
20-
use rand::RngUtil;
2120
use vec;
2221

2322
#[cfg(test)] use rand;
23+
#[cfg(test)] use rand::RngUtil;
2424

2525
pub mod rustrt {
2626
use libc::{c_int, c_void, size_t};

src/libcore/hashmap.rs

+5
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,11 @@ pub mod linear {
656656
fn reserve_at_least(&mut self, n: uint) {
657657
self.map.reserve_at_least(n)
658658
}
659+
660+
/// Consumes all of the elements in the set, emptying it out
661+
fn consume(&mut self, f: &fn(T)) {
662+
self.map.consume(|k, _| f(k))
663+
}
659664
}
660665

661666
#[test]

src/libcore/logging.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
//! Logging
1212
13-
use libc;
14-
1513
pub mod rustrt {
1614
use libc;
1715

@@ -49,6 +47,7 @@ pub fn console_off() {
4947
pub fn log_type<T>(level: u32, object: &T) {
5048
use cast::transmute;
5149
use io;
50+
use libc;
5251
use repr;
5352
use vec;
5453

src/libcore/rt/io/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use option::*;
12-
use comm::{GenericPort, GenericChan};
13-
1411
pub mod file;
1512

1613
// FIXME #5370 Strongly want this to be StreamError(&mut Stream)

src/libcore/rt/uv/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use ptr;
4242
use libc::{c_void, c_int, size_t, malloc, free, ssize_t};
4343
use cast::{transmute, transmute_mut_region};
4444
use ptr::null;
45-
use sys::size_of;
4645
use super::uvll;
4746
use super::uvll::*;
4847
use unstable::finally::Finally;

src/libcore/rt/uvll.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t};
3333
use libc::{malloc, free};
3434
use prelude::*;
35-
use ptr::to_unsafe_ptr;
3635

3736
pub struct uv_err_t {
3837
code: c_int,

src/librustc/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
642642
643643
pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
644644
match ccx.type_hashcodes.find(&t) {
645-
Some(h) => h,
645+
Some(&h) => h,
646646
None => {
647647
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
648648
ccx.type_hashcodes.insert(t, hash);

src/librustc/driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
246246

247247
// These next two const passes can probably be merged
248248
time(time_passes, ~"const marking", ||
249-
middle::const_eval::process_crate(crate, def_map, ty_cx));
249+
middle::const_eval::process_crate(crate, ty_cx));
250250

251251
time(time_passes, ~"const checking", ||
252252
middle::check_const::check_crate(sess, crate, ast_map, def_map,
@@ -546,11 +546,11 @@ pub fn build_session_options(+binary: ~str,
546546
let flags = vec::append(getopts::opt_strs(matches, level_short),
547547
getopts::opt_strs(matches, level_name));
548548
for flags.each |lint_name| {
549-
let lint_name = @str::replace(*lint_name, ~"-", ~"_");
549+
let lint_name = str::replace(*lint_name, ~"-", ~"_");
550550
match lint_dict.find(&lint_name) {
551551
None => {
552552
early_error(demitter, fmt!("unknown %s flag: %s",
553-
level_name, *lint_name));
553+
level_name, lint_name));
554554
}
555555
Some(lint) => {
556556
lint_opts.push((lint.lint, *level));

src/librustc/lib/llvm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
use core::prelude::*;
1212

13+
use core::hashmap::linear::LinearMap;
1314
use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
1415
use core::option;
1516
use core::ptr;
1617
use core::str;
1718
use core::vec;
18-
use std::oldmap::HashMap;
1919

2020
pub type Opcode = u32;
2121
pub type Bool = c_uint;
@@ -1467,8 +1467,8 @@ pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
14671467
/* Memory-managed object interface to type handles. */
14681468

14691469
pub struct TypeNames {
1470-
type_names: HashMap<TypeRef, @str>,
1471-
named_types: HashMap<@str, TypeRef>
1470+
type_names: @mut LinearMap<TypeRef, @str>,
1471+
named_types: @mut LinearMap<@str, TypeRef>
14721472
}
14731473

14741474
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
@@ -1477,17 +1477,17 @@ pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
14771477
}
14781478

14791479
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
1480-
return tn.type_names.find(&t);
1480+
return tn.type_names.find(&t).map_consume(|x| *x);
14811481
}
14821482

14831483
pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
1484-
return tn.named_types.find(&s);
1484+
return tn.named_types.find(&s).map_consume(|x| *x);
14851485
}
14861486

14871487
pub fn mk_type_names() -> @TypeNames {
14881488
@TypeNames {
1489-
type_names: HashMap(),
1490-
named_types: HashMap()
1489+
type_names: @mut LinearMap::new(),
1490+
named_types: @mut LinearMap::new()
14911491
}
14921492
}
14931493

src/librustc/metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use metadata::filesearch::FileSearch;
1919
use metadata::loader;
2020

2121
use core::either;
22+
use core::hashmap::linear::LinearMap;
2223
use core::vec;
2324
use syntax::attr;
2425
use syntax::codemap::{span, dummy_sp};
2526
use syntax::diagnostic::span_handler;
2627
use syntax::parse::token::ident_interner;
2728
use syntax::visit;
2829
use syntax::{ast, ast_util};
29-
use std::oldmap::HashMap;
3030

3131
// Traverses an AST, reading all the information about use'd crates and extern
3232
// libraries necessary for later resolving, typechecking, linking, etc.
@@ -307,7 +307,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
307307
debug!("resolving deps of external crate");
308308
// The map from crate numbers in the crate we're resolving to local crate
309309
// numbers
310-
let cnum_map = HashMap();
310+
let mut cnum_map = LinearMap::new();
311311
for decoder::get_crate_deps(e.intr, cdata).each |dep| {
312312
let extrn_cnum = dep.cnum;
313313
let cname = dep.name;
@@ -334,7 +334,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
334334
}
335335
}
336336
}
337-
return cnum_map;
337+
return @mut cnum_map;
338338
}
339339

340340
// Local Variables:

src/librustc/metadata/cstore.rs

+27-36
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use core::prelude::*;
1717
use metadata::cstore;
1818
use metadata::decoder;
1919

20+
use core::hashmap::linear::LinearMap;
2021
use core::vec;
21-
use std::oldmap;
2222
use std;
2323
use syntax::{ast, attr};
2424
use syntax::parse::token::ident_interner;
@@ -27,7 +27,7 @@ use syntax::parse::token::ident_interner;
2727
// local crate numbers (as generated during this session). Each external
2828
// crate may refer to types in other external crates, and each has their
2929
// own crate numbers.
30-
pub type cnum_map = oldmap::HashMap<ast::crate_num, ast::crate_num>;
30+
pub type cnum_map = @mut LinearMap<ast::crate_num, ast::crate_num>;
3131

3232
pub struct crate_metadata {
3333
name: @~str,
@@ -37,7 +37,7 @@ pub struct crate_metadata {
3737
}
3838

3939
pub struct CStore {
40-
priv metas: oldmap::HashMap<ast::crate_num, @crate_metadata>,
40+
priv metas: LinearMap <ast::crate_num, @crate_metadata>,
4141
priv extern_mod_crate_map: extern_mod_crate_map,
4242
priv used_crate_files: ~[Path],
4343
priv used_libraries: ~[~str],
@@ -46,111 +46,102 @@ pub struct CStore {
4646
}
4747

4848
// Map from node_id's of local extern mod statements to crate numbers
49-
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
49+
type extern_mod_crate_map = LinearMap<ast::node_id, ast::crate_num>;
5050

5151
pub fn mk_cstore(intr: @ident_interner) -> CStore {
52-
let meta_cache = oldmap::HashMap();
53-
let crate_map = oldmap::HashMap();
5452
return CStore {
55-
metas: meta_cache,
56-
extern_mod_crate_map: crate_map,
53+
metas: LinearMap::new(),
54+
extern_mod_crate_map: LinearMap::new(),
5755
used_crate_files: ~[],
5856
used_libraries: ~[],
5957
used_link_args: ~[],
6058
intr: intr
6159
};
6260
}
6361

64-
pub fn get_crate_data(cstore: @mut CStore, cnum: ast::crate_num)
62+
pub fn get_crate_data(cstore: &CStore, cnum: ast::crate_num)
6563
-> @crate_metadata {
66-
return cstore.metas.get(&cnum);
64+
return *cstore.metas.get(&cnum);
6765
}
6866

69-
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
67+
pub fn get_crate_hash(cstore: &CStore, cnum: ast::crate_num) -> @~str {
7068
let cdata = get_crate_data(cstore, cnum);
7169
decoder::get_crate_hash(cdata.data)
7270
}
7371

74-
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
72+
pub fn get_crate_vers(cstore: &CStore, cnum: ast::crate_num) -> @~str {
7573
let cdata = get_crate_data(cstore, cnum);
7674
decoder::get_crate_vers(cdata.data)
7775
}
7876

79-
pub fn set_crate_data(cstore: @mut CStore,
77+
pub fn set_crate_data(cstore: &mut CStore,
8078
cnum: ast::crate_num,
8179
data: @crate_metadata) {
82-
let metas = cstore.metas;
83-
metas.insert(cnum, data);
80+
cstore.metas.insert(cnum, data);
8481
}
8582

86-
pub fn have_crate_data(cstore: @mut CStore, cnum: ast::crate_num) -> bool {
83+
pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
8784
cstore.metas.contains_key(&cnum)
8885
}
8986

90-
pub fn iter_crate_data(cstore: @mut CStore,
87+
pub fn iter_crate_data(cstore: &CStore,
9188
i: &fn(ast::crate_num, @crate_metadata)) {
92-
let metas = cstore.metas;
93-
for metas.each |&k, &v| {
89+
for cstore.metas.each |&(&k, &v)| {
9490
i(k, v);
9591
}
9692
}
9793

98-
pub fn add_used_crate_file(cstore: @mut CStore, lib: &Path) {
99-
let cstore = &mut *cstore;
94+
pub fn add_used_crate_file(cstore: &mut CStore, lib: &Path) {
10095
if !vec::contains(cstore.used_crate_files, lib) {
10196
cstore.used_crate_files.push(copy *lib);
10297
}
10398
}
10499

105-
pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
100+
pub fn get_used_crate_files(cstore: &CStore) -> ~[Path] {
106101
return /*bad*/copy cstore.used_crate_files;
107102
}
108103

109-
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
104+
pub fn add_used_library(cstore: &mut CStore, lib: @~str) -> bool {
110105
fail_unless!(*lib != ~"");
111106

112-
let cstore = &mut *cstore;
113107
if cstore.used_libraries.contains(&*lib) { return false; }
114108
cstore.used_libraries.push(/*bad*/ copy *lib);
115109
true
116110
}
117111

118-
pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] {
112+
pub fn get_used_libraries(cstore: &CStore) -> ~[~str] {
119113
/*bad*/copy cstore.used_libraries
120114
}
121115

122-
pub fn add_used_link_args(cstore: @mut CStore, args: &str) {
116+
pub fn add_used_link_args(cstore: &mut CStore, args: &str) {
123117
for args.each_split_char(' ') |s| {
124118
cstore.used_link_args.push(s.to_owned());
125119
}
126120
}
127121

128-
pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
122+
pub fn get_used_link_args(cstore: &CStore) -> ~[~str] {
129123
/*bad*/copy cstore.used_link_args
130124
}
131125

132-
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
126+
pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
133127
emod_id: ast::node_id,
134128
cnum: ast::crate_num) {
135-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
136-
extern_mod_crate_map.insert(emod_id, cnum);
129+
cstore.extern_mod_crate_map.insert(emod_id, cnum);
137130
}
138131

139-
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
132+
pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
140133
emod_id: ast::node_id)
141134
-> Option<ast::crate_num> {
142-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
143-
extern_mod_crate_map.find(&emod_id)
135+
cstore.extern_mod_crate_map.find(&emod_id).map_consume(|x| *x)
144136
}
145137

146138
// returns hashes of crates directly used by this crate. Hashes are sorted by
147139
// (crate name, crate version, crate hash) in lexicographic order (not semver)
148-
pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
140+
pub fn get_dep_hashes(cstore: &CStore) -> ~[~str] {
149141
struct crate_hash { name: @~str, vers: @~str, hash: @~str }
150142
let mut result = ~[];
151143

152-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
153-
for extern_mod_crate_map.each_value |&cnum| {
144+
for cstore.extern_mod_crate_map.each_value |&cnum| {
154145
let cdata = cstore::get_crate_data(cstore, cnum);
155146
let hash = decoder::get_crate_hash(cdata.data);
156147
let vers = decoder::get_crate_vers(cdata.data);

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
11321132
}
11331133

11341134
match cdata.cnum_map.find(&did.crate) {
1135-
option::Some(n) => ast::def_id { crate: n, node: did.node },
1135+
option::Some(&n) => ast::def_id { crate: n, node: did.node },
11361136
option::None => fail!(~"didn't find a crate in the cnum_map")
11371137
}
11381138
}

0 commit comments

Comments
 (0)