Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fb3585f5b0d0
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6f2125258ca9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 15, 2016

  1. compiler: warn about unused kernel_invariant entries.

    Fixes #543.
    whitequark authored and jordens committed Sep 15, 2016
    Copy the full SHA
    ecb01d0 View commit details
  2. compiler: skip kernel_invariant linting for exception types.

    whitequark authored and jordens committed Sep 15, 2016
    Copy the full SHA
    6f21252 View commit details
Showing with 48 additions and 0 deletions.
  1. +28 −0 artiq/compiler/embedding.py
  2. +20 −0 artiq/test/lit/embedding/warning_invariant_missing.py
28 changes: 28 additions & 0 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -736,6 +736,34 @@ def finalize(self):
# do one last pass unconditionally.
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]
if not hasattr(instance_type, "constant_attributes"):
# Exceptions lack user-definable attributes.
continue

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.
source_buffer = source.Buffer("", "<synthesized>")
self.typedtree = asttyped.ModuleT(
20 changes: 20 additions & 0 deletions artiq/test/lit/embedding/warning_invariant_missing.py
Original file line number Diff line number Diff line change
@@ -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