Skip to content

Commit 74d2f56

Browse files
committed
Adding move_val and move_val_init intrinsics.
1 parent 1642df8 commit 74d2f56

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/rustc/middle/trans/native.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,26 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
812812
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
813813
fcx.llretptr);
814814
}
815+
"move_val" {
816+
let tp_ty = substs.tys[0];
817+
let src = {bcx: bcx,
818+
val: get_param(decl, first_real_arg + 1u),
819+
kind: owned };
820+
bcx = move_val(bcx, DROP_EXISTING,
821+
get_param(decl, first_real_arg),
822+
src,
823+
tp_ty);
824+
}
825+
"move_val_init" {
826+
let tp_ty = substs.tys[0];
827+
let src = {bcx: bcx,
828+
val: get_param(decl, first_real_arg + 1u),
829+
kind: owned };
830+
bcx = move_val(bcx, INIT,
831+
get_param(decl, first_real_arg),
832+
src,
833+
tp_ty);
834+
}
815835
"min_align_of" {
816836
let tp_ty = substs.tys[0];
817837
let lltp_ty = type_of::type_of(ccx, tp_ty);

src/rustc/middle/trans/type_use.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
7979
let flags = alt check *i.ident {
8080
"visit_ty" { 3u }
8181
"size_of" | "pref_align_of" | "min_align_of" |
82-
"init" | "reinterpret_cast" { use_repr }
82+
"init" | "reinterpret_cast" | "move_val" | "move_val_init" {
83+
use_repr
84+
}
8385
"get_tydesc" | "needs_drop" { use_tydesc }
8486
"forget" | "addr_of" { 0u }
8587
};

src/rustc/middle/typeck/check.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl methods for @fn_ctxt {
456456
none { result::err("no block is in scope here") }
457457
}
458458
}
459+
#[inline(always)]
459460
fn write_ty(node_id: ast::node_id, ty: ty::t) {
460461
#debug["write_ty(%d, %s) in fcx %s",
461462
node_id, ty_to_str(self.tcx(), ty), self.tag()];
@@ -2310,6 +2311,11 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
23102311
param(ccx, 1u)) }
23112312
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
23122313
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
2314+
"move_val" | "move_val_init" {
2315+
(1u, [arg(ast::by_mutbl_ref, param(ccx, 0u)),
2316+
arg(ast::by_move, param(ccx, 0u))],
2317+
ty::mk_nil(tcx))
2318+
}
23132319
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
23142320

23152321
"visit_ty" {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[abi = "rust-intrinsic"]
2+
native mod rusti {
3+
fn move_val_init<T>(&dst: T, -src: T);
4+
fn move_val<T>(&dst: T, -src: T);
5+
}
6+
7+
fn main() {
8+
let mut x = @1;
9+
let mut y = @2;
10+
rusti::move_val(y, x);
11+
assert *y == 1;
12+
}

0 commit comments

Comments
 (0)