From 6a6ed0f74164b6d487113a57afb33a86b3edcbb2 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 10 Dec 2024 15:43:14 -0600 Subject: [PATCH] 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). --- scripts/code.py | 30 ++++-------------------------- scripts/cov.py | 30 ++++-------------------------- scripts/csv.py | 30 ++++-------------------------- scripts/ctx.py | 31 ++++--------------------------- scripts/data.py | 30 ++++-------------------------- scripts/perf.py | 30 ++++-------------------------- scripts/perfbd.py | 30 ++++-------------------------- scripts/stack.py | 31 ++++--------------------------- scripts/structs.py | 31 ++++--------------------------- 9 files changed, 36 insertions(+), 237 deletions(-) diff --git a/scripts/code.py b/scripts/code.py index 0433a45e..d994ae7e 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -667,7 +667,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -689,15 +688,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): @@ -706,13 +701,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 @@ -731,17 +725,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_)) @@ -899,7 +886,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) @@ -934,20 +921,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] + "| ", @@ -967,7 +946,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/cov.py b/scripts/cov.py index 4e5974e8..2eaa12ec 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -401,7 +401,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -423,15 +422,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): @@ -440,13 +435,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 @@ -465,17 +459,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_)) @@ -633,7 +620,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) @@ -668,20 +655,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] + "| ", @@ -701,7 +680,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/csv.py b/scripts/csv.py index 097c9da3..471fe6c9 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1416,7 +1416,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -1438,15 +1437,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): @@ -1455,13 +1450,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 @@ -1480,17 +1474,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_)) @@ -1648,7 +1635,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) @@ -1683,20 +1670,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] + "| ", @@ -1716,7 +1695,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/ctx.py b/scripts/ctx.py index dc1da3cd..68130359 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -875,7 +875,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -897,15 +896,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): @@ -914,13 +909,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 @@ -939,17 +933,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_)) @@ -1107,7 +1094,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) @@ -1142,20 +1129,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] + "| ", @@ -1175,7 +1154,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", @@ -1326,7 +1304,6 @@ def main(obj_paths, *, by=by if by is not None else ['function'], fields=fields, sort=sort, - detect_cycles=False, **args) diff --git a/scripts/data.py b/scripts/data.py index 52b0dc23..3e741b08 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -667,7 +667,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -689,15 +688,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): @@ -706,13 +701,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 @@ -731,17 +725,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_)) @@ -899,7 +886,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) @@ -934,20 +921,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] + "| ", @@ -967,7 +946,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/perf.py b/scripts/perf.py index 27e8906d..bdb184d2 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -847,7 +847,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -869,15 +868,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): @@ -886,13 +881,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 @@ -911,17 +905,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_)) @@ -1079,7 +1066,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) @@ -1114,20 +1101,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] + "| ", @@ -1147,7 +1126,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/perfbd.py b/scripts/perfbd.py index 00f37d66..5fd80e4c 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -817,7 +817,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -839,15 +838,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): @@ -856,13 +851,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 @@ -881,17 +875,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_)) @@ -1049,7 +1036,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) @@ -1084,20 +1071,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] + "| ", @@ -1117,7 +1096,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", diff --git a/scripts/stack.py b/scripts/stack.py index ca0a8a3d..f4763641 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -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 diff --git a/scripts/structs.py b/scripts/structs.py index 7a08ed7d..32ac2607 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -689,7 +689,6 @@ def table(Result, results, diff_results=None, *, summary=False, depth=1, hot=None, - detect_cycles=True, **_): all_, all = all, __builtins__.all @@ -711,15 +710,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): @@ -728,13 +723,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 @@ -753,17 +747,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_)) @@ -921,7 +908,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) @@ -956,20 +943,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] + "| ", @@ -989,7 +968,6 @@ def table(Result, results, diff_results=None, *, if name in table and depth > 1: recurse(getattr(table[name], Result._children), depth-1, - {name}, ("|-> ", "'-> ", "| ", @@ -1140,7 +1118,6 @@ def main(obj_paths, *, by=by if by is not None else ['struct'], fields=fields, sort=sort, - detect_cycles=False, **args)