forked from M-Labs/artiq
1
0
Fork 0

compiler: warn about unused kernel_invariant entries.

Fixes #543.
This commit is contained in:
whitequark 2016-09-14 23:28:55 +00:00
parent 494cfca41c
commit feeb089505
2 changed files with 44 additions and 0 deletions

View File

@ -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(

View 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