More temp arg assignment avoidance.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 25 Feb 2011 06:27:31 +0000 (22:27 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 25 Feb 2011 06:27:31 +0000 (22:27 -0800)
Cython/Compiler/ExprNodes.py

index c1d56d9b34326be8cf76baa783531620f9497dee..2a94ad1f6f5edc0cd4c3288c0cc98655b74bf9cb 100755 (executable)
@@ -368,7 +368,7 @@ class ExprNode(Node):
     def nonlocally_immutable(self):
         # Returns whether this variable is a safe reference, i.e.
         # can't be modified as part of globals or closures.
-        return self.is_temp
+        return self.is_temp or self.type.is_array or self.type.is_cfunction
 
     # --------------- Type Analysis ------------------
 
@@ -1477,6 +1477,8 @@ class NameNode(AtomicExprNode):
         return 1
 
     def nonlocally_immutable(self):
+        if ExprNode.nonlocally_immutable(self):
+            return True
         entry = self.entry
         return entry and (entry.is_local or entry.is_arg) and not entry.in_closure
 
@@ -3038,10 +3040,8 @@ class SimpleCallNode(CallNode):
                 if i == 0 and self.self is not None:
                     continue # self is ok
                 arg = self.args[i]
-                if arg.is_name and arg.entry and (
-                    (arg.entry.is_local and not arg.entry.in_closure)
-                    or arg.entry.type.is_cfunction):
-                    # local variables and C functions are safe
+                if arg.nonlocally_immutable():
+                    # locals, C functions, unassignable types are safe.
                     pass
                 elif arg.type.is_cpp_class:
                     # Assignment has side effects, avoid.