Skip to content

Commit 0de1cbe

Browse files
committed
---
yaml --- r: 14582 b: refs/heads/try c: 6473a87 h: refs/heads/master v: v3
1 parent bee55ad commit 0de1cbe

File tree

14 files changed

+271
-189
lines changed

14 files changed

+271
-189
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: def72bda47977b3bc36143eba9692bff12a8303c
5+
refs/heads/try: 6473a87cec100682764f4d926541fc7eb455b00c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

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

Lines changed: 42 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import syntax::ast;
22
import syntax::fold;
33
import syntax::visit;
44
import syntax::ast_util;
5+
import syntax::ast_util::inlined_item_methods;
56
import syntax::codemap::span;
67
import std::map::map;
78
import std::smallintmap::map;
@@ -31,8 +32,6 @@ import syntax::print::pprust;
3132

3233
export encode_inlined_item;
3334
export decode_inlined_item;
34-
export encode_inlined_method;
35-
export decode_inlined_method;
3635

3736
type decode_ctxt = @{
3837
cdata: cstore::crate_metadata,
@@ -53,123 +52,49 @@ iface tr {
5352
// ______________________________________________________________________
5453
// Top-level methods.
5554

56-
// The type inline_fn should be a type that can represent both methods
57-
// and top-level items. As it happens, the type ast::method is perfect
58-
// for this purpose, but I use this typedef just to keep clear when
59-
// the thing may not, in fact, be an actual method in the AST but
60-
// rather some sort of function.
61-
enum inline_fn = @ast::method;
62-
6355
fn encode_inlined_item(ecx: @e::encode_ctxt,
6456
ebml_w: ebml::writer,
6557
path: ast_map::path,
66-
item: @ast::item) {
67-
let ifn = inline_fn(alt item.node {
68-
ast::item_fn(decl, tps, body) {
69-
@{ident: item.ident,
70-
attrs: item.attrs,
71-
tps: tps,
72-
decl: decl,
73-
body: body,
74-
id: item.id,
75-
span: item.span}
76-
}
77-
78-
_ {
79-
ecx.ccx.sess.span_bug(item.span, "Cannot inline non-function")
80-
}
81-
});
82-
83-
encode_inlined_fn(ecx, ebml_w, path, ifn);
84-
}
85-
86-
fn decode_inlined_item(cdata: cstore::crate_metadata,
87-
tcx: ty::ctxt,
88-
maps: maps,
89-
path: ast_map::path,
90-
par_doc: ebml::doc) -> option<@ast::item> {
91-
let oifn = decode_inlined_fn(cdata, tcx, maps, path, par_doc);
92-
option::map(oifn) {|ifn|
93-
let item = @{ident: ifn.ident,
94-
attrs: ifn.attrs,
95-
id: ifn.id,
96-
node: ast::item_fn(ifn.decl, ifn.tps, ifn.body),
97-
span: ifn.span};
98-
ast_map::map_decoded_item(tcx.items, path, item);
99-
item
100-
}
101-
}
102-
103-
fn encode_inlined_method(ecx: @e::encode_ctxt,
104-
ebml_w: ebml::writer,
105-
path: ast_map::path,
106-
mthd: @ast::method) {
107-
encode_inlined_fn(ecx, ebml_w, path, inline_fn(mthd))
108-
}
109-
110-
fn decode_inlined_method(cdata: cstore::crate_metadata,
111-
tcx: ty::ctxt,
112-
maps: maps,
113-
path: ast_map::path,
114-
par_doc: ebml::doc) -> option<@ast::method> {
115-
let oifn = decode_inlined_fn(cdata, tcx, maps, path, par_doc);
116-
option::map(oifn) {|ifn|
117-
ast_map::map_decoded_method(tcx.items, path, *ifn);
118-
*ifn
119-
}
120-
}
121-
122-
fn encode_inlined_fn(ecx: @e::encode_ctxt,
123-
ebml_w: ebml::writer,
124-
path: ast_map::path,
125-
ifn: inline_fn) {
126-
58+
ii: ast::inlined_item) {
12759
#debug["> Encoding inlined item: %s::%s (%u)",
128-
ast_map::path_to_str(path),
129-
ifn.ident,
60+
ast_map::path_to_str(path), ii.ident(),
13061
ebml_w.writer.tell()];
13162

132-
let id_range = compute_id_range(ifn);
63+
let id_range = compute_id_range(ii);
13364
ebml_w.wr_tag(c::tag_ast as uint) {||
13465
encode_id_range(ebml_w, id_range);
135-
encode_ast(ebml_w, ifn);
136-
encode_side_tables_for_ifn(ecx, ebml_w, ifn);
66+
encode_ast(ebml_w, ii);
67+
encode_side_tables_for_ii(ecx, ebml_w, ii);
13768
}
13869

13970
#debug["< Encoded inlined fn: %s::%s (%u)",
140-
ast_map::path_to_str(path),
141-
ifn.ident,
71+
ast_map::path_to_str(path), ii.ident(),
14272
ebml_w.writer.tell()];
14373
}
14474

