forked from M-Labs/artiq
1
0
Fork 0

compiler.types: fix TVar.find() for very large paths.

This commit is contained in:
whitequark 2015-11-27 18:02:18 +08:00
parent 00164390a1
commit bf1a583fda
1 changed files with 12 additions and 2 deletions

View File

@ -60,8 +60,18 @@ class TVar(Type):
if self.parent is self: if self.parent is self:
return self return self
else: else:
root = self.parent.find() # The recursive find() invocation is turned into a loop
self.parent = root # path compression # because paths resulting from unification of large arrays
# can easily cause a stack overflow.
root = self
while isinstance(root, TVar):
if root is root.parent:
break
else:
root = root.parent
# path compression
self.parent = root
return root return root
def unify(self, other): def unify(self, other):