mirror of https://github.com/m-labs/artiq.git
compiler.types: fix TVar.find() for very large paths.
This commit is contained in:
parent
00164390a1
commit
bf1a583fda
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue