From af44ec2856603b8a978a1f2582c285c7c0065403 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 24 Jun 2010 13:32:59 -0700 Subject: [PATCH] Issue 24, drop output slot when not initializing. Un-XFAIL generic-tag.rs. Add test for output slot modes with several broken cases. --- src/Makefile | 2 +- src/boot/me/trans.ml | 16 ++++--- src/test/run-pass/output-slot-variants.rs | 58 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/test/run-pass/output-slot-variants.rs diff --git a/src/Makefile b/src/Makefile index 193f04d7ef3..2244c350273 100644 --- a/src/Makefile +++ b/src/Makefile @@ -321,7 +321,6 @@ TEST_XFAILS_X86 := test/run-pass/mlist-cycle.rs \ test/run-pass/vec-slice.rs \ test/run-pass/generic-fn-infer.rs \ test/run-pass/generic-recursive-tag.rs \ - test/run-pass/generic-tag.rs \ test/run-pass/bind-obj-ctor.rs \ test/run-pass/task-comm.rs \ test/compile-fail/rec-missing-fields.rs \ @@ -391,6 +390,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \ obj-dtor.rs \ obj-with-vec.rs \ opeq.rs \ + output-slot-variants.rs \ preempt.rs \ pred.rs \ readalias.rs \ diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index fe4a542f489..cb492561226 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -3708,7 +3708,7 @@ let trans_visitor and trans_prepare_call - ((*initializing*)_:bool) + (initializing:bool) (logname:(unit -> string)) (call:call) : Il.operand = @@ -3718,11 +3718,15 @@ let trans_visitor (Printf.sprintf "copy args for call to %s" (logname ()))); copy_fn_args false CLONE_none call; iflog (fun _ -> annotate (Printf.sprintf "call %s" (logname ()))); - (* FIXME (issue #24): we need to actually handle writing to an - * already-initialised slot. Currently we blindly assume we're - * initializing, overwrite the slot; this is ok if we're writing - * to an interior output slot, but we'll leak any exteriors as we - * do that. *) + if not initializing + then + begin + match call.call_callee_ty with + Ast.TY_fn (tsig, _) -> + drop_slot (get_ty_params_of_current_frame()) call.call_output + tsig.Ast.sig_output_slot None; + | _ -> bug () "calling non-fn" + end; callee_fptr and callee_drop_slot diff --git a/src/test/run-pass/output-slot-variants.rs b/src/test/run-pass/output-slot-variants.rs new file mode 100644 index 00000000000..65d03fd8b63 --- /dev/null +++ b/src/test/run-pass/output-slot-variants.rs @@ -0,0 +1,58 @@ +fn ret_int_i() -> int { + ret 10; +} + +fn ret_ext_i() -> @int { + ret 10; +} + +fn ret_int_tup() -> tup(int,int) { + ret tup(10, 10); +} + +fn ret_ext_tup() -> @tup(int,int) { + ret tup(10, 10); +} + +fn ret_ext_mem() -> tup(@int, @int) { + ret tup(@10, @10); +} + +fn ret_ext_ext_mem() -> @tup(@int, @int) { + ret tup(@10, @10); +} + +fn main() { + + let int int_i; + let @int ext_i; + let tup(int,int) int_tup; + let @tup(int,int) ext_tup; + let tup(@int,@int) ext_mem; + let @tup(@int,@int) ext_ext_mem; + + int_i = ret_int_i(); // initializing + int_i = ret_int_i(); // non-initializing + int_i = ret_int_i(); // non-initializing + + //ext_i = ret_ext_i(); // initializing + //ext_i = ret_ext_i(); // non-initializing + //ext_i = ret_ext_i(); // non-initializing + + int_tup = ret_int_tup(); // initializing + int_tup = ret_int_tup(); // non-initializing + int_tup = ret_int_tup(); // non-initializing + + //ext_tup = ret_ext_tup(); // initializing + //ext_tup = ret_ext_tup(); // non-initializing + //ext_tup = ret_ext_tup(); // non-initializing + + ext_mem = ret_ext_mem(); // initializing + ext_mem = ret_ext_mem(); // non-initializing + ext_mem = ret_ext_mem(); // non-initializing + + //ext_ext_mem = ret_ext_ext_mem(); // initializing + //ext_ext_mem = ret_ext_ext_mem(); // non-initializing + //ext_ext_mem = ret_ext_ext_mem(); // non-initializing + +}