From f68e4ae5194b23c897e21ec74125d5c24a9ab7a1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 5 Dec 2016 05:08:57 +0000 Subject: [PATCH] compiler: rein in overzealous cast monomorphization. --- artiq/compiler/transforms/cast_monomorphizer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/cast_monomorphizer.py b/artiq/compiler/transforms/cast_monomorphizer.py index c12eb9663..50e2bda4f 100644 --- a/artiq/compiler/transforms/cast_monomorphizer.py +++ b/artiq/compiler/transforms/cast_monomorphizer.py @@ -4,7 +4,7 @@ expressions of undetermined integer type to either 32 or 64 bits. """ from pythonparser import algorithm, diagnostic -from .. import types, builtins +from .. import types, builtins, asttyped class CastMonomorphizer(algorithm.Visitor): def __init__(self, engine): @@ -20,5 +20,12 @@ class CastMonomorphizer(algorithm.Visitor): if (not types.is_var(typ["width"]) 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): + # Binary operations are a bit special: they can widen, and so their + # return type is indeterminate until both argument types are fully known. + # In case we first monomorphize the return type, and then some argument type, + # and argument type is wider than return type, we'll introduce a conflict. + return + node.args[0].type.unify(typ)