Skip to content

Commit

Permalink
Remove purity from fn_decl and move it out to containing AST elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Aug 24, 2012
1 parent 34886ed commit 0f996f7
Show file tree
Hide file tree
Showing 27 changed files with 208 additions and 192 deletions.
12 changes: 6 additions & 6 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ type ty_field_ = {ident: ident, mt: mt};
type ty_field = spanned<ty_field_>;

#[auto_serialize]
type ty_method = {ident: ident, attrs: ~[attribute],
type ty_method = {ident: ident, attrs: ~[attribute], purity: purity,
decl: fn_decl, tps: ~[ty_param], self_ty: self_ty,
id: node_id, span: span};

Expand Down Expand Up @@ -582,7 +582,7 @@ enum ty_ {
ty_ptr(mt),
ty_rptr(@region, mt),
ty_rec(~[ty_field]),
ty_fn(proto, @~[ty_param_bound], fn_decl),
ty_fn(proto, purity, @~[ty_param_bound], fn_decl),
ty_tup(~[@ty]),
ty_path(@path, node_id),
ty_fixed_length(@ty, option<uint>),
Expand All @@ -600,7 +600,6 @@ type arg = {mode: mode, ty: @ty, ident: ident, id: node_id};
type fn_decl =
{inputs: ~[arg],
output: @ty,
purity: purity,
cf: ret_style};

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

#[auto_serialize]
type method = {ident: ident, attrs: ~[attribute],
tps: ~[ty_param], self_ty: self_ty, decl: fn_decl, body: blk,
tps: ~[ty_param], self_ty: self_ty,
purity: purity, decl: fn_decl, body: blk,
id: node_id, span: span, self_id: node_id,
vis: visibility}; // always public, unless it's a
// class method
Expand Down Expand Up @@ -775,7 +775,7 @@ type item = {ident: ident, attrs: ~[attribute],
#[auto_serialize]
enum item_ {
item_const(@ty, @expr),
item_fn(fn_decl, ~[ty_param], blk),
item_fn(fn_decl, purity, ~[ty_param], blk),
item_mod(_mod),
item_foreign_mod(foreign_mod),
item_ty(@ty, ~[ty_param]),
Expand Down Expand Up @@ -821,7 +821,7 @@ type foreign_item =

#[auto_serialize]
enum foreign_item_ {
foreign_item_fn(fn_decl, ~[ty_param]),
foreign_item_fn(fn_decl, purity, ~[ty_param]),
}

// The data we save and restore about an inlined item or method. This is not
Expand Down
7 changes: 4 additions & 3 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ fn trait_method_to_ty_method(method: trait_method) -> ty_method {
required(m) => m,
provided(m) => {
{ident: m.ident, attrs: m.attrs,
decl: m.decl, tps: m.tps, self_ty: m.self_ty,
purity: m.purity, decl: m.decl,
tps: m.tps, self_ty: m.self_ty,
id: m.id, span: m.span}
}
}
Expand Down Expand Up @@ -411,7 +412,7 @@ fn dtor_dec() -> fn_decl {
{inputs: ~[{mode: ast::expl(ast::by_ref),
ty: nil_t, ident: parse::token::special_idents::underscore,
id: 0}],
output: nil_t, purity: impure_fn, cf: return_val}
output: nil_t, cf: return_val}
}

// ______________________________________________________________________
Expand Down Expand Up @@ -515,7 +516,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
vfn(self_id);
vfn(parent_id.node);
}
visit::fk_item_fn(_, tps) => {
visit::fk_item_fn(_, tps, _) => {
vec::iter(tps, |tp| vfn(tp.id));
}
visit::fk_method(_, tps, m) => {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/auto_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ impl ext_ctxt: ext_ctxt_helpers {

@{id: self.next_id(),
node: ast::ty_fn(ast::proto_block,
ast::impure_fn,
@~[],
{inputs: args,
output: output,
purity: ast::impure_fn,
cf: ast::return_val}),
span: span}
}
Expand Down Expand Up @@ -604,8 +604,8 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
id: cx.next_id(),
node: ast::item_fn({inputs: ser_inputs,
output: ser_output,
purity: ast::impure_fn,
cf: ast::return_val},
ast::impure_fn,
ser_tps,
ser_blk),
vis: ast::public,
Expand Down Expand Up @@ -810,8 +810,8 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
id: cx.next_id(),
node: ast::item_fn({inputs: deser_inputs,
output: v_ty,
purity: ast::impure_fn,
cf: ast::return_val},
ast::impure_fn,
deser_tps,
deser_blk),
vis: ast::public,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/pipes/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ impl ext_ctxt: ext_ctxt_ast_builder {
output: @ast::ty) -> ast::fn_decl {
{inputs: inputs,
output: output,
purity: ast::impure_fn,
cf: ast::return_val}
}

Expand All @@ -226,6 +225,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
self.item(name,
self.empty_span(),
ast::item_fn(self.fn_decl(inputs, output),
ast::impure_fn,
ty_params,
body))
}
Expand Down
24 changes: 13 additions & 11 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
return {inputs: vec::map(decl.inputs, |x| fold_arg_(x, fld) ),
output: fld.fold_ty(decl.output),
purity: decl.purity,
cf: decl.cf}
}

Expand Down Expand Up @@ -190,12 +189,12 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
attrs: vec::map(ni.attrs, fold_attribute),
node:
match ni.node {
foreign_item_fn(fdec, typms) => {
foreign_item_fn(fdec, purity, typms) => {
foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
output: fld.fold_ty(fdec.output),
purity: fdec.purity,
cf: fdec.cf},
fold_ty_params(typms, fld))
output: fld.fold_ty(fdec.output),
cf: fdec.cf},
purity,
fold_ty_params(typms, fld))
}
},
id: fld.new_id(ni.id),
Expand Down Expand Up @@ -224,8 +223,9 @@ fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold)
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
return match i {
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
item_fn(decl, typms, body) => {
item_fn(decl, purity, typms, body) => {
item_fn(fold_fn_decl(decl, fld),
purity,
fold_ty_params(typms, fld),
fld.fold_block(body))
}
Expand Down Expand Up @@ -314,6 +314,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
attrs: /* FIXME (#2543) */ copy m.attrs,
tps: fold_ty_params(m.tps, fld),
self_ty: m.self_ty,
purity: m.purity,
decl: fold_fn_decl(m.decl, fld),
body: fld.fold_block(m.body),
id: fld.new_id(m.id),
Expand Down Expand Up @@ -531,10 +532,11 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
ty_ptr(mt) => ty_ptr(fold_mt(mt, fld)),
ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)),
ty_rec(fields) => ty_rec(vec::map(fields, |f| fold_field(f, fld))),
ty_fn(proto, bounds, decl) =>
ty_fn(proto, @vec::map(*bounds,
|x| fold_ty_param_bound(x, fld)),
fold_fn_decl(decl, fld)),
ty_fn(proto, purity, bounds, decl) =>
ty_fn(proto, purity,
@vec::map(*bounds,
|x| fold_ty_param_bound(x, fld)),
fold_fn_decl(decl, fld)),
ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(ty))),
ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)),
ty_fixed_length(t, vs) => ty_fixed_length(fld.fold_ty(t), vs),
Expand Down
64 changes: 29 additions & 35 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ struct parser {
proto = self.parse_fn_ty_proto();
bounds = self.parse_optional_ty_param_bounds();
};
ty_fn(proto, bounds, self.parse_ty_fn_decl(purity))
ty_fn(proto, purity, bounds, self.parse_ty_fn_decl())
}

