Skip to content

Commit df4273f

Browse files
committed
auto merge of #4996 : luqmana/rust/no-rec-pipes, r=catamorphism
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 1171a21 + baeac2f commit df4273f

File tree

5 files changed

+179
-172
lines changed

5 files changed

+179
-172
lines changed

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -67,61 +67,68 @@ 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,
97+
fields: ~[ast::field]) -> @ast::expr;
98+
fn variant(&self, name: ident, span: span,
99+
+tys: ~[@ast::Ty]) -> ast::variant;
100+
fn item_mod(&self, name: ident, span: span,
101+
+items: ~[@ast::item]) -> @ast::item;
102+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
103+
fn item_ty_poly(&self, name: ident,
95104
span: span,
96105
ty: @ast::Ty,
97106
+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];
107+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
108+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
109+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
110+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field;
111+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field;
112+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
113+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt;
114+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt;
115+
fn block_expr(&self, b: ast::blk) -> @ast::expr;
116+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
117+
fn ty_infer(&self) -> @ast::Ty;
118+
fn ty_nil_ast_builder(&self) -> @ast::Ty;
119+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param];
113120
}
114121

115122
pub impl ext_ctxt_ast_builder for ext_ctxt {
116-
fn ty_option(ty: @ast::Ty) -> @ast::Ty {
123+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
117124
self.ty_path_ast_builder(path_global(~[
118125
self.ident_of(~"core"),
119126
self.ident_of(~"option"),
120127
self.ident_of(~"Option")
121128
], dummy_sp()).add_ty(ty))
122129
}
123130

124-
fn block_expr(b: ast::blk) -> @ast::expr {
131+
fn block_expr(&self, b: ast::blk) -> @ast::expr {
125132
@expr {
126133
id: self.next_id(),
127134
callee_id: self.next_id(),
@@ -130,33 +137,24 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
130137
}
131138
}
132139

133-
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
140+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
134141
@spanned { node: ast::stmt_expr(e, self.next_id()),
135142
span: dummy_sp()}
136143
}
137144

138-
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
139-
let ext_cx = self;
145+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
146+
let ext_cx = *self;
140147
quote_stmt!( let $ident = $e; )
141148
}
142149