145-
// Decodes the inlined function and associated side tables. Does
146-
// *not* insert the function into the ast_map, since the correct way
147-
// to do this depends on whether this is an inlined item or method;
148-
// therefore, you ought to be invoking decode_inlined_item() or
149-
// decode_inlined_method() and not this helper function.
150-
fn decode_inlined_fn(cdata: cstore::crate_metadata,
151-
tcx: ty::ctxt,
152-
maps: maps,
153-
path: ast_map::path,
154-
par_doc: ebml::doc) -> option<inline_fn> {
75+
fn decode_inlined_item(cdata: cstore::crate_metadata,
76+
tcx: ty::ctxt,
77+
maps: maps,
78+
path: ast_map::path,
79+
par_doc: ebml::doc) -> option<ast::inlined_item> {
15580
let dcx = @{cdata: cdata, tcx: tcx, maps: maps};
15681
alt par_doc.opt_child(c::tag_ast) {
15782
none { none }
15883
some(ast_doc) {
159-
#debug["> Decoding inlined fn: %s", ast_map::path_to_str(path)];
84+
#debug["> Decoding inlined fn: %s::?", ast_map::path_to_str(path)];
16085
let from_id_range = decode_id_range(ast_doc);
16186
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
16287
let xcx = @{dcx: dcx,
16388
from_id_range: from_id_range,
16489
to_id_range: to_id_range};
165-
let raw_ifn = decode_ast(ast_doc);
166-
let ifn = renumber_ast(xcx, raw_ifn);
167-
#debug["Fn named: %s", ifn.ident];
90+
let raw_ii = decode_ast(ast_doc);
91+
let ii = renumber_ast(xcx, raw_ii);
92+
ast_map::map_decoded_item(dcx.tcx.items, path, ii);
93+
#debug["Fn named: %s", ii.ident()];
16894
decode_side_tables(xcx, ast_doc);
16995
#debug["< Decoded inlined fn: %s::%s",
170-
ast_map::path_to_str(path),
171-
ifn.ident];
172-
some(ifn)
96+
ast_map::path_to_str(path), ii.ident()];
97+
some(ii)
17398
}
17499
}
175100
}
@@ -183,7 +108,7 @@ fn empty(range: id_range) -> bool {
183108
range.min >= range.max
184109
}
185110

