From 280790e438c681880b1445ce4f64798369d67c7f Mon Sep 17 00:00:00 2001 From: kamilisjon Date: Sun, 4 Jan 2026 08:04:13 +0200 Subject: [PATCH] Reuse toposort in recursive_property (#13993) --- tinygrad/uop/ops.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index 529cfa0295..e8cd8bb054 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -104,15 +104,7 @@ class recursive_property(property): self.__doc__ = fxn.__doc__ def __get__(self, x:UOp|None, owner=None): if x is None: return self - # this is very similar to toposort/topovisit - stack: list[tuple[UOp, bool]] = [(x, False)] - while stack: - node, visited = stack.pop() - if self.nm in node.__dict__: continue - if not visited: - stack.append((node, True)) - for s in reversed(node.src): stack.append((s, False)) - else: node.__dict__[self.nm] = self.fxn(node) + for node in x.toposort(gate=lambda node: self.nm not in node.__dict__): node.__dict__[self.nm] = self.fxn(node) return x.__dict__[self.nm] # we import this late so we can use resolve/smax in mixins