143-
fn field_imm(name: ident, e: @ast::expr) -> ast::field {
150+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
144151
spanned {
145152
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
146153
span: dummy_sp(),
147154
}
148155
}
149156

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 {
157+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
160158
spanned {
161159
node: ast::ty_field_ {
162160
ident: name,
@@ -166,29 +164,21 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
166164
}
167165
}
168166

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 {
167+
fn ty_infer(&self) -> @ast::Ty {
178168
@ast::Ty {
179169
id: self.next_id(),
180170
node: ast::ty_infer,
181171
span: dummy_sp(),
182172
}
183173
}
184174

185-
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
175+
fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
186176
-> ast::ty_param
187177
{
188178
ast::ty_param { ident: id, id: self.next_id(), bounds: @bounds }
189179
}
190180

191-
fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
181+
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
192182
ast::arg {
193183
mode: ast::infer(self.next_id()),
194184
is_mutbl: false,
@@ -205,7 +195,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
205195
}
206196
}
207197

208-
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
198+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
209199
let blk = ast::blk_ {
210200
view_items: ~[],
211201
stmts: stmts,
@@ -217,11 +207,11 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
217207
spanned { node: blk, span: dummy_sp() }
218208
}
219209

220-
fn expr_block(e: @ast::expr) -> ast::blk {
210+
fn expr_block(&self, e: @ast::expr) -> ast::blk {
221211
self.block(~[], e)
222212
}
223213

224-
fn fn_decl(+inputs: ~[ast::arg],
214+
fn fn_decl(&self, +inputs: ~[ast::arg],
225215
output: @ast::Ty) -> ast::fn_decl {
226216
ast::fn_decl {
227217
inputs: inputs,
@@ -230,8 +220,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
230220
}
231221
}
232222

233-
fn item(name: ident,
234-
span: span,
223+
fn item(&self, name: ident, span: span,
235224
+node: ast::item_) -> @ast::item {
236225

237226
// XXX: Would be nice if our generated code didn't violate
@@ -254,7 +243,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
254243
span: span }
255244
}
256245

257-
fn item_fn_poly(name: ident,
246+
fn item_fn_poly(&self, name: ident,
258247
+inputs: ~[ast::arg],
259248
output: @ast::Ty,
260249
+ty_params: ~[ast::ty_param],
@@ -267,27 +256,46 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
267256
body))
268257
}
269258

270-
fn item_fn(name: ident,
259+
fn item_fn(&self, name: ident,
271260
+inputs: ~[ast::arg],
272261
output: @ast::Ty,
273262
+body: ast::blk) -> @ast::item {
274263
self.item_fn_poly(name, inputs, output, ~[], body)
275264
}
276265

277-
fn item_enum_poly(name: ident,
278-
span: span,
266+
fn item_enum_poly(&self, name: ident, span: span,
279267
+enum_definition: ast::enum_def,
280268
+ty_params: ~[ast::ty_param]) -> @ast::item {
281269
self.item(name, span, ast::item_enum(enum_definition, ty_params))
282270
}
283271

284-
fn item_enum(name: ident, span: span,
272+
fn item_enum(&self, name: ident, span: span,
285273
+enum_definition: ast::enum_def) -> @ast::item {
286274
self.item_enum_poly(name, span, enum_definition, ~[])
287275
}
288276

289-
fn variant(name: ident,
290-
span: span,
277+
fn item_struct(&self, name: ident, span: span,
278+
struct_def: ast::struct_def) -> @ast::item {
279+
self.item_struct_poly(name, span, struct_def, ~[])
280+
}
281+
282+
fn item_struct_poly(&self, name: ident, span: span,
283+
struct_def: ast::struct_def,
284+
ty_params: ~[ast::ty_param]) -> @ast::item {
285+
self.item(name, span, ast::item_struct(@struct_def, ty_params))
286+
}
287+
288+
fn struct_expr(&self, path: @ast::path,
289+
fields: ~[ast::field]) -> @ast::expr {
290+
@ast::expr {
291+
id: self.next_id(),
292+
callee_id: self.next_id(),
293+
node: ast::expr_struct(path, fields, None),
294+
span: dummy_sp()
295+
}
296+
}
297+
298+
fn variant(&self, name: ident, span: span,
291299
+tys: ~[@ast::Ty]) -> ast::variant {
292300
let args = do tys.map |ty| {
293301
ast::variant_arg { ty: *ty, id: self.next_id() }
@@ -300,14 +308,15 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
300308
kind: ast::tuple_variant_kind(args),
301309
id: self.next_id(),
302310
disr_expr: None,
303-
vis: ast::public},
311+
vis: ast::public
312+
},
304313
span: span,
305314
}
306315
}
307316

308-
fn item_mod(name: ident,
309-
span: span,
317+
fn item_mod(&self, name: ident, span: span,
310318
+items: ~[@ast::item]) -> @ast::item {
319+
311320
// XXX: Total hack: import `core::kinds::Owned` to work around a
312321
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
313322
let vi = ast::view_item_import(~[
@@ -345,45 +354,43 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
345354
)
346355
}
347356

348-
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
357+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
349358
@ast::Ty {
350359
id: self.next_id(),
351360
node: ast::ty_path(path, self.next_id()),
352361
span: path.span,
353362
}
354363
}
355364

356-
fn ty_nil_ast_builder() -> @ast::Ty {
365+
fn ty_nil_ast_builder(&self) -> @ast::Ty {
357366
@ast::Ty {
358367
id: self.next_id(),
359368
node: ast::ty_nil,
360369
span: dummy_sp(),
361370
}
362371
}
363372

364-
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
373+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
365374
do bounds.map |ty_param| {
366375
ast::ty_param { bounds: @~[], ..copy *ty_param }
367376
}
368377
}
369378

370-
fn item_ty_poly(name: ident,
371-
span: span,
372-
ty: @ast::Ty,
379+
fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
373380
+params: ~[ast::ty_param]) -> @ast::item {
374381
self.item(name, span, ast::item_ty(ty, params))
375382
}
376383

377-
fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item {
384+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
378385
self.item_ty_poly(name, span, ty, ~[])
379386
}
380387

381-
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
388+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
382389
ty_params.map(|p| self.ty_path_ast_builder(
383390
path(~[p.ident], dummy_sp())))
384391
}
385392

386-
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
393+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
387394
ty_params.map(|p| self.ty_path_ast_builder(
388395
path(~[p.ident], dummy_sp())))
389396
}

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)