Skip to content

Commit 0b8237a

Browse files
committed
auto merge of #4996 : luqmana/rust/no-rec-pipes, r=graydon
Removes the last use of structural records in the pipes extension and with that, libcore has no more structural records. Also, explicit-self-ification.
2 parents a6945f2 + cfc91b2 commit 0b8237a

File tree

5 files changed

+173
-172
lines changed

5 files changed

+173
-172
lines changed

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -67,61 +67,65 @@ pub impl append_types for @ast::path {
6767
}
6868

6969
pub trait ext_ctxt_ast_builder {
70-
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
70+
fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
7171
-> ast::ty_param;
72-
fn arg(name: ident, ty: @ast::Ty) -> ast::arg;
73-
fn expr_block(e: @ast::expr) -> ast::blk;
74-
fn fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
75-
fn item(name: ident, span: span, +node: ast::item_) -> @ast::item;
76-
fn item_fn_poly(name: ident,
72+
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg;
73+
fn expr_block(&self, e: @ast::expr) -> ast::blk;
74+
fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
75+
fn item(&self, name: ident, span: span, +node: ast::item_) -> @ast::item;
76+
fn item_fn_poly(&self, name: ident,
7777
+inputs: ~[ast::arg],
7878
output: @ast::Ty,
7979
+ty_params: ~[ast::ty_param],
8080
+body: ast::blk) -> @ast::item;
81-
fn item_fn(name: ident,
81+
fn item_fn(&self, name: ident,
8282
+inputs: ~[ast::arg],
8383
output: @ast::Ty,
8484
+body: ast::blk) -> @ast::item;
85-
fn item_enum_poly(name: ident,
85+
fn item_enum_poly(&self, name: ident,
8686
span: span,
8787
+enum_definition: ast::enum_def,
8888
+ty_params: ~[ast::ty_param]) -> @ast::item;
89-
fn item_enum(name: ident, span: span,
89+
fn item_enum(&self, name: ident, span: span,
9090
+enum_definition: ast::enum_def) -> @ast::item;
91-
fn variant(name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
92-
fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
93-
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty;
94-
fn item_ty_poly(name: ident,
91+
fn item_struct_poly(&self, name: ident, span: span,
92+
struct_def: ast::struct_def,
93+
ty_params: ~[ast::ty_param]) -> @ast::item;
94+
fn item_struct(&self, name: ident, span: span,
95+
struct_def: ast::struct_def) -> @ast::item;
96+
fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
97+
fn variant(&self, name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
98+
fn item_mod(&self, name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
99+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
100+
fn item_ty_poly(&self, name: ident,
95101
span: span,
96102
ty: @ast::Ty,
97103
+params: ~[ast::ty_param]) -> @ast::item;
98-
fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item;
99-
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
100-
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
101-
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field;
102-
fn ty_rec(+v: ~[ast::ty_field]) -> @ast::Ty;
103-
fn field_imm(name: ident, e: @ast::expr) -> ast::field;
104-
fn rec(+v: ~[ast::field]) -> @ast::expr;
105-
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
106-
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
107-
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
108-
fn block_expr(b: ast::blk) -> @ast::expr;
109-
fn ty_option(ty: @ast::Ty) -> @ast::Ty;
110-
fn ty_infer() -> @ast::Ty;
111-
fn ty_nil_ast_builder() -> @ast::Ty;
112-
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param];
104+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
105+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
106+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
107+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field;
108+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field;
109+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
110+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt;
111+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt;
112+
fn block_expr(&self, b: ast::blk) -> @ast::expr;
113+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
114+
fn ty_infer(&self) -> @ast::Ty;
115+
fn ty_nil_ast_builder(&self) -> @ast::Ty;
116+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param];
113117
}
114118

115119
pub impl ext_ctxt_ast_builder for ext_ctxt {
116-
fn ty_option(ty: @ast::Ty) -> @ast::Ty {
120+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
117121
self.ty_path_ast_builder(path_global(~[
118122
self.ident_of(~"core"),
119123
self.ident_of(~"option"),
120124
self.ident_of(~"Option")
121125
], dummy_sp()).add_ty(ty))
122126
}
123127

124-
fn block_expr(b: ast::blk) -> @ast::expr {
128+
fn block_expr(&self, b: ast::blk) -> @ast::expr {
125129
@expr {
126130
id: self.next_id(),
127131
callee_id: self.next_id(),
@@ -130,33 +134,24 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
130134
}
131135
}
132136

133-
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
137+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
134138
@spanned { node: ast::stmt_expr(e, self.next_id()),
135139
span: dummy_sp()}
136140
}
137141

138-
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
139-
let ext_cx = self;
142+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
143+
let ext_cx = *self;
140144
quote_stmt!( let $ident = $e; )
141145
}
142146

143-
fn field_imm(name: ident, e: @ast::expr) -> ast::field {
147+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
144148
spanned {
145149
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
146150
span: dummy_sp(),
147151
}
148152
}
149153

150-
fn rec(+fields: ~[ast::field]) -> @ast::expr {
151-
@expr {
152-
id: self.next_id(),
153-
callee_id: self.next_id(),
154-
node: ast::expr_rec(fields, None),
155-
span: dummy_sp(),
156-
}
157-
}
158-
159-
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
154+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
160155
spanned {
161156
node: ast::ty_field_ {
162157
ident: name,
@@ -166,29 +161,21 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
166161
}
167162
}
168163

169-
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
170-
@ast::Ty {
171-
id: self.next_id(),
172-
node: ast::ty_rec(fields),
173-
span: dummy_sp(),
174-
}
175-
}
176-
177-
fn ty_infer() -> @ast::Ty {
164+
fn ty_infer(&self) -> @ast::Ty {
178165
@ast::Ty {
179166
id: self.next_id(),
180167
node: ast::ty_infer,
181168
span: dummy_sp(),
182169
}
183170
}
184171

185-
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
172+
fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
186173
-> ast::ty_param
187174
{
188175
ast::ty_param { ident: id, id: self.next_id(), bounds: @bounds }
189176
}
190177

191-
fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
178+
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
192179
ast::arg {
193180
mode: ast::infer(self.next_id()),
194181
is_mutbl: false,
@@ -205,7 +192,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
205192
}
206193
}
207194

208-
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
195+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
209196
let blk = ast::blk_ {
210197
view_items: ~[],
211198
stmts: stmts,
@@ -217,11 +204,11 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
217204
spanned { node: blk, span: dummy_sp() }
218205
}
219206

220-
fn expr_block(e: @ast::expr) -> ast::blk {
207+
fn expr_block(&self, e: @ast::expr) -> ast::blk {
221208
self.block(~[], e)
222209
}
223210

224-
fn fn_decl(+inputs: ~[ast::arg],
211+
fn fn_decl(&self, +inputs: ~[ast::arg],
225212
output: @ast::Ty) -> ast::fn_decl {
226213
ast::fn_decl {
227214
inputs: inputs,
@@ -230,8 +217,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
230217
}
231218
}
232219

233-
fn item(name: ident,
234-
span: span,
220+
fn item(&self, name: ident, span: span,
235221
+node: ast::item_) -> @ast::item {
236222

237223
// XXX: Would be nice if our generated code didn't violate
@@ -254,7 +240,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
254240
span: span }
255241
}
256242

257-
fn item_fn_poly(name: ident,
243+
fn item_fn_poly(&self, name: ident,
258244
+inputs: ~[ast::arg],
259245
output: @ast::Ty,
260246
+ty_params: ~[ast::ty_param],
@@ -267,27 +253,45 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
267253
body))
268254
}
269255

270-
fn item_fn(name: ident,
256+
fn item_fn(&self, name: ident,
271257
+inputs: ~[ast::arg],
272258
output: @ast::Ty,
273259
+body: ast::blk) -> @ast::item {
274260
self.item_fn_poly(name, inputs, output, ~[], body)
275261
}
276262

277-
fn item_enum_poly(name: ident,
278-
span: span,
263+
fn item_enum_poly(&self, name: ident, span: span,
279264
+enum_definition: ast::enum_def,
280265
+ty_params: ~[ast::ty_param]) -> @ast::item {
281266
self.item(name, span, ast::item_enum(enum_definition, ty_params))
282267
}
283268

284-
fn item_enum(name: ident, span: span,
269+
fn item_enum(&self, name: ident, span: span,
285270
+enum_definition: ast::enum_def) -> @ast::item {
286271
self.item_enum_poly(name, span, enum_definition, ~[])
287272
}
288273

289-
fn variant(name: ident,
290-
span: span,
274+
fn item_struct(&self, name: ident, span: span,
275+
struct_def: ast::struct_def) -> @ast::item {
276+
self.item_struct_poly(name, span, struct_def, ~[])
277+
}
278+
279+
fn item_struct_poly(&self, name: ident, span: span,
280+
struct_def: ast::struct_def,
281+
ty_params: ~[ast::ty_param]) -> @ast::item {
282+
self.item(name, span, ast::item_struct(@struct_def, ty_params))
283+
}
284+
285+
fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
286+
@ast::expr {
287+
id: self.next_id(),
288+
callee_id: self.next_id(),
289+
node: ast::expr_struct(path, fields, None),
290+
span: dummy_sp()
291+
}
292+
}
293+
294+
fn variant(&self, name: ident, span: span,
291295
+tys: ~[@ast::Ty]) -> ast::variant {
292296
let args = do tys.map |ty| {
293297
ast::variant_arg { ty: *ty, id: self.next_id() }
@@ -300,14 +304,15 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
300304
kind: ast::tuple_variant_kind(args),
301305
id: self.next_id(),
302306
disr_expr: None,
303-
vis: ast::public},
307+
vis: ast::public
308+
},
304309
span: span,
305310
}
306311
}
307312

308-
fn item_mod(name: ident,
309-
span: span,
313+
fn item_mod(&self, name: ident, span: span,
310314
+items: ~[@ast::item]) -> @ast::item {
315+
311316
// XXX: Total hack: import `core::kinds::Owned` to work around a
312317
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
313318
let vi = ast::view_item_import(~[
@@ -345,45 +350,43 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
345350
)
346351
}
347352

348-
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
353+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
349354
@ast::Ty {
350355
id: self.next_id(),
351356
node: ast::ty_path(path, self.next_id()),
352357
span: path.span,
353358
}
354359
}
355360

356-
fn ty_nil_ast_builder() -> @ast::Ty {
361+
fn ty_nil_ast_builder(&self) -> @ast::Ty {
357362
@ast::Ty {
358363
id: self.next_id(),
359364
node: ast::ty_nil,
360365
span: dummy_sp(),
361366
}
362367
}
363368

364-
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
369+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
365370
do bounds.map |ty_param| {
366371
ast::ty_param { bounds: @~[], ..copy *ty_param }
367372
}
368373
}
369374

370-
fn item_ty_poly(name: ident,
371-
span: span,
372-
ty: @ast::Ty,
375+
fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
373376
+params: ~[ast::ty_param]) -> @ast::item {
374377
self.item(name, span, ast::item_ty(ty, params))
375378
}
376379

377-
fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item {
380+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
378381
self.item_ty_poly(name, span, ty, ~[])
379382
}
380383

381-
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
384+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
382385
ty_params.map(|p| self.ty_path_ast_builder(
383386
path(~[p.ident], dummy_sp())))
384387
}
385388

386-
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
389+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
387390
ty_params.map(|p| self.ty_path_ast_builder(
388391
path(~[p.ident], dummy_sp())))
389392
}

src/libsyntax/ext/pipes/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ use ext::pipes::proto::{state, protocol, next_state};
3838
use ext::pipes::proto;
3939

4040
pub impl proto::visitor<(), (), ()> for ext_ctxt {
41-
fn visit_proto(_proto: protocol,
41+
fn visit_proto(&self, _proto: protocol,
4242
_states: &[()]) { }
4343

44-
fn visit_state(state: state, _m: &[()]) {
44+
fn visit_state(&self, state: state, _m: &[()]) {
4545
if state.messages.len() == 0 {
4646
self.span_warn(
4747
state.span, // use a real span!
@@ -51,7 +51,7 @@ pub impl proto::visitor<(), (), ()> for ext_ctxt {
5151
}
5252
}
5353

54-
fn visit_message(name: ~str, _span: span, _tys: &[@ast::Ty],
54+
fn visit_message(&self, name: ~str, _span: span, _tys: &[@ast::Ty],
5555
this: state, next: Option<next_state>) {
5656
match next {
5757
Some(next_state { state: ref next, tys: next_tys }) => {

src/libsyntax/ext/pipes/parse_proto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use parse::token;
1717
use core::prelude::*;
1818

1919
pub trait proto_parser {
20-
fn parse_proto(id: ~str) -> protocol;
21-
fn parse_state(proto: protocol);
22-
fn parse_message(state: state);
20+
fn parse_proto(&self, id: ~str) -> protocol;
21+
fn parse_state(&self, proto: protocol);
22+
fn parse_message(&self, state: state);
2323
}
2424

2525
pub impl proto_parser for parser::Parser {
26-
fn parse_proto(id: ~str) -> protocol {
26+
fn parse_proto(&self, id: ~str) -> protocol {
2727
let proto = protocol(id, self.span);
2828

2929
self.parse_seq_to_before_end(token::EOF,
@@ -33,7 +33,7 @@ pub impl proto_parser for parser::Parser {
3333
return proto;
3434
}
3535

36-
fn parse_state(proto: protocol) {
36+
fn parse_state(&self, proto: protocol) {
3737
let id = self.parse_ident();
3838
let name = *self.interner.get(id);
3939

@@ -63,7 +63,7 @@ pub impl proto_parser for parser::Parser {
6363
|self| self.parse_message(state));
6464
}
6565

66-
fn parse_message(state: state) {
66+
fn parse_message(&self, state: state) {
6767
let mname = *self.interner.get(self.parse_ident());
6868

6969
let args = if self.token == token::LPAREN {

0 commit comments

Comments
 (0)