Menu

#434 Tail recursion in xsl:function/xsl:choose

v8.6.1
closed
5
2012-10-08
2005-11-28
Michael Kay
No

When the body of an xsl:function uses xsl:choose, a
recursive tail-call within one branch of the xsl:choose
is not recognized as a tail call. This may cause a
stack overflow when the recursion depth exceeds the
Java stack space available.

The problem may also occur with a typeswitch in XQuery.

The fix involves addding the following two methods to
net.sf.saxon.instruct.Choose:

public int getImplementationMethod() {
    return Expression.PROCESS_METHOD |

Expression.ITERATE_METHOD;
}

public boolean markTailFunctionCalls() {
    boolean result = false;
    for (int i=0; i<actions.length; i++) {
        if (actions[i] instanceof ComputedExpression) {
            result |=

((ComputedExpression)actions[i]).markTailFunctionCalls();
}
}
return result;
}

Applies to Saxon 8.6.1 and earlier releases.

Discussion