> the optimizer has a field day
> rewriting your code as something quite unrecognizable. I'm on the case.
Glad to help :)
Dimitre
On Tue, Jan 18, 2011 at 7:05 AM, Michael Kay <mike@...> wrote:
> Thanks. This is going to be another tricky one to bottom out - as you
> can see if you run it with -explain, the optimizer has a field day
> rewriting your code as something quite unrecognizable. I'm on the case.
>
> Michael Kay
> Saxonica.
>
> On 18/01/2011 03:25, Dimitre Novatchev wrote:
>> Dear Dr. Kay,
>>
>> I have followed your guidelines and now I get the following error
>> without line-number, so I don't know what and where went wrong:
>>
>> SystemID: C:\CVS-DDN\fxsl-xslt3\DataStructs\Tree.xsl
>> Engine name: Saxon-EE 9.3.0.4
>> Severity: error
>> Description: Internal error: invalid slot number for local variable
>> (No slot allocated)
>>
>> As before, I would greatly appreciate any hints about what may be
>> wrong and if there is a workaround.
>>
>>
>> My code is just a little bigger now and I am trying to test the
>> tree:empty() function only:
>>
>> <xsl:stylesheet version="3.0"
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:tree="http://fxsl.sf.net/dataStructures/binTree"
>> exclude-result-prefixes="xs tree">
>>
>> <xsl:template match="/">
>> <xsl:variable name="vEmptyTree" select="tree:tree()"/>
>>
>> <xsl:sequence select="tree:empty($vEmptyTree)"/>
>>
>> <!--
>> <xsl:variable name="vFilledTree" select=
>> "tree:print(tree:insert($vEmptyTree,5))
>> "/>
>>
>> <xsl:sequence select="$vFilledTree"/>
>> -->
>>
>> </xsl:template>
>>
>> <xsl:function name="tree:top" as="item()?">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>
>> <xsl:sequence select="$pTree[1]()"/>
>> </xsl:function>
>>
>> <xsl:function name="tree:left" as="function() as item()*">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>
>> <xsl:sequence select="$pTree[2]()"/>
>> </xsl:function>
>>
>> <xsl:function name="tree:right" as="function() as item()*">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>
>> <xsl:sequence select="$pTree[3]()"/>
>> </xsl:function>
>>
>> <xsl:function name="tree:tree" as="(function() as item()*)+">
>>
>> <xsl:sequence select=
>> "function() {()}, (: top() :)
>> function() {()}, (: left() :)
>> function() {()} (: right() :)
>> "/>
>> </xsl:function>
>>
>> <xsl:function name="tree:empty" as="xs:boolean">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>
>> <xsl:sequence select=
>> "let $vTree := $pTree
>> return empty($pTree[1]())"/>
>> </xsl:function>
>>
>> <xsl:function name="tree:insert" as="(function() as item()*)+">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>> <xsl:param name="pItem" as="item()"/>
>>
>> <xsl:sequence select=
>> "let $pItem := $pItem return
>> let $pTree := $pTree return
>>
>> if(tree:empty($pTree))
>> then
>> (
>> function() {$pItem}, (: top() :)
>> function() {()}, (: left() :)
>> function() {()} (: right() :)
>> )
>> else
>> if($pItem lt tree:top($pTree))
>> then
>> (
>> function() {tree:top($pTree)},
>> function() {tree:insert(tree:left($pTree), $pItem)},
>> function() {tree:right($pTree)}
>> )
>> else
>> if($pItem gt tree:top($pTree))
>> then
>> (
>> function() {tree:top($pTree)},
>> function() {tree:left($pTree)},
>> function() {tree:insert(tree:right($pTree), $pItem)}
>> )
>> else
>> $pTree
>> "/>
>> "/>
>> </xsl:function>
>>
>> <xsl:function name="tree:print" as="element()?">
>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>
>> <xsl:if test="not(let $vTree := $pTree
>> return tree:empty($vTree))">
>> <treeNode>
>> <value>
>> <xsl:sequence select=
>> "let $vTree := $pTree
>> return string(tree:top($vTree))" />
>> </value>
>> <xsl:sequence select=
>> "let $vTree := $pTree
>> return tree:print(tree:left($vTree))"/>
>> <xsl:sequence select=
>> "let $vTree := $pTree
>> return tree:print(tree:right($vTree))"/>
>> </treeNode>
>> </xsl:if>
>> </xsl:function>
>>
>> </xsl:stylesheet>
>>
>> Thanks,
>> Dimitre
>>
>> On Mon, Jan 17, 2011 at 10:25 AM, Michael Kay<mike@...> wrote:
>>> This bug is now logged in the SourceForge bug tracker; I have committed
>>> a patch and added a test case.
>>>
>>> The way that Saxon handles inline functions that contain references to
>>> local variables declared outside the function body is a little
>>> complicated. What happens is that if you write this:
>>>
>>> let $x := XXXXX
>>> return function($w){ $x + $w }
>>>
>>> then what you get is essentially this:
>>>
>>> let $x := XXXXX
>>> let $temp := function($x, $w) { $x + $w }
>>> return $temp($x, ?)
>>>
>>> The creation of the intermediate function was not working in the case
>>> where $x was an XSLT-defined variable rather than an XPath-defined
>>> variable; the fix was complicated because the expansion shown above is
>>> done during XPath expression parsing, at which point XSLT variables have
>>> not yet been fully compiled. Later on in the process, XSLT variables and
>>> XPath variables become indistinguishable.
>>>
>>> Michael Kay
>>> Saxonica
>>>
>>>
>>> On 17/01/2011 16:41, Dimitre Novatchev wrote:
>>>> Thank you,
>>>>
>>>> I'll try this when I come back home from work.
>>>>
>>>> Dimitre
>>>>
>>>> On Mon, Jan 17, 2011 at 8:18 AM, Michael Kay<mike@...> wrote:
>>>>> This is proving quite a tough one to crack. As a workaround, you can
>>>>> rewrite the relevant expression as:
>>>>>
>>>>> <xsl:sequence select=
>>>>> "let $pItem := $pItem return
>>>>> let $pTree := $pTree return
>>>>> if(tree:empty($pTree))
>>>>> then
>>>>> (
>>>>> function() {$pItem}, (: top() :)
>>>>> function() {()}, (: left() :)
>>>>> function() {()} (: right() :)
>>>>> )
>>>>> else
>>>>> if($pItem lt tree:top($pTree))
>>>>> then
>>>>> (
>>>>> function() {tree:top($pTree)},
>>>>> function() {tree:insert(tree:left($pTree), $pItem)},
>>>>> function() {tree:right($pTree)}
>>>>> )
>>>>> else
>>>>> if($pItem gt tree:top($pTree))
>>>>> then
>>>>> (
>>>>> function() {tree:top($pTree)},
>>>>> function() {tree:left($pTree)},
>>>>> function() {tree:insert(tree:right($pTree), $pItem)}
>>>>> )
>>>>> else
>>>>> $pTree
>>>>> "/>
>>>>>
>>>>> (Note that there are a couple of typos fixed here, as well as binding
>>>>> the range variables $pItem and $pTree at the start.)
>>>>>
>>>>> Michael Kay
>>>>> Saxonica
>>>>>
>>>>> On 17/01/2011 13:26, Dimitre Novatchev wrote:
>>>>>> Thank you, Michael.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Cheers,
>>>>>> Dimitre Novatchev
>>>>>> ---------------------------------------
>>>>>> Truly great madness cannot be achieved without significant intelligence.
>>>>>> ---------------------------------------
>>>>>> To invent, you need a good imagination and a pile of junk
>>>>>> -------------------------------------
>>>>>> Never fight an inanimate object
>>>>>> -------------------------------------
>>>>>> You've achieved success in your field when you don't know whether what
>>>>>> you're doing is work or play
>>>>>> -------------------------------------
>>>>>> Facts do not cease to exist because they are ignored.
>>>>>>
>>>>>> On Mon, Jan 17, 2011 at 1:45 AM, Michael Kay<mike@...> wrote:
>>>>>>> Thanks for reporting it, Dimitre.
>>>>>>>
>>>>>>> On lines 53 and 54 I think you need to change
>>>>>>>
>>>>>>> function() {}
>>>>>>>
>>>>>>> to
>>>>>>>
>>>>>>> function() {()}
>>>>>>>
>>>>>>> - but unfortunately that doesn't actually solve the problem.
>>>>>>>
>>>>>>> It seems that references from the body of an inline function to
>>>>>>> variables or parameters of an outer function are working in XQuery but
>>>>>>> not in XSLT. I'm working on a solution.
>>>>>>>
>>>>>>> Michael Kay
>>>>>>> Saxonica
>>>>>>>
>>>>>>> On 17/01/2011 04:06, Dimitre Novatchev wrote:
>>>>>>>> I modified the code to the one below, but still get the same
>>>>>>>> NullPointerException.
>>>>>>>>
>>>>>>>> <xsl:stylesheet version="3.0"
>>>>>>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>>>>>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>>>>>> xmlns:tree="http://fxsl.sf.net"
>>>>>>>> exclude-result-prefixes="xs tree">
>>>>>>>>
>>>>>>>> <xsl:template match="/">
>>>>>>>> <xsl:variable name="vEmptyTree" select="tree:tree()"/>
>>>>>>>> </xsl:template>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:top" as="item()?">
>>>>>>>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>>>>>>>
>>>>>>>> <xsl:sequence select="$pTree[1]()"/>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:left" as="function() as item()*">
>>>>>>>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>>>>>>>
>>>>>>>> <xsl:sequence select="$pTree[2]()"/>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:right" as="function() as item()*">
>>>>>>>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>>>>>>>
>>>>>>>> <xsl:sequence select="$pTree[3]()"/>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:tree" as="(function() as item()*)+">
>>>>>>>>
>>>>>>>> <xsl:sequence select=
>>>>>>>> "function() {()}, (: top() :)
>>>>>>>> function() {()}, (: left() :)
>>>>>>>> function() {()} (: right() :)
>>>>>>>> "/>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:empty" as="xs:boolean">
>>>>>>>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>>>>>>>
>>>>>>>> <xsl:sequence select="empty($pTree[1]())"/>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> <xsl:function name="tree:insert" as="(function() as item()*)+">
>>>>>>>> <xsl:param name="pTree" as="(function() as item()*)+"/>
>>>>>>>> <xsl:param name="pItem" as="item()"/>
>>>>>>>>
>>>>>>>> <xsl:sequence select=
>>>>>>>> "if(tree:empty($pTree))
>>>>>>>> then
>>>>>>>> (
>>>>>>>> function() {$pItem}, (: top() :)
>>>>>>>> function() {}, (: left() :)
>>>>>>>> function() {} (: right() :)
>>>>>>>> )
>>>>>>>> else
>>>>>>>> if($pItem lt tree:top($pTree))
>>>>>>>> then
>>>>>>>> (
>>>>>>>> function() {tree:top($pTree)},
>>>>>>>> function() {tree:insert(tree:left($pTree), $pItem)}
>>>>>>>> function() {tree:right($pTree)}
>>>>>>>> )
>>>>>>>> else
>>>>>>>> if($pItem gt tree:top($pTree))
>>>>>>>> then
>>>>>>>> (
>>>>>>>> function() {tree:top($pTree)},
>>>>>>>> function() {tree:left($pTree)}
>>>>>>>> function() {tree:insert(tree:right($pTree), $pItem)}
>>>>>>>> )
>>>>>>>> else
>>>>>>>> $pTree
>>>>>>>> "/>
>>>>>>>>
>>>>>>>> </xsl:function>
>>>>>>>>
>>>>>>>> </xsl:stylesheet>
>>>>>>>>
>>>>>>>>
>>>>>>> ------------------------------------------------------------------------------
>>>>>>> Protect Your Site and Customers from Malware Attacks
>>>>>>> Learn about various malware tactics and how to avoid them. Understand
>>>>>>> malware threats, the impact they can have on your business, and how you
>>>>>>> can protect your company and customers by using code signing.
>>>>>>> http://p.sf.net/sfu/oracle-sfdevnl
>>>>>>> _______________________________________________
>>>>>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>>>>>> saxon-help@...
>>>>>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>>>>>
>>>>>> --
>>>>>>
>>>>>> ------------------------------------------------------------------------------
>>>>>> Protect Your Site and Customers from Malware Attacks
>>>>>> Learn about various malware tactics and how to avoid them. Understand
>>>>>> malware threats, the impact they can have on your business, and how you
>>>>>> can protect your company and customers by using code signing.
>>>>>> http://p.sf.net/sfu/oracle-sfdevnl
>>>>>> _______________________________________________
>>>>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>>>>> saxon-help@...
>>>>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>>> ------------------------------------------------------------------------------
>>>>> Protect Your Site and Customers from Malware Attacks
>>>>> Learn about various malware tactics and how to avoid them. Understand
>>>>> malware threats, the impact they can have on your business, and how you
>>>>> can protect your company and customers by using code signing.
>>>>> http://p.sf.net/sfu/oracle-sfdevnl
>>>>> _______________________________________________
>>>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>>>> saxon-help@...
>>>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>>>
>>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Protect Your Site and Customers from Malware Attacks
>>> Learn about various malware tactics and how to avoid them. Understand
>>> malware threats, the impact they can have on your business, and how you
>>> can protect your company and customers by using code signing.
>>> http://p.sf.net/sfu/oracle-sfdevnl
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> saxon-help@...
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>
>>
>
>
> ------------------------------------------------------------------------------
> Protect Your Site and Customers from Malware Attacks
> Learn about various malware tactics and how to avoid them. Understand
> malware threats, the impact they can have on your business, and how you
> can protect your company and customers by using code signing.
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
|