<?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>1728</bug_id>
          
          <creation_ts>2005-07-18 21:47:53 +0000</creation_ts>
          <short_desc>[FS] stronger inference is possible in 7.2.13 &quot;fn:subsequence&quot;</short_desc>
          <delta_ts>2006-04-22 02:34:18 +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>Formal Semantics 1.0</component>
          <version>Last Call drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 2000</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fred Zemke">fred.zemke</reporter>
          <assigned_to name="Jerome Simeon">simeon</assigned_to>
          <cc>jens.teubner</cc>
    
    <cc>jmdyck</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>4840</commentid>
    <comment_count>0</comment_count>
    <who name="Fred Zemke">fred.zemke</who>
    <bug_when>2005-07-18 21:47:53 +0000</bug_when>
    <thetext>7.2.13 fn:subsequence
When the third argument is 1 and the Expr&apos;s quantifier is *,
one can conclude that the length of 
the result is 0 or 1, ie, the quantifier is ?, without even 
knowing the second argument.  Thus the 
third and fourth inferences under &quot;static analysis&quot; can be combined
into a single and more powerful rule, to wit

statEnv |- Expr1 : Type
quantifier (Type) in {*}
------------------------
statEnv |- fn:subsequence (Expr1, Expr2, 1) : prime(Type)?

However, I note that the first sentence of the section says that 
the section only applies when the second argument is 1 or fs:last,
so perhaps it was decided to deliberately forgo this opportunity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4916</commentid>
    <comment_count>1</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-07-19 18:26:29 +0000</bug_when>
    <thetext>Reverted to &apos;major&apos; for simpler handling.
- Jerome</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4967</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Rys">mrys</who>
    <bug_when>2005-07-20 00:52:32 +0000</bug_when>
    <thetext>The joint XQuery/XSLT face-to-face meeting resolves this bug in the following 
way:
Bug 1728 is resolved by generalizing the 3rd inference rule of 7.2.13 to work 
with fn:subsequence(expression, numeric literal, 1) and not generalize to 
arbitrary expressions.

Note that while your proposed rule is a generalization, we decided to not 
require static typing implementations to implement this rule, since it means 
that one of the main use cases, when people write Expr[1] to reduce the 
cardinality would have to be extended to also reduce cardinality in the much 
less likely case of Expr[1+6 div 6]. Note that implementations are allowed to 
use your more general rule, but we did not feel that the use cases make it 
useful to require it.

If you disagree with the resolution, please reopen the bug with your 
objection, otherwise please indicate your acceptance by closing the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5035</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Rys">mrys</who>
    <bug_when>2005-07-20 21:41:24 +0000</bug_when>
    <thetext>*** Bug 1766 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5042</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-07-20 22:19:47 +0000</bug_when>
    <thetext>[Coming in from Bug 1766...]

