[Bug 4980] Optimization rules

http://www.w3.org/Bugs/Public/show_bug.cgi?id=4980





------- Comment #1 from mike@saxonica.com  2007-08-23 15:10 -------

Personal response.

>I am a bit confused as to what optimizations are permitted by the spec.

I think it's generally true that the spec doesn't try to provide a completely
black-and-white answer to this question.

>Could, for example,

let $x = codepoints-to-string(12)
return $x = $x

>be legitimately optimized down to true(), despite the fact that
codepoints-to-string(12) should throw an FOCH0001 error?

I think the answer is yes. If you can establish that $x is not empty and is not
NaN, that is sufficient to deduce that $x=$x is true; you aren't required to
establish that evaluating $x is error-free.

>If this is correct then could the following expression be optimised down to
true() as well (which is clearly not the intention of the query)?...
typeswitch(.)

There's currently a special rule for conditionals and typeswitch to the effect
that you can't evaluate a branch unless the controlling condition is true. If I
recall correctly there's an erratum in preparation that makes this a bit more
strict, by saying that if the controlling condition is true you must evaluate
the branch, even if the only reason for doing so is to distinguish between an
error and a non-error result.

Received on Thursday, 23 August 2007 15:10:13 UTC