Comments
Patch
@@ -2491,7 +2491,13 @@ def _optimize(x, small, order):
return sum(ws), (op,) + ts
elif op == 'func':
f = getstring(x[1], _("not a symbol"))
- wa, ta = _optimize(x[2], small, defineorder)
+ # 'f' may have its own ordering requirement, but 'present(set)' is
+ # known to return the argument set with no modification, so forward
+ # the requirement in that case.
+ d = defineorder
+ if f == "present":
+ d = order
+ wa, ta = _optimize(x[2], small, d)
if f in ("author branch closed date desc file grep keyword "
"outgoing user"):
w = 10 # slow
@@ -1190,7 +1190,9 @@ ordering defined by it.
<baseset [0, 1]>>>
2
- 'present()' should do nothing other than suppressing an error:
+ because 'present()' does nothing other than suppressing an error, the
+ ordering requirement should be forwarded to the nested expression, and
+ '_unordered' should be inserted only when necessary:
$ try --optimize '2:0 & present(0 + 1 + 2)'
(and
@@ -1211,14 +1213,45 @@ ordering defined by it.
(func
('symbol', 'present')
(func
- ('symbol', '_list')
- ('string', '0\x001\x002'))))
+ ('symbol', '_unordered')
+ (func
+ ('symbol', '_list')
+ ('string', '0\x001\x002')))))
* set:
- <baseset [0, 1, 2]>
+ <filteredset
+ <spanset- 0:2>,
+ <baseset [0, 1, 2]>>
+ 2
+ 1
0
+
+ $ try --optimize '2:0 & present(all())'
+ (and
+ (range
+ ('symbol', '2')
+ ('symbol', '0'))
+ (func
+ ('symbol', 'present')
+ (func
+ ('symbol', 'all')
+ None)))
+ * optimized:
+ (and
+ (range
+ ('symbol', '2')
+ ('symbol', '0'))
+ (func
+ ('symbol', 'present')
+ (func
+ ('symbol', 'all')
+ None)))
+ * set:
+ <filteredset
+ <spanset- 0:2>,
+ <spanset+ 0:9>>
+ 2
1
- 2
- BROKEN: should be '2 1 0'
+ 0
'reverse()' should take effect only if it is the outermost expression: