Skip to content

Commit f94b009

Browse files
committed
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 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
1 parent 83bfdb6 commit f94b009

8 files changed

+1892
-728
lines changed

Diff for: src/sort/gen_sort_variants.go

+521
Large diffs are not rendered by default.

Diff for: src/sort/genzfunc.go

-127
This file was deleted.

0 commit comments

Comments
 (0)