Skip to content

Commit 30a4eab

Browse files
committed
Autoderef indexes and fields of unique boxes
Issue #409
1 parent dff4986 commit 30a4eab

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,12 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
23052305
v1 = PointerCast(cx, body, T_ptr(llty));
23062306
} else { v1 = body; }
23072307
}
2308-
ty::ty_uniq(t) { fail "autoderef uniq unimplemented"; }
2308+
ty::ty_uniq(_) {
2309+
check trans_uniq::type_is_unique_box(cx, t1);
2310+
let derefed = trans_uniq::autoderef(cx, v1, t1);
2311+
t1 = derefed.t;
2312+
v1 = derefed.v;
2313+
}
23092314
ty::ty_res(did, inner, tps) {
23102315
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
23112316
v1 = GEP(cx, v1, [C_int(0), C_int(1)]);

src/comp/middle/trans_uniq.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import trans::{
1515
new_sub_block_ctxt
1616
};
1717

18-
export trans_uniq, make_free_glue, type_is_unique_box, copy_val;
18+
export trans_uniq, make_free_glue, type_is_unique_box, copy_val, autoderef;
1919

2020
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
2121
unchecked {
@@ -100,4 +100,11 @@ fn copy_val(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
100100
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
101101
Store(bcx, src, llptr);
102102
ret bcx;
103+
}
104+
105+
fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t)
106+
: type_is_unique_box(bcx, t) -> {v: ValueRef, t: ty::t} {
107+
108+
let content_ty = content_ty(bcx, t);
109+
ret {v: v, t: content_ty};
103110
}

src/comp/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
845845
let t1 = t;
846846
while true {
847847
alt structure_of(fcx, sp, t1) {
848-
ty::ty_box(inner) {
848+
ty::ty_box(inner) | ty::ty_uniq(inner) {
849849
alt ty::struct(fcx.ccx.tcx, t1) {
850850
ty::ty_var(v1) {
851851
if ty::occurs_check_fails(fcx.ccx.tcx, some(sp), v1,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let i = ~{
3+
j: 100
4+
};
5+
assert i.j == 100;
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let i = ~[100];
3+
assert i[0] == 100;
4+
}

0 commit comments

Comments
 (0)