Commit 64b44e31 authored by Stefan Behnel's avatar Stefan Behnel

disable type inference for closures and work around prematurely created...

disable type inference for closures and work around prematurely created closure fields with incorrect type information
parent a643524d
...@@ -1207,6 +1207,10 @@ class CreateClosureClasses(CythonTransform): ...@@ -1207,6 +1207,10 @@ class CreateClosureClasses(CythonTransform):
for entry in func_scope.entries.values(): for entry in func_scope.entries.values():
# This is wasteful--we should do this later when we know # This is wasteful--we should do this later when we know
# which vars are actually being used inside... # which vars are actually being used inside...
#
# Also, this happens before type inference and type
# analysis, so the entries created here may end up having
# incorrect or at least unspecified types.
cname = entry.cname cname = entry.cname
class_scope.declare_var(pos=entry.pos, class_scope.declare_var(pos=entry.pos,
name=entry.name, name=entry.name,
......
...@@ -188,7 +188,7 @@ class SimpleAssignmentTypeInferer: ...@@ -188,7 +188,7 @@ class SimpleAssignmentTypeInferer:
# TODO: Implement a real type inference algorithm. # TODO: Implement a real type inference algorithm.
# (Something more powerful than just extending this one...) # (Something more powerful than just extending this one...)
def infer_types(self, scope): def infer_types(self, scope):
enabled = scope.directives['infer_types'] enabled = not scope.is_closure_scope and scope.directives['infer_types']
verbose = scope.directives['infer_types.verbose'] verbose = scope.directives['infer_types.verbose']
if enabled == True: if enabled == True:
spanning_type = aggressive_spanning_type spanning_type = aggressive_spanning_type
...@@ -198,6 +198,8 @@ class SimpleAssignmentTypeInferer: ...@@ -198,6 +198,8 @@ class SimpleAssignmentTypeInferer:
for entry in scope.entries.values(): for entry in scope.entries.values():
if entry.type is unspecified_type: if entry.type is unspecified_type:
entry.type = py_object_type entry.type = py_object_type
if scope.is_closure_scope:
fix_closure_entries(scope)
return return
dependancies_by_entry = {} # entry -> dependancies dependancies_by_entry = {} # entry -> dependancies
...@@ -259,6 +261,19 @@ class SimpleAssignmentTypeInferer: ...@@ -259,6 +261,19 @@ class SimpleAssignmentTypeInferer:
entry.type = py_object_type entry.type = py_object_type
if verbose: if verbose:
message(entry.pos, "inferred '%s' to be of type '%s' (default)" % (entry.name, entry.type)) message(entry.pos, "inferred '%s' to be of type '%s' (default)" % (entry.name, entry.type))
#if scope.is_closure_scope:
# fix_closure_entries(scope)
def fix_closure_entries(scope):
"""Temporary work-around to fix field types in the closure class
that were unknown at the time of creation and only determined
during type inference.
"""
closure_entries = scope.scope_class.type.scope.entries
for name, entry in scope.entries.iteritems():
if name in closure_entries:
closure_entry = closure_entries[name]
closure_entry.type = entry.type
def find_spanning_type(type1, type2): def find_spanning_type(type1, type2):
if type1 is type2: if type1 is type2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment