compiler: remove obsolete watchdog code (#1458)

pull/1561/head
Sebastien Bourdeauducq 2020-12-08 13:24:58 +08:00
parent ccdc741e73
commit 072053c3b2
8 changed files with 14 additions and 98 deletions

View File

@ -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")

View File

@ -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(),

View File

@ -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),

View File

@ -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(),

View File

@ -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

View File

@ -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);
}

View File

@ -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)

View File

@ -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()