compiler: do not try to re-coerce fully coerced numerics.

This commit is contained in:
whitequark 2018-04-21 18:24:00 +00:00
parent 742e273441
commit 58967f14fd
2 changed files with 21 additions and 1 deletions

View File

@ -310,9 +310,17 @@ class Inferencer(algorithm.Visitor):
node_types = [] node_types = []
for node in nodes: for node in nodes:
if isinstance(node, asttyped.CoerceT): if isinstance(node, asttyped.CoerceT):
# If we already know exactly what we coerce this value to, use that type,
# or we'll get an unification error in case the coerced type is not the same
# as the type of the coerced value.
# Otherwise, use the potentially more specific subtype when considering possible
# coercions, or we may get stuck.
if node.type.fold(False, lambda acc, ty: acc or types.is_var(ty)):
node_types.append(node.value.type) node_types.append(node.value.type)
else: else:
node_types.append(node.type) node_types.append(node.type)
else:
node_types.append(node.type)
if any(map(types.is_var, node_types)): # not enough info yet if any(map(types.is_var, node_types)): # not enough info yet
return return
elif not all(map(builtins.is_numeric, node_types)): elif not all(map(builtins.is_numeric, node_types)):

View File

@ -0,0 +1,12 @@
# RUN: %python -m artiq.compiler.testbench.inferencer +mono %s >%t
# RUN: OutputCheck %s --file-to-check=%t
# CHECK-L: n:numpy.int32 =
n = 0
# CHECK-L: a:numpy.int32 =
a = n // 1
# CHECK-L: b:numpy.int32 =
b = n // 10
# CHECK-L: q:numpy.int64 =
q = (a << 0) + (b << 8)
core_log(int64(q))