Commit Graph

11 Commits

Author SHA1 Message Date
Andrew Kelley
75efb736ce zig reduce: run results through astgen
and use that to fix up usused variable declarations and parameters that
are caused by transformations.

also add a transformation to replace global variable init with
`undefined`.
2023-11-04 17:38:10 -07:00
Andrew Kelley
fc1e7a5644 zig reduce: rename identifiers when inlining an @import 2023-11-04 15:48:28 -07:00
Andrew Kelley
8bd01d2d9b zig reduce: add transformation for inlining file-based @import
One thing is missing for it to be useful, however, which is dealing with
ambiguous reference errors introduced by the inlining process.
2023-11-04 13:57:29 -07:00
Andrew Kelley
31529f912b zig reduce: add transformation of replacing var init with undefined 2023-11-03 22:08:01 -07:00
Andrew Kelley
a2f4adbd19 zig reduce: add "delete unused globals" transform
While walking the AST looking for reductions, notice if any globals are
unreferenced, and if they are, add a transformation for removing the
global.
2023-11-03 21:31:32 -07:00
Andrew Kelley
1396479656 zig reduce: redesign
Now it works like this:
1. Walk the AST of the source file looking for independent
   reductions and collecting them all into an array list.
2. Randomize the list of transformations. A future enhancement will add
   priority weights to the sorting but for now they are completely
   shuffled.
3. Apply a subset consisting of 1/2 of the transformations and check for
   interestingness.
4. If not interesting, half the subset size again and check again.
5. Repeat until the subset size is 1, then march the transformation
   index forward by 1 with each non-interesting attempt.

At any point if a subset of transformations succeeds in producing an interesting
result, restart the whole process, reparsing the AST and re-generating the list
of all possible transformations and shuffling it again.

As for std.zig.render, the fixups operate based on AST Node Index rather
than Nth index of the function occurence. This allows precise control
over how to mutate the input.
2023-11-03 20:05:32 -07:00
Andrew Kelley
815b85d8a2 zig reduce: check once upfront to verify interestingness 2023-11-03 20:05:32 -07:00
Andrew Kelley
f90ba235d0 zig reduce proof of concept 2023-11-03 20:05:32 -07:00
Andrew Kelley
73b96ac114 accept a transformation index 2023-11-03 20:05:32 -07:00
Andrew Kelley
5f1f145199 add a transformation for gutting the body of a function 2023-11-03 20:05:32 -07:00
Andrew Kelley
f8c24c2cd0 add zig reduce subcommand
Also adds `-Donly-reduce` flag in build.zig which disables LLVM and
irrelevant code for faster iteration cycles.
2023-11-03 20:05:32 -07:00