Skip to content

Commit

Permalink
sort: use a different codegen strategy
Browse files Browse the repository at this point in the history
The existing codegen strategy in sort.go relied on parsing the sort.go source
with go/ast and a combination of an AST rewrite + code text rewrite with regexes
to generate zfuncversion -- the same sort functionality with a different variant
of data.

In preparation for implementing golang#47619, we need a more robust codegen
strategy. To generate variants required for the generic sort functions
in the slices package, we'd need significanly more complicated AST
rewrites, which would make genzfunc.go much heavier.

Instead, redo the codegen strategy to use text/template instead of AST rewrites.
gen_sort_variants.go now contains the code for the underlying sort functions,
and generates multiple versions of them based on Variant configuration structs.
With this approach, adding new variants to generate generic sort functions for
the slices package becomes trivial.

See the discussion in golang#47619 for more details on the design decisions.

Change-Id: I8af784c41b1dc8ef92aaf6321359e8faa5fe106c
  • Loading branch information
eliben committed Jan 12, 2022
1 parent 83bfdb6 commit a30bc3c
Show file tree
Hide file tree
Showing 6 changed files with 1,160 additions and 728 deletions.
Loading

0 comments on commit a30bc3c

Please sign in to comment.