Skip to content

Commit 24bf8bf

Browse files
committed
---
yaml --- r: 3014 b: refs/heads/master c: fccf065 h: refs/heads/master v: v3
1 parent 5b9ce5d commit 24bf8bf

File tree

12 files changed

+109
-65
lines changed

12 files changed

+109
-65
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: 798bbd2e226c17024252192f939ce5c9ae59a99b
2+
refs/heads/master: fccf0652661f8f76875655628e6a61d7e00bd856

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn unop_to_str(unop op) -> str {
203203
204204
tag mode {
205205
val;
206-
alias;
206+
alias(bool);
207207
}
208208
209209
type stmt = spanned[stmt_];

trunk/src/comp/front/creader.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,12 @@ fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty::arg], ty::t,
328328
while (peek(st) as char != ']') {
329329
auto mode = ty::mo_val;
330330
if (peek(st) as char == '&') {
331-
mode = ty::mo_alias;
332-
st.pos = st.pos + 1u;
331+
mode = ty::mo_alias(false);
332+
st.pos += 1u;
333+
if (peek(st) as char == 'm') {
334+
mode = ty::mo_alias(true);
335+
st.pos += 1u;
336+
}
333337
}
334338
inputs += [rec(mode=mode, ty=parse_ty(st, sd))];
335339
}

