https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2022-02-24T20:11:08ZSaxonica Developer CommunitySaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196462022-02-24T20:11:08ZAlexander Stein
<ul><li><strong>Company</strong> set to <i>Fed</i></li><li><strong>Contact person</strong> set to <i>Alexander J. Stein</i></li></ul><p>Hello, any updates on this issue?</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196552022-02-25T12:07:45ZMichael Kaymike@saxonica.com
<ul></ul><p>I have reproduced the problem and am re-familiarising myself with the code in this area.</p>
<p>The error originates from line 367 of parseFast.js. It is looking for an accumulator with name <code>Q{}total-items</code>, but the index of accumulator names in the static context is empty.</p>
<p>I am suspicious about line 176 in xpath.xsl which initializes the <code>$accumulators</code> tunnel variable with a reference to <code>ex:accumulator</code> (on the child axis). All other references to top-level components in this template rule use either <code>.//ex:function</code> or <code>./*:co/ex:function</code>.</p>
<p>No, I've checked: the package element does have ex:accumulator as a direct child, the accumulator element exists and has the right @name value.</p>
<p>And at line 179 the <code>$accumulators</code> variable has the correct value <code>{"Q{}total-items":"FM k[1AS ] v[1ADI ] "}</code>.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196582022-02-25T13:06:27ZMichael Kaymike@saxonica.com
<ul></ul><p>I note that the call on accumulator-after() succeeds if we convert <code><xsl:variable name="total-items-count"></code> to be a local variable rather than a global variable.</p>
<p>So I think that the problem might be that at xpath.xsl#196 when processing global variables, we aren't passing the tunnel parameter <code>$accumulators</code> through.</p>
<p>This seems to fix it. Solution: in the binding of variable $typed-globals at xpath.xsl#196, add:</p>
<pre><code><xsl:with-param name="accumulators" tunnel="true" select="$accumulators"
use-when="not($COMPILE_GLOBAL)"/>
</code></pre>
<p>Note in passing: the code here is over-complex because it includes multiple options for configuring the compiler, as a results of experiments to improve performance. We ought to decide which of these options we are actually using, and get rid of the code for the paths that are dormant.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196592022-02-25T13:08:20ZMichael Kaymike@saxonica.com
<ul><li><strong>Subject</strong> changed from <i>Discrepancy between behavior and standard conformance with accumulator-after in SaxonJS and Saxon HE (Java)</i> to <i>XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variable</i></li><li><strong>Category</strong> set to <i>XX compiler</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>In Progress</i></li><li><strong>Assignee</strong> set to <i>Michael Kay</i></li></ul> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196602022-02-25T13:14:27ZMichael Kaymike@saxonica.com
<ul></ul><p>A couple of observations:</p>
<p>(a) you may be able to work around the problem by moving the accumulator-after call so it is not in a global variable, or by changing the argument to accumulator-after so it is not a string literal (e.g use a global parameter)</p>
<p>(b) It's probably rather inefficient to use an accumulator like this, if you only want the value at the end of the document. That's because the current accumulator value will potentially be stored on every node in the tree. Computing it conventionally using template rules with a special mode, or using xsl:iterate or fn:fold-left(), would probably perform better.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196622022-02-25T14:16:09ZAlexander Stein
<ul><li><strong>Additional contact person</strong> Wendell A. Piez added</li></ul><p>OK, thanks Michael. I will evaluate this approach in the context of our code base once I sync up with the team, and more quickly in the same reproduction library of course.</p>
<p>I will follow up in the next few days.</p>
<hr>
<p>From: Saxonica Developer Community<br>
Sent: Friday, February 25, 2022 8:06 AM<br>
Subject: [SaxonJS - Bug <a class="issue tracker-1 status-3 priority-2 priority-default closed" title="Bug: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs ... (Closed)" href="https://saxonica.plan.io/issues/5338">#5338</a>] Discrepancy between behavior and standard conformance with accumulator-after in SaxonJS and Saxon HE (Java)</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196632022-02-25T14:17:44ZAlexander Stein
<ul></ul><p>Also, thanks for this feedback on the transforms. I will definitely want to sync up with the team to address these as well, I need their feedback to understand the original code (not repro) and the implications of b better. We will follow up soon enough.</p>
<hr>
<p>From: Saxonica Developer Community<br>
Sent: Friday, February 25, 2022 8:14 AM<br>
Subject: [SaxonJS - Bug <a class="issue tracker-1 status-3 priority-2 priority-default closed" title="Bug: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs ... (Closed)" href="https://saxonica.plan.io/issues/5338">#5338</a>] XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variable</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196712022-02-25T18:35:25ZMichael Kaymike@saxonica.com
<ul></ul><p>Added test case accumulator-090.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196732022-02-25T21:40:56ZWendell Piezwapiez@wendellpiez.com
<ul></ul><p>Hello Mike and Saxonians,</p>
<p>Deeper background/tldr: we installed the offending code into our pipeline as a replacement for earlier code that addressed functional requirements (wrt pipeline internals) that we were also splitting out and refactoring as we worked (under a deadline IIRC). So despite its being a significant performance improvement over what it replaced, I am not surprised to hear there are alternatives we can try as well to make it even better. Yet we do feel bound to report bugs we (think we) find -- and AJ being new to our team, we decided to assign this one to him.</p>
<p>So adding to AJ's thanks, we will definitely be looking at the proposed alternatives. Maybe xsl:iterate is the first obvious thing to try.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196742022-02-25T22:03:38ZMichael Kaymike@saxonica.com
<ul></ul><p>Please keep reporting them! My commentary wasn't based on any thought no-one should be doing this, but more on thinking "why is it that no-one has found this bug before? What are they doing that other people aren't doing?"</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=196752022-02-25T22:22:27ZJohn Lumleyjohn@saxonica.com
<ul></ul><p>When writing the code for the XX compiler, there are so many corner cases (many thousands of them?) that might need to be satisfied that it’s pretty much impossible to cover them all. In this case during the XPath compiling of global variables, rather than other declarations, such as templates, I neglected to add the tunnelled variable defining in-scope accumulators, hence the error.</p>
<p>Unfortunately none of the then XSLT test suite cases covered reference to an accumulator in a global variable…. hence the failure. These cases happen, but as Michael says, some of them are very rarely used in practice… That’s why reporting these to the Saxonica forum is so helpful!</p>
<p>Sent from my iPad</p>
<blockquote>
<p>On 25 Feb 2022, at 22:03, Saxonica Developer Community <a href="mailto:notifications@plan.io" class="email">notifications@plan.io</a> wrote:</p>
<p>Please keep reporting them! My commentary wasn't based on any thought no-one should be doing this, but more on thinking "why is it that no-one has found this bug before? What are they doing that other people aren't doing?"</p>
</blockquote> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=197112022-03-01T11:02:05ZMichael Kaymike@saxonica.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Resolved</i></li><li><strong>Fix Committed on JS Branch</strong> <i>Trunk</i> added</li></ul><p>Fix committed.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=202692022-04-01T20:32:43ZWendell Piezwapiez@wendellpiez.com
<ul></ul><p>Now we have solid alternatives and in the meantime we have also found a bug in applying this approach to the problem it is supposed to solve -- so good work all around, if exposing subtle bugs counts as good work. We will post again with more edge cases if we find any. With thanks for responsiveness and looking forward to the repair (since we are not done with accumulators even if we won't be doing quite <em>this</em>) - Cheers, Wendell.</p> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=203062022-04-07T10:09:02ZDebbie Lockettdebbie@saxonica.com
<ul><li><strong>Fix Committed on JS Branch</strong> <i>2</i> added</li><li><strong>Fix Committed on JS Branch</strong> deleted (<del><i>Trunk</i></del>)</li></ul> SaxonJS - Bug #5338: XX Compiler reports "Unknown accumulator NNNNN" when an accumulator-before or -after call occurs in a global variablehttps://saxonica.plan.io/issues/5338?journal_id=205532022-05-12T13:22:39ZDebbie Lockettdebbie@saxonica.com
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li><li><strong>Fixed in JS Release</strong> set to <i>SaxonJS 2.4</i></li></ul><p>Bug fix applied in the SaxonJS 2.4 maintenance release.</p>