Enable futile_union_intersection_subtraction

master
Salvo 'LtWorf' Tomaselli 2020-06-09 11:43:14 +07:00
parent 0dcd639c9d
commit 50647294cb
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
1 changed files with 17 additions and 25 deletions

@ -125,7 +125,7 @@ def duplicated_select(n: parser.Node) -> Tuple[parser.Node, int]:
return n, changes return n, changes
def futile_union_intersection_subtraction(n: parser.Node) -> int: def futile_union_intersection_subtraction(n: parser.Node) -> Tuple[parser.Node, int]:
'''This function locates things like r r, and replaces them with r. '''This function locates things like r r, and replaces them with r.
R R --> R R R --> R
R R --> R R R --> R
@ -140,47 +140,39 @@ def futile_union_intersection_subtraction(n: parser.Node) -> int:
# Union and intersection of the same thing # Union and intersection of the same thing
if n.name in (UNION, INTERSECTION, JOIN, JOIN_LEFT, JOIN_RIGHT, JOIN_FULL) and n.left == n.right: if n.name in (UNION, INTERSECTION, JOIN, JOIN_LEFT, JOIN_RIGHT, JOIN_FULL) and n.left == n.right:
changes = 1 return n.left, 1
replace_node(n, n.left)
# selection and union of the same thing # selection and union of the same thing
elif (n.name == UNION): elif (n.name == UNION):
if n.left.name == SELECTION and n.left.child == n.right: if n.left.name == SELECTION and n.left.child == n.right:
changes = 1 return n.right, 1
replace_node(n, n.right)
elif n.right.name == SELECTION and n.right.child == n.left: elif n.right.name == SELECTION and n.right.child == n.left:
changes = 1 return n.left, 1
replace_node(n, n.left)
# selection and intersection of the same thing # selection and intersection of the same thing
elif n.name == INTERSECTION: elif n.name == INTERSECTION:
if n.left.name == SELECTION and n.left.child == n.right: if n.left.name == SELECTION and n.left.child == n.right:
changes = 1 return n.left, 1
replace_node(n, n.left)
elif n.right.name == SELECTION and n.right.child == n.left: elif n.right.name == SELECTION and n.right.child == n.left:
changes = 1 return n.right, 1
replace_node(n, n.right)
# Subtraction and selection of the same thing # Subtraction and selection of the same thing
elif n.name == DIFFERENCE and \ elif n.name == DIFFERENCE and \
n.right.name == SELECTION and \ n.right.name == SELECTION and \
n.right.child == n.left: n.right.child == n.left:
n.name = n.right.name return parser.Unary(
n.kind = n.right.kind SELECTION,
n.child = n.right.child '(not (%s))' % n.right.prop,
n.prop = '(not (%s))' % n.right.prop n.right.child), 1
n.left = n.right = None
# Subtraction of the same thing or with selection on the left child # Subtraction of the same thing or with selection on the left child
elif n.name == DIFFERENCE and (n.left == n.right or (n.left.name == SELECTION and n.left.child == n.right)): elif n.name == DIFFERENCE and (n.left == n.right or (n.left.name == SELECTION and n.left.child == n.right)):
changes = 1 return parser.Unary(
n.kind = parser.UNARY SELECTION,
n.name = SELECTION 'False',
n.prop = 'False' n.get_left_leaf()
n.child = n.left.get_left_leaf() ), 1
# n.left=n.right=None return n, 0
return changes + recoursive_scan(futile_union_intersection_subtraction, n)
def down_to_unions_subtractions_intersections(n: parser.Node) -> int: def down_to_unions_subtractions_intersections(n: parser.Node) -> int:
@ -690,7 +682,7 @@ general_optimizations = [
#selection_inside_projection, #selection_inside_projection,
#subsequent_renames, #subsequent_renames,
#swap_rename_select, #swap_rename_select,
#futile_union_intersection_subtraction, futile_union_intersection_subtraction,
#swap_union_renames, #swap_union_renames,
#swap_rename_projection, #swap_rename_projection,
#select_union_intersect_subtract, #select_union_intersect_subtract,