Skip to content

Commit 9b9170f

Browse files
committed
rustc: Introduce the concept of inline to the AST
1 parent ad92595 commit 9b9170f

File tree

17 files changed

+104
-86
lines changed

17 files changed

+104
-86
lines changed

src/comp/front/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn fold_mod(cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod {
5959
// we want to be main.
6060
fn nomain(item: &@ast::item) -> option::t[@ast::item] {
6161
alt item.node {
62-
ast::item_fn(f, _) {
62+
ast::item_fn(f, _, _) {
6363
if item.ident == "main" {
6464
option::none
6565
} else { option::some(item) }
@@ -107,7 +107,7 @@ fn is_test_fn(i: &@ast::item) -> bool {
107107

108108
fn has_test_signature(i: &@ast::item) -> bool {
109109
alt i.node {
110-
ast::item_fn(f, tps) {
110+
ast::item_fn(f, tps, _) {
111111
let input_cnt = ivec::len(f.decl.inputs);
112112
let no_output = f.decl.output.node == ast::ty_nil;
113113
let tparm_cnt = ivec::len(tps);
@@ -191,7 +191,7 @@ fn mk_tests(cx: &test_ctxt) -> @ast::item {
191191

192192
let fn_ = {decl: decl, proto: proto, body: body};
193193

194-
let item_ = ast::item_fn(fn_, ~[]);
194+
let item_ = ast::item_fn(fn_, ~[], ast::il_normal);
195195
let item: ast::item =
196196
{ident: "tests",
197197
attrs: ~[],
@@ -309,7 +309,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item {
309309

310310
let fn_ = {decl: decl, proto: proto, body: body};
311311

312-
let item_ = ast::item_fn(fn_, ~[]);
312+
let item_ = ast::item_fn(fn_, ~[], ast::il_normal);
313313
let item: ast::item =
314314
{ident: "main",
315315
attrs: ~[],

src/comp/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn encode_module_item_paths(ebml_w: &ebmlivec::writer, module: &_mod,
8181
encode_def_id(ebml_w, local_def(it.id));
8282
ebmlivec::end_tag(ebml_w);
8383
}
84-
item_fn(_, tps) {
84+
item_fn(_, tps, _) {
8585
add_to_index(ebml_w, path, index, it.ident);
8686
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
8787
encode_name(ebml_w, it.ident);
@@ -250,7 +250,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
250250
encode_symbol(ecx, ebml_w, item.id);
251251
ebmlivec::end_tag(ebml_w);
252252
}
253-
item_fn(fd, tps) {
253+
item_fn(fd, tps, _) {
254254
ebmlivec::start_tag(ebml_w, tag_items_data_item);
255255
encode_def_id(ebml_w, local_def(item.id));
256256
encode_family(ebml_w,

src/comp/middle/alias.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ast::ident;
44
import ast::fn_ident;
55
import ast::node_id;
66
import ast::def_id;
7+
import ast::inlineness;
78
import syntax::codemap::span;
89
import syntax::visit;
910
import visit::vt;
@@ -42,7 +43,7 @@ fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) {
4243
// Stores information about object fields and function
4344
// arguments that's otherwise not easily available.
4445
let cx = @{tcx: tcx, local_map: std::map::new_int_hash()};
45-
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
46+
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _, _),
4647
visit_item: bind visit_item(cx, _, _, _),
4748
visit_expr: bind visit_expr(cx, _, _, _),
4849
visit_decl: bind visit_decl(cx, _, _, _)
@@ -51,8 +52,9 @@ fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) {
5152
tcx.sess.abort_if_errors();
5253
}
5354

54-
fn visit_fn(cx: &@ctx, f: &ast::_fn, tp: &ast::ty_param[], sp: &span,
55-
name: &fn_ident, id: ast::node_id, sc: &scope, v: &vt[scope]) {
55+
fn visit_fn(cx: &@ctx, f: &ast::_fn, tp: &ast::ty_param[], il: inlineness,
56+
sp: &span, name: &fn_ident, id: ast::node_id, sc: &scope,
57+
v: &vt[scope]) {
5658
visit::visit_fn_decl(f.decl, sc, v);
5759
for arg_: ast::arg in f.decl.inputs {
5860
cx.local_map.insert(arg_.id, arg(arg_.mode));

src/comp/middle/freevars.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import std::option;
88
import std::int;
99
import std::option::*;
1010
import syntax::ast;
11+
import syntax::ast::inlineness;
1112
import syntax::visit;
1213
import driver::session;
1314
import middle::resolve;
@@ -45,8 +46,8 @@ fn collect_freevars(def_map: &resolve::def_map, sess: &session::session,
4546
for decl: ast::node_id in initial_decls { set_add(decls, decl); }
4647
let refs = @mutable ~[];
4748

48-
let walk_fn = lambda(f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
49-
i: &ast::fn_ident, nid: ast::node_id) {
49+
let walk_fn = lambda(f: &ast::_fn, tps: &ast::ty_param[], il: inlineness,
50+
sp: &span, i: &ast::fn_ident, nid: ast::node_id) {
5051
for a: ast::arg in f.decl.inputs { set_add(decls, a.id); }
5152
};
5253
let walk_expr = lambda(expr: &@ast::expr) {
@@ -107,10 +108,10 @@ fn annotate_freevars(sess: &session::session, def_map: &resolve::def_map,
107108
crate: &@ast::crate) -> freevar_map {
108109
let freevars = new_int_hash();
109110

110-
let walk_fn = lambda(f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
111-
i: &ast::fn_ident, nid: ast::node_id) {
111+
let walk_fn = lambda(f: &ast::_fn, tps: &ast::ty_param[], il: inlineness,
112+
sp: &span, i: &ast::fn_ident, nid: ast::node_id) {
112113
let start_walk = lambda(v: &visit::vt[()]) {
113-
v.visit_fn(f, tps, sp, i, nid, (), v);
114+
v.visit_fn(f, tps, il, sp, i, nid, (), v);
114115
};
115116
let vars = collect_freevars(def_map, sess, start_walk, ~[]);
116117
freevars.insert(nid, vars);

src/comp/middle/resolve.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ast::def;
77
import ast::def_id;
88
import ast::node_id;
99
import ast::local_def;
10+
import ast::inlineness;
1011

1112
import metadata::csearch;
1213
import metadata::cstore;
@@ -259,7 +260,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
259260
visit_expr: bind walk_expr(e, _, _, _),
260261
visit_ty: bind walk_ty(e, _, _, _),
261262
visit_constr: bind walk_constr(e, _, _, _, _, _),
262-
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
263+
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
263264
with *visit::default_visitor()};
264265
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
265266
e.sess.abort_if_errors();
@@ -328,8 +329,8 @@ fn visit_native_item_with_scope(ni: &@ast::native_item, sc: &scopes,
328329
}
329330

330331
fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &ast::ty_param[],
331-
sp: &span, name: &fn_ident, id: node_id, sc: &scopes,
332-
v: &vt[scopes]) {
332+
il: inlineness, sp: &span, name: &fn_ident,
333+
id: node_id, sc: &scopes, v: &vt[scopes]) {
333334
// is this a main fn declaration?
334335
alt name {
335336
some(nm) {
@@ -348,7 +349,7 @@ fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &ast::ty_param[],
348349
for c: @ast::constr in f.decl.constraints {
349350
resolve_constr(e, id, c, sc, v);
350351
}
351-
visit::visit_fn(f, tp, sp, name, id,
352+
visit::visit_fn(f, tp, il, sp, name, id,
352353
cons(scope_fn(f.decl, f.proto, tp), @sc), v);
353354
}
354355

@@ -824,7 +825,7 @@ fn found_def_item(i: &@ast::item, ns: namespace) -> option::t[def] {
824825
ast::item_const(_, _) {
825826
if ns == ns_value { ret some(ast::def_const(local_def(i.id))); }
826827
}
827-
ast::item_fn(f, _) {
828+
ast::item_fn(f, _, _) {
828829
if ns == ns_value {
829830
ret some(ast::def_fn(local_def(i.id), f.decl.purity));
830831
}
@@ -1082,7 +1083,7 @@ fn index_mod(md: &ast::_mod) -> mod_index {
10821083
}
10831084
for it: @ast::item in md.items {
10841085
alt it.node {
1085-
ast::item_const(_, _) | ast::item_fn(_, _) | ast::item_mod(_) |
1086+
ast::item_const(_, _) | ast::item_fn(_, _, _) | ast::item_mod(_) |
10861087
ast::item_native_mod(_) | ast::item_ty(_, _) |
10871088
ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) {
10881089
add_to_index(index, it.ident, mie_item(it));
@@ -1218,7 +1219,7 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt[()]) {
12181219
}
12191220
visit::visit_item(i, x, v);
12201221
alt i.node {
1221-
ast::item_fn(f, ty_params) {
1222+
ast::item_fn(f, ty_params, _) {
12221223
check_fn(*e, i.span, f);
12231224
ensure_unique(*e, i.span, typaram_names(ty_params),
12241225
ident_id, "type parameter");
@@ -1302,7 +1303,7 @@ fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt[()]) {
13021303
ast::item_mod(_) | ast::item_native_mod(_) {
13031304
add_name(mods, it.span, it.ident);
13041305
}
1305-
ast::item_const(_, _) | ast::item_fn(_, _) {
1306+
ast::item_const(_, _) | ast::item_fn(_, _, _) {
13061307
add_name(values, it.span, it.ident);
13071308
}
13081309
ast::item_ty(_, _) { add_name(types, it.span, it.ident); }

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7329,7 +7329,7 @@ fn trans_const(cx: &@crate_ctxt, e: @ast::expr, id: ast::node_id) {
73297329

73307330
fn trans_item(cx: @local_ctxt, item: &ast::item) {
73317331
alt item.node {
7332-
ast::item_fn(f, tps) {
7332+
ast::item_fn(f, tps, _) {
73337333
let sub_cx = extend_path(cx, item.ident);
73347334
alt cx.ccx.item_ids.find(item.id) {
73357335
some(llfndecl) {
@@ -7740,7 +7740,7 @@ fn collect_item_2(ccx: &@crate_ctxt, i: &@ast::item, pt: &str[],
77407740
let new_pt = pt + item_path(i);
77417741
visit::visit_item(i, new_pt, v);
77427742
alt i.node {
7743-
ast::item_fn(f, tps) {
7743+
ast::item_fn(f, tps, _) {
77447744
if !ccx.obj_methods.contains_key(i.id) {
77457745
decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id);
77467746
}

src/comp/middle/tstate/annotate.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ fn collect_ids_local(l: &@local, rs: @mutable node_id[]) {
4747
*rs += pat_binding_ids(l.node.pat);
4848
}
4949

50-
fn node_ids_in_fn(f: &_fn, tps: &ty_param[], sp: &span, i: &fn_ident,
51-
id: node_id, rs: @mutable node_id[]) {
50+
fn node_ids_in_fn(f: &_fn, tps: &ty_param[], il: inlineness, sp: &span,
51+
i: &fn_ident, id: node_id, rs: @mutable node_id[]) {
5252
let collect_ids =
5353
visit::mk_simple_visitor(@{visit_expr: bind collect_ids_expr(_, rs),
5454
visit_block: bind collect_ids_block(_, rs),
5555
visit_stmt: bind collect_ids_stmt(_, rs),
5656
visit_local: bind collect_ids_local(_, rs)
5757
with *visit::default_simple_visitor()});
58-
visit::visit_fn(f, tps, sp, i, id, (), collect_ids);
58+
visit::visit_fn(f, tps, il, sp, i, id, (), collect_ids);
5959
}
6060

6161
fn init_vecs(ccx: &crate_ctxt, node_ids: &node_id[], len: uint) {
@@ -66,24 +66,25 @@ fn init_vecs(ccx: &crate_ctxt, node_ids: &node_id[], len: uint) {
6666
}
6767

6868
fn visit_fn(ccx: &crate_ctxt, num_constraints: uint, f: &_fn,
69-
tps: &ty_param[], sp: &span, i: &fn_ident, id: node_id) {
69+
tps: &ty_param[], il: inlineness, sp: &span, i: &fn_ident,
70+
id: node_id) {
7071
let node_ids: @mutable node_id[] = @mutable ~[];
71-
node_ids_in_fn(f, tps, sp, i, id, node_ids);
72+
node_ids_in_fn(f, tps, il, sp, i, id, node_ids);
7273
let node_id_vec = *node_ids;
7374
init_vecs(ccx, node_id_vec, num_constraints);
7475
}
7576

76-
fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &ty_param[], sp: &span,
77-
i: &fn_ident, id: node_id) {
77+
fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &ty_param[], il: inlineness,
78+
sp: &span, i: &fn_ident, id: node_id) {
7879
let f_info = get_fn_info(ccx, id);
79-
visit_fn(ccx, num_constraints(f_info), f, tps, sp, i, id);
80+
visit_fn(ccx, num_constraints(f_info), f, tps, il, sp, i, id);
8081
}
8182

8283
fn annotate_crate(ccx: &crate_ctxt, crate: &crate) {
8384
let do_ann =
8485
visit::mk_simple_visitor(@{visit_fn:
85-
bind annotate_in_fn(ccx, _, _, _, _, _)
86-
with *visit::default_simple_visitor()});
86+
bind annotate_in_fn(ccx, _, _, _, _, _, _)
87+
with *visit::default_simple_visitor()});
8788
visit::visit_crate(crate, (), do_ann);
8889
}
8990
//

src/comp/middle/tstate/auxiliary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,8 @@ fn op_to_oper_ty(io: init_op) -> oper_type {
10511051
}
10521052

10531053
// default function visitor
1054-
fn do_nothing[T](f: &_fn, tp: &ty_param[], sp: &span, i: &fn_ident,
1055-
iid: node_id, cx: &T, v: &visit::vt[T]) {
1054+
fn do_nothing[T](f: &_fn, tp: &ty_param[], il: inlineness, sp: &span,
1055+
i: &fn_ident, iid: node_id, cx: &T, v: &visit::vt[T]) {
10561056
}
10571057

10581058

src/comp/middle/tstate/ck.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ast::crate;
1717
import ast::return;
1818
import ast::noreturn;
1919
import ast::expr;
20+
import ast::inlineness;
2021
import syntax::visit;
2122
import syntax::codemap::span;
2223
import middle::ty::type_is_nil;
@@ -125,8 +126,8 @@ fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt[fn_ctxt]) {
125126
}
126127

127128
fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
128-
tps: &ast::ty_param[], id: node_id,
129-
sp: &span, i: &fn_ident) {
129+
tps: &ast::ty_param[], il: inlineness,
130+
id: node_id, sp: &span, i: &fn_ident) {
130131
/* Postorder traversal instead of pre is important
131132
because we want the smallest possible erroneous statement
132133
or expression. */
@@ -137,7 +138,7 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
137138
@{visit_stmt: check_states_stmt,
138139
visit_expr: check_states_expr,
139140
visit_fn: do_nothing with *visitor};
140-
visit::visit_fn(f, tps, sp, i, id, fcx, visit::mk_vt(visitor));
141+
visit::visit_fn(f, tps, il, sp, i, id, fcx, visit::mk_vt(visitor));
141142

142143
/* Check that the return value is initialized */
143144
let post = aux::block_poststate(fcx.ccx, f.body);
@@ -170,8 +171,8 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
170171
check_unused_vars(fcx);
171172
}
172173

173-
fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &ast::ty_param[], id: node_id,
174-
sp: &span, i: &fn_ident) {
174+
fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &ast::ty_param[],
175+
il: inlineness, id: node_id, sp: &span, i: &fn_ident) {
175176
/* Compute the pre- and post-states for this function */
176177

177178
// Fixpoint iteration
@@ -180,19 +181,20 @@ fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &ast::ty_param[], id: node_id,
180181
/* Now compare each expr's pre-state to its precondition
181182
and post-state to its postcondition */
182183

183-
check_states_against_conditions(fcx, f, tps, id, sp, i);
184+
check_states_against_conditions(fcx, f, tps, il, id, sp, i);
184185
}
185186

186-
fn fn_states(f: &_fn, tps: &ast::ty_param[], sp: &span, i: &fn_ident,
187-
id: node_id, ccx: &crate_ctxt, v: &visit::vt[crate_ctxt]) {
188-
visit::visit_fn(f, tps, sp, i, id, ccx, v);
187+
fn fn_states(f: &_fn, tps: &ast::ty_param[], il: inlineness, sp: &span,
188+
i: &fn_ident, id: node_id, ccx: &crate_ctxt,
189+
v: &visit::vt[crate_ctxt]) {
190+
visit::visit_fn(f, tps, il, sp, i, id, ccx, v);
189191
/* Look up the var-to-bit-num map for this function */
190192

191193
assert (ccx.fm.contains_key(id));
192194
let f_info = ccx.fm.get(id);
193195
let name = option::from_maybe("anon", i);
194196
let fcx = {enclosing: f_info, id: id, name: name, ccx: ccx};
195-
check_fn_states(fcx, f, tps, id, sp, i);
197+
check_fn_states(fcx, f, tps, il, id, sp, i);
196198
}
197199

198200
fn check_crate(cx: ty::ctxt, crate: @crate) {

src/comp/middle/tstate/collect_locals.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt[ctxt]) {
4343
visit::visit_expr(e, cx, v);
4444
}
4545

46-
fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &ty_param[], sp: &span,
47-
i: &fn_ident, id: node_id) -> ctxt {
46+
fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &ty_param[], il: inlineness,
47+
sp: &span, i: &fn_ident, id: node_id) -> ctxt {
4848
let cx: ctxt = {cs: @mutable ~[], tcx: tcx};
4949
let visitor = visit::default_visitor[ctxt]();
5050

5151
visitor =
5252
@{visit_local: collect_local,
5353
visit_expr: collect_pred,
5454
visit_fn: do_nothing with *visitor};
55-
visit::visit_fn(f, tps, sp, i, id, cx, visit::mk_vt(visitor));
55+
visit::visit_fn(f, tps, il, sp, i, id, cx, visit::mk_vt(visitor));
5656
ret cx;
5757
}
5858

@@ -88,13 +88,13 @@ fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map)
8888

8989
/* builds a table mapping each local var defined in f
9090
to a bit number in the precondition/postcondition vectors */
91-
fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &ty_param[], f_sp: &span,
92-
f_name: &fn_ident, id: node_id) {
91+
fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &ty_param[], il: inlineness,
92+
f_sp: &span, f_name: &fn_ident, id: node_id) {
9393
let name = fn_ident_to_string(id, f_name);
9494
let res_map = @new_def_hash[constraint]();
9595
let next: uint = 0u;
9696

97-
let cx: ctxt = find_locals(ccx.tcx, f, tp, f_sp, f_name, id);
97+
let cx: ctxt = find_locals(ccx.tcx, f, tp, il, f_sp, f_name, id);
9898
/* now we have to add bit nums for both the constraints
9999
and the variables... */
100100

@@ -144,7 +144,7 @@ fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &ty_param[], f_sp: &span,
144144
fn mk_f_to_fn_info(ccx: &crate_ctxt, c: @crate) {
145145
let visitor =
146146
visit::mk_simple_visitor(@{visit_fn:
147-
bind mk_fn_info(ccx, _, _, _, _, _)
147+
bind mk_fn_info(ccx, _, _, _, _, _, _)
148148
with *visit::default_simple_visitor()});
149149
visit::visit_crate(*c, (), visitor);
150150
}

0 commit comments

Comments
 (0)