From 25e282470984e2f20c775d89b848a5d031ecc38e Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 30 Dec 2015 16:19:35 +0800 Subject: [PATCH] validators.escape: infer correct region for arguments. --- artiq/compiler/types.py | 3 +++ artiq/compiler/validators/escape.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 2f7bf798c..ebea69b08 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -248,6 +248,9 @@ class TFunction(Type): def arity(self): return len(self.args) + len(self.optargs) + def arg_names(self): + return list(self.args.keys()) + list(self.optargs.keys()) + def find(self): return self diff --git a/artiq/compiler/validators/escape.py b/artiq/compiler/validators/escape.py index 2e8438f88..346f0c130 100644 --- a/artiq/compiler/validators/escape.py +++ b/artiq/compiler/validators/escape.py @@ -211,7 +211,7 @@ class EscapeValidator(algorithm.Visitor): loc) ] - def visit_in_region(self, node, region, typing_env): + def visit_in_region(self, node, region, typing_env, args=[]): try: old_youngest_region = self.youngest_region self.youngest_region = region @@ -221,7 +221,10 @@ class EscapeValidator(algorithm.Visitor): for name in typing_env: if has_region(typing_env[name]): - self.youngest_env[name] = Region(None) # not yet known + if name in args: + self.youngest_env[name] = self.youngest_region + else: + self.youngest_env[name] = Region(None) # not yet known else: self.youngest_env[name] = None # lives forever self.env_stack.append(self.youngest_env) @@ -237,7 +240,8 @@ class EscapeValidator(algorithm.Visitor): def visit_FunctionDefT(self, node): self.youngest_env[node.name] = self.youngest_region - self.visit_in_region(node, Region(node.loc), node.typing_env) + self.visit_in_region(node, Region(node.loc), node.typing_env, + args=node.signature_type.find().arg_names()) def visit_ClassDefT(self, node): self.youngest_env[node.name] = self.youngest_region