Skip to content

Commit a080c28

Browse files
committed
---
yaml --- r: 3729 b: refs/heads/master c: 85535fc h: refs/heads/master i: 3727: 6aba671 v: v3
1 parent d9714b9 commit a080c28

File tree

4 files changed

+67
-59
lines changed

4 files changed

+67
-59
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 513b2276c22a298bd7d2b2b92842046f5cde68bf
2+
refs/heads/master: 85535fc3e0c16a665e29516e81a900551196c6ab

trunk/src/comp/metadata/creader.rs

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ export list_file_metadata;
3030

3131
// Traverses an AST, reading all the information about use'd crates and native
3232
// libraries necessary for later resolving, typechecking, linking, etc.
33-
fn read_crates(session::session sess, resolve::crate_map crate_map,
33+
fn read_crates(session::session sess,
3434
&ast::crate crate) {
3535
auto e =
3636
@rec(sess=sess,
37-
crate_map=crate_map,
3837
crate_cache=@std::map::new_str_hash[int](),
3938
library_search_paths=sess.get_opts().library_search_paths,
4039
mutable next_crate_num=1);
@@ -45,6 +44,55 @@ fn read_crates(session::session sess, resolve::crate_map crate_map,
4544
walk::walk_crate(v, crate);
4645
}
4746

47+
type env =
48+
@rec(session::session sess,
49+
@hashmap[str, int] crate_cache,
50+
vec[str] library_search_paths,
51+
mutable int next_crate_num);
52+
53+
fn visit_view_item(env e, &@ast::view_item i) {
54+
alt (i.node) {
55+
case (ast::view_item_use(?ident, ?meta_items, ?id)) {
56+
auto cnum;
57+
if (!e.crate_cache.contains_key(ident)) {
58+
cnum = e.next_crate_num;
59+
load_library_crate(e.sess, i.span, cnum, ident,
60+
meta_items, e.library_search_paths);
61+
e.crate_cache.insert(ident, e.next_crate_num);
62+
e.next_crate_num += 1;
63+
} else { cnum = e.crate_cache.get(ident); }
64+
cstore::add_use_stmt_cnum(e.sess.get_cstore(), id, cnum);
65+
}
66+
case (_) { }
67+
}
68+
}
69+
70+
fn visit_item(env e, &@ast::item i) {
71+
alt (i.node) {
72+
case (ast::item_native_mod(?m)) {
73+
if (m.abi != ast::native_abi_rust &&
74+
m.abi != ast::native_abi_cdecl) {
75+
ret;
76+
}
77+
auto cstore = e.sess.get_cstore();
78+
if (!cstore::add_used_library(cstore, m.native_name)) {
79+
ret;
80+
}
81+
for (ast::attribute a in
82+
attr::find_attrs_by_name(i.attrs, "link_args")) {
83+
alt (attr::get_meta_item_value_str(attr::attr_meta(a))) {
84+
case (some(?linkarg)) {
85+
cstore::add_used_link_args(cstore, linkarg);
86+
}
87+
case (none) { /* fallthrough */ }
88+
}
89+
}
90+
}
91+
case (_) {
92+
}
93+
}
94+
}
95+
4896
// A diagnostic function for dumping crate metadata to an output stream
4997
fn list_file_metadata(str path, io::writer out) {
5098
alt (get_metadata_section(path)) {
@@ -178,55 +226,6 @@ fn load_library_crate(&session::session sess, span span, int cnum,
178226
sess.span_fatal(span, #fmt("can't find crate for '%s'", ident));
179227
}
180228

181-
type env =
182-
@rec(session::session sess,
183-
resolve::crate_map crate_map,
184-
@hashmap[str, int] crate_cache,
185-
vec[str] library_search_paths,
186-
mutable int next_crate_num);
187-
188-
fn visit_view_item(env e, &@ast::view_item i) {
189-
alt (i.node) {
190-
case (ast::view_item_use(?ident, ?meta_items, ?id)) {
191-
auto cnum;
192-
if (!e.crate_cache.contains_key(ident)) {
193-
cnum = e.next_crate_num;
194-
load_library_crate(e.sess, i.span, cnum, ident,
195-
meta_items, e.library_search_paths);
196-
e.crate_cache.insert(ident, e.next_crate_num);
197-
e.next_crate_num += 1;
198-
} else { cnum = e.crate_cache.get(ident); }
199-
e.crate_map.insert(id, cnum);
200-
}
201-
case (_) { }
202-
}
203-
}
204-
205-
fn visit_item(env e, &@ast::item i) {
206-
alt (i.node) {
207-
case (ast::item_native_mod(?m)) {
208-
if (m.abi != ast::native_abi_rust &&
209-
m.abi != ast::native_abi_cdecl) {
210-
ret;
211-
}
212-
auto cstore = e.sess.get_cstore();
213-
if (!cstore::add_used_library(cstore, m.native_name)) {
214-
ret;
215-
}
216-
for (ast::attribute a in
217-
attr::find_attrs_by_name(i.attrs, "link_args")) {
218-
alt (attr::get_meta_item_value_str(attr::attr_meta(a))) {
219-
case (some(?linkarg)) {
220-
cstore::add_used_link_args(cstore, linkarg);
221-
}
222-
case (none) { /* fallthrough */ }
223-
}
224-
}
225-
}
226-
case (_) {
227-
}
228-
}
229-
}
230229

231230

232231
// Local Variables:

trunk/src/comp/metadata/cstore.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
import std::map;
55
import std::vec;
66
import std::str;
7+
import syntax::ast;
78

89
type crate_metadata = rec(str name, vec[u8] data);
910

11+
// Map from node_id's of local use statements to crate numbers
12+
type use_crate_map = map::hashmap[ast::node_id, ast::crate_num];
13+
1014
type cstore = @rec(map::hashmap[int, crate_metadata] metas,
15+
use_crate_map use_crate_map,
1116
mutable vec[str] used_crate_files,
1217
mutable vec[str] used_libraries,
1318
mutable vec[str] used_link_args);
1419

1520
fn mk_cstore() -> cstore {
1621
auto meta_cache = map::new_int_hash[crate_metadata]();
22+
auto crate_map = map::new_int_hash[ast::crate_num]();
1723
ret @rec(metas = meta_cache,
24+
use_crate_map = crate_map,
1825
mutable used_crate_files = [],
1926
mutable used_libraries = [],
2027
mutable used_link_args = []);
@@ -65,6 +72,11 @@ fn get_used_link_args(&cstore cstore) -> vec[str] {
6572
ret cstore.used_link_args;
6673
}
6774

75+
fn add_use_stmt_cnum(&cstore cstore, ast::node_id use_id, int cnum) {
76+
cstore.use_crate_map.insert(use_id, cnum);
77+
}
78+
79+
6880
// Local Variables:
6981
// mode: rust
7082
// fill-column: 78;

trunk/src/comp/middle/resolve.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ast::local_def;
99

1010
import metadata::creader;
1111
import metadata::decoder;
12+
import metadata::cstore;
1213
import driver::session::session;
1314
import util::common::new_def_hash;
1415
import std::map::new_int_hash;
@@ -32,7 +33,6 @@ import std::vec;
3233

3334
export resolve_crate;
3435
export def_map;
35-
export crate_map;
3636

3737
// Resolving happens in two passes. The first pass collects defids of all
3838
// (internal) imports and modules, so that they can be looked up when needed,
@@ -103,13 +103,10 @@ type indexed_mod =
103103
/* native modules can't contain tags, and we don't store their ASTs because we
104104
only need to look at them to determine exports, which they can't control.*/
105105

106-
// It should be safe to use index to memoize lookups of globbed names.
107-
type crate_map = hashmap[node_id, ast::crate_num];
108-
109106
type def_map = hashmap[node_id, def];
110107

111108
type env =
112-
rec(crate_map crate_map,
109+
rec(cstore::use_crate_map crate_map,
113110
def_map def_map,
114111
constr_table fn_constrs,
115112
ast_map::map ast_map,
@@ -128,8 +125,9 @@ tag namespace { ns_value; ns_type; ns_module; }
128125

129126
fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
130127
tup(def_map, constr_table) {
128+
creader::read_crates(sess, *crate);
131129
auto e =
132-
@rec(crate_map=new_int_hash[ast::crate_num](),
130+
@rec(crate_map=sess.get_cstore().use_crate_map,
133131
def_map=new_int_hash[def](),
134132
fn_constrs = new_int_hash[ty::constr_def[]](),
135133
ast_map=amap,
@@ -138,7 +136,6 @@ fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
138136
ext_map=new_def_hash[vec[ident]](),
139137
ext_cache=new_ext_hash(),
140138
sess=sess);
141-
creader::read_crates(sess, e.crate_map, *crate);
142139
map_crate(e, crate);
143140
resolve_imports(*e);
144141
check_for_collisions(e, *crate);

0 commit comments

Comments
 (0)