Skip to content

Commit 0b3c24b

Browse files
committed
---
yaml --- r: 5350 b: refs/heads/master c: fa74df0 h: refs/heads/master v: v3
1 parent ba51912 commit 0b3c24b

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0d4b51d10d1f2e386ec4424a8319b8fabd96f97f
2+
refs/heads/master: fa74df033d5a6dc4f16a2cb9d075cfba539a2e16

trunk/src/comp/middle/trans.rs

+49-23
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import tvec = trans_vec;
4949
fn type_of(cx: @crate_ctxt, sp: span, t: ty::t) : type_has_static_size(cx, t)
5050
-> TypeRef {
5151
// Should follow from type_has_static_size -- argh.
52-
// FIXME
52+
// FIXME (requires Issue #586)
5353
check non_ty_var(cx, t);
5454
type_of_inner(cx, sp, t)
5555
}
@@ -59,6 +59,8 @@ fn type_of_explicit_args(cx: @crate_ctxt, sp: span, inputs: [ty::arg]) ->
5959
let atys = [];
6060
for arg in inputs {
6161
let arg_ty = arg.ty;
62+
// FIXME: would be nice to have a constraint on arg
63+
// that would obviate the need for this check
6264
check non_ty_var(cx, arg_ty);
6365
atys += [T_ptr(type_of_inner(cx, sp, arg_ty))];
6466
}
@@ -114,9 +116,12 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
114116

