From bf1a583fdaad45e79625690dcd43244331105558 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 27 Nov 2015 18:02:18 +0800 Subject: [PATCH] compiler.types: fix TVar.find() for very large paths. --- artiq/compiler/types.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 16f21c913..795e8f80e 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -60,8 +60,18 @@ class TVar(Type): if self.parent is self: return self else: - root = self.parent.find() - self.parent = root # path compression + # The recursive find() invocation is turned into a loop + # 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 def unify(self, other):