trunk/src/comp/front/parser.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,10 @@ fn parse_ty_fn(ast::proto proto, &parser p, uint lo)
319319
-> ast::ty_ {
320320
fn parse_fn_input_ty(&parser p) -> ast::ty_arg {
321321
auto lo = p.get_lo_pos();
322-
auto mode;
322+
auto mode = ast::val;
323323
if (p.peek() == token::BINOP(token::AND)) {
324324
p.bump();
325-
mode = ast::alias;
326-
327-
if (eat_word(p, "mutable")) {
328-
// TODO: handle mutable alias args
329-
}
330-
} else {
331-
mode = ast::val;
325+
mode = ast::alias(eat_word(p, "mutable"));
332326
}
333327

334328
auto t = parse_ty(p);
@@ -598,11 +592,8 @@ fn parse_ty(&parser p) -> @ast::ty {
598592
fn parse_arg(&parser p) -> ast::arg {
599593
let ast::mode m = ast::val;
600594
if (p.peek() == token::BINOP(token::AND)) {
601-
m = ast::alias;
602595
p.bump();
603-
604-
// TODO: handle mutable alias args
605-
eat_word(p, "mutable");
596+
m = ast::alias(eat_word(p, "mutable"));
606597
}
607598
let @ast::ty t = parse_ty(p);
608599
let ast::ident i = parse_value_ident(p);

trunk/src/comp/middle/alias.rs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ type restrict = @rec(vec[def_num] root_vars,
2323
vec[uint] depends_on,
2424
mutable valid ok);
2525

26-
type scope = vec[restrict];
26+
type scope = rec(vec[tup(def_num, ast::mode)] args,
27+
vec[restrict] rs);
28+
fn scope(&scope sc, vec[restrict] add) -> scope {
29+
ret rec(args=sc.args, rs=sc.rs + add);
30+
}
31+
2732
type ctx = rec(@ty::ctxt tcx,
2833
resolve::def_map dm);
2934

@@ -32,13 +37,17 @@ fn check_crate(@ty::ctxt tcx, resolve::def_map dm, &@ast::crate crate) {
3237
auto v = @rec(visit_fn = visit_fn,
3338
visit_expr = bind visit_expr(cx, _, _, _)
3439
with *visit::default_visitor[scope]());
35-
visit::visit_crate(*crate, [], visit::vtor(v));
40+
visit::visit_crate(*crate, rec(args=[], rs=[]), visit::vtor(v));
3641
}
3742

3843
fn visit_fn(&ast::_fn f, &vec[ast::ty_param] tp, &span sp, &ident name,
3944
&ast::def_id d_id, &ast::ann a, &scope sc, &vt[scope] v) {
4045
visit::visit_fn_decl(f.decl, sc, v);
41-
vt(v).visit_block(f.body, [], v);
46+
auto args = [];
47+
for (ast::arg arg in f.decl.inputs) {
48+
vec::push(args, tup(arg.id._1, arg.mode));
49+
}
50+
vt(v).visit_block(f.body, rec(args=args, rs=[]), v);
4251
}
4352

4453
fn visit_expr(&@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
@@ -179,12 +188,12 @@ fn check_alt(&ctx cx, &@ast::expr input, &vec[ast::arm] arms,
179188
auto dnums = arm_defnums(a);
180189
auto new_sc = sc;
181190
if (vec::len(dnums) > 0u) {
182-
vec::push(new_sc, @rec(root_vars=roots,
183-
block_defnum=dnums.(0),
184-
bindings=dnums,
185-
tys=forbidden_tp,
186-
depends_on=deps(sc, roots),
187-
mutable ok=valid));
191+
new_sc = scope(sc, [@rec(root_vars=roots,
192+
block_defnum=dnums.(0),
193+
bindings=dnums,
194+
tys=forbidden_tp,
195+
depends_on=deps(sc, roots),
196+
mutable ok=valid)]);
188197
}
189198
visit::visit_arm(a, new_sc, v);
190199
}
@@ -225,7 +234,7 @@ fn check_for_each(&ctx cx, &@ast::decl decl, &@ast::expr call,
225234
tys=data.unsafe_ts,
226235
depends_on=deps(sc, data.root_vars),
227236
mutable ok=valid);
228-
visit::visit_block(block, sc + [new_sc], v);
237+
visit::visit_block(block, scope(sc, [new_sc]), v);
229238
}
230239
}
231240
}
@@ -261,7 +270,7 @@ fn check_for(&ctx cx, &@ast::decl decl, &@ast::expr seq,
261270
tys=unsafe,
262271
depends_on=deps(sc, root_def),
263272
mutable ok=valid);
264-
visit::visit_block(block, sc + [new_sc], v);
273+
visit::visit_block(block, scope(sc, [new_sc]), v);
265274
}
266275

267276
fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::ann ann, bool assign,
@@ -270,7 +279,7 @@ fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::ann ann, bool assign,
270279
if (!def_is_local(def)) { ret; }
271280
auto my_defnum = ast::def_id_of_def(def)._1;
272281
auto var_t = ty::expr_ty(*cx.tcx, ex);
273-
for (restrict r in sc) {
282+
for (restrict r in sc.rs) {
274283
// excludes variables introduced since the alias was made
275284
if (my_defnum < r.block_defnum) {
276285
for (ty::t t in r.tys) {
@@ -287,14 +296,29 @@ fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::ann ann, bool assign,
287296
fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src,
288297
&scope sc, &vt[scope] v) {
289298
visit_expr(cx, src, sc, v);
299+
290300
alt (dest.node) {
291301
case (ast::expr_path(?p, ?ann)) {
292302
auto dnum = ast::def_id_of_def(cx.dm.get(ann.id))._1;
303+
304+
for (tup(def_num, ast::mode) arg in sc.args) {
305+
if (arg._0 == dnum && arg._1 == ast::alias(false)) {
306+
cx.tcx.sess.span_err
307+
(dest.span, "assigning to immutable alias");
308+
}
309+
}
310+
293311
auto var_t = ty::expr_ty(*cx.tcx, dest);
294-
for (restrict r in sc) {
312+
for (restrict r in sc.rs) {
295313
if (vec::member(dnum, r.root_vars)) {
296314
r.ok = overwritten(dest.span, p);
297315
}
316+
for (def_num bnd in r.bindings) {
317+
if (dnum == bnd) {
318+
cx.tcx.sess.span_err
319+
(dest.span, "assigning to immutable alias");
320+
}
321+
}
298322
}
299323
check_var(*cx, dest, p, ann, true, sc);
300324
}
@@ -308,7 +332,7 @@ fn test_scope(&ctx cx, &scope sc, &restrict r, &ast::path p) {
308332
auto prob = r.ok;
309333
for (uint dep in r.depends_on) {
310334
if (prob != valid) { break; }
311-
prob = sc.(dep).ok;
335+
prob = sc.rs.(dep).ok;
312336
}
313337
if (prob != valid) {
314338
auto msg = alt (prob) {
@@ -328,7 +352,7 @@ fn test_scope(&ctx cx, &scope sc, &restrict r, &ast::path p) {
328352
fn deps(&scope sc, vec[def_num] roots) -> vec[uint] {
329353
auto i = 0u;
330354
auto result = [];
331-
for (restrict r in sc) {
355+
for (restrict r in sc.rs) {
332356
for (def_num dn in roots) {
333357
if (vec::member(dn, r.bindings)) {
334358
vec::push(result, i);

trunk/src/comp/middle/metadata.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,13 @@ mod Encode {
250250
&ast::controlflow cf, &vec[@ast::constr] constrs) {
251251
w.write_char('[');
252252
for (ty::arg arg in args) {
253-
if (arg.mode == ty::mo_alias) { w.write_char('&'); }
253+
alt (arg.mode) {
254+
case (ty::mo_alias(?mut)) {
255+
w.write_char('&');
256+
if (mut) { w.write_char('m'); }
257+
}
258+
case (ty::mo_val) {}
259+
}
254260
enc_ty(w, cx, arg.ty);
255261
}
256262
w.write_char(']');

trunk/src/comp/middle/trans.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,12 @@ fn type_of_explicit_args(&@crate_ctxt cx, &span sp,
691691
let vec[TypeRef] atys = [];
692692
for (ty::arg arg in inputs) {
693693
if (ty::type_has_dynamic_size(cx.tcx, arg.ty)) {
694-
assert (arg.mode == ty::mo_alias);
694+
assert (arg.mode != ty::mo_val);
695695
atys += [T_typaram_ptr(cx.tn)];
696696
} else {
697697
let TypeRef t;
698698
alt (arg.mode) {
699-
case (ty::mo_alias) {
699+
case (ty::mo_alias(_)) {
700700
t = T_ptr(type_of_inner(cx, sp, arg.ty));
701701
}
702702
case (_) {
@@ -762,9 +762,9 @@ fn type_of_fn_full(&@crate_ctxt cx,
762762
atys +=
763763
[T_fn_pair(cx.tn,
764764
type_of_fn_full(cx, sp, ast::proto_fn, none[TypeRef],
765-
[rec(mode=ty::mo_alias,
766-
ty=output)],
767-
ty::mk_nil(cx.tcx), 0u))];
765+
[rec(mode=ty::mo_alias(false),
766+
ty=output)],
767+
ty::mk_nil(cx.tcx), 0u))];
768768
}
769769

770770
// ... then explicit args.
@@ -923,7 +923,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
923923
fn type_of_arg(@local_ctxt cx, &span sp, &ty::arg arg) -> TypeRef {
924924
alt (ty::struct(cx.ccx.tcx, arg.ty)) {
925925
case (ty::ty_param(_)) {
926-
if (arg.mode == ty::mo_alias) {
926+
if (arg.mode != ty::mo_val) {
927927
ret T_typaram_ptr(cx.ccx.tn);
928928
}
929929
}
@@ -933,7 +933,7 @@ fn type_of_arg(@local_ctxt cx, &span sp, &ty::arg arg) -> TypeRef {
933933
}
934934

935935
auto typ;
936-
if (arg.mode == ty::mo_alias) {
936+
if (arg.mode != ty::mo_val) {
937937
typ = T_ptr(type_of_inner(cx.ccx, sp, arg.ty));
938938
} else {
939939
typ = type_of_inner(cx.ccx, sp, arg.ty);
@@ -4063,7 +4063,7 @@ fn trans_for_each(&@block_ctxt cx,
40634063
auto iter_body_llty =
40644064
type_of_fn_full(lcx.ccx, cx.sp, ast::proto_fn,
40654065
none[TypeRef],
4066-
[rec(mode=ty::mo_alias, ty=decl_ty)],
4066+
[rec(mode=ty::mo_alias(false), ty=decl_ty)],
40674067
ty::mk_nil(lcx.ccx.tcx), 0u);
40684068

40694069
let ValueRef lliterbody = decl_internal_fastcall_fn(lcx.ccx.llmod,
@@ -4840,7 +4840,7 @@ fn trans_bind_thunk(&@local_ctxt cx,
48404840
}
48414841
} else if (ty::type_contains_params(cx.ccx.tcx,
48424842
out_arg.ty)) {
4843-
assert (out_arg.mode == ty::mo_alias);
4843+
assert (out_arg.mode != ty::mo_val);
48444844
val = bcx.build.PointerCast(val, llout_arg_ty);
48454845
}
48464846

@@ -4853,7 +4853,7 @@ fn trans_bind_thunk(&@local_ctxt cx,
48534853
let ValueRef passed_arg = llvm::LLVMGetParam(llthunk, a);
48544854

48554855
if (ty::type_contains_params(cx.ccx.tcx, out_arg.ty)) {
4856-
assert (out_arg.mode == ty::mo_alias);
4856+
assert (out_arg.mode != ty::mo_val);
48574857
passed_arg = bcx.build.PointerCast(passed_arg,
48584858
llout_arg_ty);
48594859
}
@@ -5098,7 +5098,7 @@ fn trans_arg_expr(&@block_ctxt cx,
50985098
auto re = trans_expr(bcx, e);
50995099
val = re.val;
51005100
bcx = re.bcx;
5101-
} else if (arg.mode == ty::mo_alias) {
5101+
} else if (arg.mode != ty::mo_val) {
51025102
let lval_result lv;
51035103
if (ty::is_lval(e)) {
51045104
lv = trans_lval(bcx, e);
@@ -5125,7 +5125,7 @@ fn trans_arg_expr(&@block_ctxt cx,
51255125
bcx = re.bcx;
51265126
}
51275127

5128-
if (arg.mode != ty::mo_alias) {
5128+
if (arg.mode == ty::mo_val) {
51295129
bcx = take_ty(bcx, val, e_ty).bcx;
51305130
}
51315131

@@ -5930,7 +5930,7 @@ fn trans_put(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
59305930
case (none) { }
59315931
case (some(?x)) {
59325932
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x);
5933-
auto arg = rec(mode=ty::mo_alias, ty=e_ty);
5933+
auto arg = rec(mode=ty::mo_alias(false), ty=e_ty);
59345934
auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx,
59355935
x.span, [arg]);
59365936
auto r = trans_arg_expr(bcx, arg, arg_tys.(0), x);
@@ -6194,7 +6194,7 @@ fn mk_spawn_wrapper(&@block_ctxt cx,
61946194

61956195
let TypeRef wrapper_fn_type =
61966196
type_of_fn(cx.fcx.lcx.ccx, cx.sp, ast::proto_fn,
6197-
[rec(mode = ty::mo_alias, ty = args_ty)],
6197+
[rec(mode = ty::mo_alias(false), ty = args_ty)],
61986198
ty::idx_nil,
61996199
0u);
62006200

@@ -6401,7 +6401,7 @@ fn trans_anon_obj(@block_ctxt cx, &span sp,
64016401
case (some(?fields)) {
64026402
addtl_fields = fields;
64036403
for (ast::obj_field f in fields) {
6404-
addtl_fn_args += [rec(mode=ast::alias, ty=f.ty,
6404+
addtl_fn_args += [rec(mode=ast::alias(false), ty=f.ty,
64056405
ident=f.ident, id=f.id)];
64066406
}
64076407
}
@@ -7045,7 +7045,7 @@ fn copy_args_to_allocas(@fn_ctxt fcx,
70457045

70467046
let uint arg_n = 0u;
70477047
for (ast::arg aarg in args) {
7048-
if (aarg.mode != ast::alias) {
7048+
if (aarg.mode == ast::val) {
70497049
auto arg_t = type_of_arg(bcx.fcx.lcx, fcx.sp, arg_tys.(arg_n));
70507050
auto a = alloca(bcx, arg_t);
70517051
auto argval = bcx.fcx.llargs.get(aarg.id);
@@ -7063,7 +7063,7 @@ fn add_cleanups_for_args(&@block_ctxt bcx,
70637063
vec[ty::arg] arg_tys) {
70647064
let uint arg_n = 0u;
70657065
for (ast::arg aarg in args) {
7066-
if (aarg.mode != ast::alias) {
7066+
if (aarg.mode == ast::val) {
70677067
auto argval = bcx.fcx.llargs.get(aarg.id);
70687068
find_scope_cx(bcx).cleanups +=
70697069
[clean(bind drop_slot(_, argval, arg_tys.(arg_n).ty))];
@@ -7329,7 +7329,8 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid,
73297329
// we're creating.
73307330
let vec[ast::arg] fn_args = [];
73317331
for (ast::obj_field f in ob.fields) {
7332-
fn_args += [rec(mode=ast::alias, ty=f.ty, ident=f.ident, id=f.id)];
7332+
fn_args += [rec(mode=ast::alias(false),
7333+
ty=f.ty, ident=f.ident, id=f.id)];
73337334
}
73347335
auto fcx = new_fn_ctxt(cx, sp, llctor_decl);
73357336

@@ -7522,10 +7523,10 @@ fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id,
75227523
let vec[ast::arg] fn_args = [];
75237524
auto i = 0u;
75247525
for (ast::variant_arg varg in variant.node.args) {
7525-
fn_args += [rec(mode=ast::alias,
7526-
ty=varg.ty,
7527-
ident="arg" + uint::to_str(i, 10u),
7528-
id=varg.id)];
7526+
fn_args += [rec(mode=ast::alias(false),
7527+
ty=varg.ty,
7528+
ident="arg" + uint::to_str(i, 10u),
7529+
id=varg.id)];
75297530
}
75307531

75317532
assert (cx.ccx.item_ids.contains_key(variant.node.id));

trunk/src/comp/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import util::data::interner;
4141

4242
tag mode {
4343
mo_val;
44-
mo_alias;
44+
mo_alias(bool);
4545
}
4646

4747
type arg = rec(mode mode, t ty);

0 commit comments

Comments
 (0)