Skip to content

Commit 1dde5e7

Browse files
committed
Thread spans through the pipe compiler. They aren't perfect, but they make debugging far easier than core.rc:0:0.
Changed the is_bounded check, so we fail compiling core right now due to not supporting type parameters.
1 parent 7ecddb2 commit 1dde5e7

File tree

6 files changed

+91
-71
lines changed

6 files changed

+91
-71
lines changed

src/libcore/pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import arc::methods;
88
// Things used by code generated by the pipe compiler.
99
export entangle, get_buffer, drop_buffer;
1010
export send_packet_buffered, recv_packet_buffered;
11-
export packet, mk_packet, entangle_buffer, has_buffer;
11+
export packet, mk_packet, entangle_buffer, has_buffer, buffer_header;
1212

1313
// export these so we can find them in the buffer_resource
1414
// destructor. This is probably another metadata bug.

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,25 @@ fn ident(s: ~str) -> ast::ident {
1919
@(copy s)
2020
}
2121

22-
fn empty_span() -> span {
23-
{lo: 0, hi: 0, expn_info: none}
24-
}
25-
26-
fn span<T>(+x: T) -> ast::spanned<T> {
27-
{node: x,
28-
span: empty_span()}
29-
}
30-
31-
fn path(id: ident) -> @ast::path {
32-
@{span: empty_span(),
22+
fn path(id: ident, span: span) -> @ast::path {
23+
@{span: span,
3324
global: false,
3425
idents: ~[id],
3526
rp: none,
3627
types: ~[]}
3728
}
3829

30+
fn empty_span() -> span {
31+
{lo: 0, hi: 0, expn_info: none}
32+
}
33+
3934
trait path_concat {
4035
fn +(id: ident) -> @ast::path;
4136
}
4237

4338
impl methods of path_concat for ident {
4439
fn +(id: ident) -> @ast::path {
45-
path(self) + id
40+
path(self, empty_span()) + id
4641
}
4742
}
4843

@@ -107,19 +102,24 @@ trait ext_ctxt_ast_builder {
107102
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
108103
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
109104
fn block_expr(b: ast::blk) -> @ast::expr;
105+
fn empty_span() -> span;
110106
}
111107

112108
impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
109+
fn empty_span() -> span {
110+
{lo: 0, hi: 0, expn_info: self.backtrace()}
111+
}
112+
113113
fn block_expr(b: ast::blk) -> @ast::expr {
114114
@{id: self.next_id(),
115115
callee_id: self.next_id(),
116116
node: ast::expr_block(b),
117-
span: empty_span()}
117+
span: self.empty_span()}
118118
}
119119

120120
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
121121
@{node: ast::stmt_expr(e, self.next_id()),
122-
span: empty_span()}
122+
span: self.empty_span()}
123123
}
124124

125125
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
@@ -133,43 +133,44 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
133133
@{node: {is_mutbl: false,
134134
ty: self.ty_infer(),
135135
pat: @{id: self.next_id(),
136-
node: ast::pat_ident(path(ident), none),
137-
span: empty_span()},
136+
node: ast::pat_ident(
137+
path(ident, self.empty_span()), none),
138+
span: self.empty_span()},
138139
init: some({op: ast::init_move,
139140
expr: e}),
140141
id: self.next_id()},
141-
span: empty_span()}]),
142-
span: empty_span()}, self.next_id()),
143-
span: empty_span()}
142+
span: self.empty_span()}]),
143+
span: self.empty_span()}, self.next_id()),
144+
span: self.empty_span()}
144145
}
145146

146147
fn field_imm(name: ident, e: @ast::expr) -> ast::field {
147148
{node: {mutbl: ast::m_imm, ident: name, expr: e},
148-
span: empty_span()}
149+
span: self.empty_span()}
149150
}
150151

151152
fn rec(+fields: ~[ast::field]) -> @ast::expr {
152153
@{id: self.next_id(),
153154
callee_id: self.next_id(),
154155
node: ast::expr_rec(fields, none),
155-
span: empty_span()}
156+
span: self.empty_span()}
156157
}
157158

