From 2f20f53e906026e9e79eb6162c96bf5d50f85fb8 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 28 Feb 2025 23:34:52 -0600 Subject: [PATCH] scripts: csv.py: Reverted define filtering to before expr eval It's just too unintuitive to filter after exprs. Note this is consistent with how exprs/mods are evaluated. Exprs/mods can't reference other exprs/mods because csv.py is only single-pass, so allowing defines to reference exprs/mods is surprising. And the solution to needing these sort of post-expr/mod references is the same for defines: You can always chain multiple csv.py calls. The reason defines were change to evaluate after expr eval was because this seemed inconsistent with other result scripts, but this is not actually the case. Other result scripts simply don't have exprs/mods, so filtering in fold is the same as filtering during collection. Note that even in fold, filtering is done _before_ the actual fold/sum operation. --- Also fixed a recursive-define regression when folding. Counter- intuitively, we _don't_ want to recursively apply define filters. If we do the results will just end up too confusing to be useful. --- scripts/code.py | 2 +- scripts/cov.py | 2 +- scripts/csv.py | 26 ++++++++++++++++---------- scripts/ctx.py | 2 +- scripts/data.py | 2 +- scripts/perf.py | 2 +- scripts/perfbd.py | 2 +- scripts/stack.py | 2 +- scripts/structs.py | 2 +- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/scripts/code.py b/scripts/code.py index bb004c3d..7cc06958 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -572,7 +572,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/cov.py b/scripts/cov.py index 65775e58..48f23bd5 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -433,7 +433,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/csv.py b/scripts/csv.py index 5c59bc9b..ce73603d 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1412,7 +1412,6 @@ def compile(fields_, results, fields=None, mods=[], exprs=[], - defines=[], sort=None, children=None, hot=None, @@ -1420,10 +1419,6 @@ def compile(fields_, results, by = by.copy() fields = fields.copy() - # make sure define fields are included - for k, _ in defines: - if k not in by and k not in fields: - by.append(k) # make sure sort/hot fields are included for k, reverse in it.chain(sort or [], hot or []): # this defaults to typechecking sort/hot fields, which is @@ -1562,20 +1557,32 @@ def compile(fields_, results, def homogenize(Result, results, *, enumerates=None, + defines=[], depth=1): # this just converts all (possibly recursive) results to our # result type results_ = [] - for i, r in enumerate(results): + for r in results: + # filter by matching defines + # + # we do this here instead of in fold to be consistent with + # evaluation order of exprs/mods/etc, note this isn't really + # inconsistent with the other scripts, since they don't really + # evaluate anything + if not all(k in r and str(r[k]) in vs for k, vs in defines): + continue + + # append a result results_.append(Result(**( r # enumerate? - | ({e: i for e in enumerates} + | ({e: len(results_) for e in enumerates} if enumerates is not None else {}) # recurse? | ({Result._children: homogenize( Result, r[Result._children], + # only filter defines at the top level! enumerates=enumerates, depth=depth-1)} if hasattr(Result, '_children') @@ -1661,7 +1668,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] @@ -2260,7 +2267,6 @@ def main(csv_paths, *, fields=fields, mods=mods, exprs=exprs, - defines=defines, sort=sort, children=children, hot=hot, @@ -2269,12 +2275,12 @@ def main(csv_paths, *, # homogenize results = homogenize(Result, results, enumerates=enumerates, + defines=defines, depth=depth) # fold results = fold(Result, results, by=by, - defines=defines, depth=depth) # hotify? diff --git a/scripts/ctx.py b/scripts/ctx.py index 8a2fcb54..c85d4152 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -783,7 +783,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/data.py b/scripts/data.py index 3665d8cf..a1cbc573 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -572,7 +572,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/perf.py b/scripts/perf.py index 4aa31f6a..fde71e8d 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -887,7 +887,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/perfbd.py b/scripts/perfbd.py index 645dda3c..8408c169 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -857,7 +857,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/stack.py b/scripts/stack.py index 405635e7..c1a28fb9 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -529,7 +529,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded] diff --git a/scripts/structs.py b/scripts/structs.py index 93a1d760..c52c50a2 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -603,7 +603,7 @@ def fold(Result, results, *, Result._children: fold( Result, getattr(r, Result._children), by=by, - defines=defines, + # only filter defines at the top level! sort=sort, depth=depth-1)}) for r in folded]