186-
fn visit_ids(ifn: inline_fn, vfn: fn@(ast::node_id)) {
111+
fn visit_ids(item: ast::inlined_item, vfn: fn@(ast::node_id)) {
187112
let visitor = visit::mk_simple_visitor(@{
188113
visit_mod: fn@(_m: ast::_mod, _sp: span, id: ast::node_id) {
189114
vfn(id)
@@ -292,13 +217,13 @@ fn visit_ids(ifn: inline_fn, vfn: fn@(ast::node_id)) {
292217
}
293218
});
294219

295-
visit::visit_method_helper(*ifn, (), visitor);
220+
item.accept((), visitor)
296221
}
297222

298-
fn compute_id_range(ifn: inline_fn) -> id_range {
223+
fn compute_id_range(item: ast::inlined_item) -> id_range {
299224
let min = @mutable int::max_value;
300225
let max = @mutable int::min_value;
301-
visit_ids(ifn) {|id|
226+
visit_ids(item) {|id|
302227
*min = int::min(*min, id);
303228
*max = int::max(*max, id + 1);
304229
}
@@ -395,25 +320,34 @@ impl deserializer_helpers<D: serialization::deserializer> for D {
395320
// We also have to adjust the spans: for now we just insert a dummy span,
396321
// but eventually we should add entries to the local codemap as required.
397322

398-
fn encode_ast(ebml_w: ebml::writer, ifn: inline_fn) {
323+
fn encode_ast(ebml_w: ebml::writer, item: ast::inlined_item) {
399324
ebml_w.wr_tag(c::tag_tree as uint) {||
400-
astencode_gen::serialize_syntax_ast_method(ebml_w, **ifn)
325+
astencode_gen::serialize_syntax_ast_inlined_item(ebml_w, item)
401326
}
402327
}
403328

404-
fn decode_ast(par_doc: ebml::doc) -> inline_fn {
329+
fn decode_ast(par_doc: ebml::doc) -> ast::inlined_item {
405330
let chi_doc = par_doc[c::tag_tree];
406331
let d = serialization::mk_ebml_deserializer(chi_doc);
407-
inline_fn(@astencode_gen::deserialize_syntax_ast_method(d))
332+
astencode_gen::deserialize_syntax_ast_inlined_item(d)
408333
}
409334

410-
fn renumber_ast(xcx: extended_decode_ctxt, ifn: inline_fn) -> inline_fn {
335+
fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
336+
-> ast::inlined_item {
411337
let fld = fold::make_fold({
412338
new_id: xcx.tr_id(_),
413339
new_span: xcx.tr_span(_)
414340
with *fold::default_ast_fold()
415341
});
416-
inline_fn(fld.fold_method(*ifn))
342+
343+
alt ii {
344+
ast::ii_item(i) {
345+
ast::ii_item(fld.fold_item(i))
346+
}
347+
ast::ii_method(d, m) {
348+
ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m))
349+
}
350+
}
417351
}
418352

419353
// ______________________________________________________________________
@@ -664,11 +598,11 @@ impl writer for ebml::writer {
664598
}
665599
}
666600

667-
fn encode_side_tables_for_ifn(ecx: @e::encode_ctxt,
668-
ebml_w: ebml::writer,
669-
ifn: inline_fn) {
601+
fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
602+
ebml_w: ebml::writer,
603+
ii: ast::inlined_item) {
670604
ebml_w.wr_tag(c::tag_table as uint) {||
671-
visit_ids(ifn, fn@(id: ast::node_id) {
605+
visit_ids(ii, fn@(id: ast::node_id) {
672606
// Note: this will cause a copy of ebml_w, which is bad as
673607
// it has mutable fields. But I believe it's harmless since
674608
// we generate balanced EBML.

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

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8748,12 +8748,84 @@ fn deserialize_syntax_ast_def_id<S: std::serialization::deserializer>(s: S) ->
87488748
syntax::ast::def_id {
87498749
deserialize_162(s)
87508750
}
8751-
fn serialize_syntax_ast_method<S: std::serialization::serializer>(s: S,
8752-
v:
8753-
syntax::ast::method) {
8754-
serialize_160(s, v);
8751+
/*syntax::ast::inlined_item*/
8752+
fn serialize_168<S: std::serialization::serializer>(s: S,
8753+
v:
8754+
syntax::ast::inlined_item) {
8755+
s.emit_enum("syntax::ast::inlined_item",
8756+
/*@syntax::ast::item*/
8757+
/*syntax::ast::def_id*//*@syntax::ast::method*/
8758+
{||
8759+
alt v {
8760+
syntax::ast::ii_item(v0) {
8761+
s.emit_enum_variant("syntax::ast::ii_item", 0u, 1u,
8762+
{||
8763+
{
8764+
s.emit_enum_variant_arg(0u,
8765+
{||
8766+
serialize_117(s,
8767+
v0)
8768+
})
8769+
}
8770+
})
8771+
}
8772+
syntax::ast::ii_method(v0, v1) {
8773+
s.emit_enum_variant("syntax::ast::ii_method", 1u, 2u,
8774+
{||
8775+
{
8776+
s.emit_enum_variant_arg(0u,
8777+
{||
8778+
serialize_162(s,
8779+
v0)
8780+
});
8781+
s.emit_enum_variant_arg(1u,
8782+
{||
8783+
serialize_159(s,
8784+
v1)
8785+
})
8786+
}
8787+
})
8788+
}
8789+
}
8790+
});
87558791
}
8756-
fn deserialize_syntax_ast_method<S: std::serialization::deserializer>(s: S) ->
8757-
syntax::ast::method {
8758-
deserialize_160(s)
8792+
fn serialize_syntax_ast_inlined_item<S: std::serialization::serializer>(s: S,
8793+
v:
8794+
syntax::ast::inlined_item) {
8795+
serialize_168(s, v);
8796+
}
8797+
/*syntax::ast::inlined_item*/
8798+
fn deserialize_168<S: std::serialization::deserializer>(s: S) ->
8799+
syntax::ast::inlined_item {
8800+
s.read_enum("syntax::ast::inlined_item",
8801+
/*@syntax::ast::item*/
8802+
8803+
/*syntax::ast::def_id*//*@syntax::ast::method*/
8804+
{||
8805+
s.read_enum_variant({|v_id|
8806+
alt check v_id {
8807+
0u {
8808+
syntax::ast::ii_item(s.read_enum_variant_arg(0u,
8809+
{||
8810+
deserialize_117(s)
8811+
}))
8812+
}
8813+
1u {
8814+
syntax::ast::ii_method(s.read_enum_variant_arg(0u,
8815+
{||
8816+
deserialize_162(s)
8817+
}),
8818+
s.read_enum_variant_arg(1u,
8819+
{||
8820+
deserialize_159(s)
8821+
}))
8822+
}
8823+
}
8824+
})
8825+
})
8826+
}
8827+
fn deserialize_syntax_ast_inlined_item<S: std::serialization::deserializer>(s:
8828+
S)
8829+
-> syntax::ast::inlined_item {
8830+
deserialize_168(s)
87598831
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
7979
// not marked for inlining, then the AST will not be present and hence none
8080
// will be returned.
8181
fn maybe_get_item_ast(tcx: ty::ctxt, maps: maps, def: ast::def_id)
82-
-> option<@ast::item> {
82+
-> option<ast::inlined_item> {
8383
let cstore = tcx.sess.cstore;
8484
let cdata = cstore::get_crate_data(cstore, def.crate);
8585
decoder::maybe_get_item_ast(cdata, tcx, maps, def.node)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn get_item_path(cdata: cmd, id: ast::node_id) -> ast_map::path {
264264
}
265265

266266
fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt, maps: maps,
267-
id: ast::node_id) -> option<@ast::item> {
267+
id: ast::node_id) -> option<ast::inlined_item> {
268268
let item_doc = lookup_item(id, cdata.data);
269269
let path = vec::init(item_path(item_doc));
270270
astencode::decode_inlined_item(cdata, tcx, maps, path, item_doc)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
352352
encode_symbol(ecx, ebml_w, item.id);
353353
encode_path(ebml_w, path, ast_map::path_name(item.ident));
354354
if should_inline(path, item) {
355-
astencode::encode_inlined_item(ecx, ebml_w, path, item);
355+
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
356356
}
357357
ebml_w.end_tag();
358358
}

0 commit comments

Comments
 (0)