Skip to content

Commit daf8f6a

Browse files
committed
---
yaml --- r: 14063 b: refs/heads/try c: 77b06d2 h: refs/heads/master i: 14061: 261ccd1 14059: 42c4a59 14055: 835601e 14047: 52a3e5d v: v3
1 parent 5f05a7c commit daf8f6a

File tree

21 files changed

+310
-167
lines changed

21 files changed

+310
-167
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 5163606d060ccb2c6462d34f590e2a1f30ce4a1f
5+
refs/heads/try: 77b06d24cd76bf808138f1f7df4dcff40260ff38
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
382382
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
383383

384384
let args_arg: ast::arg =
385-
{mode: ast::by_val,
385+
{mode: ast::expl(ast::by_val),
386386
ty: @args_ty,
387387
ident: "args",
388388
id: cx.sess.next_node_id()};

branches/try/src/comp/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
353353
'#' { ast::by_val }
354354
};
355355
st.pos += 1u;
356-
inputs += [{mode: mode, ty: parse_ty(st, conv)}];
356+
inputs += [{mode: ast::expl(mode), ty: parse_ty(st, conv)}];
357357
}
358358
st.pos += 1u; // eat the ']'
359359
let cs = parse_constrs(st, conv);

branches/try/src/comp/metadata/tyencode.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,12 @@ fn enc_proto(w: io::writer, proto: proto) {
203203
fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
204204
w.write_char('[');
205205
for arg: ty::arg in ft.inputs {
206-
alt arg.mode {
206+
alt ty::resolved_mode(cx.tcx, arg.mode) {
207207
by_mut_ref { w.write_char('&'); }
208208
by_move { w.write_char('-'); }
209209
by_copy { w.write_char('+'); }
210210
by_ref { w.write_char('='); }
211211
by_val { w.write_char('#'); }
212-
// tediously, this has to be there until there's a way
213-
// to constraint post-typeck types not to contain a mode_infer
214-
mode_infer { cx.tcx.sess.bug("enc_ty_fn: shouldn't see \
215-
mode_infer"); }
216212
}
217213
enc_ty(w, cx, arg.ty);
218214
}

branches/try/src/comp/middle/alias.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ fn visit_fn(cx: @ctx, _fk: visit::fn_kind, decl: ast::fn_decl,
8282
let fty = ty::node_id_to_type(cx.tcx, id);
8383
let args = ty::ty_fn_args(cx.tcx, fty);
8484
for arg in args {
85-
if arg.mode == ast::by_val &&
86-
ty::type_has_dynamic_size(cx.tcx, arg.ty) {
85+
alt ty::resolved_mode(cx.tcx, arg.mode) {
86+
ast::by_val if ty::type_has_dynamic_size(cx.tcx, arg.ty) {
8787
err(*cx, sp, "can not pass a dynamically-sized type by value");
88+
}
89+
_ { /* fallthrough */ }
8890
}
8991
}
9092

@@ -226,26 +228,30 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
226228
for arg_t: ty::arg in arg_ts {
227229
let arg = args[i];
228230
let root = expr_root(cx, arg, false);
229-
if arg_t.mode == ast::by_mut_ref {
231+
alt ty::resolved_mode(cx.tcx, arg_t.mode) {
232+
ast::by_mut_ref {
230233
alt path_def(cx, arg) {
231234
some(def) {
232235
let dnum = ast_util::def_id_of_def(def).node;
233236
mut_roots += [{arg: i, node: dnum}];
234237
}
235238
_ { }
236239
}
240+
}
241+
ast::by_ref | ast::by_val | ast::by_move | ast::by_copy { }
237242
}
238243
let root_var = path_def_id(cx, root.ex);
244+
let arg_copied = alt ty::resolved_mode(cx.tcx, arg_t.mode) {
245+
ast::by_move | ast::by_copy { copied }
246+
ast::by_mut_ref { not_allowed }
247+
ast::by_ref | ast::by_val { not_copied }
248+
};
239249
bindings += [@{node_id: arg.id,
240250
span: arg.span,
241251
root_var: root_var,
242252
local_id: 0u,
243253
unsafe_tys: unsafe_set(root.mut),
244-
mutable copied: alt arg_t.mode {
245-
ast::by_move | ast::by_copy { copied }
246-
ast::by_mut_ref { not_allowed }
247-
_ { not_copied }
248-
}}];
254+
mutable copied: arg_copied}];
249255
i += 1u;
250256
}
251257
let f_may_close =
@@ -279,7 +285,8 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
279285
for unsafe_ty in b.unsafe_tys {
280286
let i = 0u;
281287
for arg_t: ty::arg in arg_ts {
282-
let mut_alias = arg_t.mode == ast::by_mut_ref;
288+
let mut_alias =
289+
(ast::by_mut_ref == ty::arg_mode(cx.tcx, arg_t));
283290
if i != j &&
284291
ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty,
285292
mut_alias) &&

branches/try/src/comp/middle/block_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
2828
v.visit_expr(f, cx, v);
2929
let i = 0u;
3030
for arg_t in ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f)) {
31-
cx.allow_block = arg_t.mode == by_ref;
31+
cx.allow_block = (ty::arg_mode(cx.tcx, arg_t) == by_ref);
3232
v.visit_expr(args[i], cx, v);
3333
i += 1u;
3434
}

branches/try/src/comp/middle/kind.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
165165
expr_call(f, args, _) {
166166
let i = 0u;
167167
for arg_t in ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f)) {
168-
alt arg_t.mode { by_copy { maybe_copy(cx, args[i]); } _ {} }
168+
alt ty::arg_mode(cx.tcx, arg_t) {
169+
by_copy { maybe_copy(cx, args[i]); }
170+
by_ref | by_val | by_mut_ref | by_move { }
171+
}
169172
i += 1u;
170173
}
171174
}

branches/try/src/comp/middle/last_use.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
157157
fns += [arg];
158158
}
159159
_ {
160-
alt arg_ts[i].mode {
160+
alt ty::arg_mode(cx.tcx, arg_ts[i]) {
161161
by_mut_ref { clear_if_path(cx, arg, v, false); }
162162
_ { v.visit_expr(arg, cx, v); }
163163
}
@@ -286,11 +286,21 @@ fn clear_in_current(cx: ctx, my_def: node_id, to: bool) {
286286
fn clear_def_if_path(cx: ctx, d: def, to: bool)
287287
-> option<node_id> {
288288
alt d {
289-
def_local(def_id, let_copy) | def_arg(def_id, by_copy) |
290-
def_arg(def_id, by_move) {
289+
def_local(def_id, let_copy) {
291290
clear_in_current(cx, def_id.node, to);
292291
some(def_id.node)
293292
}
293+
def_arg(def_id, m) {
294+
alt ty::resolved_mode(cx.tcx, m) {
295+
by_copy | by_move {
296+
clear_in_current(cx, def_id.node, to);
297+
some(def_id.node)
298+
}
299+
by_ref | by_val | by_mut_ref {
300+
none
301+
}
302+
}
303+
}
294304
_ {
295305
none
296306
}

branches/try/src/comp/middle/mut.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ fn check_call(cx: @ctx, f: @expr, args: [@expr]) {
228228
let arg_ts = ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f));
229229
let i = 0u;
230230
for arg_t: ty::arg in arg_ts {
231-
alt arg_t.mode {
231+
alt ty::resolved_mode(cx.tcx, arg_t.mode) {
232232
by_mut_ref { check_lval(cx, args[i], msg_mut_ref); }
233233
by_move { check_lval(cx, args[i], msg_move_out); }
234-
_ {}
234+
by_ref | by_val | by_copy { }
235235
}
236236
i += 1u;
237237
}
@@ -267,8 +267,12 @@ fn is_immutable_def(cx: @ctx, def: def) -> option<str> {
267267
def_use(_) {
268268
some("static item")
269269
}
270-
def_arg(_, by_ref) | def_arg(_, by_val) |
271-
def_arg(_, mode_infer) { some("argument") }
270+
def_arg(_, m) {
271+
alt ty::resolved_mode(cx.tcx, m) {
272+
by_ref | by_val { some("argument") }
273+
by_mut_ref | by_move | by_copy { none }
274+
}
275+
}
272276
def_self(_) { some("self argument") }
273277
def_upvar(_, inner, node_id) {
274278
let ty = ty::node_id_to_type(cx.tcx, node_id);

branches/try/src/comp/middle/trans/base.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ fn type_of(cx: @crate_ctxt, t: ty::t) : type_has_static_size(cx, t)
6363

6464
fn type_of_explicit_args(cx: @crate_ctxt, inputs: [ty::arg]) ->
6565
[TypeRef] {
66-
let atys = [];
67-
for arg in inputs {
66+
let tcx = ccx_tcx(cx);
67+
vec::map(inputs) {|arg|
6868
let arg_ty = arg.ty;
6969
// FIXME: would be nice to have a constraint on arg
7070
// that would obviate the need for this check
7171
check non_ty_var(cx, arg_ty);
7272
let llty = type_of_inner(cx, arg_ty);
73-
atys += [if arg.mode == ast::by_val { llty } else { T_ptr(llty) }];
73+
alt ty::resolved_mode(tcx, arg.mode) {
74+
ast::by_val { llty }
75+
_ { T_ptr(llty) }
76+
}
7477
}
75-
ret atys;
7678
}
7779

7880

@@ -2981,15 +2983,16 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
29812983
let lv = trans_temp_lval(cx, e);
29822984
let bcx = lv.bcx;
29832985
let val = lv.val;
2986+
let arg_mode = ty::resolved_mode(ccx.tcx, arg.mode);
29842987
if is_bot {
29852988
// For values of type _|_, we generate an
29862989
// "undef" value, as such a value should never
29872990
// be inspected. It's important for the value
29882991
// to have type lldestty (the callee's expected type).
29892992
val = llvm::LLVMGetUndef(lldestty);
2990-
} else if arg.mode == ast::by_ref || arg.mode == ast::by_val {
2993+
} else if arg_mode == ast::by_ref || arg_mode == ast::by_val {
29912994
let copied = false, imm = ty::type_is_immediate(ccx.tcx, e_ty);
2992-
if arg.mode == ast::by_ref && lv.kind != owned && imm {
2995+
if arg_mode == ast::by_ref && lv.kind != owned && imm {
29932996
val = do_spill_noroot(bcx, val);
29942997
copied = true;
29952998
}
@@ -3002,10 +3005,10 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
30023005
} else { bcx = take_ty(bcx, val, e_ty); }
30033006
add_clean(bcx, val, e_ty);
30043007
}
3005-
if arg.mode == ast::by_val && (lv.kind == owned || !imm) {
3008+
if arg_mode == ast::by_val && (lv.kind == owned || !imm) {
30063009
val = Load(bcx, val);
30073010
}
3008-
} else if arg.mode == ast::by_copy {
3011+
} else if arg_mode == ast::by_copy {
30093012
let {bcx: cx, val: alloc} = alloc_ty(bcx, e_ty);
30103013
let last_use = ccx.last_uses.contains_key(e.id);
30113014
bcx = cx;
@@ -3031,7 +3034,7 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
30313034
}
30323035

30333036
// Collect arg for later if it happens to be one we've moving out.
3034-
if arg.mode == ast::by_move {
3037+
if arg_mode == ast::by_move {
30353038
if lv.kind == owned {
30363039
// Use actual ty, not declared ty -- anything else doesn't make
30373040
// sense if declared ty is a ty param
@@ -4414,17 +4417,18 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
44144417

44154418
fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
44164419
arg_tys: [ty::arg]) -> @block_ctxt {
4420+
let tcx = bcx_tcx(bcx);
44174421
let arg_n: uint = 0u, bcx = bcx;
4418-
fn epic_fail_(bcx: @block_ctxt) -> ! {
4419-
bcx_tcx(bcx).sess.bug("Someone forgot\
4422+
let epic_fail = fn@() -> ! {
4423+
tcx.sess.bug("Someone forgot\
44204424
to document an invariant in copy_args_to_allocas!");
44214425
}
44224426
let epic_fail = bind epic_fail_(bcx);
44234427
for arg in arg_tys {
44244428
let id = args[arg_n].id;
44254429
let argval = alt fcx.llargs.get(id) { local_mem(v) { v }
44264430
_ { epic_fail() } };
4427-
alt arg.mode {
4431+
alt ty::resolved_mode(tcx, arg.mode) {
44284432
ast::by_mut_ref { }
44294433
ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); }
44304434
ast::by_val {
@@ -4438,7 +4442,6 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
44384442
}
44394443
}
44404444
ast::by_ref {}
4441-
_ { epic_fail(); }
44424445
}
44434446
if fcx_ccx(fcx).sess.opts.extra_debuginfo {
44444447
debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
@@ -4585,7 +4588,7 @@ fn trans_enum_variant(ccx: @crate_ctxt,
45854588
// Translate variant arguments to function arguments.
45864589
let fn_args = [], i = 0u;
45874590
for varg in variant.node.args {
4588-
fn_args += [{mode: ast::by_copy,
4591+
fn_args += [{mode: ast::expl(ast::by_copy),
45894592
ty: varg.ty,
45904593
ident: "arg" + uint::to_str(i, 10u),
45914594
id: varg.id}];
@@ -5039,7 +5042,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50395042
takes_argv: bool) -> ValueRef {
50405043
let unit_ty = ty::mk_str(ccx.tcx);
50415044
let vecarg_ty: ty::arg =
5042-
{mode: ast::by_val,
5045+
{mode: ast::expl(ast::by_val),
50435046
ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})};
50445047
// FIXME: mk_nil should have a postcondition
50455048
let nt = ty::mk_nil(ccx.tcx);

branches/try/src/comp/middle/trans/closure.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,20 @@ fn trans_bind_thunk(ccx: @crate_ctxt,
895895
[0, abi::closure_body_bindings, b]);
896896
bcx = bound_arg.bcx;
897897
let val = bound_arg.val;
898-
if out_arg.mode == ast::by_val { val = Load(bcx, val); }
899-
if out_arg.mode == ast::by_copy {
898+
899+
alt ty::resolved_mode(tcx, out_arg.mode) {
900+
ast::by_val {
901+
val = Load(bcx, val);
902+
}
903+
ast::by_copy {
900904
let {bcx: cx, val: alloc} = alloc_ty(bcx, out_arg.ty);
901905
bcx = memmove_ty(cx, alloc, val, out_arg.ty);
902906
bcx = take_ty(bcx, alloc, out_arg.ty);
903907
val = alloc;
908+
}
909+
ast::by_ref | ast::by_mut_ref | ast::by_move { }
904910
}
911+
905912
// If the type is parameterized, then we need to cast the
906913
// type we actually have to the parameterized out type.
907914
if ty::type_contains_params(ccx.tcx, out_arg.ty) {

branches/try/src/comp/middle/trans/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, inner_t: ty::t)
300300
let nil_res = ty::mk_nil(ccx.tcx);
301301
// FIXME: Silly check -- mk_nil should have a postcondition
302302
check non_ty_var(ccx, nil_res);
303-
let f_t = type_of_fn(ccx, [{mode: ast::by_ref, ty: inner_t}],
303+
let fn_mode = ast::expl(ast::by_ref);
304+
let f_t = type_of_fn(ccx, [{mode: fn_mode, ty: inner_t}],
304305
nil_res, *param_bounds);
305306
ret base::get_extern_const(ccx.externs, ccx.llmod,
306307
csearch::get_symbol(ccx.sess.cstore,

branches/try/src/comp/middle/trans/impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
6363
fn trans_self_arg(bcx: @block_ctxt, base: @ast::expr) -> result {
6464
let tz = [], tr = [];
6565
let basety = expr_ty(bcx, base);
66-
let {bcx, val} = trans_arg_expr(bcx, {mode: ast::by_ref, ty: basety},
66+
let m_by_ref = ast::expl(ast::by_ref);
67+
let {bcx, val} = trans_arg_expr(bcx, {mode: m_by_ref, ty: basety},
6768
T_ptr(type_of_or_i8(bcx, basety)), tz,
6869
tr, base);
6970
rslt(bcx, PointerCast(bcx, val, T_opaque_cbox_ptr(bcx_ccx(bcx))))

branches/try/src/comp/middle/tstate/auxiliary.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,12 @@ fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [mode] {
10891089
}
10901090

10911091
fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] {
1092-
fn mode_to_op(m: mode) -> init_op {
1093-
alt m { by_move { init_move } _ { init_assign } }
1092+
vec::map(callee_modes(fcx, callee)) {|m|
1093+
alt ty::resolved_mode(fcx.ccx.tcx, m) {
1094+
by_move { init_move }
1095+
by_copy | by_ref | by_val | by_mut_ref { init_assign }
1096+
}
10941097
}
1095-
vec::map(callee_modes(fcx, callee), mode_to_op)
10961098
}
10971099

10981100
fn anon_bindings(ops: [init_op], es: [@expr]) -> [binding] {

branches/try/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,11 @@ fn handle_var_def(fcx: fn_ctxt, rslt: pre_and_post, def: def, name: ident) {
276276

277277
fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: [mode],
278278
operands: [@expr]) {
279-
let i = 0u;
280-
for mode: mode in modes {
281-
if mode == by_move {
282-
forget_in_postcond(fcx, parent.id, operands[i].id);
279+
vec::iteri(modes) {|i,mode|
280+
alt ty::resolved_mode(fcx.ccx.tcx, mode) {
281+
by_move { forget_in_postcond(fcx, parent.id, operands[i].id); }
282+
by_ref | by_val | by_mut_ref | by_copy { }
283283
}
284-
i += 1u;
285284
}
286285
}
287286

0 commit comments

Comments
 (0)