Skip to content

Commit 06391dd

Browse files
committed
Make the interface to metadata::csearch more consistent
1 parent 8521284 commit 06391dd

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

src/comp/metadata/csearch.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
import driver::session;
21
import syntax::ast;
32
import middle::ty;
43
import std::io;
54

6-
fn get_symbol(session::session sess, ast::def_id def) -> str {
5+
fn get_symbol(&cstore::cstore cstore, ast::def_id def) -> str {
76
auto cnum = def._0;
87
auto node_id = def._1;
9-
auto cstore = sess.get_cstore();
108
auto cdata = cstore::get_crate_data(cstore, cnum).data;
119
ret decoder::get_symbol(cdata, node_id);
1210
}
1311

1412
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
15-
decoder::get_tag_variants(tcx, def)
13+
auto cstore = tcx.sess.get_cstore();
14+
auto cnum = def._0;
15+
auto cdata = cstore::get_crate_data(cstore, cnum).data;
16+
ret decoder::get_tag_variants(cdata, def, tcx)
1617
}
1718

1819
fn get_type(ty::ctxt tcx, ast::def_id def) -> ty::ty_param_count_and_ty {
19-
decoder::get_type(tcx, def)
20+
auto cstore = tcx.sess.get_cstore();
21+
auto cnum = def._0;
22+
auto cdata = cstore::get_crate_data(cstore, cnum).data;
23+
decoder::get_type(cdata, def, tcx)
2024
}
2125

22-
fn get_type_param_count(ty::ctxt tcx, &ast::def_id def) -> uint {
26+
fn get_type_param_count(&cstore::cstore cstore, &ast::def_id def) -> uint {
2327
auto cnum = def._0;
2428
auto node_id = def._1;
25-
auto cstore = tcx.sess.get_cstore();
2629
auto cdata = cstore::get_crate_data(cstore, cnum).data;
2730
ret decoder::get_type_param_count(cdata, node_id);
2831
}
2932

30-
fn lookup_defs(session::session sess, ast::crate_num cnum,
33+
fn lookup_defs(&cstore::cstore cstore, ast::crate_num cnum,
3134
vec[ast::ident] path) -> vec[ast::def] {
32-
auto cstore = sess.get_cstore();
3335
auto cdata = cstore::get_crate_data(cstore, cnum).data;
3436
ret decoder::lookup_defs(cdata, cnum, path);
3537
}

src/comp/metadata/decoder.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ fn lookup_def(ast::crate_num cnum, vec[u8] data,
171171
ret def;
172172
}
173173

174-
fn get_type(ty::ctxt tcx, ast::def_id def) -> ty::ty_param_count_and_ty {
175-
auto external_crate_id = def._0;
176-
auto data = cstore::get_crate_data(tcx.sess.get_cstore(),
177-
external_crate_id).data;
178-
auto item = lookup_item(def._1, data);
179-
auto t = item_type(item, external_crate_id, tcx);
174+
fn get_type(&vec[u8] data, ast::def_id def,
175+
&ty::ctxt tcx) -> ty::ty_param_count_and_ty {
176+
auto this_cnum = def._0;
177+
auto node_id = def._1;
178+
auto item = lookup_item(node_id, data);
179+
auto t = item_type(item, this_cnum, tcx);
180180
auto tp_count;
181181
auto kind_ch = item_kind(item);
182182
auto has_ty_params = kind_has_type_params(kind_ch);
@@ -194,7 +194,8 @@ fn get_symbol(&vec[u8] data, ast::node_id id) -> str {
194194
ret item_symbol(lookup_item(id, data));
195195
}
196196

197-
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
197+
fn get_tag_variants(&vec[u8] data, ast::def_id def,
198+
&ty::ctxt tcx) -> ty::variant_info[] {
198199
auto external_crate_id = def._0;
199200
auto data = cstore::get_crate_data(tcx.sess.get_cstore(),
200201
external_crate_id).data;

src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ fn ns_for_def(def d) -> namespace {
11431143

11441144
fn lookup_external(&env e, int cnum, vec[ident] ids, namespace ns) ->
11451145
option::t[def] {
1146-
for (def d in csearch::lookup_defs(e.sess, cnum, ids)) {
1146+
for (def d in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids)) {
11471147
e.ext_map.insert(ast::def_id_of_def(d), ids);
11481148
if (ns == ns_for_def(d)) { ret some(d); }
11491149
}

src/comp/middle/trans.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,12 +2220,13 @@ fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
22202220
case (_) { ccx.tcx.sess.bug("internal error in trans_res_drop") }
22212221
}
22222222
} else {
2223-
auto params = csearch::get_type_param_count(ccx.tcx, did);
2223+
auto params = csearch::get_type_param_count(ccx.sess.get_cstore(),
2224+
did);
22242225
auto f_t = type_of_fn(ccx, cx.sp, ast::proto_fn,
22252226
~[rec(mode=ty::mo_alias(false), ty=inner_t)],
22262227
ty::mk_nil(ccx.tcx), params);
22272228
get_extern_const(ccx.externs, ccx.llmod,
2228-
csearch::get_symbol(ccx.sess, did),
2229+
csearch::get_symbol(ccx.sess.get_cstore(), did),
22292230
T_fn_pair(ccx.tn, f_t))
22302231
};
22312232
auto dtor_addr = cx.build.Load
@@ -4942,7 +4943,7 @@ fn lval_val(&@block_ctxt cx, ValueRef val) -> lval_result {
49424943
fn trans_external_path(&@block_ctxt cx, &ast::def_id did,
49434944
&ty::ty_param_count_and_ty tpt) -> lval_result {
49444945
auto lcx = cx.fcx.lcx;
4945-
auto name = csearch::get_symbol(lcx.ccx.sess, did);
4946+
auto name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
49464947
auto v =
49474948
get_extern_const(lcx.ccx.externs, lcx.ccx.llmod, name,
49484949
type_of_ty_param_count_and_ty(lcx, cx.sp, tpt));
@@ -4988,7 +4989,7 @@ fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid)
49884989
// It's an external discriminant that we haven't seen yet.
49894990

49904991
assert (vid._0 != ast::local_crate);
4991-
auto sym = csearch::get_symbol(lcx.ccx.sess, vid);
4992+
auto sym = csearch::get_symbol(lcx.ccx.sess.get_cstore(), vid);
49924993
auto gvar =
49934994
llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(), str::buf(sym));
49944995
llvm::LLVMSetLinkage(gvar,

0 commit comments

Comments
 (0)