compiler: fix overly strict constness analysis.

Before this commit, the following code would fail to compile...
  obj.foo.bar = True
... if foo is marked kernel_invariant in obj, even if bar is not
marked as such in obj.foo.
This commit is contained in:
whitequark 2017-02-26 01:58:21 +00:00
parent a07bd918f0
commit 3a1f14c16c
2 changed files with 26 additions and 1 deletions

View File

@ -24,7 +24,10 @@ class Constness(algorithm.Visitor):
self.in_assign = old_in_assign
def visit_AttributeT(self, node):
self.generic_visit(node)
old_in_assign, self.in_assign = self.in_assign, False
self.visit(node.value)
self.in_assign = old_in_assign
if self.in_assign:
typ = node.value.type.find()
if types.is_instance(typ) and node.attr in typ.constant_attributes:

View File

@ -0,0 +1,22 @@
# RUN: %python -m artiq.compiler.testbench.embedding %s
from artiq.language.core import *
from artiq.language.types import *
class ClassA:
def __init__(self):
self.foo = False
class ClassB:
kernel_invariants = {"bar"}
def __init__(self):
self.bar = ClassA()
obj = ClassB()
@kernel
def entrypoint():
obj.bar.foo = True