Skip to content

Commit 0f996f7

Browse files
committed
Remove purity from fn_decl and move it out to containing AST elements.
1 parent 34886ed commit 0f996f7

27 files changed

+208
-192
lines changed

src/libsyntax/ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ type ty_field_ = {ident: ident, mt: mt};
531531
type ty_field = spanned<ty_field_>;
532532

533533
#[auto_serialize]
534-
type ty_method = {ident: ident, attrs: ~[attribute],
534+
type ty_method = {ident: ident, attrs: ~[attribute], purity: purity,
535535
decl: fn_decl, tps: ~[ty_param], self_ty: self_ty,
536536
id: node_id, span: span};
537537

@@ -582,7 +582,7 @@ enum ty_ {
582582
ty_ptr(mt),
583583
ty_rptr(@region, mt),
584584
ty_rec(~[ty_field]),
585-
ty_fn(proto, @~[ty_param_bound], fn_decl),
585+
ty_fn(proto, purity, @~[ty_param_bound], fn_decl),
586586
ty_tup(~[@ty]),
587587
ty_path(@path, node_id),
588588
ty_fixed_length(@ty, option<uint>),
@@ -600,7 +600,6 @@ type arg = {mode: mode, ty: @ty, ident: ident, id: node_id};
600600
type fn_decl =
601601
{inputs: ~[arg],
602602
output: @ty,
603-
purity: purity,
604603
cf: ret_style};
605604

606605
#[auto_serialize]
@@ -633,7 +632,8 @@ type self_ty = spanned<self_ty_>;
633632

634633
#[auto_serialize]
635634
type method = {ident: ident, attrs: ~[attribute],
636-
tps: ~[ty_param], self_ty: self_ty, decl: fn_decl, body: blk,
635+
tps: ~[ty_param], self_ty: self_ty,
636+
purity: purity, decl: fn_decl, body: blk,
637637
id: node_id, span: span, self_id: node_id,
638638
vis: visibility}; // always public, unless it's a
639639
// class method
@@ -775,7 +775,7 @@ type item = {ident: ident, attrs: ~[attribute],
775775
#[auto_serialize]
776776
enum item_ {
777777
item_const(@ty, @expr),
778-
item_fn(fn_decl, ~[ty_param], blk),
778+
item_fn(fn_decl, purity, ~[ty_param], blk),
779779
item_mod(_mod),
780780
item_foreign_mod(foreign_mod),
781781
item_ty(@ty, ~[ty_param]),
@@ -821,7 +821,7 @@ type foreign_item =
821821

822822
#[auto_serialize]
823823
enum foreign_item_ {
824-
foreign_item_fn(fn_decl, ~[ty_param]),
824+
foreign_item_fn(fn_decl, purity, ~[ty_param]),
825825
}
826826

827827
// The data we save and restore about an inlined item or method. This is not

src/libsyntax/ast_util.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ fn trait_method_to_ty_method(method: trait_method) -> ty_method {
311311
required(m) => m,
312312
provided(m) => {
313313
{ident: m.ident, attrs: m.attrs,
314-
decl: m.decl, tps: m.tps, self_ty: m.self_ty,
314+
purity: m.purity, decl: m.decl,
315+
tps: m.tps, self_ty: m.self_ty,
315316
id: m.id, span: m.span}
316317
}
317318
}
@@ -411,7 +412,7 @@ fn dtor_dec() -> fn_decl {
411412
{inputs: ~[{mode: ast::expl(ast::by_ref),
412413
ty: nil_t, ident: parse::token::special_idents::underscore,
413414
id: 0}],
414-
output: nil_t, purity: impure_fn, cf: return_val}
415+
output: nil_t, cf: return_val}
415416
}
416417

417418
// ______________________________________________________________________
@@ -515,7 +516,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
515516
vfn(self_id);
516517
vfn(parent_id.node);
517518
}
518-
visit::fk_item_fn(_, tps) => {
519+
visit::fk_item_fn(_, tps, _) => {
519520
vec::iter(tps, |tp| vfn(tp.id));
520521
}
521522
visit::fk_method(_, tps, m) => {

src/libsyntax/ext/auto_serialize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ impl ext_ctxt: ext_ctxt_helpers {
191191

192192
@{id: self.next_id(),
193193
node: ast::ty_fn(ast::proto_block,
194+
ast::impure_fn,
194195
@~[],
195196
{inputs: args,
196197
output: output,
197-
purity: ast::impure_fn,
198198
cf: ast::return_val}),
199199
span: span}
200200
}
@@ -604,8 +604,8 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
604604
id: cx.next_id(),
605605
node: ast::item_fn({inputs: ser_inputs,
606606
output: ser_output,
607-
purity: ast::impure_fn,
608607
cf: ast::return_val},
608+
ast::impure_fn,
609609
ser_tps,
610610
ser_blk),
611611
vis: ast::public,
@@ -810,8 +810,8 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
810810
id: cx.next_id(),
811811
node: ast::item_fn({inputs: deser_inputs,
812812
output: v_ty,
813-
purity: ast::impure_fn,
814813
cf: ast::return_val},
814+
ast::impure_fn,
815815
deser_tps,
816816
deser_blk),
817817
vis: ast::public,

src/libsyntax/ext/pipes/ast_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ impl ext_ctxt: ext_ctxt_ast_builder {
203203
output: @ast::ty) -> ast::fn_decl {
204204
{inputs: inputs,
205205
output: output,
206-
purity: ast::impure_fn,
207206
cf: ast::return_val}
208207
}
209208

@@ -226,6 +225,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
226225
self.item(name,
227226
self.empty_span(),
228227
ast::item_fn(self.fn_decl(inputs, output),
228+
ast::impure_fn,
229229
ty_params,
230230
body))
231231
}

src/libsyntax/fold.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
127127
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
128128
return {inputs: vec::map(decl.inputs, |x| fold_arg_(x, fld) ),
129129
output: fld.fold_ty(decl.output),
130-
purity: decl.purity,
131130
cf: decl.cf}
132131
}
133132

@@ -190,12 +189,12 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
190189
attrs: vec::map(ni.attrs, fold_attribute),
191190
node:
192191
match ni.node {
193-
foreign_item_fn(fdec, typms) => {
192+
foreign_item_fn(fdec, purity, typms) => {
194193
foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
195-
output: fld.fold_ty(fdec.output),
196-
purity: fdec.purity,
197-
cf: fdec.cf},
198-
fold_ty_params(typms, fld))
194+
output: fld.fold_ty(fdec.output),
195+
cf: fdec.cf},
196+
purity,
197+
fold_ty_params(typms, fld))
199198
}
200199
},
201200
id: fld.new_id(ni.id),
@@ -224,8 +223,9 @@ fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold)
224223
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
225224
return match i {
226225
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
227-
item_fn(decl, typms, body) => {
226+
item_fn(decl, purity, typms, body) => {
228227
item_fn(fold_fn_decl(decl, fld),
228+
purity,
229229
fold_ty_params(typms, fld),
230230
fld.fold_block(body))
231231
}
@@ -314,6 +314,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
314314
attrs: /* FIXME (#2543) */ copy m.attrs,
315315
tps: fold_ty_params(m.tps, fld),
316316
self_ty: m.self_ty,
317+
purity: m.purity,
317318
decl: fold_fn_decl(m.decl, fld),
318319
body: fld.fold_block(m.body),
319320
id: fld.new_id(m.id),
@@ -531,10 +532,11 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
531532
ty_ptr(mt) => ty_ptr(fold_mt(mt, fld)),
532533
ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)),
533534
ty_rec(fields) => ty_rec(vec::map(fields, |f| fold_field(f, fld))),
534-
ty_fn(proto, bounds, decl) =>
535-
ty_fn(proto, @vec::map(*bounds,
536-
|x| fold_ty_param_bound(x, fld)),
537-
fold_fn_decl(decl, fld)),
535+
ty_fn(proto, purity, bounds, decl) =>
536+
ty_fn(proto, purity,
537+
@vec::map(*bounds,
538+
|x| fold_ty_param_bound(x, fld)),
539+
fold_fn_decl(decl, fld)),
538540
ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(ty))),
539541
ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)),
540542
ty_fixed_length(t, vs) => ty_fixed_length(fld.fold_ty(t), vs),

