Skip to content

Commit 1386420

Browse files
committed
Move used_crate_files from session to cstore
1 parent 82983e5 commit 1386420

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

src/comp/driver/rustc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// -*- rust -*-
44
import metadata::creader;
5+
import metadata::cstore;
56
import syntax::parse::parser;
67
import syntax::parse::token;
78
import syntax::ast;
@@ -352,8 +353,8 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
352353

353354
fn build_session(@session::options sopts) -> session::session {
354355
auto target_cfg = build_target_config();
355-
auto cstore = metadata::cstore::mk_cstore();
356-
ret session::session(target_cfg, sopts, cstore, [],
356+
auto cstore = cstore::mk_cstore();
357+
ret session::session(target_cfg, sopts, cstore,
357358
[], [], codemap::new_codemap(), 0u);
358359
}
359360

@@ -516,7 +517,7 @@ fn main(vec[str] args) {
516517
};
517518
}
518519

519-
for (str cratepath in sess.get_used_crate_files()) {
520+
for (str cratepath in cstore::get_used_crate_files(sess.get_cstore())) {
520521
auto dir = fs::dirname(cratepath);
521522
if (dir != "") {
522523
gcc_args += ["-L" + dir];

src/comp/driver/session.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type crate_metadata = rec(str name, vec[u8] data);
4646
obj session(@config targ_cfg,
4747
@options opts,
4848
metadata::cstore::cstore cstore,
49-
mutable vec[str] used_crate_files,
5049
mutable vec[str] used_libraries,
5150
mutable vec[str] used_link_args,
5251
codemap::codemap cm,
@@ -123,19 +122,6 @@ obj session(@config targ_cfg,
123122
fn get_used_libraries() -> vec[str] {
124123
ret used_libraries;
125124
}
126-
fn add_used_crate_file(&str lib) {
127-
// A program has a small number of crates, so a vector is probably
128-
// a good data structure in here.
129-
for (str l in used_crate_files) {
130-
if (l == lib) {
131-
ret;
132-
}
133-
}
134-
used_crate_files += [lib];
135-
}
136-
fn get_used_crate_files() -> vec[str] {
137-
ret used_crate_files;
138-
}
139125
fn get_codemap() -> codemap::codemap { ret cm; }
140126
fn lookup_pos(uint pos) -> codemap::loc {
141127
ret codemap::lookup_pos(cm, pos);

src/comp/metadata/creader.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ fn load_library_crate(&session::session sess, span span, int cnum,
138138
&vec[str] library_search_paths) {
139139
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
140140
case (some(?t)) {
141-
cstore::set_crate_data(sess.get_cstore(), cnum,
141+
auto cstore = sess.get_cstore();
142+
cstore::set_crate_data(cstore, cnum,
142143
rec(name=ident, data=t._1));
143-
sess.add_used_crate_file(t._0);
144+
cstore::add_used_crate_file(cstore, t._0);
144145
ret;
145146
}
146147
case (_) { }

src/comp/metadata/cstore.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import std::map;
2+
import std::vec;
23

34
type crate_metadata = rec(str name, vec[u8] data);
45

56
type cstore = @rec(map::hashmap[int, crate_metadata] metas,
6-
vec[str] used_crate_files,
7-
vec[str] used_libraries,
8-
vec[str] used_link_args);
7+
mutable vec[str] used_crate_files,
8+
mutable vec[str] used_libraries,
9+
mutable vec[str] used_link_args);
910

1011
fn mk_cstore() -> cstore {
1112
auto meta_cache = map::new_int_hash[crate_metadata]();
1213
ret @rec(metas = meta_cache,
13-
used_crate_files = [],
14-
used_libraries = [],
15-
used_link_args = []);
14+
mutable used_crate_files = [],
15+
mutable used_libraries = [],
16+
mutable used_link_args = []);
1617
}
1718

1819
fn get_crate_data(&cstore cstore, int cnum) -> crate_metadata {
@@ -27,6 +28,16 @@ fn have_crate_data(&cstore cstore, int cnum) -> bool {
2728
ret cstore.metas.contains_key(cnum);
2829
}
2930

31+
fn add_used_crate_file(&cstore cstore, &str lib) {
32+
if (!vec::member(lib, cstore.used_crate_files)) {
33+
cstore.used_crate_files += [lib];
34+
}
35+
}
36+
37+
fn get_used_crate_files(&cstore cstore) -> vec[str] {
38+
ret cstore.used_crate_files;
39+
}
40+
3041
// Local Variables:
3142
// mode: rust
3243
// fill-column: 78;

0 commit comments

Comments
 (0)