From 8a892af24481d341b01ee5aa08c5f120498232a5 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 14 Mar 2021 18:46:28 +0000 Subject: [PATCH] compiler: Fix type inference in slice expressions This was a long-standing issue affecting both lists and the new NumPy array implementation, just caused by the generic inference passes not being run on the slice subexpressions (and thus e.g. ints not being monomorphized). GitHub: Fixes #1632. --- artiq/compiler/transforms/inferencer.py | 1 + artiq/test/lit/regression/issue_1632.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 artiq/test/lit/regression/issue_1632.py diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 684c575de..a8bb6cbee 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -216,6 +216,7 @@ class Inferencer(algorithm.Visitor): value.loc, None) def visit_SliceT(self, node): + self.generic_visit(node) if (node.lower, node.upper, node.step) == (None, None, None): self._unify(node.type, builtins.TInt32(), node.loc, None) diff --git a/artiq/test/lit/regression/issue_1632.py b/artiq/test/lit/regression/issue_1632.py new file mode 100644 index 000000000..c7f36f96b --- /dev/null +++ b/artiq/test/lit/regression/issue_1632.py @@ -0,0 +1,19 @@ +# RUN: %python -m artiq.compiler.testbench.embedding %s + +from artiq.language.core import * +from artiq.language.types import * +import numpy as np + +class A: + def __init__(self): + self.n = 2 + + @kernel + def run(self): + print([1, 2, 3][:self.n]) + +a = A() + +@kernel +def entrypoint(): + a.run()