(In reply to comment #2)
&gt; static typing implementations ... would have to be extended to also
&gt; reduce cardinality in the much less likely case of Expr[1+6 div 6].

Expr[1+6 div 6] doesn&apos;t entail a call to fn:subsequence, so how is it
relevant to STA of fn:subsequence?

And I don&apos;t understand why static typing implementations would have to be
&apos;extended&apos;. It seems to me that going from having to ask
    &quot;Is the 2nd arg a 1 or $fs:last?&quot;
to
    &quot;Is the 2nd arg an expr?&quot; (Duh!)
is a simplification, not an extension.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5044</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Rys">mrys</who>
    <bug_when>2005-07-20 22:24:05 +0000</bug_when>
    <thetext>Personal response:

The normalization of [] predicates is mapped to fn:subsequence. The desire to 
allow people to get static type reductions in Expr[numeric-literal] was the 
main driving scenario to have these static rules. If we widen the rules on 
fn:subsequence, it thus also affects [] expressions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5047</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-07-20 22:55:24 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt;
&gt; The normalization of [] predicates is mapped to fn:subsequence.

Not always. In particular, not for Expr[1+6 div 6].

&gt; The desire to 
&gt; allow people to get static type reductions in Expr[numeric-literal] was the 
&gt; main driving scenario to have these static rules. If we widen the rules on 
&gt; fn:subsequence, it thus also affects [] expressions.

Calls to fn:subsequence() resulting from normalization of predicates have a
second arg that is either a NumericLiteral, $fs:last, or $fs:position. Given
that you&apos;ve just agreed to generalize fn:subsequence rule 3 to NumericLiteral,
the only further effect (on STA for predicates) of simplifying the STA for
fn:subsequence() in the suggested way would be to handle $fs:position, and my
guess is that you actually *want* cardinality reduction in a case like
ancestor::node()[2].
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5109</commentid>
    <comment_count>7</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-07-21 21:57:07 +0000</bug_when>
    <thetext>Yes you are right. I got a closer look at where fn:subsequence is used in
normalization of predicates and we have at least three specific changes to make
it consistent:

 (1) Add a specific static typing rules for $fs:position, in [Section 7.2.13 The
fn:subsequence function], as follows:

statEnv |- Expr : Type      quantifier(Type) in { * }
------------------------------------------------------------
statEnv |- fn:subsequence(Expr, $fs:last, 1) : prime(Type) ?

 (2) Add a normalization rule for PrimaryExpr[last()] in [Section 4.3.2 Filter
Expressions]. I think this has just been overlooked.

 [| PrimaryExpr PredicateList [ last() ] |]Expr
  ==
 let $fs:sequence := [PrimaryExpr PredicateList]Expr return
 fn:subsequence($fs:sequence,last(),1)

 (3) Remove the second inference rule in [Section 7.2.13 The fn:subsequence
function]:

statEnv |- Expr : Type      quantifier(Type) in { 1, + }
---------------------------------------------------------
statEnv |- fn:subsequence(Expr, $fs:last, 1) : prime(Type)

I believe this rule will not be type safe, when the normalization result from 
something else than a predicate. For instance:

 $x//a/fn:subsequence(1,last(),1)

NOTE: this last problem is subtle and somewhat worrying. We may want to
reconsider the use of fn:subsequence for predicates, and instead use a
fs:subsequence function which will be introduced only for the normalization of
predicates (with will be dynamically equivalent to fn:subsequence, but with the
more precise typing rules), and use the simpler more general rule consistently
for fn:subsequence.

- Jerome
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5232</commentid>
    <comment_count>8</comment_count>
    <who name="Jim Melton">jim.melton</who>
    <bug_when>2005-07-26 16:36:36 +0000</bug_when>
    <thetext>This is the formal response from the XML Query WG and the XSL WG. 

We particularly request that both the original commenter (Fred Zemke) and the
additional contributer (Michael Dyck) to consider this response. 

We have agreed to make the changes suggested in Additional Comment #7 and
believe that the changes resolve the comment entirely. 

Please let us know if you agree with this resolution of your issue, by adding a
comment to the issue record and changing the Status of the issue to Closed. Or,
if you do not agree with this resolution, please add a comment explaining why.
If you wish to appeal the WG&apos;s decision to the Director, then also change the
Status of the record to Reopened. If you wish to record your dissent, but do not
wish to appeal the decision to the Director, then change the Status of the
record to Closed. If we do not hear from you in the next two weeks, we will
assume you agree with the WG decision.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5725</commentid>
    <comment_count>9</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-09-06 15:49:23 +0000</bug_when>
    <thetext>*** Bug 1968 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6514</commentid>
    <comment_count>10</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-09-28 10:18:13 +0000</bug_when>
    <thetext>*** Bug 2303 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>9404</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2006-04-22 02:34:18 +0000</bug_when>
    <thetext>So, if an XQuery processor implements STA, is it required to apply the STA rules of 7.2.13 on fn:subsequence calls that *don&apos;t* arise from normalization of predicates?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>