From d79afd7916dc2b5353666c301b93c09fdba29134 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 19 Jul 2011 14:31:55 -0700 Subject: [PATCH] Improving move semantics for channel operations. This lets us un-XFAIL task-comm-10.rs. --- src/comp/middle/trans_comm.rs | 9 +++++---- src/rt/memory_region.cpp | 2 +- src/rt/rust_chan.cpp | 10 +++++----- src/rt/rust_chan.h | 5 +++-- src/rt/rust_port.cpp | 4 ++-- src/rt/rust_upcall.cpp | 2 +- src/test/run-pass/task-comm-10.rs | 2 -- src/test/run-pass/task-comm-16.rs | 11 ++++------- 8 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/comp/middle/trans_comm.rs b/src/comp/middle/trans_comm.rs index 3ea1f588c95b..aca28347cacf 100644 --- a/src/comp/middle/trans_comm.rs +++ b/src/comp/middle/trans_comm.rs @@ -247,10 +247,11 @@ fn recv_val(&@block_ctxt cx, ValueRef to, &@ast::expr from, &ty::t unit_ty, bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.recv, ~[bcx.fcx.lltaskptr, lldataptr, llportptr]); auto data_load = load_if_immediate(bcx, to, unit_ty); - auto cp = copy_val(bcx, action, to, data_load, unit_ty); - bcx = cp.bcx; - // TODO: Any cleanup need to be done here? - ret rslt(bcx, to); + //auto cp = copy_val(bcx, action, to, data_load, unit_ty); + //bcx = cp.bcx; + + add_clean_temp(cx, data_load, unit_ty); + ret rslt(bcx, data_load); } // Does a deep copy of a value. This is needed for passing arguments to child diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index 603ec12e796a..f2a2a9889645 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -4,7 +4,7 @@ // NB: please do not commit code with this uncommented. It's // hugely expensive and should only be used as a last resort. // -#define TRACK_ALLOCATIONS +// #define TRACK_ALLOCATIONS #define MAGIC 0xbadc0ffe diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp index 23af8a5fef6a..92edaa77650a 100644 --- a/src/rt/rust_chan.cpp +++ b/src/rt/rust_chan.cpp @@ -4,12 +4,10 @@ /** * Create a new rust channel and associate it with the specified port. */ -rust_chan::rust_chan(rust_task *task, - maybe_proxy *port, +rust_chan::rust_chan(rust_kernel *kernel, maybe_proxy *port, size_t unit_sz) : ref_count(1), - kernel(task->kernel), - task(task), + kernel(kernel), port(port), buffer(kernel, unit_sz) { if (port) { @@ -39,6 +37,7 @@ void rust_chan::associate(maybe_proxy *port) { this, port); ++this->ref_count; this->task = port->referent()->task; + this->task->ref(); this->port->referent()->chans.push(this); } } @@ -59,6 +58,7 @@ void rust_chan::disassociate() { "disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR, this, port->referent()); --this->ref_count; + --this->task->ref_count; this->task = NULL; port->referent()->chans.swap_delete(this); } @@ -118,7 +118,7 @@ rust_chan *rust_chan::clone(maybe_proxy *target) { target_task = target->as_proxy()->handle()->referent(); } return new (target_task->kernel, "cloned chan") - rust_chan(target_task, port, unit_sz); + rust_chan(kernel, port, unit_sz); } /** diff --git a/src/rt/rust_chan.h b/src/rt/rust_chan.h index 52ebc40e8040..056d70cebe4d 100644 --- a/src/rt/rust_chan.h +++ b/src/rt/rust_chan.h @@ -5,12 +5,13 @@ class rust_chan : public kernel_owned, public rust_cond { public: RUST_REFCOUNTED_WITH_DTOR(rust_chan, destroy()) - rust_chan(rust_task *task, maybe_proxy *port, size_t unit_sz); + rust_chan(rust_kernel *kernel, maybe_proxy *port, + size_t unit_sz); ~rust_chan(); rust_kernel *kernel; - smart_ptr task; + rust_task *task; maybe_proxy *port; size_t idx; circular_buffer buffer; diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp index 48ce42ca7cb1..19592f4c8695 100644 --- a/src/rt/rust_port.cpp +++ b/src/rt/rust_port.cpp @@ -10,8 +10,8 @@ rust_port::rust_port(rust_task *task, size_t unit_sz) PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this); // Allocate a remote channel, for remote channel data. - remote_channel = new (task->kernel, "remote chan") - rust_chan(task, this, unit_sz); + remote_channel = new (kernel, "remote chan") + rust_chan(kernel, this, unit_sz); } rust_port::~rust_port() { diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 8a61e5e95a51..8313399130ca 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -130,7 +130,7 @@ upcall_new_chan(rust_task *task, rust_port *port) { (uintptr_t) task, task->name, port); I(sched, port); return new (task->kernel, "rust_chan") - rust_chan(task, port, port->unit_sz); + rust_chan(task->kernel, port, port->unit_sz); } /** diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 29ab1f579b2f..3b96caf7483b 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -1,6 +1,4 @@ // xfail-stage0 -// xfail-stage1 -// xfail-stage2 use std; import std::task; diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs index f6cc8b8fe824..4d8a9bb858aa 100644 --- a/src/test/run-pass/task-comm-16.rs +++ b/src/test/run-pass/task-comm-16.rs @@ -1,6 +1,3 @@ - - - // -*- rust -*- // Tests of ports and channels on various types @@ -19,11 +16,11 @@ fn test_rec() { } fn test_vec() { - let port[vec[int]] po = port(); - let chan[vec[int]] ch = chan(po); - let vec[int] v0 = [0, 1, 2]; + let port[int[]] po = port(); + let chan[int[]] ch = chan(po); + let int[] v0 = ~[0, 1, 2]; ch <| v0; - let vec[int] v1; + let int[] v1; po |> v1; assert (v1.(0) == 0); assert (v1.(1) == 1);