Skip to content

Commit

Permalink
compiler.embedding: always do one final inference pass.
Browse files Browse the repository at this point in the history
Fixes #477.
whitequark committed Jun 17, 2016
1 parent 770dda6 commit cc28b59
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -560,6 +560,11 @@ def finalize(self):
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)

# For every host class we embed, fill in the function slots
# with their corresponding closures.
for instance_type, constructor_type in list(self.type_map.values()):
@@ -579,7 +584,6 @@ def finalize(self):
getattr(constructor, attr))
synthesizer.finalize()
self._inject(ast)

# After we have found all functions, synthesize a module to hold them.
source_buffer = source.Buffer("", "<synthesized>")
self.typedtree = asttyped.ModuleT(
20 changes: 20 additions & 0 deletions artiq/test/lit/embedding/bug_477.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit cc28b59

Please sign in to comment.