forked from M-Labs/artiq
1
0
Fork 0

validators.escape: infer correct region for arguments.

This commit is contained in:
whitequark 2015-12-30 16:19:35 +08:00
parent 72b6cca9c3
commit 25e2824709
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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,6 +221,9 @@ class EscapeValidator(algorithm.Visitor):
for name in typing_env:
if has_region(typing_env[name]):
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
@ -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