From a37f6fb60a69de3c7942369da14b23beec8a5c28 Mon Sep 17 00:00:00 2001 From: 6clc Date: Mon, 5 Feb 2024 15:42:12 +0800 Subject: [PATCH] cinn(py-dsl): skip eval string in python-dsl (#61380) (#61586) --- python/cinn/compiler/expr_executor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/cinn/compiler/expr_executor.py b/python/cinn/compiler/expr_executor.py index cff9a9d62d7c4..c888be369c3d6 100644 --- a/python/cinn/compiler/expr_executor.py +++ b/python/cinn/compiler/expr_executor.py @@ -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="", mode="eval") return eval(exec, self.var_table)