From 78fa5beceab064f95eceaf14589e25e1c1919594 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 18 Mar 2016 02:01:14 +0000 Subject: [PATCH] compiler: refuse to embed a function from another core device. Fixes #332. --- artiq/compiler/embedding.py | 17 +++++++++++++++-- artiq/compiler/testbench/perf_embedding.py | 2 +- artiq/coredevice/core.py | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 1058c6a70..664b97a0b 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -448,7 +448,9 @@ class TypedtreeHasher(algorithm.Visitor): return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields)) class Stitcher: - def __init__(self, engine=None): + def __init__(self, core, dmgr, engine=None): + self.core = core + self.dmgr = dmgr if engine is None: self.engine = diagnostic.Engine(all_errors_are_fatal=True) else: @@ -473,7 +475,7 @@ class Stitcher: # We synthesize source code for the initial call so that # diagnostics would have something meaningful to display to the user. - synthesizer = self._synthesizer() + synthesizer = self._synthesizer(self._function_loc(function.artiq_embedded.function)) call_node = synthesizer.call(function_node, args, kwargs, callback) synthesizer.finalize() self.typedtree.append(call_node) @@ -752,6 +754,17 @@ class Stitcher: notes=[note]) self.engine.process(diag) + if self.dmgr.get(function.artiq_embedded.core_name) != self.core: + note = diagnostic.Diagnostic("note", + "called from this function", {}, + loc) + diag = diagnostic.Diagnostic("fatal", + "this function runs on a different core device '{name}'", + {"name": function.artiq_embedded.core_name}, + self._function_loc(function.artiq_embedded.function), + notes=[note]) + self.engine.process(diag) + # Insert the typed AST for the new function and restart inference. # It doesn't really matter where we insert as long as it is before # the final call. diff --git a/artiq/compiler/testbench/perf_embedding.py b/artiq/compiler/testbench/perf_embedding.py index da9679685..ad6df71fa 100644 --- a/artiq/compiler/testbench/perf_embedding.py +++ b/artiq/compiler/testbench/perf_embedding.py @@ -31,7 +31,7 @@ def main(): def embed(): experiment = testcase_vars["Benchmark"](dmgr) - stitcher = Stitcher() + stitcher = Stitcher(core=experiment.core, dmgr=dmgr) stitcher.stitch_call(experiment.run, (experiment,), {}) stitcher.finalize() return stitcher diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index a836f5093..c9d1bc1f4 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -67,6 +67,7 @@ class Core: self.comm = dmgr.get(comm_device) self.first_run = True + self.dmgr = dmgr self.core = self self.comm.core = self @@ -74,7 +75,7 @@ class Core: try: engine = _DiagnosticEngine(all_errors_are_fatal=True) - stitcher = Stitcher(engine=engine) + stitcher = Stitcher(engine=engine, core=self, dmgr=self.dmgr) stitcher.stitch_call(function, args, kwargs, set_result) stitcher.finalize()