Skip to content

Commit

Permalink
transforms.iodelay_estimator: reject control flow in 'with parallel:' (
Browse files Browse the repository at this point in the history
…fixes #195).
whitequark committed Dec 18, 2015
1 parent 64ad388 commit 2759310
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions artiq/compiler/transforms/iodelay_estimator.py
Original file line number Diff line number Diff line change
@@ -229,6 +229,23 @@ def visit_With(self, node):
# inside a `with` statement after all.
self.engine.process(error.cause)

flow_stmt = None
if self.current_goto is not None:
flow_stmt = self.current_goto
elif self.current_return is not None:
flow_stmt = self.current_return

if flow_stmt is not None:
note = diagnostic.Diagnostic("note",
"this '{kind}' statement transfers control out of "
"the 'with parallel:' statement",
{"kind": flow_stmt.keyword_loc.source()},
flow_stmt.loc)
diag = diagnostic.Diagnostic("error",
"cannot interleave this 'with parallel:' statement", {},
node.keyword_loc.join(node.colon_loc), notes=[note])
self.engine.process(diag)

elif len(node.items) == 1 and types.is_builtin(context_expr.type, "sequential"):
self.visit(node.body)
else:
17 changes: 17 additions & 0 deletions lit-test/test/interleaving/error_toplevel_control_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# RUN: %python -m artiq.compiler.testbench.signature +diag %s >%t
# RUN: OutputCheck %s --file-to-check=%t

def f():
# CHECK-L: ${LINE:+1}: error: cannot interleave this 'with parallel:' statement
with parallel:
# CHECK-L: ${LINE:+1}: note: this 'return' statement transfers control out of the 'with parallel:' statement
return
delay(1.0)

def g():
while True:
# CHECK-L: ${LINE:+1}: error: cannot interleave this 'with parallel:' statement
with parallel:
# CHECK-L: ${LINE:+1}: note: this 'break' statement transfers control out of the 'with parallel:' statement
break
delay(1.0)

0 comments on commit 2759310

Please sign in to comment.