Skip to content

Commit 82cc017

Browse files
committed
Move visit_tuple up + remove redundant set casts
1 parent 4d1b64b commit 82cc017

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def lookup_method(self, instance) -> Callable[..., Iterator[Any]]:
7878
return super().lookup_method(instance)
7979

8080
def _visit(self, o, *args, **kwargs) -> Iterator[Any]:
81-
"""Visit ``o``."""
81+
"""Visit `o`."""
8282
meth = self.lookup_method(o)
8383
yield from meth(o, *args, **kwargs)
8484

@@ -89,9 +89,15 @@ def _post_visit(self, ret: Iterator[Any]) -> TResult:
8989
def visit_object(self, o: object, **kwargs) -> Iterator[Any]:
9090
yield from self.default_retval()
9191

92-
def visit_Node(self, o: Node, **kwargs):
92+
def visit_Node(self, o: Node, **kwargs) -> Iterator[Any]:
9393
yield from self._visit(o.children, **kwargs)
9494

95+
def visit_tuple(self, o: Sequence[Any]) -> Iterator[Any]:
96+
for i in o:
97+
yield from self._visit(i)
98+
99+
visit_list = visit_tuple
100+
95101

96102
class PrintAST(Visitor):
97103

@@ -1067,12 +1073,6 @@ def __init__(self, mode: str = 'symbolics') -> None:
10671073
def _post_visit(self, ret):
10681074
return sorted(filter_ordered(ret, key=id), key=str)
10691075

1070-
def visit_tuple(self, o: Sequence[Any]) -> Iterator[Any]:
1071-
for i in o:
1072-
yield from self._visit(i)
1073-
1074-
visit_list = visit_tuple
1075-
10761076
def visit_Node(self, o: Node) -> Iterator[Any]:
10771077
yield from self._visit(o.children)
10781078
yield from self.rule(o)
@@ -1117,12 +1117,6 @@ def __init__(self, match: type, mode: str = 'type'):
11171117
self.match = match
11181118
self.rule = self.rules[mode]
11191119

1120-
def visit_tuple(self, o: Sequence[Any]) -> Iterator[Any]:
1121-
for i in o:
1122-
yield from self._visit(i)
1123-
1124-
visit_list = visit_tuple
1125-
11261120
def visit_Node(self, o: Node) -> Iterator[Any]:
11271121
if self.rule(self.match, o):
11281122
yield o
@@ -1147,26 +1141,22 @@ def __init__(self, cls: type[TApp] = Application):
11471141
def _post_visit(self, ret):
11481142
return set(ret)
11491143

1150-
def visit_tuple(self, o: Sequence[Any]) -> Iterator[TApp]:
1151-
for i in o:
1152-
yield from self._visit(i)
1153-
11541144
def visit_Node(self, o: Node) -> Iterator[TApp]:
11551145
for i in o.children:
11561146
yield from self._visit(i)
11571147

11581148
def visit_Expression(self, o: Expression, **kwargs) -> Iterator[TApp]:
1159-
yield from set(o.expr.find(self.match))
1149+
yield from o.expr.find(self.match)
11601150

11611151
def visit_Iteration(self, o: Iteration, **kwargs) -> Iterator[TApp]:
11621152
yield from self._visit(o.children)
1163-
yield from set(o.symbolic_min.find(self.match))
1164-
yield from set(o.symbolic_max.find(self.match))
1153+
yield from o.symbolic_min.find(self.match)
1154+
yield from o.symbolic_max.find(self.match)
11651155

11661156
def visit_Call(self, o: Call, **kwargs) -> Iterator[TApp]:
11671157
for i in o.arguments:
11681158
try:
1169-
yield from set(i.find(self.match))
1159+
yield from i.find(self.match)
11701160
except (AttributeError, TypeError):
11711161
yield from self._visit(i)
11721162

0 commit comments

Comments
 (0)