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