From 072053c3b23108870a7bf66a50438d7717a04c6f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 8 Dec 2020 13:24:58 +0800 Subject: [PATCH] compiler: remove obsolete watchdog code (#1458) --- artiq/compiler/builtins.py | 3 -- artiq/compiler/prelude.py | 1 - .../compiler/transforms/artiq_ir_generator.py | 38 +++++++------------ artiq/compiler/transforms/inferencer.py | 7 +--- .../compiler/transforms/llvm_ir_generator.py | 11 ------ artiq/test/libartiq_support/lib.rs | 11 ------ .../test/lit/codegen/error_illegal_builtin.py | 5 --- artiq/test/lit/time/watchdog.py | 36 ------------------ 8 files changed, 14 insertions(+), 98 deletions(-) delete mode 100644 artiq/test/lit/codegen/error_illegal_builtin.py delete mode 100644 artiq/test/lit/time/watchdog.py diff --git a/artiq/compiler/builtins.py b/artiq/compiler/builtins.py index 7a0aa6161..b5662aec6 100644 --- a/artiq/compiler/builtins.py +++ b/artiq/compiler/builtins.py @@ -222,9 +222,6 @@ def obj_interleave(): def obj_sequential(): return types.TBuiltin("sequential") -def fn_watchdog(): - return types.TBuiltinFunction("watchdog") - def fn_delay(): return types.TBuiltinFunction("delay") diff --git a/artiq/compiler/prelude.py b/artiq/compiler/prelude.py index 9e1a3846d..13f319650 100644 --- a/artiq/compiler/prelude.py +++ b/artiq/compiler/prelude.py @@ -44,7 +44,6 @@ def globals(): "parallel": builtins.obj_parallel(), "interleave": builtins.obj_interleave(), "sequential": builtins.obj_sequential(), - "watchdog": builtins.fn_watchdog(), # ARTIQ time management functions "delay": builtins.fn_delay(), diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 2a7f56d26..afa75b61b 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -851,35 +851,23 @@ class ARTIQIRGenerator(algorithm.Visitor): cleanup = [] for item_node in node.items: + # user-defined context manager context_expr_node = item_node.context_expr optional_vars_node = item_node.optional_vars + context_mgr = self.visit(context_expr_node) + enter_fn = self.append(ir.GetAttr(context_mgr, '__enter__')) + exit_fn = self.append(ir.GetAttr(context_mgr, '__exit__')) - if isinstance(context_expr_node, asttyped.CallT) and \ - types.is_builtin(context_expr_node.func.type, "watchdog"): - timeout = self.visit(context_expr_node.args[0]) - timeout_ms = self.append(ir.Arith(ast.Mult(loc=None), timeout, - ir.Constant(1000, builtins.TFloat()))) - timeout_ms_int = self.append(ir.Coerce(timeout_ms, builtins.TInt64())) + try: + self.current_assign = self._user_call(enter_fn, [], {}) + if optional_vars_node is not None: + self.visit(optional_vars_node) + finally: + self.current_assign = None - watchdog_id = self.append(ir.Builtin("watchdog_set", [timeout_ms_int], - builtins.TInt32())) - cleanup.append(lambda: - self.append(ir.Builtin("watchdog_clear", [watchdog_id], builtins.TNone()))) - else: # user-defined context manager - context_mgr = self.visit(context_expr_node) - enter_fn = self.append(ir.GetAttr(context_mgr, '__enter__')) - exit_fn = self.append(ir.GetAttr(context_mgr, '__exit__')) - - try: - self.current_assign = self._user_call(enter_fn, [], {}) - if optional_vars_node is not None: - self.visit(optional_vars_node) - finally: - self.current_assign = None - - none = self.append(ir.Alloc([], builtins.TNone())) - cleanup.append(lambda: - self._user_call(exit_fn, [none, none, none], {})) + none = self.append(ir.Alloc([], builtins.TNone())) + cleanup.append(lambda: + self._user_call(exit_fn, [none, none, none], {})) self._try_finally( body_gen=lambda: self.visit(node.body), diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 0de455c8d..684c575de 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -1211,9 +1211,6 @@ class Inferencer(algorithm.Visitor): elif types.is_builtin(typ, "at_mu"): simple_form("at_mu(time_mu:numpy.int64) -> None", [builtins.TInt64()]) - elif types.is_builtin(typ, "watchdog"): - simple_form("watchdog(time:float) -> [builtin context manager]", - [builtins.TFloat()], builtins.TNone()) elif types.is_constructor(typ): # An user-defined class. self._unify(node.type, typ.find().instance, @@ -1458,9 +1455,7 @@ class Inferencer(algorithm.Visitor): typ = node.context_expr.type if (types.is_builtin(typ, "interleave") or types.is_builtin(typ, "sequential") or - types.is_builtin(typ, "parallel") or - (isinstance(node.context_expr, asttyped.CallT) and - types.is_builtin(node.context_expr.func.type, "watchdog"))): + types.is_builtin(typ, "parallel")): # builtin context managers if node.optional_vars is not None: self._unify(node.optional_vars.type, builtins.TNone(), diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 8ee010cc7..ce2530bf4 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -395,10 +395,6 @@ class LLVMIRGenerator: elif name == "delay_mu": llty = ll.FunctionType(llvoid, [lli64]) - elif name == "watchdog_set": - llty = ll.FunctionType(lli32, [lli64]) - elif name == "watchdog_clear": - llty = ll.FunctionType(llvoid, [lli32]) else: assert False @@ -407,7 +403,6 @@ class LLVMIRGenerator: if name in ("__artiq_raise", "__artiq_reraise", "llvm.trap"): llglobal.attributes.add("noreturn") if name in ("rtio_log", "rpc_send", "rpc_send_async", - "watchdog_set", "watchdog_clear", self.target.print_function): llglobal.attributes.add("nounwind") if name.find("__py_") == 0: @@ -1239,12 +1234,6 @@ class LLVMIRGenerator: return llstore_lo else: return self.llbuilder.call(self.llbuiltin("delay_mu"), [llinterval]) - elif insn.op == "watchdog_set": - interval, = insn.operands - return self.llbuilder.call(self.llbuiltin("watchdog_set"), [self.map(interval)]) - elif insn.op == "watchdog_clear": - id, = insn.operands - return self.llbuilder.call(self.llbuiltin("watchdog_clear"), [self.map(id)]) else: assert False diff --git a/artiq/test/libartiq_support/lib.rs b/artiq/test/libartiq_support/lib.rs index 51344b402..77e8f4160 100644 --- a/artiq/test/libartiq_support/lib.rs +++ b/artiq/test/libartiq_support/lib.rs @@ -76,14 +76,3 @@ fn terminate(exception: &eh_artiq::Exception, mut _backtrace: &mut [usize]) -> ! #[export_name = "now"] pub static mut NOW: i64 = 0; - -#[export_name = "watchdog_set"] -pub extern fn watchdog_set(ms: i64) -> i32 { - println!("watchdog_set {}", ms); - ms as i32 -} - -#[export_name = "watchdog_clear"] -pub extern fn watchdog_clear(id: i32) { - println!("watchdog_clear {}", id); -} diff --git a/artiq/test/lit/codegen/error_illegal_builtin.py b/artiq/test/lit/codegen/error_illegal_builtin.py deleted file mode 100644 index ae75ad9b7..000000000 --- a/artiq/test/lit/codegen/error_illegal_builtin.py +++ /dev/null @@ -1,5 +0,0 @@ -# RUN: %python -m artiq.compiler.testbench.signature +diag %s >%t -# RUN: OutputCheck %s --file-to-check=%t - -# CHECK-L: ${LINE:+1}: error: builtin function 'watchdog' cannot be used in this context -watchdog(1.0) diff --git a/artiq/test/lit/time/watchdog.py b/artiq/test/lit/time/watchdog.py deleted file mode 100644 index ccd3048bc..000000000 --- a/artiq/test/lit/time/watchdog.py +++ /dev/null @@ -1,36 +0,0 @@ -# RUN: %python -m artiq.compiler.testbench.jit %s >%t -# RUN: OutputCheck %s --file-to-check=%t -# REQUIRES: time - -def f(): - with watchdog(1.0): - pass - -def g(): - with watchdog(2.0): - raise Exception() - -def h(): - try: - g() - except: - pass - -def i(): - try: - with watchdog(3.0): - raise Exception() - except: - pass - -# CHECK-L: watchdog_set 1000 -# CHECK-L: watchdog_clear 1000 -f() - -# CHECK-L: watchdog_set 2000 -# CHECK-L: watchdog_clear 2000 -h() - -# CHECK-L: watchdog_set 3000 -# CHECK-L: watchdog_clear 3000 -i()