Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1e851adf4f68
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d862db8b9d02
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jul 21, 2015

  1. Require boolean condition in If, While, IfExp.

    whitequark committed Jul 21, 2015
    Copy the full SHA
    e21829c View commit details
  2. Require boolean operand in BoolOp.

    whitequark committed Jul 21, 2015
    Copy the full SHA
    d862db8 View commit details
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/asttyped_rewriter.py
Original file line number Diff line number Diff line change
@@ -305,7 +305,7 @@ def visit_Subscript(self, node):

def visit_BoolOp(self, node):
node = self.generic_visit(node)
node = asttyped.BoolOpT(type=types.TVar(),
node = asttyped.BoolOpT(type=builtins.TBool(),
op=node.op, values=node.values,
op_locs=node.op_locs, loc=node.loc)
return self.visit(node)
13 changes: 11 additions & 2 deletions artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -145,6 +145,8 @@ def visit_SubscriptT(self, node):

def visit_IfExpT(self, node):
self.generic_visit(node)
self._unify(node.test.type, builtins.TBool(),
node.test.loc, None)
self._unify(node.body.type, node.orelse.type,
node.body.loc, node.orelse.loc)
self._unify(node.type, node.body.type,
@@ -153,8 +155,8 @@ def visit_IfExpT(self, node):
def visit_BoolOpT(self, node):
self.generic_visit(node)
for value in node.values:
self._unify(node.type, value.type,
node.loc, value.loc, self._makenotes_elts(node.values, "an operand"))
self._unify(value.type, builtins.TBool(),
value.loc, None)

def visit_UnaryOpT(self, node):
self.generic_visit(node)
@@ -788,6 +790,11 @@ def visit_AugAssign(self, node):

node.value = self._coerce_one(value_type, node.value, other_node=node.target)

def visit_If(self, node):
self.generic_visit(node)
self._unify(node.test.type, builtins.TBool(),
node.test.loc, None)

def visit_For(self, node):
old_in_loop, self.in_loop = self.in_loop, True
self.generic_visit(node)
@@ -798,6 +805,8 @@ def visit_While(self, node):
old_in_loop, self.in_loop = self.in_loop, True
self.generic_visit(node)
self.in_loop = old_in_loop
self._unify(node.test.type, builtins.TBool(),
node.test.loc, None)

def visit_Break(self, node):
if not self.in_loop:
14 changes: 9 additions & 5 deletions lit-test/compiler/inferencer/error_unify.py
Original file line number Diff line number Diff line change
@@ -12,11 +12,6 @@
# CHECK-L: note: a list element of type int(width='a)
# CHECK-L: note: a list element of type list(elt='b)

# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
1 and False
# CHECK-L: note: an operand of type int(width='a)
# CHECK-L: note: an operand of type bool

# CHECK-L: ${LINE:+1}: error: expected unary '+' operand to be of numeric type, not list(elt='a)
+[]

@@ -25,3 +20,12 @@

# CHECK-L: ${LINE:+1}: error: type int(width='a) does not have an attribute 'x'
(1).x

# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
1 if 1 else 1

# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
if 1: pass

# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
while 1: pass
2 changes: 1 addition & 1 deletion lit-test/compiler/inferencer/gcd.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
def _gcd(a, b):
if a < 0:
a = -a
while a:
while a > 0:
c = a
a = b % a
b = c
17 changes: 7 additions & 10 deletions lit-test/compiler/inferencer/unify.py
Original file line number Diff line number Diff line change
@@ -33,26 +33,23 @@
j += [1.0]
# CHECK-L: j:list(elt=float)

1 if a else 2
# CHECK-L: 1:int(width='f) if a:int(width='a) else 2:int(width='f):int(width='f)
1 if c else 2
# CHECK-L: 1:int(width='f) if c:bool else 2:int(width='f):int(width='f)

True and False
# CHECK-L: True:bool and False:bool:bool

1 and 0
# CHECK-L: 1:int(width='g) and 0:int(width='g):int(width='g)

~1
# CHECK-L: 1:int(width='h):int(width='h)
# CHECK-L: ~1:int(width='g):int(width='g)

not 1
# CHECK-L: 1:int(width='i):bool
not True
# CHECK-L: not True:bool:bool

[x for x in [1]]
# CHECK-L: [x:int(width='j) for x:int(width='j) in [1:int(width='j)]:list(elt=int(width='j))]:list(elt=int(width='j))
# CHECK-L: [x:int(width='h) for x:int(width='h) in [1:int(width='h)]:list(elt=int(width='h))]:list(elt=int(width='h))

lambda x, y=1: x
# CHECK-L: lambda x:'k, y:int(width='l)=1:int(width='l): x:'k:(x:'k, ?y:int(width='l))->'k
# CHECK-L: lambda x:'i, y:int(width='j)=1:int(width='j): x:'i:(x:'i, ?y:int(width='j))->'i

k = "x"
# CHECK-L: k:str