Skip to content

Commit 0698017

Browse files
committed
---
yaml --- r: 974 b: refs/heads/master c: 3e08171 h: refs/heads/master v: v3
1 parent bb1ce5f commit 0698017

File tree

7 files changed

+52
-76
lines changed

7 files changed

+52
-76
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 386f363cfea72899fa3c3f2a194d00819cdbe806
2+
refs/heads/master: 3e08171fc21f7fcc403aa315d8fb54f04c552841

trunk/src/boot/me/type.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ let check_block (cx:Semant.ctxt) : (fn_ctx -> Ast.block -> unit) =
910910
Array.iter check_stmt' block.Common.node
911911

912912
and check_stmt (stmt:Ast.stmt) : unit =
913+
try
914+
check_stmt_full stmt
915+
with
916+
Common.Semant_err (None, msg) ->
917+
raise (Common.Semant_err ((Some stmt.Common.id), msg))
918+
919+
and check_stmt_full (stmt:Ast.stmt) : unit =
913920
check_ret stmt;
914921
match stmt.Common.node with
915922
Ast.STMT_spawn (dst, _, _, callee, args) ->

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ tag ty_ {
152152
ty_str;
153153
ty_box(@ty);
154154
ty_vec(@ty);
155-
ty_tup(vec[tup(mutability, @ty)]);
155+
ty_tup(vec[@ty]);
156156
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
157157
ty_path(path, option.t[def]);
158158
ty_mutable(@ty);

trunk/src/comp/front/parser.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ impure fn parse_ident(parser p) -> ast.ident {
9696
}
9797
}
9898

