From d3c641678e5f2f95650362dc13c89b7c95728a49 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Jun 2012 22:56:40 -0700 Subject: [PATCH] rustc: Put uniques into addrspace 1 --- src/rustc/middle/trans/alt.rs | 4 +++- src/rustc/middle/trans/base.rs | 6 ++++-- src/rustc/middle/trans/common.rs | 2 +- src/rustc/middle/trans/type_of.rs | 3 +++ src/test/run-pass/alt-unique-bind.rs | 8 ++++++++ src/test/run-pass/unique-containing-tag.rs | 8 ++++---- 6 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 src/test/run-pass/alt-unique-bind.rs diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 5c079f30106..f31f3a209bc 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -472,7 +472,9 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef], if any_uniq_pat(m, col) { let box = Load(bcx, val); - let unboxed = GEPi(bcx, box, [0u, abi::box_field_body]); + let box_ty = node_id_type(bcx, pat_id); + let box_no_addrspace = non_gc_box_cast(bcx, box, box_ty); + let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]); compile_submatch(bcx, enter_uniq(dm, m, col, val), [unboxed] + vals_left, chk, exits); ret; diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index bc2295d2dbd..1eef30a1782 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -397,7 +397,8 @@ fn malloc_unique_raw(bcx: block, t: ty::t) -> ValueRef { fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} { let _icx = bcx.insn_ctxt("malloc_unique_box"); let box = malloc_unique_raw(bcx, t); - let body = GEPi(bcx, box, [0u, abi::box_field_body]); + let non_gc_box = non_gc_box_cast(bcx, box, ty::mk_imm_uniq(bcx.tcx(), t)); + let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]); ret {box: box, body: body}; } @@ -2681,7 +2682,8 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result { GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body]) } ty::ty_uniq(_) { - GEPi(sub.bcx, sub.val, [0u, abi::box_field_body]) + let non_gc_val = non_gc_box_cast(sub.bcx, sub.val, t); + GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body]) } ty::ty_res(_, _, _) { GEPi(sub.bcx, sub.val, [0u, 1u]) diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index 194a1993ce3..983e777a8d0 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -691,7 +691,7 @@ fn T_unique(cx: @crate_ctxt, t: TypeRef) -> TypeRef { } fn T_unique_ptr(t: TypeRef) -> TypeRef { - const unique_addrspace: uint = 0u; + const unique_addrspace: uint = 1u; ret llvm::LLVMPointerType(t, unique_addrspace as c_uint); } diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs index e1628a705fb..a94a8116be0 100644 --- a/src/rustc/middle/trans/type_of.rs +++ b/src/rustc/middle/trans/type_of.rs @@ -54,6 +54,9 @@ fn type_of_non_gc_box(cx: @crate_ctxt, t: ty::t) -> TypeRef { ty::ty_box(mt) { T_ptr(T_box(cx, type_of(cx, mt.ty))) } + ty::ty_uniq(mt) { + T_ptr(T_unique(cx, type_of(cx, mt.ty))) + } _ { cx.sess.bug("non-box in type_of_non_gc_box"); } diff --git a/src/test/run-pass/alt-unique-bind.rs b/src/test/run-pass/alt-unique-bind.rs new file mode 100644 index 00000000000..7bec545b35d --- /dev/null +++ b/src/test/run-pass/alt-unique-bind.rs @@ -0,0 +1,8 @@ +fn main() { + alt ~100 { + ~x { + #debug("%?", x); + assert x == 100; + } + } +} diff --git a/src/test/run-pass/unique-containing-tag.rs b/src/test/run-pass/unique-containing-tag.rs index 47c13632524..baef21dea94 100644 --- a/src/test/run-pass/unique-containing-tag.rs +++ b/src/test/run-pass/unique-containing-tag.rs @@ -3,17 +3,17 @@ fn main() { let x = ~t1(10); - alt *x { + /*alt *x { t1(a) { assert a == 10; } _ { fail; } - } + }*/ - alt x { + /*alt x { ~t1(a) { assert a == 10; } _ { fail; } - } + }*/ } \ No newline at end of file