From 72c14d5a4108e91dcdce17c8ccc6f7953fde8a70 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 2 Sep 2011 12:21:01 -0700 Subject: [PATCH] Eliminate const_refcount. Issue #855 --- src/comp/back/abi.rs | 4 ---- src/comp/middle/trans.rs | 24 ++++++------------------ src/lib/dbg.rs | 3 --- src/rt/rust_builtin.cpp | 7 +------ src/rt/rust_internal.h | 7 ------- src/test/run-pass/alt-pattern-drop.rs | 4 ---- 6 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index b14afb0d594f..e71ed2eeff96 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -4,10 +4,6 @@ // FIXME: Most of these should be uints. const rc_base_field_refcnt: int = 0; - -// FIXME: import from std::dbg when imported consts work. -const const_refcount: uint = 0x7bad_face_u; - const task_field_refcnt: int = 0; const task_field_stk: int = 2; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 6363d44a30ea..e03b23bf43c1 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1318,16 +1318,9 @@ fn incr_refcnt_of_boxed(cx: &@block_ctxt, box_ptr: ValueRef) -> @block_ctxt { let rc_ptr = GEP(cx, box_ptr, [C_int(0), C_int(abi::box_rc_field_refcnt)]); let rc = Load(cx, rc_ptr); - let rc_adj_cx = new_sub_block_ctxt(cx, ~"rc++"); - let next_cx = new_sub_block_ctxt(cx, ~"next"); - let const_test = - ICmp(cx, lib::llvm::LLVMIntEQ, C_int(abi::const_refcount as int), - rc); - CondBr(cx, const_test, next_cx.llbb, rc_adj_cx.llbb); - rc = Add(rc_adj_cx, rc, C_int(1)); - Store(rc_adj_cx, rc, rc_ptr); - Br(rc_adj_cx, next_cx.llbb); - ret next_cx; + rc = Add(cx, rc, C_int(1)); + Store(cx, rc, rc_ptr); + ret cx; } fn make_free_glue(bcx: &@block_ctxt, v0: ValueRef, t: ty::t) { @@ -1466,7 +1459,6 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id, fn decr_refcnt_maybe_free(cx: &@block_ctxt, box_ptr_alias: ValueRef, full_alias: ValueRef, t: ty::t) -> @block_ctxt { let ccx = bcx_ccx(cx); - let load_rc_cx = new_sub_block_ctxt(cx, ~"load rc"); let rc_adj_cx = new_sub_block_ctxt(cx, ~"rc--"); let free_cx = new_sub_block_ctxt(cx, ~"free"); let next_cx = new_sub_block_ctxt(cx, ~"next"); @@ -1474,15 +1466,11 @@ fn decr_refcnt_maybe_free(cx: &@block_ctxt, box_ptr_alias: ValueRef, let llbox_ty = T_opaque_obj_ptr(*ccx); box_ptr = PointerCast(cx, box_ptr, llbox_ty); let null_test = IsNull(cx, box_ptr); - CondBr(cx, null_test, next_cx.llbb, load_rc_cx.llbb); + CondBr(cx, null_test, next_cx.llbb, rc_adj_cx.llbb); let rc_ptr = - GEP(load_rc_cx, box_ptr, + GEP(rc_adj_cx, box_ptr, [C_int(0), C_int(abi::box_rc_field_refcnt)]); - let rc = Load(load_rc_cx, rc_ptr); - let const_test = - ICmp(load_rc_cx, lib::llvm::LLVMIntEQ, - C_int(abi::const_refcount as int), rc); - CondBr(load_rc_cx, const_test, next_cx.llbb, rc_adj_cx.llbb); + let rc = Load(rc_adj_cx, rc_ptr); rc = Sub(rc_adj_cx, rc, C_int(1)); Store(rc_adj_cx, rc, rc_ptr); let zero_test = ICmp(rc_adj_cx, lib::llvm::LLVMIntEQ, C_int(0), rc); diff --git a/src/lib/dbg.rs b/src/lib/dbg.rs index 77587bd058c7..6858b30419a6 100644 --- a/src/lib/dbg.rs +++ b/src/lib/dbg.rs @@ -8,9 +8,6 @@ * logging. */ -// FIXME: handle 64-bit case. -const const_refcount: uint = 0x7bad_face_u; - native "rust" mod rustrt { fn debug_tydesc(); fn debug_opaque(x: &T); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 814822e8f1ea..0ed30a8cbf63 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -90,9 +90,6 @@ leak(rust_task *task, type_desc *t, void *thing) { extern "C" CDECL intptr_t refcount(rust_task *task, type_desc *t, intptr_t *v) { - if (*v == CONST_REFCOUNT) - return CONST_REFCOUNT; - // Passed-in value has refcount 1 too high // because it was ref'ed while making the call. return (*v) - 1; @@ -249,9 +246,7 @@ debug_box(rust_task *task, type_desc *t, rust_box *box) LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box); debug_tydesc_helper(task, t); LOG(task, stdlib, " refcount %" PRIdPTR, - box->ref_count == CONST_REFCOUNT - ? CONST_REFCOUNT - : box->ref_count - 1); // -1 because we ref'ed for this call + box->ref_count - 1); // -1 because we ref'ed for this call for (uintptr_t i = 0; i < t->size; ++i) { LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]); } diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h index 4a5d208915df..d2c8574280b0 100644 --- a/src/rt/rust_internal.h +++ b/src/rt/rust_internal.h @@ -95,13 +95,6 @@ struct chan_handle { static size_t const TIME_SLICE_IN_MS = 10; -// Since every refcounted object is > 4 bytes, any refcount with any of the -// top two bits set is invalid. We reserve a particular bit pattern in this -// set for indicating objects that are "constant" as far as the memory model -// knows. - -static intptr_t const CONST_REFCOUNT = 0x7badface; - // This accounts for logging buffers. static size_t const BUF_BYTES = 2048; diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs index 28067b6d7cdb..1447b48d515d 100644 --- a/src/test/run-pass/alt-pattern-drop.rs +++ b/src/test/run-pass/alt-pattern-drop.rs @@ -5,10 +5,6 @@ use std; import std::dbg; -// FIXME: import std::dbg.const_refcount. Currently -// cross-crate const references don't work. -const const_refcount: uint = 0x7bad_face_u; - tag t { make_t(@int); clam; } fn foo(s: @int) {