From 260a0df5b742697276b762bcddd34c141aed9942 Mon Sep 17 00:00:00 2001 From: Miguel Sofer Date: Sat, 21 Mar 2009 11:46:09 +0000 Subject: * tclInt.h: comments * tests/tailcall.test: added tests to show that [tailcall] does not currently always execute in constant space: interp-alias, ns-imports and ensembles "leak" as of this commit. --- ChangeLog | 6 ++++ generic/tclInt.h | 6 ++-- tests/tailcall.test | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00b05d0..bb6eb0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-03-21 Miguel Sofer + * tclInt.h: comments + + * tests/tailcall.test: added tests to show that [tailcall] does + not currently always execute in constant space: interp-alias, + ns-imports and ensembles "leak" as of this commit. + * tests/nre.test: [foreach] has been NR-enabled for a while, the test was marked 'knownBug': unmark it. diff --git a/generic/tclInt.h b/generic/tclInt.h index 3c45cc1..5c9e127 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.420 2009/03/21 09:42:07 msofer Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.421 2009/03/21 11:46:10 msofer Exp $ */ #ifndef _TCLINT @@ -1059,9 +1059,7 @@ typedef struct CallFrame { struct TEOV_callback *tailcallPtr; /* The callback implementing the call to be * executed by the command that pushed this - * frame. It can be TAILCALL_NONE to signal - * that we are tailcalling a frame further up - * the stack. + * frame. */ } CallFrame; diff --git a/tests/tailcall.test b/tests/tailcall.test index 4cfbebf..f67a5e9 100644 --- a/tests/tailcall.test +++ b/tests/tailcall.test @@ -9,7 +9,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tailcall.test,v 1.4 2009/03/21 09:42:07 msofer Exp $ +# RCS: @(#) $Id: tailcall.test,v 1.5 2009/03/21 11:46:10 msofer Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -61,7 +61,7 @@ if {[testConstraint testnrelevels]} { namespace import testnre::* } -test tailcall-0 {tailcall is constant space} -constraints testnrelevels -setup { +test tailcall-0.1 {tailcall is constant space} -constraints testnrelevels -setup { proc a i { if {[incr i] > 10} { return [depthDiff] @@ -75,6 +75,92 @@ test tailcall-0 {tailcall is constant space} -constraints testnrelevels -setup { rename a {} } -result {0 0 0 0 0 0} +test tailcall-0.2 {tailcall is constant space} -constraints testnrelevels -setup { + set a { i { + if {[incr i] > 10} { + return [depthDiff] + } + depthDiff + upvar 1 a a + tailcall apply $a $i + }} +} -body { + apply $a 0 +} -cleanup { + unset a +} -result {0 0 0 0 0 0} + +test tailcall-0.3 {tailcall is constant space} -constraints testnrelevels -setup { + proc a i { + if {[incr i] > 10} { + return [depthDiff] + } + depthDiff + tailcall b $i + } + interp alias {} b {} a +} -body { + b 0 +} -cleanup { + rename a {} + rename b {} +} -result {0 0 0 0 0 0} + +test tailcall-0.4 {tailcall is constant space} -constraints testnrelevels -setup { + namespace eval ::ns { + namespace export * + } + proc ::ns::a i { + if {[incr i] > 10} { + return [depthDiff] + } + depthDiff + set b [uplevel 1 [list namespace which b]] + tailcall $b $i + } + namespace import ::ns::a + rename a b +} -body { + b 0 +} -cleanup { + rename b {} + namespace delete ::ns +} -result {0 0 0 0 0 0} + +test tailcall-0.5 {tailcall is constant space} -constraints testnrelevels -setup { + proc b i { + if {[incr i] > 10} { + return [depthDiff] + } + depthDiff + tailcall a b $i + } + namespace ensemble create -command a -map {b b} +} -body { + a b 0 +} -cleanup { + rename a {} + rename b {} +} -result {0 0 0 0 0 0} + +test tailcall-0.6 {tailcall is constant space} -constraints testnrelevels -setup { + oo::class create foo { + method b i { + if {[incr i] > 10} { + return [depthDiff] + } + depthDiff + tailcall [self] b $i + } + } +} -body { + foo create a + a b 0 +} -cleanup { + rename a {} + rename foo {} +} -result {0 0 0 0 0 0} + test tailcall-1 {tailcall} -body { namespace eval a { variable x *::a -- cgit v0.12