From ccc993071b36dab565f849b1883d6fece08723ae Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 10 Dec 2015 21:29:16 +0800 Subject: [PATCH] transforms.artiq_ir_generator: treat builtins in 'with' syntactically. --- artiq/compiler/transforms/artiq_ir_generator.py | 9 +++++++-- artiq/compiler/transforms/inferencer.py | 6 +++++- lit-test/test/inferencer/error_illegal_builtin.py | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 lit-test/test/inferencer/error_illegal_builtin.py diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index e29949299..f7510516b 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -695,9 +695,11 @@ class ARTIQIRGenerator(algorithm.Visitor): context_expr_node = node.items[0].context_expr optional_vars_node = node.items[0].optional_vars - if types.is_builtin(context_expr_node.type, "sequential"): + if isinstance(context_expr_node, asttyped.NameT) and \ + context_expr_node.id == "sequential": self.visit(node.body) - elif types.is_builtin(context_expr_node.type, "parallel"): + elif isinstance(context_expr_node, asttyped.NameT) and \ + context_expr_node.id == "parallel": parallel = self.append(ir.Parallel([])) heads, tails = [], [] @@ -715,6 +717,9 @@ class ARTIQIRGenerator(algorithm.Visitor): if not tail.is_terminated(): tail.append(ir.Branch(self.current_block)) + else: + assert False + # Expression visitors # These visitors return a node in addition to mutating # the IR. diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 8ebe4f5b7..38115fdf2 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -762,7 +762,11 @@ class Inferencer(algorithm.Visitor): self._unify(node.type, typ.find().instance, node.loc, None) else: - assert False + diag = diagnostic.Diagnostic("error", + "builtin function '{name}' cannot be used in this context", + {"name": typ.name}, + node.loc) + self.engine.process(diag) def visit_CallT(self, node): self.generic_visit(node) diff --git a/lit-test/test/inferencer/error_illegal_builtin.py b/lit-test/test/inferencer/error_illegal_builtin.py new file mode 100644 index 000000000..ea8b66a3f --- /dev/null +++ b/lit-test/test/inferencer/error_illegal_builtin.py @@ -0,0 +1,5 @@ +# RUN: %python -m artiq.compiler.testbench.inferencer +diag %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +# CHECK-L: ${LINE:+1}: error: builtin function 'sequential' cannot be used in this context +sequential()