Skip to content

Commit f8393cc

Browse files
marijnhgraydon
authored andcommitted
Add effect field to ast.ty_fn.
Still not used, except by the pretty-printer.
1 parent e7e6f39 commit f8393cc

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

src/comp/front/ast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ tag lit_ {
305305
type mt = rec(@ty ty, mutability mut);
306306
type ty_field = rec(ident ident, mt mt);
307307
type ty_arg = rec(mode mode, @ty ty);
308-
// TODO: effect
309-
type ty_method = rec(proto proto, ident ident,
308+
type ty_method = rec(effect effect, proto proto, ident ident,
310309
vec[ty_arg] inputs, @ty output);
311310
type ty = spanned[ty_];
312311
tag ty_ {
@@ -324,7 +323,7 @@ tag ty_ {
324323
ty_chan(@ty);
325324
ty_tup(vec[mt]);
326325
ty_rec(vec[ty_field]);
327-
ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
326+
ty_fn(effect, proto, vec[ty_arg], @ty);
328327
ty_obj(vec[ty_method]);
329328
ty_path(path, option.t[def]);
330329
ty_type;

src/comp/front/parser.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
184184
}
185185

186186

187-
impure fn parse_ty_fn(ast.proto proto, parser p,
187+
impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
188188
ast.span lo) -> ast.ty_ {
189189
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
190190
auto mode;
@@ -228,7 +228,7 @@ impure fn parse_ty_fn(ast.proto proto, parser p,
228228
output = @spanned(lo, inputs.span, ast.ty_nil);
229229
}
230230

231-
ret ast.ty_fn(proto, inputs.node, output);
231+
ret ast.ty_fn(eff, proto, inputs.node, output);
232232
}
233233

234234
impure fn parse_proto(parser p) -> ast.proto {
@@ -245,15 +245,14 @@ impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
245245
impure fn parse_method_sig(parser p) -> ast.ty_method {
246246
auto flo = p.get_span();
247247

248-
// FIXME: do something with this, currently it's dropped on the floor.
249248
let ast.effect eff = parse_effect(p);
250249
let ast.proto proto = parse_proto(p);
251250
auto ident = parse_ident(p);
252-
auto f = parse_ty_fn(proto, p, flo);
251+
auto f = parse_ty_fn(eff, proto, p, flo);
253252
expect(p, token.SEMI);
254253
alt (f) {
255-
case (ast.ty_fn(?proto, ?inputs, ?output)) {
256-
ret rec(proto=proto, ident=ident,
254+
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
255+
ret rec(effect=eff, proto=proto, ident=ident,
257256
inputs=inputs, output=output);
258257
}
259258
}
@@ -342,9 +341,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
342341
auto hi = lo;
343342
let ast.ty_ t;
344343

345-
// FIXME: do something with these; currently they're
346-
// dropped on the floor.
344+
// FIXME: make sure these are only used when valid
347345
let ast.effect eff = parse_effect(p);
346+
// FIXME: do something with this
348347
let ast.layer lyr = parse_layer(p);
349348

350349
alt (p.peek()) {
@@ -412,9 +411,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
412411
case (token.FN) {
413412
auto flo = p.get_span();
414413
p.bump();
415-
t = parse_ty_fn(ast.proto_fn, p, flo);
414+
t = parse_ty_fn(eff, ast.proto_fn, p, flo);
416415
alt (t) {
417-
case (ast.ty_fn(_, _, ?out)) {
416+
case (ast.ty_fn(_, _, _, ?out)) {
418417
hi = out.span;
419418
}
420419
}
@@ -423,9 +422,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
423422
case (token.ITER) {
424423
auto flo = p.get_span();
425424
p.bump();
426-
t = parse_ty_fn(ast.proto_iter, p, flo);
425+
t = parse_ty_fn(eff, ast.proto_iter, p, flo);
427426
alt (t) {
428-
case (ast.ty_fn(_, _, ?out)) {
427+
case (ast.ty_fn(_, _, _, ?out)) {
429428
hi = out.span;
430429
}
431430
}

src/comp/middle/fold.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type ast_fold[ENV] =
6060
vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
6161

6262
(fn(&ENV e, &span sp,
63+
ast.effect eff,
6364
ast.proto proto,
6465
vec[rec(ast.mode mode, @ty ty)] inputs,
6566
@ty output) -> @ty) fold_ty_fn,
@@ -388,13 +389,13 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
388389
case (ast.ty_obj(?meths)) {
389390
let vec[ast.ty_method] meths_ = vec();
390391
for (ast.ty_method m in meths) {
391-
auto tfn = fold_ty_fn(env_, fld, t.span, m.proto,
392+
auto tfn = fold_ty_fn(env_, fld, t.span, m.effect, m.proto,
392393
m.inputs, m.output);
393394
alt (tfn.node) {
394-
case (ast.ty_fn(?p, ?ins, ?out)) {
395+
case (ast.ty_fn(?eff, ?p, ?ins, ?out)) {
395396
_vec.push[ast.ty_method]
396-
(meths_, rec(proto=p, inputs=ins, output=out
397-
with m));
397+
(meths_, rec(effect=eff, proto=p, inputs=ins,
398+
output=out with m));
398399
}
399400
}
400401
}
@@ -406,8 +407,8 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
406407
ret fld.fold_ty_path(env_, t.span, pth_, ref_opt);
407408
}
408409

409-
case (ast.ty_fn(?proto, ?inputs, ?output)) {
410-
ret fold_ty_fn(env_, fld, t.span, proto, inputs, output);
410+
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
411+
ret fold_ty_fn(env_, fld, t.span, eff, proto, inputs, output);
411412
}
412413

413414
case (ast.ty_chan(?ty)) {
@@ -423,7 +424,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
423424
}
424425

425426
fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
426-
ast.proto proto,
427+
ast.effect eff, ast.proto proto,
427428
vec[rec(ast.mode mode, @ty ty)] inputs,
428429
@ty output) -> @ty {
429430
auto output_ = fold_ty(env, fld, output);
@@ -433,7 +434,7 @@ fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
433434
auto input_ = rec(ty=ty_ with input);
434435
inputs_ += vec(input_);
435436
}
436-
ret fld.fold_ty_fn(env, sp, proto, inputs_, output_);
437+
ret fld.fold_ty_fn(env, sp, eff, proto, inputs_, output_);
437438
}
438439

439440
fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
@@ -1131,10 +1132,10 @@ fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
11311132
}
11321133

11331134
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
1134-
ast.proto proto,
1135+
ast.effect eff, ast.proto proto,
11351136
vec[rec(ast.mode mode, @ty ty)] inputs,
11361137
@ty output) -> @ty {
1137-
ret @respan(sp, ast.ty_fn(proto, inputs, output));
1138+
ret @respan(sp, ast.ty_fn(eff, proto, inputs, output));
11381139
}
11391140

11401141
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
@@ -1569,7 +1570,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
15691570
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
15701571
fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_),
15711572
fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_),
1572-
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_),
1573+
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_,_),
15731574
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
15741575
fold_ty_chan = bind identity_fold_ty_chan[ENV](_,_,_),
15751576
fold_ty_port = bind identity_fold_ty_port[ENV](_,_,_),

src/comp/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
337337
sty = ty.ty_rec(flds);
338338
}
339339

340-
case (ast.ty_fn(?proto, ?inputs, ?output)) {
340+
case (ast.ty_fn(_, ?proto, ?inputs, ?output)) {
341341
auto f = bind ast_arg_to_arg(getter, _);
342342
auto i = _vec.map[ast.ty_arg, arg](f, inputs);
343343
sty = ty.ty_fn(proto, i, ast_ty_to_ty(getter, output));

src/comp/pretty/pprust.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ impure fn print_type(ps s, &@ast.ty ty) {
127127
bopen(s);
128128
for (ast.ty_method m in methods) {
129129
hbox(s);
130-
print_ty_fn(s, m.proto, option.some[str](m.ident),
130+
print_ty_fn(s, m.effect, m.proto, option.some[str](m.ident),
131131
m.inputs, m.output);
132132
wrd(s.s, ";");
133133
end(s.s);
134134
line(s.s);
135135
}
136136
bclose_c(s, ty.span);
137137
}
138-
case (ast.ty_fn(?proto,?inputs,?output)) {
139-
print_ty_fn(s, proto, option.none[str], inputs, output);
138+
case (ast.ty_fn(?eff, ?proto,?inputs,?output)) {
139+
print_ty_fn(s, eff, proto, option.none[str], inputs, output);
140140
}
141141
case (ast.ty_path(?path,_)) {
142142
print_path(s, path);
@@ -843,8 +843,13 @@ impure fn print_string(ps s, str st) {
843843
wrd(s.s, "\""); wrd(s.s, escape_str(st, '"')); wrd(s.s, "\"");
844844
}
845845

846-
impure fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
846+
impure fn print_ty_fn(ps s, ast.effect eff, ast.proto proto, option.t[str] id,
847847
vec[ast.ty_arg] inputs, @ast.ty output) {
848+
alt (eff) {
849+
case (ast.eff_impure) {wrd1(s, "impure");}
850+
case (ast.eff_unsafe) {wrd1(s, "unsafe");}
851+
case (_) {}
852+
}
848853
if (proto == ast.proto_fn) {wrd(s.s, "fn");}
849854
else {wrd(s.s, "iter");}
850855
alt (id) {

0 commit comments

Comments
 (0)