99-
impure fn parse_possibly_mutable_ty(parser p)
100-
-> tup(ast.mutability, @ast.ty) {
101-
auto mut;
102-
if (p.peek() == token.MUTABLE) {
103-
p.bump();
104-
mut = ast.mut;
105-
} else {
106-
mut = ast.imm;
107-
}
108-
109-
ret tup(mut, parse_ty(p));
110-
}
111-
11299
impure fn parse_ty_fn(parser p) -> ast.ty_ {
113100
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
114101
auto mode;
@@ -192,11 +179,10 @@ impure fn parse_ty(parser p) -> @ast.ty {
192179

193180
case (token.TUP) {
194181
p.bump();
195-
auto f = parse_possibly_mutable_ty; // FIXME: trans_const_lval bug
196-
auto elems =
197-
parse_seq[tup(ast.mutability, @ast.ty)]
198-
(token.LPAREN,
199-
token.RPAREN, some(token.COMMA), f, p);
182+
auto f = parse_ty; // FIXME: trans_const_lval bug
183+
auto elems = parse_seq[@ast.ty] (token.LPAREN,
184+
token.RPAREN,
185+
some(token.COMMA), f, p);
200186
hi = p.get_span();
201187
t = ast.ty_tup(elems.node);
202188
}

trunk/src/comp/middle/fold.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ type ast_fold[ENV] =
4646
(fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_box,
4747
(fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_vec,
4848

49-
(fn(&ENV e, &span sp,
50-
vec[tup(mutability, @ty)] elts) -> @ty) fold_ty_tup,
49+
(fn(&ENV e, &span sp, vec[@ty] elts) -> @ty) fold_ty_tup,
5150

5251
(fn(&ENV e, &span sp,
5352
vec[rec(ast.mode mode, @ty ty)] inputs,
@@ -246,9 +245,9 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
246245
}
247246

248247
case (ast.ty_tup(?elts)) {
249-
let vec[tup(mutability, @ty)] elts_ = vec();
250-
for (tup(mutability, @ty) elt in elts) {
251-
elts_ += tup(elt._0, fold_ty(env, fld, elt._1));
248+
let vec[@ty] elts_ = vec();
249+
for (@ty elt in elts) {
250+
append[@ty](elts_,fold_ty(env, fld, elt));
252251
}
253252
ret fld.fold_ty_tup(env_, t.span, elts);
254253
}
@@ -652,7 +651,7 @@ fn identity_fold_ty_vec[ENV](&ENV env, &span sp, @ty t) -> @ty {
652651
}
653652

654653
fn identity_fold_ty_tup[ENV](&ENV env, &span sp,
655-
vec[tup(mutability,@ty)] elts) -> @ty {
654+
vec[@ty] elts) -> @ty {
656655
ret @respan(sp, ast.ty_tup(elts));
657656
}
658657

trunk/src/comp/middle/trans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
275275
}
276276
case (typeck.ty_tup(?elts)) {
277277
let vec[TypeRef] tys = vec();
278-
for (tup(ast.mutability, @typeck.ty) elt in elts) {
279-
tys += type_of(cx, elt._1);
278+
for (@typeck.ty elt in elts) {
279+
tys += type_of(cx, elt);
280280
}
281281
ret T_struct(tys);
282282
}
@@ -493,9 +493,9 @@ fn iter_structural_ty(@block_ctxt cx,
493493
alt (t.struct) {
494494
case (typeck.ty_tup(?args)) {
495495
let int i = 0;
496-
for (tup(ast.mutability, @typeck.ty) arg in args) {
496+
for (@typeck.ty arg in args) {
497497
auto elt = r.bcx.build.GEP(v, vec(C_int(0), C_int(i)));
498-
r = f(r.bcx, elt, arg._1);
498+
r = f(r.bcx, elt, arg);
499499
i += 1;
500500
}
501501
}

trunk/src/comp/middle/typeck.rs

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tag sty {
4040
ty_str;
4141
ty_box(@ty);
4242
ty_vec(@ty);
43-
ty_tup(vec[tup(mutability, @ty)]);
43+
ty_tup(vec[@ty]);
4444
ty_fn(vec[arg], @ty); // TODO: effect
4545
ty_var(int); // ephemeral type var
4646
ty_local(ast.def_id); // type of a local var
@@ -66,16 +66,6 @@ type ty_getter = fn(ast.def_id) -> @ty;
6666
// Error-reporting utility functions
6767

6868
fn ast_ty_to_str(&@ast.ty ty) -> str {
69-
fn ast_tup_elem_to_str(&tup(mutability, @ast.ty) elem) -> str {
70-
auto s;
71-
if (elem._0 == ast.mut) {
72-
s = "mutable ";
73-
} else {
74-
s = "";
75-
}
76-
77-
ret s + ast_ty_to_str(elem._1);
78-
}
7969

8070
fn ast_fn_input_to_str(&rec(ast.mode mode, @ast.ty ty) input) -> str {
8171
auto s;
@@ -101,11 +91,9 @@ fn ast_ty_to_str(&@ast.ty ty) -> str {
10191
case (ast.ty_vec(?t)) { s = "vec[" + ast_ty_to_str(t) + "]"; }
10292

10393
case (ast.ty_tup(?elems)) {
104-
auto f = ast_tup_elem_to_str;
94+
auto f = ast_ty_to_str;
10595
s = "tup(";
106-
s +=
107-
_str.connect(_vec.map[tup(mutability,@ast.ty),str](f, elems),
108-
",");
96+
s += _str.connect(_vec.map[@ast.ty,str](f, elems), ",");
10997
s += ")";
11098
}
11199

@@ -153,17 +141,7 @@ fn path_to_str(&ast.path path) -> str {
153141
ret _str.connect(_vec.map[ast.name,str](f, path), ".");
154142
}
155143

156-
fn ty_to_str(@ty typ) -> str {
157-
fn tup_elem_to_str(&tup(mutability, @ty) elem) -> str {
158-
auto s;
159-
if (elem._0 == ast.mut) {
160-
s = "mutable ";
161-
} else {
162-
s = "";
163-
}
164-
165-
ret s + ty_to_str(elem._1);
166-
}
144+
fn ty_to_str(&@ty typ) -> str {
167145

168146
fn fn_input_to_str(&rec(ast.mode mode, @ty ty) input) -> str {
169147
auto s;
@@ -176,7 +154,11 @@ fn ty_to_str(@ty typ) -> str {
176154
ret s + ty_to_str(input.ty);
177155
}
178156

179-
auto s;
157+
auto s = "";
158+
if (typ.mut == ast.mut) {
159+
s += "mutable ";
160+
}
161+
180162
alt (typ.struct) {
181163
case (ty_nil) { s = "()"; }
182164
case (ty_bool) { s = "bool"; }
@@ -189,8 +171,8 @@ fn ty_to_str(@ty typ) -> str {
189171
case (ty_vec(?t)) { s = "vec[" + ty_to_str(t) + "]"; }
190172

191173
case (ty_tup(?elems)) {
192-
auto f = tup_elem_to_str;
193-
auto strs = _vec.map[tup(mutability,@ty),str](f, elems);
174+
auto f = ty_to_str;
175+
auto strs = _vec.map[@ty,str](f, elems);
194176
s = "tup(" + _str.connect(strs, ",") + ")";
195177
}
196178

@@ -234,9 +216,9 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty {
234216
case (ast.ty_box(?t)) { sty = ty_box(ast_ty_to_ty(getter, t)); }
235217
case (ast.ty_vec(?t)) { sty = ty_vec(ast_ty_to_ty(getter, t)); }
236218
case (ast.ty_tup(?fields)) {
237-
let vec[tup(mutability,@ty)] flds = vec();
238-
for (tup(mutability, @ast.ty) field in fields) {
239-
flds += tup(field._0, ast_ty_to_ty(getter, field._1));
219+
let vec[@ty] flds = vec();
220+
for (@ast.ty field in fields) {
221+
append[@ty](flds, ast_ty_to_ty(getter, field));
240222
}
241223
sty = ty_tup(flds);
242224
}
@@ -710,10 +692,8 @@ fn unify(&fn_ctxt fcx, @ty expected, @ty actual) -> unify_result {
710692
case (ty_tup(?expected_elems)) {
711693
alt (actual.struct) {
712694
case (ty_tup(?actual_elems)) {
713-
auto expected_len =
714-
_vec.len[tup(mutability,@ty)](expected_elems);
715-
auto actual_len =
716-
_vec.len[tup(mutability,@ty)](actual_elems);
695+
auto expected_len = _vec.len[@ty](expected_elems);
696+
auto actual_len = _vec.len[@ty](actual_elems);
717697
if (expected_len != actual_len) {
718698
auto err = terr_tuple_size(expected_len,
719699
actual_len);
@@ -722,24 +702,23 @@ fn unify(&fn_ctxt fcx, @ty expected, @ty actual) -> unify_result {
722702

723703
// TODO: implement an iterator that can iterate over
724704
// two arrays simultaneously.
725-
let vec[tup(mutability, @ty)] result_elems = vec();
705+
let vec[@ty] result_elems = vec();
726706
auto i = 0u;
727707
while (i < expected_len) {
728708
auto expected_elem = expected_elems.(i);
729709
auto actual_elem = actual_elems.(i);
730-
if (expected_elem._0 != actual_elem._0) {
710+
if (expected_elem.mut != actual_elem.mut) {
731711
auto err = terr_tuple_mutability;
732712
ret ures_err(err, expected, actual);
733713
}
734714

735715
auto result = unify_step(fcx,
736716
bindings,
737-
expected_elem._1,
738-
actual_elem._1);
717+
expected_elem,
718+
actual_elem);
739719
alt (result) {
740720
case (ures_ok(?rty)) {
741-
result_elems += vec(tup(expected_elem._0,
742-
rty));
721+
append[@ty](result_elems,rty);
743722
}
744723
case (_) {
745724
ret result;
@@ -1258,12 +1237,17 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
12581237

12591238
case (ast.expr_tup(?args, _)) {
12601239
let vec[tup(mutability, @ast.expr)] args_1 = vec();
1261-
let vec[tup(mutability, @ty)] args_t = vec();
1240+
let vec[@ty] args_t = vec();
12621241

12631242
for (tup(mutability, @ast.expr) arg in args) {
12641243
auto expr_1 = check_expr(fcx, arg._1);
12651244
args_1 += tup(arg._0, expr_1);
1266-
args_t += tup(arg._0, expr_ty(expr_1));
1245+
if (arg._0 == ast.mut) {
1246+
append[@ty](args_t,@rec(mut=ast.mut
1247+
with *expr_ty(expr_1)));
1248+
} else {
1249+
append[@ty](args_t,expr_ty(expr_1));
1250+
}
12671251
}
12681252

12691253
auto ann = ast.ann_type(plain_ty(ty_tup(args_t)));
@@ -1278,11 +1262,11 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
12781262
case (ty_tup(?args)) {
12791263
let uint ix = field_num(fcx.ccx.sess,
12801264
expr.span, field);
1281-
if (ix >= _vec.len[tup(mutability,@ty)](args)) {
1265+
if (ix >= _vec.len[@ty](args)) {
12821266
fcx.ccx.sess.span_err(expr.span,
12831267
"bad index on tuple");
12841268
}
1285-
auto ann = ast.ann_type(args.(ix)._1);
1269+
auto ann = ast.ann_type(args.(ix));
12861270
ret @fold.respan[ast.expr_](expr.span,
12871271
ast.expr_field(base_1,
12881272
field,

0 commit comments

Comments
 (0)