158159
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field {
159160
{node: {ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
160-
span: empty_span()}
161+
span: self.empty_span()}
161162
}
162163

163164
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::ty {
164165
@{id: self.next_id(),
165166
node: ast::ty_rec(fields),
166-
span: empty_span()}
167+
span: self.empty_span()}
167168
}
168169

169170
fn ty_infer() -> @ast::ty {
170171
@{id: self.next_id(),
171172
node: ast::ty_infer,
172-
span: empty_span()}
173+
span: self.empty_span()}
173174
}
174175

175176
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
@@ -201,7 +202,7 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
201202
rules: ast::default_blk};
202203

203204
{node: blk,
204-
span: empty_span()}
205+
span: self.empty_span()}
205206
}
206207

207208
fn expr_block(e: @ast::expr) -> ast::blk {
@@ -223,7 +224,7 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
223224
id: self.next_id(),
224225
node: node,
225226
vis: ast::public,
226-
span: empty_span()}
227+
span: self.empty_span()}
227228
}
228229

229230
fn item_fn_poly(name: ident,
@@ -261,12 +262,13 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
261262
+tys: ~[@ast::ty]) -> ast::variant {
262263
let args = tys.map(|ty| {ty: ty, id: self.next_id()});
263264

264-
span({name: name,
265-
attrs: ~[],
266-
args: args,
267-
id: self.next_id(),
268-
disr_expr: none,
269-
vis: ast::public})
265+
{node: {name: name,
266+
attrs: ~[],
267+
args: args,
268+
id: self.next_id(),
269+
disr_expr: none,
270+
vis: ast::public},
271+
span: self.empty_span()}
270272
}
271273

272274
fn item_mod(name: ident,
@@ -281,13 +283,13 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
281283
// FIXME #2886: make sure the node ids are legal.
282284
@{id: self.next_id(),
283285
node: ast::ty_path(path, self.next_id()),
284-
span: empty_span()}
286+
span: self.empty_span()}
285287
}
286288

287289
fn ty_nil_ast_builder() -> @ast::ty {
288290
@{id: self.next_id(),
289291
node: ast::ty_nil,
290-
span: empty_span()}
292+
span: self.empty_span()}
291293
}
292294

293295
fn item_ty_poly(name: ident,
@@ -301,6 +303,7 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
301303
}
302304

303305
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty] {
304-
ty_params.map(|p| self.ty_path_ast_builder(path(p.ident)))
306+
ty_params.map(|p| self.ty_path_ast_builder(
307+
path(p.ident, self.empty_span())))
305308
}
306309
}

src/libsyntax/ext/pipes/check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt {
3535
fn visit_state(state: state, _m: &[()]) {
3636
if state.messages.len() == 0 {
3737
self.span_warn(
38-
empty_span(), // use a real span!
38+
state.span, // use a real span!
3939
#fmt("state %s contains no messages, \
4040
consider stepping to a terminal state instead",
4141
*state.name))
4242
}
4343
}
4444

