Tail recursion in xsl:function/xsl:choose
The Saxon XSLT and XQuery processor, developed by Saxonica
Brought to you by:
mhkay
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.