def visit_For(self, node): if not (self.top_level or self.current_scope.allows_for_loop): import taichi as ti raise ti.KernelDefError( f'No more for loops allowed, at {self.get_error_location(node)}' ) with self.new_scope(): super().generic_visit(node) if not self.top_level: self.current_scope.mark_no_more_stmt()
def generic_visit(self, node): if not self.should_check(node): super().generic_visit(node) return if not (self.top_level or self.current_scope.allows_more_stmt): import taichi as ti raise ti.KernelDefError( f'No more statements allowed, at {self.get_error_location(node)}' ) old_top_level = self.top_level if old_top_level: self._scope_guards.append(self.new_scope()) # Marking here before the visit has the effect of disallow for-loops in # nested blocks. E.g. if |node| is a IfStmt, then the checker would disallow # for-loops inside it. self.current_scope.mark_no_more_for_loop() super().generic_visit(node) if old_top_level: self._scope_guards.pop()
def visit_For(self, node): if (isinstance(node.iter, ast.Call) and isinstance(node.iter.func, ast.Attribute) and isinstance(node.iter.func.value, ast.Name) and node.iter.func.value.id == 'ti' and node.iter.func.attr == 'static'): is_static = True else: is_static = False if not (self.top_level or self.current_scope.allows_for_loop or is_static): import taichi as ti raise ti.KernelDefError( f'No more for loops allowed, at {self.get_error_location(node)}' ) with self.new_scope(): super().generic_visit(node) if not (self.top_level or is_static): self.current_scope.mark_no_more_stmt()
def visit_For(self, node): # TODO: since autodiff is enhanced, AST checker rules should be relaxed. This part should be updated. return if (isinstance(node.iter, ast.Call) and isinstance(node.iter.func, ast.Attribute) and isinstance(node.iter.func.value, ast.Name) and node.iter.func.value.id == 'ti' and node.iter.func.attr == 'static'): is_static = True else: is_static = False if not (self.top_level or self.current_scope.allows_for_loop or is_static): import taichi as ti raise ti.KernelDefError( f'No more for loops allowed, at {self.get_error_location(node)}' ) with self.new_scope(): super().generic_visit(node) if not (self.top_level or is_static): self.current_scope.mark_no_more_stmt()