From cc228376275f4294da2a72038297e79989990f2a Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 16 Jan 2016 03:09:03 +0000 Subject: [PATCH] transforms.inferencer: infer a monomorphic type for slice ":" --- artiq/compiler/transforms/inferencer.py | 16 ++++++++++------ lit-test/test/inferencer/slice.py | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 lit-test/test/inferencer/slice.py diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index e2f9b5efd..2a95c01e1 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -202,12 +202,16 @@ class Inferencer(algorithm.Visitor): value.loc, None) def visit_SliceT(self, node): - self._unify(node.type, builtins.TInt(), - node.loc, None) - for operand in (node.lower, node.upper, node.step): - if operand is not None: - self._unify(operand.type, node.type, - operand.loc, None) + if (node.lower, node.upper, node.step) == (None, None, None): + self._unify(node.type, builtins.TInt32(), + node.loc, None) + else: + self._unify(node.type, builtins.TInt(), + node.loc, None) + for operand in (node.lower, node.upper, node.step): + if operand is not None: + self._unify(operand.type, node.type, + operand.loc, None) def visit_ExtSlice(self, node): diag = diagnostic.Diagnostic("error", diff --git a/lit-test/test/inferencer/slice.py b/lit-test/test/inferencer/slice.py new file mode 100644 index 000000000..1693bcd85 --- /dev/null +++ b/lit-test/test/inferencer/slice.py @@ -0,0 +1,6 @@ +# RUN: %python -m artiq.compiler.testbench.inferencer %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +x = [0] +# CHECK-L: [::int(width=32)] +x[:] = [1]