Skip to content

Commit ecbb2e6

Browse files
committed
---
yaml --- r: 3737 b: refs/heads/master c: d0a432f h: refs/heads/master i: 3735: b07c287 v: v3
1 parent 5cddd43 commit ecbb2e6

File tree

4 files changed

+65
-54
lines changed

4 files changed

+65
-54
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 00d54018f15aa6ce6a913d0ae07d308f4b9ec5e5
2+
refs/heads/master: d0a432f4bb3ca2468f4d2d52f19625e4e13898e9

trunk/src/comp/metadata/encoder.rs

+64-48
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import std::option;
99
import std::option::some;
1010
import std::option::none;
1111
import std::ebml;
12+
import std::map;
1213
import syntax::ast::*;
1314
import common::*;
1415
import middle::trans::crate_ctxt;
@@ -19,6 +20,11 @@ import front::attr;
1920
export encode_metadata;
2021
export encoded_ty;
2122

23+
type abbrev_map = map::hashmap[ty::t, tyencode::ty_abbrev];
24+
25+
type encode_ctxt = rec(@crate_ctxt ccx,
26+
abbrev_map type_abbrevs);
27+
2228
// Path table encoding
2329
fn encode_name(&ebml::writer ebml_w, &str name) {
2430
ebml::start_tag(ebml_w, tag_paths_data_name);
@@ -175,27 +181,27 @@ fn encode_variant_id(&ebml::writer ebml_w, &def_id vid) {
175181
ebml::end_tag(ebml_w);
176182
}
177183

178-
fn encode_type(&@crate_ctxt cx, &ebml::writer ebml_w, &ty::t typ) {
184+
fn encode_type(&@encode_ctxt ecx, &ebml::writer ebml_w, &ty::t typ) {
179185
ebml::start_tag(ebml_w, tag_items_data_item_type);
180186
auto f = def_to_str;
181187
auto ty_str_ctxt =
182-
@rec(ds=f, tcx=cx.tcx,
183-
abbrevs=tyencode::ac_use_abbrevs(cx.type_abbrevs));
188+
@rec(ds=f, tcx=ecx.ccx.tcx,
189+
abbrevs=tyencode::ac_use_abbrevs(ecx.type_abbrevs));
184190
tyencode::enc_ty(io::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
185191
ebml::end_tag(ebml_w);
186192
}
187193

188-
fn encode_symbol(&@crate_ctxt cx, &ebml::writer ebml_w,
194+
fn encode_symbol(&@encode_ctxt ecx, &ebml::writer ebml_w,
189195
node_id id) {
190196
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
191-
ebml_w.writer.write(str::bytes(cx.item_symbols.get(id)));
197+
ebml_w.writer.write(str::bytes(ecx.ccx.item_symbols.get(id)));
192198
ebml::end_tag(ebml_w);
193199
}
194200

195-
fn encode_discriminant(&@crate_ctxt cx, &ebml::writer ebml_w,
201+
fn encode_discriminant(&@encode_ctxt ecx, &ebml::writer ebml_w,
196202
node_id id) {
197203
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
198-
ebml_w.writer.write(str::bytes(cx.discrim_symbols.get(id)));
204+
ebml_w.writer.write(str::bytes(ecx.ccx.discrim_symbols.get(id)));
199205
ebml::end_tag(ebml_w);
200206
}
201207

@@ -205,7 +211,7 @@ fn encode_tag_id(&ebml::writer ebml_w, &def_id id) {
205211
ebml::end_tag(ebml_w);
206212
}
207213

208-
fn encode_tag_variant_info(&@crate_ctxt cx, &ebml::writer ebml_w,
214+
fn encode_tag_variant_info(&@encode_ctxt ecx, &ebml::writer ebml_w,
209215
node_id id, &variant[] variants,
210216
&mutable vec[tup(int, uint)] index,
211217
&ty_param[] ty_params) {
@@ -215,25 +221,27 @@ fn encode_tag_variant_info(&@crate_ctxt cx, &ebml::writer ebml_w,
215221
encode_def_id(ebml_w, local_def(variant.node.id));
216222
encode_kind(ebml_w, 'v' as u8);
217223
encode_tag_id(ebml_w, local_def(id));
218-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, variant.node.id));
224+
encode_type(ecx, ebml_w,
225+
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
219226
if (ivec::len[variant_arg](variant.node.args) > 0u) {
220-
encode_symbol(cx, ebml_w, variant.node.id);
227+
encode_symbol(ecx, ebml_w, variant.node.id);
221228
}
222-
encode_discriminant(cx, ebml_w, variant.node.id);
229+
encode_discriminant(ecx, ebml_w, variant.node.id);
223230
encode_type_param_count(ebml_w, ty_params);
224231
ebml::end_tag(ebml_w);
225232
}
226233
}
227234

228-
fn encode_info_for_item(@crate_ctxt cx, &ebml::writer ebml_w,
235+
fn encode_info_for_item(@encode_ctxt ecx, &ebml::writer ebml_w,
229236
@item item, &mutable vec[tup(int, uint)] index) {
230237
alt (item.node) {
231238
case (item_const(_, _)) {
232239
ebml::start_tag(ebml_w, tag_items_data_item);
233240
encode_def_id(ebml_w, local_def(item.id));
234241
encode_kind(ebml_w, 'c' as u8);
235-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, item.id));
236-
encode_symbol(cx, ebml_w, item.id);
242+
encode_type(ecx, ebml_w,
243+
node_id_to_monotype(ecx.ccx.tcx, item.id));
244+
encode_symbol(ecx, ebml_w, item.id);
237245
ebml::end_tag(ebml_w);
238246
}
239247
case (item_fn(?fd, ?tps)) {
@@ -243,8 +251,9 @@ fn encode_info_for_item(@crate_ctxt cx, &ebml::writer ebml_w,
243251
case (pure_fn) { 'p' }
244252
case (impure_fn) { 'f' } } as u8);
245253
encode_type_param_count(ebml_w, tps);
246-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, item.id));
247-
encode_symbol(cx, ebml_w, item.id);
254+
encode_type(ecx, ebml_w,
255+
node_id_to_monotype(ecx.ccx.tcx, item.id));
256+
encode_symbol(ecx, ebml_w, item.id);
248257
ebml::end_tag(ebml_w);
249258
}
250259
case (item_mod(_)) {
@@ -264,99 +273,102 @@ fn encode_info_for_item(@crate_ctxt cx, &ebml::writer ebml_w,
264273
encode_def_id(ebml_w, local_def(item.id));
265274
encode_kind(ebml_w, 'y' as u8);
266275
encode_type_param_count(ebml_w, tps);
267-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, item.id));
276+
encode_type(ecx, ebml_w,
277+
node_id_to_monotype(ecx.ccx.tcx, item.id));
268278
ebml::end_tag(ebml_w);
269279
}
270280
case (item_tag(?variants, ?tps)) {
271281
ebml::start_tag(ebml_w, tag_items_data_item);
272282
encode_def_id(ebml_w, local_def(item.id));
273283
encode_kind(ebml_w, 't' as u8);
274284
encode_type_param_count(ebml_w, tps);
275-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, item.id));
285+
encode_type(ecx, ebml_w,
286+
node_id_to_monotype(ecx.ccx.tcx, item.id));
276287
for (variant v in variants) {
277288
encode_variant_id(ebml_w, local_def(v.node.id));
278289
}
279290
ebml::end_tag(ebml_w);
280-
encode_tag_variant_info(cx, ebml_w, item.id, variants, index,
291+
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index,
281292
tps);
282293
}
283294
case (item_res(_, _, ?tps, ?ctor_id)) {
284-
auto fn_ty = node_id_to_monotype(cx.tcx, ctor_id);
295+
auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
285296

286297
ebml::start_tag(ebml_w, tag_items_data_item);
287298
encode_def_id(ebml_w, local_def(ctor_id));
288299
encode_kind(ebml_w, 'y' as u8);
289300
encode_type_param_count(ebml_w, tps);
290-
encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));
291-
encode_symbol(cx, ebml_w, item.id);
301+
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
302+
encode_symbol(ecx, ebml_w, item.id);
292303
ebml::end_tag(ebml_w);
293304

