scripts: Dropped cycle detection from table renderer

Now that cycle detection is always done at result collection time, we
don't need this in the table renderer itself.

This had a tendency to cause problems for non-function scripts (ctx.py,
structs.py).
This commit is contained in:
Christopher Haster
2024-12-10 15:43:14 -06:00
parent dd389f23ee
commit 6a6ed0f741
9 changed files with 36 additions and 237 deletions

View File

@ -906,7 +906,6 @@ def table(Result, results, diff_results=None, *,
summary=False,
depth=1,
hot=None,
detect_cycles=True,
**_):
all_, all = all, __builtins__.all
@ -928,15 +927,11 @@ def table(Result, results, diff_results=None, *,
class HotResult(Result_):
_i = '_hot_i'
_children = '_hot_children'
_notes = '_hot_notes'
def __new__(cls, r, i=None, children=None, notes=None):
self = HotResult._make(r)
self._hot_i = i
self._hot_children = children if children is not None else []
self._hot_notes = notes if notes is not None else set()
if hasattr(Result_, '_notes'):
self._hot_notes.update(getattr(r, r._notes))
return self
def __add__(self, other):
@ -945,13 +940,12 @@ def table(Result, results, diff_results=None, *,
self._hot_i if other._hot_i is None
else other._hot_i if self._hot_i is None
else min(self._hot_i, other._hot_i),
self._hot_children + other._hot_children,
self._hot_notes | other._hot_notes)
self._hot_children + other._hot_children)
results_ = []
for r in results:
hot_ = []
def recurse(results_, depth_, seen=set()):
def recurse(results_, depth_):
nonlocal hot_
if not results_:
return
@ -970,17 +964,10 @@ def table(Result, results, diff_results=None, *,
for k in it.chain(hot, [None])))
hot_.append(HotResult(r, i=len(hot_)))
# found a cycle?
if (detect_cycles
and tuple(getattr(r, k) for k in Result._by) in seen):
hot_[-1]._hot_notes.add('cycle detected')
return
# recurse?
if depth_ > 1:
recurse(getattr(r, Result._children),
depth_-1,
seen | {tuple(getattr(r, k) for k in Result._by)})
depth_-1)
recurse(getattr(r, Result._children), depth-1)
results_.append(HotResult(r, children=hot_))
@ -1138,7 +1125,7 @@ def table(Result, results, diff_results=None, *,
return entry
# recursive entry helper, only used by some scripts
def recurse(results_, depth_, seen=set(),
def recurse(results_, depth_,
prefixes=('', '', '', '')):
# build the children table at each layer
results_ = fold(Result, results_, by=by)
@ -1173,20 +1160,12 @@ def table(Result, results, diff_results=None, *,
line = [x if isinstance(x, tuple) else (x, []) for x in line]
# add prefixes
line[0] = (prefixes[0+is_last] + line[0][0], line[0][1])
# add cycle detection
if detect_cycles and name in seen:
line[-1] = (line[-1][0], line[-1][1] + ['cycle detected'])
lines.append(line)
# found a cycle?
if detect_cycles and name in seen:
continue
# recurse?
if depth_ > 1:
recurse(getattr(r, Result._children),
depth_-1,
seen | {name},
(prefixes[2+is_last] + "|-> ",
prefixes[2+is_last] + "'-> ",
prefixes[2+is_last] + "| ",
@ -1206,7 +1185,6 @@ def table(Result, results, diff_results=None, *,
if name in table and depth > 1:
recurse(getattr(table[name], Result._children),
depth-1,
{name},
("|-> ",
"'-> ",
"| ",
@ -1367,7 +1345,6 @@ def main(paths,
by=by if by is not None else ['function'],
fields=fields,
sort=sort,
detect_cycles=False,
**args)
# error on recursion