<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29590</bug_id>
          
          <creation_ts>2016-04-24 22:02:26 +0000</creation_ts>
          <short_desc>dependency cycle and indirect references</short_desc>
          <delta_ts>2016-06-07 11:37:46 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3 &amp; XPath 3 Test Suite</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Benito van der Zander">benito</reporter>
          <assigned_to name="O&apos;Neil Delpratt">oneil</assigned_to>
          <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>126072</commentid>
    <comment_count>0</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-04-24 22:02:26 +0000</bug_when>
    <thetext>In function-literal-707 we have $a depending on $f, $f depending on  local:plus#2 and local:plus depending on $a. How is this not a XQDY0054 cycle?

Just because it calls not local:plus?

But in general it is undecidable, if a dynamic reference gets called.  Especially, since it could involve the context item, which could depend on anything.



The opposite happens in fn-function-lookup-613</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126075</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-04-25 08:24:23 +0000</bug_when>
    <thetext>We very deliberately made cyclicity a dynamic error rather than a static error to permit this kind of construct. Yes, it&apos;s not statically decidable whether something gets evaluated, but it is dynamically decidable. Evaluating function-arity(F) does not involve evaluating F (it cannot involve calling F, because no arguments have been supplied); so the dynamic evaluation of this query involves no circularity.

By contrast, in function-lookup-613, dynamic evaluation is not possible. Given

        declare variable $v := function-lookup($n, 0)();
        declare function local:return-v() {$v + 1};

we can&apos;t evaluate $v without calling local:return-v (note the &quot;()&quot;) and we can&apos;t evaluate local:return-v() without evaluating $v.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126076</commentid>
    <comment_count>2</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-04-25 08:52:11 +0000</bug_when>
    <thetext>Well, I just spent two days changing my dynamic cycle checker to a static cycle checker, so it would be more efficient....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126142</commentid>
    <comment_count>3</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-04-25 23:48:44 +0000</bug_when>
    <thetext>Actually my old cycle checker was half dynamic (choosing the order of the evaluation) and half static (checking each declaration statically), and thus the latter half could not handle these two cases either.

But a fully dynamical  cycle checker crashes on K2-InternalVariablesWithout-1a, because it gets stuck in the endless recursion of  declare function local:myFunction() { local:myFunction(), 1, $local:myVar }; before it ever reaches $local:myVar ,  (actually that test was the reason, I made it half statically in the first place https://github.com/benibela/internettools/commit/bed837e9a111befbf517fa2e3ab59bbfed6bcfbf )
 


Endless loop detection does not seem to be decidable either</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126144</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-04-26 08:33:55 +0000</bug_when>
    <thetext>Interesting. Yes, I agree that it would be perfectly reasonable with K2-InternalVariablesWithout-1a to go into infinite recursion rather than detecting the error. 

Saxon is rejecting this one during a static check, which is a residue of XQuery 1.0 (which we still support, just about). Looking at the code, the static check is actually too strong: it&apos;s capable of rejecting things that wouldn&apos;t fail at run-time. Our static check appears to treat variable references and static function calls as if they are always evaluated. Reading the rules, I don&apos;t think that&apos;s conformant; the rules for conditional expressions and switch/typeswitch don&apos;t allow you to raise an error as a consequence of evaluating a branch of a conditional that isn&apos;t actually selected.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126331</commentid>
    <comment_count>5</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-05-04 23:28:29 +0000</bug_when>
    <thetext>This also happens in 

K2-InternalVariablesWithout-6a

K2-InternalVariablesWithout-7a

K2-InternalVariablesWithout-8a</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126687</commentid>
    <comment_count>6</comment_count>
    <who name="O&apos;Neil Delpratt">oneil</who>
    <bug_when>2016-06-07 11:37:46 +0000</bug_when>
    <thetext>I have committed fixes to the other test cases mentioned in comment #5</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>