115117
// Given a function type and a count of ty params, construct an llvm type
116118
fn type_of_fn_from_ty(cx: @crate_ctxt, sp: span, fty: ty::t,
117-
ty_param_count: uint) -> TypeRef {
119+
ty_param_count: uint)
120+
: returns_non_ty_var(cx, fty) -> TypeRef {
118121
let by_ref = ast_util::ret_by_ref(ty::ty_fn_ret_style(cx.tcx, fty));
119-
// FIXME: constraint?
122+
// FIXME: Check should be unnecessary, b/c it's implied
123+
// by returns_non_ty_var(t). Make that a postcondition
124+
// (see Issue #586)
120125
let ret_ty = ty::ty_fn_ret(cx.tcx, fty);
121126
check non_ty_var(cx, ret_ty);
122127
ret type_of_fn(cx, sp, ty::ty_fn_proto(cx.tcx, fty),
@@ -197,6 +202,8 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
197202
T_struct(tys)
198203
}
199204
ty::ty_fn(_, _, _, _, _) {
205+
// FIXME: could be a constraint on ty_fn
206+
check returns_non_ty_var(cx, t);
200207
T_fn_pair(*cx, type_of_fn_from_ty(cx, sp, t, 0u))
201208
}
202209
ty::ty_native_fn(abi, args, out) {
@@ -251,6 +258,7 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
251258
let t = tpt.ty;
252259
alt ty::struct(cx.tcx, t) {
253260
ty::ty_fn(_, _, _, _, _) {
261+
check returns_non_ty_var(cx, t);
254262
let llfnty = type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
255263
ret T_fn_pair(*cx, llfnty);
256264
}
@@ -2717,27 +2725,30 @@ fn trans_for_each(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
27172725
// Step 1: Generate code to build an environment containing pointers
27182726
// to all of the upvars
27192727
let lcx = cx.fcx.lcx;
2728+
let ccx = lcx.ccx;
27202729

27212730
// FIXME: possibly support alias-mode here?
2722-
let decl_ty = node_id_type(lcx.ccx, local.node.id);
2723-
let upvars = get_freevars(lcx.ccx.tcx, body.node.id);
2731+
let decl_ty = node_id_type(ccx, local.node.id);
2732+
let upvars = get_freevars(ccx.tcx, body.node.id);
27242733

27252734
let llenv = build_closure(cx, upvars, false);
27262735

27272736
// Step 2: Declare foreach body function.
27282737
let s: str =
2729-
mangle_internal_name_by_path_and_seq(lcx.ccx, lcx.path, "foreach");
2738+
mangle_internal_name_by_path_and_seq(ccx, lcx.path, "foreach");
27302739

27312740
// The 'env' arg entering the body function is a fake env member (as in
27322741
// the env-part of the normal rust calling convention) that actually
27332742
// points to a stack allocated env in this frame. We bundle that env
27342743
// pointer along with the foreach-body-fn pointer into a 'normal' fn pair
27352744
// and pass it in as a first class fn-arg to the iterator.
2745+
let iter_body_fn = ty::mk_iter_body_fn(ccx.tcx, decl_ty);
2746+
// FIXME: should be a postcondition on mk_iter_body_fn
2747+
check returns_non_ty_var(ccx, iter_body_fn);
27362748
let iter_body_llty =
2737-
type_of_fn_from_ty(lcx.ccx, cx.sp,
2738-
ty::mk_iter_body_fn(lcx.ccx.tcx, decl_ty), 0u);
2749+
type_of_fn_from_ty(ccx, cx.sp, iter_body_fn, 0u);
27392750
let lliterbody: ValueRef =
2740-
decl_internal_fastcall_fn(lcx.ccx.llmod, s, iter_body_llty);
2751+
decl_internal_fastcall_fn(ccx.llmod, s, iter_body_llty);
27412752
let fcx = new_fn_ctxt_w_id(lcx, cx.sp, lliterbody, body.node.id,
27422753
ast::return_val);
27432754
fcx.iterbodyty = cx.fcx.iterbodyty;
@@ -3258,16 +3269,21 @@ fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id) -> result {
32583269
ret rslt(e_res.bcx, newval);
32593270
}
32603271

3272+
// pth is cx.path
32613273
fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
32623274
outgoing_fty: ty::t, args: [option::t<@ast::expr>],
32633275
env_ty: ty::t, ty_param_count: uint,
3264-
target_fn: option::t<ValueRef>) ->
3265-
{val: ValueRef, ty: TypeRef} {
3266-
// FIXME
3267-
// This should be a precondition on trans_bind_thunk, but we would need
3268-
// to support record fields as constraint args
3269-
let ccx = cx.ccx;
3270-
check (type_has_static_size(ccx, incoming_fty));
3276+
target_fn: option::t<ValueRef>)
3277+
-> {val: ValueRef, ty: TypeRef} {
3278+
// If we supported constraints on record fields, we could make the
3279+
// constraints for this function:
3280+
/*
3281+
: returns_non_ty_var(ccx, outgoing_fty),
3282+
type_has_static_size(ccx, incoming_fty) ->
3283+
*/
3284+
// but since we don't, we have to do the checks at the beginning.
3285+
let ccx = cx.ccx;
3286+
check type_has_static_size(ccx, incoming_fty);
32713287

32723288
// Here we're not necessarily constructing a thunk in the sense of
32733289
// "function with no arguments". The result of compiling 'bind f(foo,
@@ -3424,8 +3440,11 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
34243440
// This is necessary because the type of the function that we have
34253441
// in the closure does not know how many type descriptors the function
34263442
// needs to take.
3443+
let ccx = bcx_ccx(bcx);
3444+
3445+
check returns_non_ty_var(ccx, outgoing_fty);
34273446
let lltargetty =
3428-
type_of_fn_from_ty(bcx_ccx(bcx), sp, outgoing_fty, ty_param_count);
3447+
type_of_fn_from_ty(ccx, sp, outgoing_fty, ty_param_count);
34293448
lltargetfn = PointerCast(bcx, lltargetfn, T_ptr(lltargetty));
34303449
FastCall(bcx, lltargetfn, llargs);
34313450
build_return(bcx);
@@ -3972,8 +3991,10 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
39723991
}
39733992
ast::expr_fn(f) {
39743993
let ccx = bcx_ccx(cx);
3994+
let fty = node_id_type(ccx, e.id);
3995+
check returns_non_ty_var(ccx, fty);
39753996
let llfnty: TypeRef =
3976-
type_of_fn_from_ty(ccx, e.span, node_id_type(ccx, e.id), 0u);
3997+
type_of_fn_from_ty(ccx, e.span, fty, 0u);
39773998
let sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon"));
39783999
let s = mangle_internal_name_by_path(ccx, sub_cx.path);
39794000
let llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfnty);
@@ -5416,13 +5437,16 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
54165437

54175438
fn decl_fn_and_pair(ccx: @crate_ctxt, sp: span, path: [str], flav: str,
54185439
ty_params: [ast::ty_param], node_id: ast::node_id) {
5419-
decl_fn_and_pair_full(ccx, sp, path, flav, ty_params, node_id,
5420-
node_id_type(ccx, node_id));
5440+
// FIXME: pull this out
5441+
let t = node_id_type(ccx, node_id);
5442+
check returns_non_ty_var(ccx, t);
5443+
decl_fn_and_pair_full(ccx, sp, path, flav, ty_params, node_id, t);
54215444
}
54225445

54235446
fn decl_fn_and_pair_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
54245447
ty_params: [ast::ty_param], node_id: ast::node_id,
5425-
node_type: ty::t) {
5448+
node_type: ty::t)
5449+
: returns_non_ty_var(ccx, node_type) {
54265450
let path = path;
54275451
let llfty =
54285452
type_of_fn_from_ty(ccx, sp, node_type, std::vec::len(ty_params));
@@ -5830,8 +5854,10 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
58305854
// the dtor_id. This is a bit counter-intuitive, but simplifies
58315855
// ty_res, which would have to carry around two def_ids otherwise
58325856
// -- one to identify the type, and one to find the dtor symbol.
5833-
decl_fn_and_pair_full(ccx, i.span, new_pt, "res_dtor", tps, i.id,
5834-
node_id_type(ccx, dtor_id));
5857+
let t = node_id_type(ccx, dtor_id);
5858+
// FIXME: how to get rid of this check?
5859+
check returns_non_ty_var(ccx, t);
5860+
decl_fn_and_pair_full(ccx, i.span, new_pt, "res_dtor", tps, i.id, t);
58355861
}
58365862
_ { }
58375863
}

0 commit comments

Comments
 (0)