fn parse_ty_fn_decl(purity: ast::purity) -> fn_decl {
fn parse_ty_fn_decl() -> fn_decl {
let inputs = do self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA)) |p| {
Expand All @@ -297,7 +297,7 @@ struct parser {
};
let (ret_style, ret_ty) = self.parse_ret_ty();
return {inputs: inputs, output: ret_ty,
purity: purity, cf: ret_style};
cf: ret_style};
}

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

let tps = p.parse_ty_params();

let (self_ty, d, _) = do self.parse_fn_decl_with_self(pur) |p| {
let (self_ty, d, _) = do self.parse_fn_decl_with_self() |p| {
// This is somewhat dubious; We don't want to allow argument
// names to be left off if there is a definition...
either::Left(p.parse_arg_general(false))
Expand All @@ -335,7 +335,7 @@ struct parser {
// NB: at the moment, visibility annotations on required
// methods are ignored; this could change.
required({ident: ident, attrs: attrs,
decl: {purity: pur with d}, tps: tps,
purity: pur, decl: d, tps: tps,
self_ty: self_ty,
id: p.get_id(), span: mk_sp(lo, hi)})
}
Expand All @@ -348,6 +348,7 @@ struct parser {
attrs: attrs,
tps: tps,
self_ty: self_ty,
purity: pur,
decl: d,
body: body,
id: p.get_id(),
Expand Down Expand Up @@ -518,7 +519,7 @@ struct parser {
self.parse_ty_fn(ast::impure_fn)
} else if self.eat_keyword(~"extern") {
self.expect_keyword(~"fn");
ty_fn(proto_bare, @~[], self.parse_ty_fn_decl(ast::impure_fn))
ty_fn(proto_bare, ast::impure_fn, @~[], self.parse_ty_fn_decl())
} else if self.token == token::MOD_SEP || is_ident(self.token) {
let path = self.parse_path_with_tps(colons_before_params);
ty_path(path, self.get_id())
Expand Down Expand Up @@ -1492,8 +1493,7 @@ struct parser {
// if we want to allow fn expression argument types to be inferred in
// the future, just have to change parse_arg to parse_fn_block_arg.
let (decl, capture_clause) =
self.parse_fn_decl(impure_fn,
|p| p.parse_arg_or_capture_item());
self.parse_fn_decl(|p| p.parse_arg_or_capture_item());

let body = self.parse_block();
return self.mk_expr(lo, body.span.hi,
Expand All @@ -1518,7 +1518,6 @@ struct parser {
node: ty_infer,
span: self.span
},
purity: impure_fn,
cf: return_val
}
},
Expand Down Expand Up @@ -2281,8 +2280,7 @@ struct parser {
} else { ~[] }
}

fn parse_fn_decl(purity: purity,
parse_arg_fn: fn(parser) -> arg_or_capture_item)
fn parse_fn_decl(parse_arg_fn: fn(parser) -> arg_or_capture_item)
-> (fn_decl, capture_clause) {

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

let (ret_style, ret_ty) = self.parse_ret_ty();
return ({inputs: inputs,
output: ret_ty,
purity: purity,
cf: ret_style}, capture_clause);
output: ret_ty,
cf: ret_style}, capture_clause);
}

fn is_self_ident() -> bool {
Expand All @@ -2316,8 +2313,7 @@ struct parser {
self.bump();
}

fn parse_fn_decl_with_self(purity: purity,
parse_arg_fn:
fn parse_fn_decl_with_self(parse_arg_fn:
fn(parser) -> arg_or_capture_item)
-> (self_ty, fn_decl, capture_clause) {

Expand Down Expand Up @@ -2401,7 +2397,6 @@ struct parser {
let fn_decl = {
inputs: inputs,
output: ret_ty,
purity: purity,
cf: ret_style
};

Expand All @@ -2425,10 +2420,9 @@ struct parser {
@{id: self.get_id(), node: ty_infer, span: self.span}
};
return ({inputs: either::lefts(inputs_captures),
output: output,
purity: impure_fn,
cf: return_val},
@either::rights(inputs_captures));
output: output,
cf: return_val},
@either::rights(inputs_captures));
}

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

fn parse_item_fn(purity: purity) -> item_info {
let t = self.parse_fn_header();
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
(t.ident, item_fn(decl, t.tps, body), some(inner_attrs))
(t.ident, item_fn(decl, purity, t.tps, body), some(inner_attrs))
}

fn parse_method_name() -> ident {
Expand All @@ -2469,7 +2463,7 @@ struct parser {
let pur = self.parse_fn_purity();
let ident = self.parse_method_name();
let tps = self.parse_ty_params();
let (self_ty, decl, _) = do self.parse_fn_decl_with_self(pur) |p| {
let (self_ty, decl, _) = do self.parse_fn_decl_with_self() |p| {
p.parse_arg()
};
// XXX: interaction between staticness, self_ty is broken now
Expand All @@ -2478,7 +2472,7 @@ struct parser {
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
let attrs = vec::append(attrs, inner_attrs);
@{ident: ident, attrs: attrs,
tps: tps, self_ty: self_ty, decl: decl,
tps: tps, self_ty: self_ty, purity: pur, decl: decl,
body: body, id: self.get_id(), span: mk_sp(lo, body.span.hi),
self_id: self.get_id(), vis: pr}
}
Expand Down Expand Up @@ -2717,7 +2711,7 @@ struct parser {
fn parse_ctor(attrs: ~[attribute],
result_ty: ast::ty_) -> class_contents {
let lo = self.last_span.lo;
let (decl_, _) = self.parse_fn_decl(impure_fn, |p| p.parse_arg());
let (decl_, _) = self.parse_fn_decl(|p| p.parse_arg());
let decl = {output: @{id: self.get_id(),
node: result_ty, span: decl_.output.span}
with decl_};
Expand Down Expand Up @@ -2837,18 +2831,18 @@ struct parser {
(id, item_mod(m), some(inner_attrs.inner))
}

fn parse_item_foreign_fn(+attrs: ~[attribute],
purity: purity) -> @foreign_item {
let lo = self.last_span.lo;
fn parse_item_foreign_fn(+attrs: ~[attribute]) -> @foreign_item {
let lo = self.span.lo;
let purity = self.parse_fn_purity();
let t = self.parse_fn_header();
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
let mut hi = self.span.hi;
self.expect(token::SEMI);
return @{ident: t.ident,
attrs: attrs,
node: foreign_item_fn(decl, t.tps),
id: self.get_id(),
span: mk_sp(lo, hi)};
attrs: attrs,
node: foreign_item_fn(decl, purity, t.tps),
id: self.get_id(),
span: mk_sp(lo, hi)};
}

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

fn parse_foreign_item(+attrs: ~[attribute]) ->
@foreign_item {
self.parse_item_foreign_fn(attrs, self.parse_fn_purity())
self.parse_item_foreign_fn(attrs)
}

fn parse_foreign_mod_items(+first_item_attrs: ~[attribute]) ->
Expand Down
Loading

0 comments on commit 0f996f7

Please sign in to comment.