From 21eafefd28fa3d24bc03acce2f05ebfc078547a9 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 18 Jul 2015 08:13:49 +0300 Subject: [PATCH] Fix inference for globals. --- artiq/compiler/asttyped.py | 2 +- artiq/compiler/transforms/asttyped_rewriter.py | 4 ++-- lit-test/compiler/inferencer/scoping.py | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/asttyped.py b/artiq/compiler/asttyped.py index 7d38bd823..e24003aba 100644 --- a/artiq/compiler/asttyped.py +++ b/artiq/compiler/asttyped.py @@ -18,7 +18,7 @@ class scoped(object): :ivar typing_env: (dict with string keys and :class:`.types.Type` values) map of variable names to variable types :ivar globals_in_scope: (set of string keys) - list of variables resolved as globals + set of variables resolved as globals """ # Typed versions of untyped nodes diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index 244f99fd0..d05a73cd1 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -151,8 +151,8 @@ class LocalExtractor(algorithm.Visitor): continue self.global_.add(name) - self._assignable(name) - self.env_stack[1][name] = self.typing_env[name] + if name in self.env_stack[1]: + self.typing_env[name] = self.env_stack[1][name] def visit_Nonlocal(self, node): for name, loc in zip(node.names, node.name_locs): diff --git a/lit-test/compiler/inferencer/scoping.py b/lit-test/compiler/inferencer/scoping.py index 595daecf6..604b2425d 100644 --- a/lit-test/compiler/inferencer/scoping.py +++ b/lit-test/compiler/inferencer/scoping.py @@ -1,8 +1,9 @@ # RUN: %python -m artiq.compiler.testbench.inferencer %s >%t # RUN: OutputCheck %s --file-to-check=%t +# CHECK-L: []:list(elt=int(width='a)) +x = [] + def f(): global x - x = 1 -# CHECK-L: [x:int(width='a)] -[x] + x[0] = 1