294305
index += [tup(ctor_id, ebml_w.writer.tell())];
295306
ebml::start_tag(ebml_w, tag_items_data_item);
296307
encode_def_id(ebml_w, local_def(ctor_id));
297308
encode_kind(ebml_w, 'f' as u8);
298309
encode_type_param_count(ebml_w, tps);
299-
encode_type(cx, ebml_w, fn_ty);
300-
encode_symbol(cx, ebml_w, ctor_id);
310+
encode_type(ecx, ebml_w, fn_ty);
311+
encode_symbol(ecx, ebml_w, ctor_id);
301312
ebml::end_tag(ebml_w);
302313
}
303314
case (item_obj(_, ?tps, ?ctor_id)) {
304-
auto fn_ty = node_id_to_monotype(cx.tcx, ctor_id);
315+
auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
305316

306317
ebml::start_tag(ebml_w, tag_items_data_item);
307318
encode_def_id(ebml_w, local_def(item.id));
308319
encode_kind(ebml_w, 'y' as u8);
309320
encode_type_param_count(ebml_w, tps);
310-
encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));
321+
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
311322
ebml::end_tag(ebml_w);
312323

313324
index += [tup(ctor_id, ebml_w.writer.tell())];
314325
ebml::start_tag(ebml_w, tag_items_data_item);
315326
encode_def_id(ebml_w, local_def(ctor_id));
316327
encode_kind(ebml_w, 'f' as u8);
317328
encode_type_param_count(ebml_w, tps);
318-
encode_type(cx, ebml_w, fn_ty);
319-
encode_symbol(cx, ebml_w, ctor_id);
329+
encode_type(ecx, ebml_w, fn_ty);
330+
encode_symbol(ecx, ebml_w, ctor_id);
320331
ebml::end_tag(ebml_w);
321332
}
322333
}
323334
}
324335

