From 56315203a95bd2ebeb3ae9c64021fcdbfef5f11e Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Jan 2019 13:37:20 +0000 Subject: [PATCH] compiler: first monomorphize ints, then casts. Fixes #1242. --- artiq/compiler/module.py | 2 +- artiq/compiler/transforms/cast_monomorphizer.py | 1 + artiq/test/lit/monomorphism/bug_1242.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 artiq/test/lit/monomorphism/bug_1242.py diff --git a/artiq/compiler/module.py b/artiq/compiler/module.py index cea86cddb..d43404b20 100644 --- a/artiq/compiler/module.py +++ b/artiq/compiler/module.py @@ -66,8 +66,8 @@ class Module: interleaver = transforms.Interleaver(engine=self.engine) invariant_detection = analyses.InvariantDetection(engine=self.engine) - cast_monomorphizer.visit(src.typedtree) int_monomorphizer.visit(src.typedtree) + cast_monomorphizer.visit(src.typedtree) inferencer.visit(src.typedtree) monomorphism_validator.visit(src.typedtree) escape_validator.visit(src.typedtree) diff --git a/artiq/compiler/transforms/cast_monomorphizer.py b/artiq/compiler/transforms/cast_monomorphizer.py index 50e2bda4f..8e373ab1e 100644 --- a/artiq/compiler/transforms/cast_monomorphizer.py +++ b/artiq/compiler/transforms/cast_monomorphizer.py @@ -18,6 +18,7 @@ class CastMonomorphizer(algorithm.Visitor): types.is_builtin(node.func.type, "int64")): typ = node.type.find() if (not types.is_var(typ["width"]) and + len(node.args) == 1 and builtins.is_int(node.args[0].type) and types.is_var(node.args[0].type.find()["width"])): if isinstance(node.args[0], asttyped.BinOpT): diff --git a/artiq/test/lit/monomorphism/bug_1242.py b/artiq/test/lit/monomorphism/bug_1242.py new file mode 100644 index 000000000..8918a30cc --- /dev/null +++ b/artiq/test/lit/monomorphism/bug_1242.py @@ -0,0 +1,8 @@ +# RUN: %python -m artiq.compiler.testbench.signature %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +x = 0x100000000 +# CHECK-L: x: numpy.int64 + +y = int32(x) +# CHECK-L: y: numpy.int32