src/libsyntax/parse/parser.rs

+29-35
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ struct parser {
285285
proto = self.parse_fn_ty_proto();
286286
bounds = self.parse_optional_ty_param_bounds();
287287
};
288-
ty_fn(proto, bounds, self.parse_ty_fn_decl(purity))
288+
ty_fn(proto, purity, bounds, self.parse_ty_fn_decl())
289289
}
290290

291-
fn parse_ty_fn_decl(purity: ast::purity) -> fn_decl {
291+
fn parse_ty_fn_decl() -> fn_decl {
292292
let inputs = do self.parse_unspanned_seq(
293293
token::LPAREN, token::RPAREN,
294294
seq_sep_trailing_disallowed(token::COMMA)) |p| {
@@ -297,7 +297,7 @@ struct parser {
297297
};
298298
let (ret_style, ret_ty) = self.parse_ret_ty();
299299
return {inputs: inputs, output: ret_ty,
300-
purity: purity, cf: ret_style};
300+
cf: ret_style};
301301
}
302302

303303
fn parse_trait_methods() -> ~[trait_method] {
@@ -316,7 +316,7 @@ struct parser {
316316

317317
let tps = p.parse_ty_params();
318318

319-
let (self_ty, d, _) = do self.parse_fn_decl_with_self(pur) |p| {
319+
let (self_ty, d, _) = do self.parse_fn_decl_with_self() |p| {
320320
// This is somewhat dubious; We don't want to allow argument
321321
// names to be left off if there is a definition...
322322
either::Left(p.parse_arg_general(false))
@@ -335,7 +335,7 @@ struct parser {
335335
// NB: at the moment, visibility annotations on required
336336
// methods are ignored; this could change.
337337
required({ident: ident, attrs: attrs,
338-
decl: {purity: pur with d}, tps: tps,
338+
purity: pur, decl: d, tps: tps,
339339
self_ty: self_ty,
340340
id: p.get_id(), span: mk_sp(lo, hi)})
341341
}
@@ -348,6 +348,7 @@ struct parser {
348348
attrs: attrs,
349349
tps: tps,
350350
self_ty: self_ty,
351+
purity: pur,
351352
decl: d,
352353
body: body,
353354
id: p.get_id(),
@@ -518,7 +519,7 @@ struct parser {
518519
self.parse_ty_fn(ast::impure_fn)
519520
} else if self.eat_keyword(~"extern") {
520521
self.expect_keyword(~"fn");
521-
ty_fn(proto_bare, @~[], self.parse_ty_fn_decl(ast::impure_fn))
522+
ty_fn(proto_bare, ast::impure_fn, @~[], self.parse_ty_fn_decl())
522523
} else if self.token == token::MOD_SEP || is_ident(self.token) {
523524
let path = self.parse_path_with_tps(colons_before_params);
524525
ty_path(path, self.get_id())
@@ -1492,8 +1493,7 @@ struct parser {
14921493
// if we want to allow fn expression argument types to be inferred in
14931494
// the future, just have to change parse_arg to parse_fn_block_arg.
14941495
let (decl, capture_clause) =
1495-
self.parse_fn_decl(impure_fn,
1496-
|p| p.parse_arg_or_capture_item());
1496+
self.parse_fn_decl(|p| p.parse_arg_or_capture_item());
14971497

14981498
let body = self.parse_block();
14991499
return self.mk_expr(lo, body.span.hi,
@@ -1518,7 +1518,6 @@ struct parser {
15181518
node: ty_infer,
15191519
span: self.span
15201520
},
1521-
purity: impure_fn,
15221521
cf: return_val
15231522
}
15241523
},
@@ -2281,8 +2280,7 @@ struct parser {
22812280
} else { ~[] }
22822281
}
22832282

2284-
fn parse_fn_decl(purity: purity,
2285-
parse_arg_fn: fn(parser) -> arg_or_capture_item)
2283+
fn parse_fn_decl(parse_arg_fn: fn(parser) -> arg_or_capture_item)
22862284
-> (fn_decl, capture_clause) {
22872285

22882286
let args_or_capture_items: ~[arg_or_capture_item] =
@@ -2295,9 +2293,8 @@ struct parser {
22952293

22962294
let (ret_style, ret_ty) = self.parse_ret_ty();
22972295
return ({inputs: inputs,
2298-
output: ret_ty,
2299-
purity: purity,
2300-
cf: ret_style}, capture_clause);
2296+
output: ret_ty,
2297+
cf: ret_style}, capture_clause);
23012298
}
23022299

23032300
fn is_self_ident() -> bool {
@@ -2316,8 +2313,7 @@ struct parser {
23162313
self.bump();
23172314
}
23182315

2319-
fn parse_fn_decl_with_self(purity: purity,
2320-
parse_arg_fn:
2316+
fn parse_fn_decl_with_self(parse_arg_fn:
23212317
fn(parser) -> arg_or_capture_item)
23222318
-> (self_ty, fn_decl, capture_clause) {
23232319

@@ -2401,7 +2397,6 @@ struct parser {
24012397
let fn_decl = {
24022398
inputs: inputs,
24032399
output: ret_ty,
2404-
purity: purity,
24052400
cf: ret_style
24062401
};
24072402

@@ -2425,10 +2420,9 @@ struct parser {
24252420
@{id: self.get_id(), node: ty_infer, span: self.span}
24262421
};
24272422
return ({inputs: either::lefts(inputs_captures),
2428-
output: output,
2429-
purity: impure_fn,
2430-
cf: return_val},
2431-
@either::rights(inputs_captures));
2423+
output: output,
2424+
cf: return_val},
2425+
@either::rights(inputs_captures));
24322426
}
24332427

24342428
fn parse_fn_header() -> {ident: ident, tps: ~[ty_param]} {
@@ -2450,9 +2444,9 @@ struct parser {
24502444

24512445
fn parse_item_fn(purity: purity) -> item_info {
24522446
let t = self.parse_fn_header();
2453-
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
2447+
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
24542448
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
2455-
(t.ident, item_fn(decl, t.tps, body), some(inner_attrs))
2449+
(t.ident, item_fn(decl, purity, t.tps, body), some(inner_attrs))
24562450
}
24572451

24582452
fn parse_method_name() -> ident {
@@ -2469,7 +2463,7 @@ struct parser {
24692463
let pur = self.parse_fn_purity();
24702464
let ident = self.parse_method_name();
24712465
let tps = self.parse_ty_params();
2472-
let (self_ty, decl, _) = do self.parse_fn_decl_with_self(pur) |p| {
2466+
let (self_ty, decl, _) = do self.parse_fn_decl_with_self() |p| {
24732467
p.parse_arg()
24742468
};
24752469
// XXX: interaction between staticness, self_ty is broken now
@@ -2478,7 +2472,7 @@ struct parser {
24782472
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
24792473
let attrs = vec::append(attrs, inner_attrs);
24802474
@{ident: ident, attrs: attrs,
2481-
tps: tps, self_ty: self_ty, decl: decl,
2475+
tps: tps, self_ty: self_ty, purity: pur, decl: decl,
24822476
body: body, id: self.get_id(), span: mk_sp(lo, body.span.hi),
24832477
self_id: self.get_id(), vis: pr}
24842478
}
@@ -2717,7 +2711,7 @@ struct parser {
27172711
fn parse_ctor(attrs: ~[attribute],
27182712
result_ty: ast::ty_) -> class_contents {
27192713
let lo = self.last_span.lo;
2720-
let (decl_, _) = self.parse_fn_decl(impure_fn, |p| p.parse_arg());
2714+
let (decl_, _) = self.parse_fn_decl(|p| p.parse_arg());
27212715
let decl = {output: @{id: self.get_id(),
27222716
node: result_ty, span: decl_.output.span}
27232717
with decl_};
@@ -2837,18 +2831,18 @@ struct parser {
28372831
(id, item_mod(m), some(inner_attrs.inner))
28382832
}
28392833

2840-
fn parse_item_foreign_fn(+attrs: ~[attribute],
2841-
purity: purity) -> @foreign_item {
2842-
let lo = self.last_span.lo;
2834+
fn parse_item_foreign_fn(+attrs: ~[attribute]) -> @foreign_item {
2835+
let lo = self.span.lo;
2836+
let purity = self.parse_fn_purity();
28432837
let t = self.parse_fn_header();
2844-
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
2838+
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
28452839
let mut hi = self.span.hi;
28462840
self.expect(token::SEMI);
28472841
return @{ident: t.ident,
2848-
attrs: attrs,
2849-
node: foreign_item_fn(decl, t.tps),
2850-
id: self.get_id(),
2851-
span: mk_sp(lo, hi)};
2842+
attrs: attrs,
2843+
node: foreign_item_fn(decl, purity, t.tps),
2844+
id: self.get_id(),
2845+
span: mk_sp(lo, hi)};
28522846
}
28532847

28542848
fn parse_fn_purity() -> purity {
@@ -2865,7 +2859,7 @@ struct parser {
28652859

28662860
fn parse_foreign_item(+attrs: ~[attribute]) ->
28672861
@foreign_item {
2868-
self.parse_item_foreign_fn(attrs, self.parse_fn_purity())
2862+
self.parse_item_foreign_fn(attrs)
28692863
}
28702864

28712865
fn parse_foreign_mod_items(+first_item_attrs: ~[attribute]) ->

0 commit comments

Comments
 (0)