Commit 3d6647f0 authored by Robert Bradshaw's avatar Robert Bradshaw

More temp arg assignment avoidance.

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