Skip to content

Commit feeb089

Browse files
author
whitequark
committedSep 14, 2016
compiler: warn about unused kernel_invariant entries.
Fixes #543.
1 parent 494cfca commit feeb089

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 

‎artiq/compiler/embedding.py

+24
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,30 @@ def finalize(self):
736736
# do one last pass unconditionally.
737737
inferencer.visit(self.typedtree)
738738

739+
# After we've discovered every referenced attribute, check if any kernel_invariant
740+
# specifications refers to ones we didn't encounter.
741+
for host_type in self.embedding_map.type_map:
742+
instance_type, constructor_type = self.embedding_map.type_map[host_type]
743+
for attribute in instance_type.constant_attributes:
744+
if attribute in instance_type.attributes:
745+
# Fast path; if the ARTIQ Python type has the attribute, then every observed
746+
# value is guaranteed to have it too.
747+
continue
748+
749+
for value, loc in self.value_map[instance_type]:
750+
if hasattr(value, attribute):
751+
continue
752+
753+
diag = diagnostic.Diagnostic("warning",
754+
"object {value} of type {typ} declares attribute '{attr}' as "
755+
"kernel invariant, but the instance referenced here does not "
756+
"have this attribute",
757+
{"value": repr(value),
758+
"typ": types.TypePrinter().name(instance_type, max_depth=0),
759+
"attr": attribute},
760+
loc)
761+
self.engine.process(diag)
762+
739763
# After we have found all functions, synthesize a module to hold them.
740764
source_buffer = source.Buffer("", "<synthesized>")
741765
self.typedtree = asttyped.ModuleT(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: %python -m artiq.compiler.testbench.embedding +diag %s 2>%t
2+
# RUN: OutputCheck %s --file-to-check=%t
3+
4+
from artiq.language.core import *
5+
from artiq.language.types import *
6+
7+
class c:
8+
kernel_invariants = {"a", "b"}
9+
a = 0
10+
11+
def __repr__(self):
12+
return "<testbench.c object>"
13+
14+
i = c()
15+
16+
@kernel
17+
def entrypoint():
18+
# 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
19+
# CHECK-L: ${LINE:+1}: note: expanded from here
20+
i

0 commit comments

Comments
 (0)