diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index be8609811..4d24c1a7b 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -5,6 +5,7 @@ from collections import OrderedDict from pythonparser import algorithm, diagnostic, ast from .. import asttyped, types, builtins +from .typedtree_printer import TypedtreePrinter class Inferencer(algorithm.Visitor): """ diff --git a/artiq/compiler/transforms/int_monomorphizer.py b/artiq/compiler/transforms/int_monomorphizer.py index 94711a43a..5002bb086 100644 --- a/artiq/compiler/transforms/int_monomorphizer.py +++ b/artiq/compiler/transforms/int_monomorphizer.py @@ -5,7 +5,7 @@ do not. """ from pythonparser import algorithm, diagnostic -from .. import types, builtins +from .. import types, builtins, asttyped class IntMonomorphizer(algorithm.Visitor): def __init__(self, engine): @@ -35,3 +35,13 @@ class IntMonomorphizer(algorithm.Visitor): typ = node.type.find() if types.is_var(typ["width"]): typ["width"].unify(types.TValue(32)) + + def visit_CoerceT(self, node): + if isinstance(node.value, asttyped.NumT) and \ + builtins.is_int(node.type) and \ + builtins.is_int(node.value.type) and \ + not types.is_var(node.type["width"]) and \ + types.is_var(node.value.type["width"]): + node.value.type.unify(node.type) + + self.generic_visit(node) diff --git a/artiq/test/lit/monomorphism/coercion.py b/artiq/test/lit/monomorphism/coercion.py new file mode 100644 index 000000000..bbd67e936 --- /dev/null +++ b/artiq/test/lit/monomorphism/coercion.py @@ -0,0 +1,10 @@ +# RUN: %python -m artiq.compiler.testbench.signature %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +def f(x): + x = int64(0) + return x + +# CHECK-L: g: ()->numpy.int64 +def g(): + return f(1 + 0)