Skip to content

Commit

Permalink
cinn(py-dsl): skip eval string in python-dsl (PaddlePaddle#61380) (Pa…
Browse files Browse the repository at this point in the history
  • Loading branch information
6clc authored Feb 5, 2024
1 parent 3452e61 commit a37f6fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/cinn/compiler/expr_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ def visit(self, node):
value = exec_func(cls_fields)
else:
new_node = node.__class__(**cls_fields)
ast.copy_location(new_node, node)
new_node = ast.Expression(new_node)
value = self.exec_expr(new_node)
return self.save_temp_value(value)

def exec_expr(self, node):
if isinstance(node, ast.expr):
node = ast.Expression(body=node)
assert isinstance(node, ast.expr)
if type(node).__name__ == "Constant":
return node.value

node = ast.Expression(node)
node = ast.fix_missing_locations(node)
exec = compile(node, filename="<ast>", mode="eval")
return eval(exec, self.var_table)
Expand Down

0 comments on commit a37f6fb

Please sign in to comment.