提交 c7bd3f69 编写于 作者: T Tim Chevalier

Merge remote-tracking branch 'graydon/master'

......@@ -126,6 +126,11 @@ fn largest_variants(ccx: &@crate_ctxt, tag_id: &ast::def_id) -> [uint] {
// when in fact it has minimum size sizeof(int).
bounded = false;
} else {
// Could avoid this check: the constraint should
// follow from how elem_t doesn't contain params.
// (Could add a postcondition to type_contains_params,
// once we implement Issue #586.)
check trans_common::type_has_static_size(ccx, elem_t);
let llty = trans::type_of(ccx, dummy_sp(), elem_t);
min_size += trans::llsize_of_real(ccx, llty);
min_align += trans::llalign_of_real(ccx, llty);
......@@ -201,6 +206,10 @@ fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint],
// We increment a "virtual data pointer" to compute the size.
let lltys = [];
for typ: ty::t in variants[vid].args {
// FIXME: there should really be a postcondition
// on tag_variants that would obviate the need for
// this check. (Issue #586)
check trans_common::type_has_static_size(ccx, typ);
lltys += [trans::type_of(ccx, dummy_sp(), typ)];
}
......
此差异已折叠。
......@@ -563,6 +563,9 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef,
ast::pat_bind(_) {
if make_copy {
let ty = ty::node_id_to_monotype(ccx.tcx, pat.id);
// FIXME: Could constrain pat_bind to make this
// check unnecessary.
check type_has_static_size(ccx, ty);
let llty = trans::type_of(ccx, pat.span, ty);
let alloc = trans::alloca(bcx, llty);
bcx = trans::copy_val(bcx, trans::INIT, alloc,
......
......@@ -858,6 +858,10 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
}
}
pure fn type_has_static_size(cx: &@crate_ctxt, t: ty::t) -> bool {
!ty::type_has_dynamic_size(cx.tcx, t)
}
//
// Local Variables:
// mode: rust
......
......@@ -791,9 +791,14 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
create_object_body_type(cx.ccx.tcx, additional_field_tys, [],
some(inner_obj_ty));
// And cast to that type.
// create_object_body_type maybe should have a postcondition...
let cx_ccx = cx.ccx;
check type_has_static_size(cx_ccx, body_ty);
llself_obj_body =
PointerCast(bcx, llself_obj_body,
T_ptr(type_of(cx.ccx, sp, body_ty)));
T_ptr(type_of(cx_ccx, sp, body_ty)));
// Now, reach into the body and grab the inner_obj.
let llinner_obj =
......
......@@ -264,12 +264,25 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
alt maybe_alt {
none. {
changed |=
find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, antec),
conseq) |
alt chk {
if_check. {
let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
let conseq_prestate = tritv_clone(expr_poststate(fcx.ccx, antec));
tritv_set(bit_num(fcx, c.node), conseq_prestate, ttrue);
changed |=
find_pre_post_state_block(fcx, conseq_prestate, conseq) |
set_poststate_ann(fcx.ccx, id,
expr_poststate(fcx.ccx, antec));
}
}
_ {
changed |=
find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, antec),
conseq) |
set_poststate_ann(fcx.ccx, id,
expr_poststate(fcx.ccx, antec));
}
}
}
some(altern) {
changed |=
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, antec),
......
......@@ -1132,13 +1132,23 @@ fn type_structurally_contains(cx: &ctxt, ty: t,
}
}
fn type_has_dynamic_size(cx: &ctxt, ty: t) -> bool {
ret type_structurally_contains(cx, ty, fn(sty: &sty) -> bool {
pure fn type_has_dynamic_size(cx: &ctxt, ty: t) -> bool {
/* type_structurally_contains can't be declared pure
because it takes a function argument. But it should be
referentially transparent, since a given type's size should
never change once it's created.
(It would be interesting to think about how to make such properties
actually checkable. It seems to me like a lot of properties
that the type context tracks about types should be immutable.)
*/
unchecked {
type_structurally_contains(cx, ty, fn(sty: &sty) -> bool {
ret alt sty {
ty_param(_, _) { true }
_ { false }
};
});
})
}
}
fn type_is_integral(cx: &ctxt, ty: t) -> bool {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册