@@ -2087,6 +2087,12 @@ methods = {
'_hexlist',
])
+# symbols which return the evaluated set with no modification. in other words,
+# functions that do 'return getset(repo, subset, x)'.
+_noopsymbols = set([
+ 'present',
+])
+
# constants for ordering policy, used in _optimize():
# 1. starts with 'define'
# 2. shifts to 'follow' by 'x & y'
@@ -2240,7 +2246,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 'noop' function is
+ # known to return the argument set with no modification, so forward
+ # the requirement in that case.
+ d = _defineorder
+ if f in _noopsymbols:
+ 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
@@ -978,6 +978,69 @@ Test order of revisions in compound expr
1
0
+ because 'present()' does nothing other than suppressing errors, the ordering
+ requirement should be forwarded to the inner expression, and '_reorder'
+ should be inserted only when necessary:
+
+ $ try --optimize '2:0 & present(0 + 1 + 2)'
+ (and
+ (range
+ ('symbol', '2')
+ ('symbol', '0'))
+ (func
+ ('symbol', 'present')
+ (or
+ ('symbol', '0')
+ ('symbol', '1')
+ ('symbol', '2'))))
+ * optimized:
+ (and
+ (range
+ ('symbol', '2')
+ ('symbol', '0'))
+ (func
+ ('symbol', 'present')
+ (func
+ ('symbol', '_reorder')
+ (func
+ ('symbol', '_list')
+ ('string', '0\x001\x002')))))
+ * set:
+ <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
+ 0
+
'_reorder' should be omitted if order doesn't matter:
$ try --optimize '2:0 & not (0 + 1)'