changeset 34010:72b5f4d53c58

revset: drop optimization about reordering "or" set elements The reordering optimization is more important for "and" than "or", given the implementation details about "addset" and "filteredset" - reordering "or" may help "__contains__" test but not iteration, reordering "and" could help both. We are going to simplify the tree to remove ordering information. Removing "or" reordering optimization would make things simpler. This effectively reverts c63cb2d10d6d. It tracks back to the "orset" function added by the initial commit of revset (c9ce8ecd6). In the future, we might consider optimization at runtime (ex. do reordering and rewrites inside "orset"). Differential Revision: https://phab.mercurial-scm.org/D561
author Jun Wu <quark@fb.com>
date Mon, 28 Aug 2017 23:44:47 -0700
parents 79ab5369d55a
children 1b28525e6698
files mercurial/revsetlang.py tests/test-revset.t
diffstat 2 files changed, 4 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revsetlang.py	Tue Aug 29 17:51:54 2017 -0700
+++ b/mercurial/revsetlang.py	Mon Aug 28 23:44:47 2017 -0700
@@ -467,9 +467,6 @@
         flushss()
         if len(ts) == 1:
             return ws[0], ts[0] # 'or' operation is fully optimized out
-        if order != defineorder:
-            # reorder by weight only when f(a + b) == f(b + a)
-            ts = [wt[1] for wt in sorted(zip(ws, ts), key=lambda wt: wt[0])]
         return max(ws), (op, ('list',) + tuple(ts), order)
     elif op == 'not':
         # Optimize not public() to _notpublic() because we have a fast version
--- a/tests/test-revset.t	Tue Aug 29 17:51:54 2017 -0700
+++ b/tests/test-revset.t	Mon Aug 28 23:44:47 2017 -0700
@@ -2076,19 +2076,19 @@
       define)
     (or
       (list
-        ('symbol', '2')
         (range
           ('symbol', '0')
           ('symbol', '1')
-          follow))
+          follow)
+        ('symbol', '2'))
       follow)
     define)
   * set:
   <filteredset
     <spanset- 0:3>,
     <addset
-      <baseset [2]>,
-      <spanset+ 0:2>>>
+      <spanset+ 0:2>,
+      <baseset [2]>>>
   2
   1
   0
@@ -2569,69 +2569,6 @@
   1
   0
 
- 'A + B' can be rewritten to 'B + A' by weight only when the order doesn't
- matter (e.g. 'X & (A + B)' can be 'X & (B + A)', but '(A + B) & X' can't):
-
-  $ try -p optimized '0:2 & (reverse(contains("a")) + 2)'
-  * optimized:
-  (and
-    (range
-      ('symbol', '0')
-      ('symbol', '2')
-      define)
-    (or
-      (list
-        ('symbol', '2')
-        (func
-          ('symbol', 'reverse')
-          (func
-            ('symbol', 'contains')
-            ('string', 'a')
-            define)
-          follow))
-      follow)
-    define)
-  * set:
-  <filteredset
-    <spanset+ 0:3>,
-    <addset
-      <baseset [2]>,
-      <filteredset
-        <fullreposet+ 0:10>,
-        <contains 'a'>>>>
-  0
-  1
-  2
-
-  $ try -p optimized '(reverse(contains("a")) + 2) & 0:2'
-  * optimized:
-  (and
-    (range
-      ('symbol', '0')
-      ('symbol', '2')
-      follow)
-    (or
-      (list
-        (func
-          ('symbol', 'reverse')
-          (func
-            ('symbol', 'contains')
-            ('string', 'a')
-            define)
-          define)
-        ('symbol', '2'))
-      define)
-    define)
-  * set:
-  <addset
-    <filteredset
-      <spanset- 0:3>,
-      <contains 'a'>>,
-    <baseset [2]>>
-  1
-  0
-  2
-
 test sort revset
 --------------------------------------------