mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-28 20:53:35 +08:00
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:
parent
a07bd918f0
commit
3a1f14c16c
@ -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:
|
||||
|
22
artiq/test/lit/embedding/invariant_nested.py
Normal file
22
artiq/test/lit/embedding/invariant_nested.py
Normal 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
|
Loading…
Reference in New Issue
Block a user