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: bfabca494bd1
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: 561d403dddde
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 3, 2015

  1. Copy the full SHA
    ee0990c View commit details
  2. Add missing _loc forwarding.

    whitequark committed Jul 3, 2015
    Copy the full SHA
    561d403 View commit details
Showing with 15 additions and 1 deletion.
  1. +2 −1 artiq/compiler/transforms/asttyped_rewriter.py
  2. +13 −0 artiq/compiler/transforms/inferencer.py
3 changes: 2 additions & 1 deletion artiq/compiler/transforms/asttyped_rewriter.py
Original file line number Diff line number Diff line change
@@ -243,7 +243,8 @@ def visit_Tuple(self, node):
def visit_List(self, node):
node = self.generic_visit(node)
node = asttyped.ListT(type=builtins.TList(),
elts=node.elts, ctx=node.ctx, loc=node.loc)
elts=node.elts, ctx=node.ctx,
begin_loc=node.begin_loc, end_loc=node.end_loc, loc=node.loc)
return self.visit(node)

def visit_Attribute(self, node):
13 changes: 13 additions & 0 deletions artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ def __init__(self, engine):
self.engine = engine
self.function = None # currently visited function, for Return inference
self.in_loop = False
self.has_return = False

def _unify(self, typea, typeb, loca, locb, makenotes=None):
try:
@@ -768,9 +769,11 @@ def visit_arguments(self, node):
def visit_FunctionDefT(self, node):
old_function, self.function = self.function, node
old_in_loop, self.in_loop = self.in_loop, False
old_has_return, self.has_return = self.has_return, False
self.generic_visit(node)
self.function = old_function
self.in_loop = old_in_loop
self.has_return = old_has_return

if any(node.decorator_list):
diag = diagnostic.Diagnostic("error",
@@ -779,6 +782,14 @@ def visit_FunctionDefT(self, node):
self.engine.process(diag)
return

# Lack of return statements is not the only case where the return
# type cannot be inferred. The other one is infinite (possibly mutual)
# recursion. Since Python functions don't have to return a value,
# we ignore that one.
if not self.has_return:
self._unify(node.return_type, builtins.TNone(),
node.name_loc, None)

signature_type = self._type_from_arguments(node.args, node.return_type)
if signature_type:
self._unify(node.signature_type, signature_type,
@@ -792,6 +803,8 @@ def visit_Return(self, node):
self.engine.process(diag)
return

self.has_return = True

self.generic_visit(node)
def makenotes(printer, typea, typeb, loca, locb):
return [