325-
fn encode_info_for_native_item(&@crate_ctxt cx, &ebml::writer ebml_w,
336+
fn encode_info_for_native_item(&@encode_ctxt ecx, &ebml::writer ebml_w,
326337
&@native_item nitem) {
327338
ebml::start_tag(ebml_w, tag_items_data_item);
328339
alt (nitem.node) {
329340
case (native_item_ty) {
330341
encode_def_id(ebml_w, local_def(nitem.id));
331342
encode_kind(ebml_w, 'T' as u8);
332-
encode_type(cx, ebml_w,
333-
ty::mk_native(cx.tcx, local_def(nitem.id)));
343+
encode_type(ecx, ebml_w,
344+
ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
334345
}
335346
case (native_item_fn(_, _, ?tps)) {
336347
encode_def_id(ebml_w, local_def(nitem.id));
337348
encode_kind(ebml_w, 'F' as u8);
338349
encode_type_param_count(ebml_w, tps);
339-
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, nitem.id));
340-
encode_symbol(cx, ebml_w, nitem.id);
350+
encode_type(ecx, ebml_w,
351+
node_id_to_monotype(ecx.ccx.tcx, nitem.id));
352+
encode_symbol(ecx, ebml_w, nitem.id);
341353
}
342354
}
343355
ebml::end_tag(ebml_w);
344356
}
345357

