From c06ea8f9445dbb5eda99ac8730d7fb2177df6816 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 25 Jun 2010 12:15:40 -0700 Subject: [PATCH] Add test of recursive object types (ha, work by default) and fix effect-walker bug revealed by it. --- src/boot/me/effect.ml | 16 ++++++++++++++++ src/test/run-pass/obj-recursion.rs | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/run-pass/obj-recursion.rs diff --git a/src/boot/me/effect.ml b/src/boot/me/effect.ml index 515cfa21ed5..289976a0985 100644 --- a/src/boot/me/effect.ml +++ b/src/boot/me/effect.ml @@ -72,6 +72,7 @@ let function_effect_propagation_visitor * - Calling a function with effect e lowers to e. *) let curr_fn = Stack.create () in + let visit_mod_item_pre n p i = begin match i.node.Ast.decl_item with @@ -80,16 +81,29 @@ let function_effect_propagation_visitor end; inner.Walk.visit_mod_item_pre n p i in + let visit_mod_item_post n p i = inner.Walk.visit_mod_item_post n p i; match i.node.Ast.decl_item with Ast.MOD_ITEM_fn _ -> ignore (Stack.pop curr_fn) | _ -> () in + + let visit_obj_fn_pre o i fi = + Stack.push fi.id curr_fn; + inner.Walk.visit_obj_fn_pre o i fi + in + + let visit_obj_fn_post o i fi = + inner.Walk.visit_obj_fn_post o i fi; + ignore (Stack.pop curr_fn) + in + let visit_obj_drop_pre o b = Stack.push b.id curr_fn; inner.Walk.visit_obj_drop_pre o b in + let visit_obj_drop_post o b = inner.Walk.visit_obj_drop_post o b; ignore (Stack.pop curr_fn); @@ -155,6 +169,8 @@ let function_effect_propagation_visitor { inner with Walk.visit_mod_item_pre = visit_mod_item_pre; Walk.visit_mod_item_post = visit_mod_item_post; + Walk.visit_obj_fn_pre = visit_obj_fn_pre; + Walk.visit_obj_fn_post = visit_obj_fn_post; Walk.visit_obj_drop_pre = visit_obj_drop_pre; Walk.visit_obj_drop_post = visit_obj_drop_post; Walk.visit_stmt_pre = visit_stmt_pre } diff --git a/src/test/run-pass/obj-recursion.rs b/src/test/run-pass/obj-recursion.rs new file mode 100644 index 00000000000..3e562e36f9e --- /dev/null +++ b/src/test/run-pass/obj-recursion.rs @@ -0,0 +1,25 @@ +type adder = + obj { + fn add(); + }; + +obj leaf_adder(int x) { + fn add() { + log "leaf"; + log x; + } +} +obj delegate_adder(adder a) { + fn add() { + a.add(); + } +} + +fn main() { + auto x = + delegate_adder + (delegate_adder + (delegate_adder + (leaf_adder(10)))); + x.add(); +} \ No newline at end of file