45-
fn visit_message(name: ident, _tys: &[@ast::ty],
45+
fn visit_message(name: ident, _span: span, _tys: &[@ast::ty],
4646
this: state, next: next_state) {
4747
alt next {
4848
some({state: next, tys: next_tys}) {
@@ -51,7 +51,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt {
5151
// This should be a span fatal, but then we need to
5252
// track span information.
5353
self.span_err(
54-
empty_span(),
54+
proto.get_state(next).span,
5555
#fmt("message %s steps to undefined state, %s",
5656
*name, *next));
5757
}
@@ -60,7 +60,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt {
6060

6161
if next.ty_params.len() != next_tys.len() {
6262
self.span_err(
63-
empty_span(), // use a real span
63+
next.span, // use a real span
6464
#fmt("message %s target (%s) \
6565
needs %u type parameters, but got %u",
6666
*name, *next.name,

src/libsyntax/ext/pipes/parse_proto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait proto_parser {
1313

1414
impl proto_parser of proto_parser for parser {
1515
fn parse_proto(id: ident) -> protocol {
16-
let proto = protocol(id);
16+
let proto = protocol(id, self.span);
1717

1818
self.parse_seq_to_before_end(token::EOF,
1919
{sep: none, trailing_sep_allowed: false},
@@ -87,7 +87,7 @@ impl proto_parser of proto_parser for parser {
8787
_ { self.fatal(~"invalid next state") }
8888
};
8989

90-
state.add_message(mname, args, next);
90+
state.add_message(mname, copy self.span, args, next);
9191

9292
}
9393
}

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl compile of gen_send for message {
4949
fn gen_send(cx: ext_ctxt) -> @ast::item {
5050
#debug("pipec: gen_send");
5151
alt self {
52-
message(id, tys, this, some({state: next, tys: next_tys})) {
52+
message(id, span, tys, this, some({state: next, tys: next_tys})) {
5353
#debug("pipec: next state exists");
5454
let next = this.proto.get_state(next);
5555
assert next_tys.len() == next.ty_params.len();
@@ -60,7 +60,7 @@ impl compile of gen_send for message {
6060
);
6161

6262
let pipe_ty = cx.ty_path_ast_builder(
63-
path(this.data_name())
63+
path(this.data_name(), span)
6464
.add_tys(cx.ty_vars(this.ty_params)));
6565
let args_ast = vec::append(
6666
~[cx.arg_mode(@~"pipe",
@@ -110,13 +110,13 @@ impl compile of gen_send for message {
110110

111111
cx.item_fn_poly(self.name(),
112112
args_ast,
113-
cx.ty_path_ast_builder(path(next.data_name())
113+
cx.ty_path_ast_builder(path(next.data_name(), span)
114114
.add_tys(next_tys)),
115115
self.get_params(),
116116
cx.expr_block(body))
117117
}
118118

119-
message(id, tys, this, none) {
119+
message(id, span, tys, this, none) {
120120
#debug("pipec: no next state");
121121
let arg_names = tys.mapi(|i, _ty| @(~"x_" + i.to_str()));
122122

@@ -126,7 +126,8 @@ impl compile of gen_send for message {
126126

127127
let args_ast = vec::append(
128128
~[cx.arg_mode(@~"pipe",
129-
cx.ty_path_ast_builder(path(this.data_name())
129+
cx.ty_path_ast_builder(path(this.data_name(),
130+
span)
130131
.add_tys(cx.ty_vars(this.ty_params))),
131132
ast::by_copy)],
132133
args_ast);
@@ -158,7 +159,7 @@ impl compile of gen_send for message {
158159
}
159160

160161
fn to_ty(cx: ext_ctxt) -> @ast::ty {
161-
cx.ty_path_ast_builder(path(self.name())
162+
cx.ty_path_ast_builder(path(self.name(), self.span())
162163
.add_tys(cx.ty_vars(self.get_params())))
163164
}
164165
}
@@ -177,7 +178,7 @@ impl compile of to_type_decls for state {
177178
let mut items_msg = ~[];
178179

179180
for self.messages.each |m| {
180-
let message(name, tys, this, next) = m;
181+
let message(name, _span, tys, this, next) = m;
181182

182183
let tys = alt next {
183184
some({state: next, tys: next_tys}) {
@@ -287,7 +288,7 @@ impl compile of gen_init for protocol {
287288

288289
fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
289290
ext_cx.rec(self.states.map_to_vec(|s| {
290-
let fty = ext_cx.ty_path_ast_builder(path(s.name));
291+
let fty = ext_cx.ty_path_ast_builder(path(s.name, s.span));
291292
ext_cx.field_imm(s.name, #ast { pipes::mk_packet::<$(fty)>() })
292293
}))
293294
}
@@ -324,7 +325,7 @@ impl compile of gen_init for protocol {
324325
cx.ty_rec(
325326
(copy self.states).map_to_vec(
326327
|s| {
327-
let ty = cx.ty_path_ast_builder(path(s.name));
328+
let ty = cx.ty_path_ast_builder(path(s.name, s.span));
328329
let fty = #ast[ty] {
329330
pipes::packet<$(ty)>
330331
};

0 commit comments

Comments
 (0)