346-
fn encode_info_for_items(&@crate_ctxt cx, &ebml::writer ebml_w) ->
358+
fn encode_info_for_items(&@encode_ctxt ecx, &ebml::writer ebml_w) ->
347359
vec[tup(int, uint)] {
348360
let vec[tup(int, uint)] index = [];
349361
ebml::start_tag(ebml_w, tag_items_data);
350362
for each (@tup(node_id, middle::ast_map::ast_node) kvp in
351-
cx.ast_map.items()) {
363+
ecx.ccx.ast_map.items()) {
352364
alt (kvp._1) {
353365
case (middle::ast_map::node_item(?i)) {
354366
index += [tup(kvp._0, ebml_w.writer.tell())];
355-
encode_info_for_item(cx, ebml_w, i, index);
367+
encode_info_for_item(ecx, ebml_w, i, index);
356368
}
357369
case (middle::ast_map::node_native_item(?i)) {
358370
index += [tup(kvp._0, ebml_w.writer.tell())];
359-
encode_info_for_native_item(cx, ebml_w, i);
371+
encode_info_for_native_item(ecx, ebml_w, i);
360372
}
361373
case (_) {}
362374
}
@@ -460,19 +472,19 @@ fn encode_attributes(&ebml::writer ebml_w, &vec[attribute] attrs) {
460472
// metadata that Rust cares about for linking crates. This attribute requires
461473
// 'name' and 'vers' items, so if the user didn't provide them we will throw
462474
// them in anyway with default values.
463-
fn synthesize_crate_attrs(&@crate_ctxt cx,
475+
fn synthesize_crate_attrs(&@encode_ctxt ecx,
464476
&@crate crate) -> vec[attribute] {
465477

466-
fn synthesize_link_attr(&@crate_ctxt cx, &(@meta_item)[] items)
478+
fn synthesize_link_attr(&@encode_ctxt ecx, &(@meta_item)[] items)
467479
-> attribute {
468480

469-
assert cx.link_meta.name != "";
470-
assert cx.link_meta.vers != "";
481+
assert ecx.ccx.link_meta.name != "";
482+
assert ecx.ccx.link_meta.vers != "";
471483

472484
auto name_item = attr::mk_name_value_item_str("name",
473-
cx.link_meta.name);
485+
ecx.ccx.link_meta.name);
474486
auto vers_item = attr::mk_name_value_item_str("vers",
475-
cx.link_meta.vers);
487+
ecx.ccx.link_meta.vers);
476488

477489
auto other_items = {
478490
auto tmp = attr::remove_meta_items_by_name(items, "name");
@@ -494,26 +506,30 @@ fn synthesize_crate_attrs(&@crate_ctxt cx,
494506
alt (attr.node.value.node) {
495507
case (meta_list(?n, ?l)) {
496508
found_link_attr = true;
497-
[synthesize_link_attr(cx, l)]
509+
[synthesize_link_attr(ecx, l)]
498510
}
499511
case (_) { [attr] }
500512
}
501513
}
502514
}
503515

504516
if (!found_link_attr) {
505-
attrs += [synthesize_link_attr(cx, ~[])];
517+
attrs += [synthesize_link_attr(ecx, ~[])];
506518
}
507519

508520
ret attrs;
509521
}
510522

511523
fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
524+
525+
auto abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
526+
auto ecx = @rec(ccx = cx, type_abbrevs = abbrevs);
527+
512528
auto string_w = io::string_writer();
513529
auto buf_w = string_w.get_writer().get_buf_writer();
514530
auto ebml_w = ebml::create_writer(buf_w);
515531

516-
auto crate_attrs = synthesize_crate_attrs(cx, crate);
532+
auto crate_attrs = synthesize_crate_attrs(ecx, crate);
517533
encode_attributes(ebml_w, crate_attrs);
518534
// Encode and index the paths.
519535

@@ -527,7 +543,7 @@ fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
527543
// Encode and index the items.
528544

529545
ebml::start_tag(ebml_w, tag_items);
530-
auto items_index = encode_info_for_items(cx, ebml_w);
546+
auto items_index = encode_info_for_items(ecx, ebml_w);
531547
auto int_writer = write_int;
532548
auto item_hasher = hash_node_id;
533549
auto items_buckets = create_index[int](items_index, item_hasher);
@@ -544,7 +560,7 @@ fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
544560
fn encoded_ty(&ty::ctxt tcx, &ty::t t) -> str {
545561
auto cx = @rec(ds = def_to_str,
546562
tcx = tcx,
547-
abbrevs = metadata::tyencode::ac_no_abbrevs);
563+
abbrevs = tyencode::ac_no_abbrevs);
548564
auto sw = io::string_writer();
549565
tyencode::enc_ty(sw.get_writer(), cx, t);
550566
ret sw.get_str();

trunk/src/comp/middle/trans.rs

-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import link::mangle_internal_name_by_seq;
6363
import link::mangle_internal_name_by_path;
6464
import link::mangle_internal_name_by_path_and_seq;
6565
import link::mangle_exported_name;
66-
import metadata::tyencode;
6766
import metadata::creader;
6867
import metadata::csearch;
6968
import metadata::cstore;
@@ -147,7 +146,6 @@ type crate_ctxt =
147146
namegen names,
148147
std::sha1::sha1 sha,
149148
hashmap[ty::t, str] type_sha1s,
150-
hashmap[ty::t, tyencode::ty_abbrev] type_abbrevs,
151149
hashmap[ty::t, str] type_short_names,
152150
ty::ctxt tcx,
153151
stats stats,
@@ -9318,7 +9316,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
93189316
auto tydescs = map::mk_hashmap[ty::t, @tydesc_info](hasher, eqer);
93199317
auto lltypes = map::mk_hashmap[ty::t, TypeRef](hasher, eqer);
93209318
auto sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
9321-
auto abbrevs = map::mk_hashmap[ty::t, tyencode::ty_abbrev](hasher, eqer);
93229319
auto short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
93239320
auto sha = std::sha1::mk_sha1();
93249321
auto ccx =
@@ -9346,7 +9343,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
93469343
names=namegen(0),
93479344
sha=sha,
93489345
type_sha1s=sha1s,
9349-
type_abbrevs=abbrevs,
93509346
type_short_names=short_names,
93519347
tcx=tcx,
93529348
stats=rec(mutable n_static_tydescs=0u,

trunk/src/comp/rustc.rc

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ mod back {
7777
}
7878

7979
mod metadata {
80-
export tyencode;
8180
export encoder;
8281
export creader;
8382
export cstore;

0 commit comments

Comments
 (0)