From aacea7e379b81abf06cda394118753414aa7ea14 Mon Sep 17 00:00:00 2001 From: 6clc Date: Wed, 31 Jan 2024 12:09:50 +0800 Subject: [PATCH] cinn(py-dsl): skip eval string in python-dsl --- 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 840dc805e89f2..eeca1b9602e15 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)