Skip to content

Commit 66d4ed4

Browse files
committed
---
yaml --- r: 14202 b: refs/heads/try c: fdddf8f h: refs/heads/master v: v3
1 parent 44eff9b commit 66d4ed4

File tree

16 files changed

+239
-30
lines changed

16 files changed

+239
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: dbcb54f4dc44957c9505958655a16e678ee4396b
5+
refs/heads/try: fdddf8f9e1d6738d42989a6d8a735dd58127e199
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ TSREQS := \
410410
FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
411411
CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
412412
RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
413+
SERIALIZER := $(HBIN3_H_$(CFG_HOST_TRIPLE))/serializer$(X)
413414

414415
all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC)
415416

branches/try/mk/tools.mk

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ CARGO_INPUTS := $(wildcard $(S)src/cargo/*rs)
1616
RUSTDOC_CRATE := $(S)src/rustdoc/rustdoc.rc
1717
RUSTDOC_INPUTS := $(wildcard $(S)src/rustdoc/*.rs)
1818

19+
# Serializer, generates serialization code
20+
# (Should eventually move into a compiler ext)
21+
SERIALIZER_CRATE := $(S)src/serializer/serializer.rc
22+
SERIALIZER_INPUTS := $(wildcard $(S)src/serializer/*.rs)
23+
1924
# FIXME: These are only built for the host arch. Eventually we'll
2025
# have tools that need to built for other targets.
2126
define TOOLS_STAGE_N
@@ -83,6 +88,21 @@ $$(HBIN$(2)_H_$(4))/rustdoc$$(X): \
8388
@$$(call E, cp: $$@)
8489
$$(Q)cp $$< $$@
8590

91+
$$(TBIN$(1)_T_$(4)_H_$(3))/serializer$$(X): \
92+
$$(SERIALIZER_CRATE) $$(SERIALIZER_INPUTS) \
93+
$$(TSREQ$(1)_T_$(4)_H_$(3)) \
94+
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \
95+
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \
96+
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC)
97+
@$$(call E, compile_and_link: $$@)
98+
$$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$<
99+
100+
$$(HBIN$(2)_H_$(4))/serializer$$(X): \
101+
$$(TBIN$(1)_T_$(4)_H_$(3))/serializer$$(X) \
102+
$$(HSREQ$(2)_$(4))
103+
@$$(call E, cp: $$@)
104+
$$(Q)cp $$< $$@
105+
86106
endef
87107

88108
$(foreach host,$(CFG_TARGET_TRIPLES), \

branches/try/src/comp/metadata/common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ const tag_impl_iface: uint = 0x32u;
7070
// discriminator value for variants
7171
const tag_disr_val: uint = 0x34u;
7272

73+
// used to encode ast_map::path and ast_map::path_elt
74+
const tag_path: uint = 0x40u;
75+
const tag_path_len: uint = 0x41u;
76+
const tag_path_elt_mod: uint = 0x42u;
77+
const tag_path_elt_name: uint = 0x43u;
78+
79+
7380
// djb's cdb hashes.
7481
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
7582

branches/try/src/comp/metadata/csearch.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import syntax::ast;
44
import syntax::ast_util;
5-
import middle::ty;
5+
import middle::{ty, ast_map};
6+
import option::{some, none};
67
import driver::session;
78

89
export get_symbol;
@@ -13,6 +14,7 @@ export get_impls_for_mod;
1314
export get_iface_methods;
1415
export get_type;
1516
export get_impl_iface;
17+
export get_item_path;
1618

1719
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
1820
let cdata = cstore::get_crate_data(cstore, def.crate).data;
@@ -55,6 +57,12 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
5557
ret result;
5658
}
5759

60+
fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
61+
let cstore = tcx.sess.cstore;
62+
let cdata = cstore::get_crate_data(cstore, def.crate);
63+
ret decoder::get_item_path(cdata, def.node);
64+
}
65+
5866
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
5967
let cstore = tcx.sess.cstore;
6068
let cdata = cstore::get_crate_data(cstore, def.crate);

branches/try/src/comp/metadata/decoder.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import syntax::{ast, ast_util};
66
import driver::session::session;
77
import front::attr;
88
import middle::ty;
9+
import middle::ast_map;
910
import common::*;
1011
import tydecode::{parse_ty_data, parse_def_id, parse_bounds_data};
1112
import syntax::print::pprust;
@@ -28,6 +29,7 @@ export get_crate_hash;
2829
export get_impls_for_mod;
2930
export get_iface_methods;
3031
export get_crate_module_paths;
32+
export get_item_path;
3133

3234
// A function that takes a def_id relative to the crate being searched and
3335
// returns a def_id relative to the compilation environment, i.e. if we hit a
@@ -176,6 +178,30 @@ fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
176178
ret result;
177179
}
178180

181+
fn item_path(item_doc: ebml::doc) -> ast_map::path {
182+
let path_doc = ebml::get_doc(item_doc, tag_path);
183+
184+
let len_doc = ebml::get_doc(path_doc, tag_path_len);
185+
let len = ebml::doc_as_uint(len_doc);
186+
187+
let result = [];
188+
vec::reserve(result, len);
189+
190+
ebml::docs(path_doc) {|tag, elt_doc|
191+
if tag == tag_path_elt_mod {
192+
let str = ebml::doc_str(elt_doc);
193+
result += [ast_map::path_mod(str)];
194+
} else if tag == tag_path_elt_name {
195+
let str = ebml::doc_str(elt_doc);
196+
result += [ast_map::path_name(str)];
197+
} else {
198+
// ignore tag_path_len element
199+
}
200+
}
201+
202+
ret result;
203+
}
204+
179205
fn item_name(item: ebml::doc) -> ast::ident {
180206
let name = ebml::get_doc(item, tag_paths_data_name);
181207
str::from_bytes(ebml::doc_data(name))
@@ -234,6 +260,10 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str {
234260
ret item_symbol(lookup_item(id, data));
235261
}
236262

263+
fn get_item_path(cdata: cmd, id: ast::node_id) -> ast_map::path {
264+
item_path(lookup_item(id, cdata.data))
265+
}
266+
237267
fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
238268
-> [ty::variant_info] {
239269
let data = cdata.data;

branches/try/src/comp/metadata/encoder.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import common::*;
1010
import middle::trans::common::crate_ctxt;
1111
import middle::ty;
1212
import middle::ty::node_id_to_type;
13+
import middle::ast_map;
1314
import front::attr;
1415
import driver::session::session;
1516

@@ -233,8 +234,9 @@ fn encode_enum_id(ebml_w: ebml::writer, id: def_id) {
233234
}
234235

235236
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
236-
id: node_id, variants: [variant],
237-
&index: [entry<int>], ty_params: [ty_param]) {
237+
id: node_id, variants: [variant],
238+
path: ast_map::path, &index: [entry<int>],
239+
ty_params: [ty_param]) {
238240
let disr_val = 0;
239241
let i = 0;
240242
let vi = ty::enum_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
@@ -256,14 +258,38 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
256258
disr_val = vi[i].disr_val;
257259
}
258260
encode_type_param_bounds(ebml_w, ecx, ty_params);
261+
encode_path(ebml_w, path, ast_map::path_name(variant.node.name));
259262
ebml::end_tag(ebml_w);
260263
disr_val += 1;
261264
i += 1;
262265
}
263266
}
264267

268+
fn encode_path(ebml_w: ebml::writer,
269+
path: ast_map::path,
270+
name: ast_map::path_elt) {
271+
fn encode_path_elt(ebml_w: ebml::writer, elt: ast_map::path_elt) {
272+
let (tag, name) = alt elt {
273+
ast_map::path_mod(name) { (tag_path_elt_mod, name) }
274+
ast_map::path_name(name) { (tag_path_elt_name, name) }
275+
};
276+
277+
ebml_w.wr_tag(tag) {||
278+
ebml_w.wr_str(name)
279+
}
280+
}
281+
282+
ebml_w.wr_tag(tag_path) {||
283+
ebml_w.wr_tag(tag_path_len) {||
284+
ebml_w.wr_uint(vec::len(path) + 1u);
285+
}
286+
vec::iter(path) {|pe| encode_path_elt(ebml_w, pe); }
287+
encode_path_elt(ebml_w, name);
288+
}
289+
}
290+
265291
fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
266-
id: node_id, name: ident) {
292+
id: node_id, path: ast_map::path, name: ident) {
267293
ebml::start_tag(ebml_w, tag_items_data_item);
268294
encode_def_id(ebml_w, local_def(id));
269295
encode_family(ebml_w, 'm' as u8);
@@ -281,11 +307,12 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
281307
_ { ecx.ccx.tcx.sess.bug("encode_info_for_mod: \
282308
undocumented invariant"); }
283309
}
310+
encode_path(ebml_w, path, ast_map::path_mod(name));
284311
ebml::end_tag(ebml_w);
285312
}
286313

287314
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
288-
&index: [entry<int>]) {
315+
&index: [entry<int>], path: ast_map::path) {
289316
let tcx = ecx.ccx.tcx;
290317
alt item.node {
291318
item_const(_, _) {
@@ -294,6 +321,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
294321
encode_family(ebml_w, 'c' as u8);
295322
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
296323
encode_symbol(ecx, ebml_w, item.id);
324+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
297325
ebml::end_tag(ebml_w);
298326
}
299327
item_fn(decl, tps, _) {
@@ -308,16 +336,18 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
308336
encode_type_param_bounds(ebml_w, ecx, tps);
309337
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
310338
encode_symbol(ecx, ebml_w, item.id);
339+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
311340
ebml::end_tag(ebml_w);
312341
}
313342
item_mod(m) {
314-
encode_info_for_mod(ecx, ebml_w, m, item.id, item.ident);
343+
encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident);
315344
}
316345
item_native_mod(_) {
317346
ebml::start_tag(ebml_w, tag_items_data_item);
318347
encode_def_id(ebml_w, local_def(item.id));
319348
encode_family(ebml_w, 'n' as u8);
320349
encode_name(ebml_w, item.ident);
350+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
321351
ebml::end_tag(ebml_w);
322352
}
323353
item_ty(_, tps) {
@@ -327,6 +357,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
327357
encode_type_param_bounds(ebml_w, ecx, tps);
328358
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
329359
encode_name(ebml_w, item.ident);
360+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
330361
ebml::end_tag(ebml_w);
331362
}
332363
item_enum(variants, tps) {
@@ -339,8 +370,10 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
339370
for v: variant in variants {
340371
encode_variant_id(ebml_w, local_def(v.node.id));
341372
}
373+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
342374
ebml::end_tag(ebml_w);
343-
encode_enum_variant_info(ecx, ebml_w, item.id, variants, index, tps);
375+
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
376+
path, index, tps);
344377
}
345378
item_class(_,_,_,_,_) {
346379
fail "encode: implement item_class";
@@ -355,6 +388,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
355388
encode_type(ecx, ebml_w, ty::ty_fn_ret(fn_ty));
356389
encode_name(ebml_w, item.ident);
357390
encode_symbol(ecx, ebml_w, item.id);
391+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
358392
ebml::end_tag(ebml_w);
359393

360394
index += [{val: ctor_id, pos: ebml_w.writer.tell()}];
@@ -364,6 +398,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
364398
encode_type_param_bounds(ebml_w, ecx, tps);
365399
encode_type(ecx, ebml_w, fn_ty);
366400
encode_symbol(ecx, ebml_w, ctor_id);
401+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
367402
ebml::end_tag(ebml_w);
368403
}
369404
item_impl(tps, ifce, _, methods) {
@@ -388,8 +423,10 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
388423
}
389424
_ {}
390425
}
426+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
391427
ebml::end_tag(ebml_w);
392428

429+
let impl_path = path + [ast_map::path_name(item.ident)];
393430
for m in methods {
394431
index += [{val: m.id, pos: ebml_w.writer.tell()}];
395432
ebml::start_tag(ebml_w, tag_items_data_item);
@@ -400,6 +437,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
400437
node_id_to_type(tcx, m.id));
401438
encode_name(ebml_w, m.ident);
402439
encode_symbol(ecx, ebml_w, m.id);
440+
encode_path(ebml_w, impl_path, ast_map::path_name(m.ident));
403441
ebml::end_tag(ebml_w);
404442
}
405443
}
@@ -419,13 +457,14 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
419457
ebml::end_tag(ebml_w);
420458
i += 1u;
421459
}
460+
encode_path(ebml_w, path, ast_map::path_name(item.ident));
422461
ebml::end_tag(ebml_w);
423462
}
424463
}
425464
}
426465

427466
fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
428-
nitem: @native_item) {
467+
nitem: @native_item, path: ast_map::path) {
429468
ebml::start_tag(ebml_w, tag_items_data_item);
430469
alt nitem.node {
431470
native_item_fn(fn_decl, tps) {
@@ -439,6 +478,7 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
439478
encode_type_param_bounds(ebml_w, ecx, tps);
440479
encode_type(ecx, ebml_w, node_id_to_type(ecx.ccx.tcx, nitem.id));
441480
encode_symbol(ecx, ebml_w, nitem.id);
481+
encode_path(ebml_w, path, ast_map::path_name(nitem.ident));
442482
}
443483
}
444484
ebml::end_tag(ebml_w);
@@ -449,16 +489,16 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
449489
let index: [entry<int>] = [];
450490
ebml::start_tag(ebml_w, tag_items_data);
451491
index += [{val: crate_node_id, pos: ebml_w.writer.tell()}];
452-
encode_info_for_mod(ecx, ebml_w, crate_mod, crate_node_id, "");
492+
encode_info_for_mod(ecx, ebml_w, crate_mod, crate_node_id, [], "");
453493
ecx.ccx.ast_map.items {|key, val|
454494
alt val {
455-
middle::ast_map::node_item(i, _) {
495+
middle::ast_map::node_item(i, path) {
456496
index += [{val: key, pos: ebml_w.writer.tell()}];
457-
encode_info_for_item(ecx, ebml_w, i, index);
497+
encode_info_for_item(ecx, ebml_w, i, index, *path);
458498
}
459-
middle::ast_map::node_native_item(i, _) {
499+
middle::ast_map::node_native_item(i, path) {
460500
index += [{val: key, pos: ebml_w.writer.tell()}];
461-
encode_info_for_native_item(ecx, ebml_w, i);
501+
encode_info_for_native_item(ecx, ebml_w, i, *path);
462502
}
463503
_ { }
464504
}

branches/try/src/comp/middle/ast_map.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import syntax::{visit, codemap};
66
enum path_elt { path_mod(str), path_name(str) }
77
type path = [path_elt];
88

9+
fn path_to_str_with_sep(p: path, sep: str) -> str {
10+
let strs = vec::map(p) {|e|
11+
alt e {
12+
path_mod(s) { s }
13+
path_name(s) { s }
14+
}
15+
};
16+
str::connect(strs, sep)
17+
}
18+
19+
fn path_to_str(p: path) -> str {
20+
path_to_str_with_sep(p, "::")
21+
}
22+
923
enum ast_node {
1024
node_item(@item, @path),
1125
node_native_item(@native_item, @path),

0 commit comments

Comments
 (0)