]> Cypherpunks repositories - gostls13.git/commit
sort: use a different codegen strategy
authorEli Bendersky <eliben@golang.org>
Tue, 28 Sep 2021 13:18:30 +0000 (06:18 -0700)
committerEli Bendersky‎ <eliben@golang.org>
Thu, 3 Mar 2022 13:42:02 +0000 (13:42 +0000)
commitda6f9a54edb85365bb345b057cdc26e2527401c8
treeb4e8cd069cb9c28eaeb1846c77db917474b427dd
parent2c6700739a6275b78a6af62707fd41783622061b
sort: use a different codegen strategy

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 #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 #47619 for more details on the design decisions.

Change-Id: I8af784c41b1dc8ef92aaf6321359e8faa5fe106c
Reviewed-on: https://go-review.googlesource.com/c/go/+/353069
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Than McIntosh <thanm@google.com>
src/sort/gen_sort_variants.go [new file with mode: 0644]
src/sort/genzfunc.go [deleted file]
src/sort/sort.go
src/sort/zfuncversion.go [deleted file]
src/sort/zsortfunc.go [new file with mode: 0644]
src/sort/zsortinterface.go [new file with mode: 0644]