mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-26 19:58:25 +08:00
parent
fb3585f5b0
commit
ecb01d055f
@ -736,6 +736,30 @@ class Stitcher:
|
|||||||
# do one last pass unconditionally.
|
# do one last pass unconditionally.
|
||||||
inferencer.visit(self.typedtree)
|
inferencer.visit(self.typedtree)
|
||||||
|
|
||||||
|
# After we've discovered every referenced attribute, check if any kernel_invariant
|
||||||
|
# specifications refers to ones we didn't encounter.
|
||||||
|
for host_type in self.embedding_map.type_map:
|
||||||
|
instance_type, constructor_type = self.embedding_map.type_map[host_type]
|
||||||
|
for attribute in instance_type.constant_attributes:
|
||||||
|
if attribute in instance_type.attributes:
|
||||||
|
# Fast path; if the ARTIQ Python type has the attribute, then every observed
|
||||||
|
# value is guaranteed to have it too.
|
||||||
|
continue
|
||||||
|
|
||||||
|
for value, loc in self.value_map[instance_type]:
|
||||||
|
if hasattr(value, attribute):
|
||||||
|
continue
|
||||||
|
|
||||||
|
diag = diagnostic.Diagnostic("warning",
|
||||||
|
"object {value} of type {typ} declares attribute '{attr}' as "
|
||||||
|
"kernel invariant, but the instance referenced here does not "
|
||||||
|
"have this attribute",
|
||||||
|
{"value": repr(value),
|
||||||
|
"typ": types.TypePrinter().name(instance_type, max_depth=0),
|
||||||
|
"attr": attribute},
|
||||||
|
loc)
|
||||||
|
self.engine.process(diag)
|
||||||
|
|
||||||
# After we have found all functions, synthesize a module to hold them.
|
# After we have found all functions, synthesize a module to hold them.
|
||||||
source_buffer = source.Buffer("", "<synthesized>")
|
source_buffer = source.Buffer("", "<synthesized>")
|
||||||
self.typedtree = asttyped.ModuleT(
|
self.typedtree = asttyped.ModuleT(
|
||||||
|
20
artiq/test/lit/embedding/warning_invariant_missing.py
Normal file
20
artiq/test/lit/embedding/warning_invariant_missing.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# RUN: %python -m artiq.compiler.testbench.embedding +diag %s 2>%t
|
||||||
|
# RUN: OutputCheck %s --file-to-check=%t
|
||||||
|
|
||||||
|
from artiq.language.core import *
|
||||||
|
from artiq.language.types import *
|
||||||
|
|
||||||
|
class c:
|
||||||
|
kernel_invariants = {"a", "b"}
|
||||||
|
a = 0
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<testbench.c object>"
|
||||||
|
|
||||||
|
i = c()
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def entrypoint():
|
||||||
|
# CHECK-L: <synthesized>:1: warning: object <testbench.c object> of type <instance testbench.c> declares attribute 'b' as kernel invariant, but the instance referenced here does not have this attribute
|
||||||
|
# CHECK-L: ${LINE:+1}: note: expanded from here
|
||||||
|
i
|
Loading…
Reference in New Issue
Block a user