Autoderef indexes and fields of unique boxes

Issue #409
This commit is contained in:
Brian Anderson 2011-09-22 16:04:27 -07:00
parent dff4986f9e
commit 30a4eab380
5 changed files with 25 additions and 3 deletions

View file

@ -2305,7 +2305,12 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
v1 = PointerCast(cx, body, T_ptr(llty));
} else { v1 = body; }
}
ty::ty_uniq(t) { fail "autoderef uniq unimplemented"; }
ty::ty_uniq(_) {
check trans_uniq::type_is_unique_box(cx, t1);
let derefed = trans_uniq::autoderef(cx, v1, t1);
t1 = derefed.t;
v1 = derefed.v;
}
ty::ty_res(did, inner, tps) {
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
v1 = GEP(cx, v1, [C_int(0), C_int(1)]);

View file

@ -15,7 +15,7 @@ import trans::{
new_sub_block_ctxt
};
export trans_uniq, make_free_glue, type_is_unique_box, copy_val;
export trans_uniq, make_free_glue, type_is_unique_box, copy_val, autoderef;
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
unchecked {
@ -100,4 +100,11 @@ fn copy_val(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
Store(bcx, src, llptr);
ret bcx;
}
fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t)
: type_is_unique_box(bcx, t) -> {v: ValueRef, t: ty::t} {
let content_ty = content_ty(bcx, t);
ret {v: v, t: content_ty};
}

View file

@ -845,7 +845,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
let t1 = t;
while true {
alt structure_of(fcx, sp, t1) {
ty::ty_box(inner) {
ty::ty_box(inner) | ty::ty_uniq(inner) {
alt ty::struct(fcx.ccx.tcx, t1) {
ty::ty_var(v1) {
if ty::occurs_check_fails(fcx.ccx.tcx, some(sp), v1,

View file

@ -0,0 +1,6 @@
fn main() {
let i = ~{
j: 100
};
assert i.j == 100;
}

View file

@ -0,0 +1,4 @@
fn main() {
let i = ~[100];
assert i[0] == 100;
}