From c0e42bbfc889fd28138f000e2e8a5a1f53fcb46b Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Jun 2016 14:18:43 +0000 Subject: [PATCH] compiler.embedding: always do one final inference pass. Fixes #477. --- artiq/compiler/embedding.py | 5 +++++ artiq/test/lit/embedding/bug_477.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 artiq/test/lit/embedding/bug_477.py diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 491a2052e..f4a9bd4cb 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -613,6 +613,11 @@ class Stitcher: break old_typedtree_hash = typedtree_hash + # When we have an excess of type information, sometimes we can infer every type + # in the AST without discovering every referenced attribute of host objects, so + # do one last pass unconditionally. + inferencer.visit(self.typedtree) + # After we have found all functions, synthesize a module to hold them. source_buffer = source.Buffer("", "") self.typedtree = asttyped.ModuleT( diff --git a/artiq/test/lit/embedding/bug_477.py b/artiq/test/lit/embedding/bug_477.py new file mode 100644 index 000000000..19d496ca6 --- /dev/null +++ b/artiq/test/lit/embedding/bug_477.py @@ -0,0 +1,20 @@ +# RUN: %python -m artiq.compiler.testbench.embedding %s + +from artiq.experiment import * + +class MyClass: + def __init__(self, **kwargs): + for k, v in kwargs.items(): + setattr(self, k, v) + + +sl = [MyClass(x=1), MyClass(x=2)] + +@kernel +def bug(l): + for c in l: + print(c.x) + +@kernel +def entrypoint(): + bug(sl)