codecop 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. codecop/__init__.py +7 -0
  2. codecop/access.py +140 -0
  3. codecop/access_postgres.py +284 -0
  4. codecop/advisor.py +1512 -0
  5. codecop/advisor_bench.py +493 -0
  6. codecop/advisor_ch.py +2080 -0
  7. codecop/advisor_view.py +381 -0
  8. codecop/advisors.py +184 -0
  9. codecop/agent.py +221 -0
  10. codecop/agentfacts.py +745 -0
  11. codecop/apply/__init__.py +327 -0
  12. codecop/apply/check.py +344 -0
  13. codecop/apply/cli.py +162 -0
  14. codecop/apply/clickhouse.py +379 -0
  15. codecop/apply/common.py +238 -0
  16. codecop/apply/html.py +264 -0
  17. codecop/apply/patch.py +213 -0
  18. codecop/apply/postgres.py +102 -0
  19. codecop/apply/trial.py +166 -0
  20. codecop/assemble.py +104 -0
  21. codecop/baseline.py +1043 -0
  22. codecop/bench.py +2464 -0
  23. codecop/blockers.py +935 -0
  24. codecop/budget.py +980 -0
  25. codecop/catalog_profile.py +525 -0
  26. codecop/changed.py +261 -0
  27. codecop/cicmd.py +1002 -0
  28. codecop/cli.py +5421 -0
  29. codecop/client.py +729 -0
  30. codecop/coverage.py +1067 -0
  31. codecop/coverage_reasons.py +116 -0
  32. codecop/crashlog.py +70 -0
  33. codecop/datagen.py +766 -0
  34. codecop/datagen_postgres.py +630 -0
  35. codecop/datagen_sqlite.py +323 -0
  36. codecop/dbcli.py +885 -0
  37. codecop/definitions.py +457 -0
  38. codecop/discover/__init__.py +702 -0
  39. codecop/discover/arms.py +160 -0
  40. codecop/discover/base.py +234 -0
  41. codecop/discover/dialect.py +296 -0
  42. codecop/discover/elixir.py +64 -0
  43. codecop/discover/engine_go.py +320 -0
  44. codecop/discover/go.py +1947 -0
  45. codecop/discover/java.py +1528 -0
  46. codecop/discover/loops.py +1671 -0
  47. codecop/discover/named_go.py +258 -0
  48. codecop/discover/origins.py +4565 -0
  49. codecop/discover/origins_ts.py +1584 -0
  50. codecop/discover/orm_django.py +2772 -0
  51. codecop/discover/orm_django_models.py +814 -0
  52. codecop/discover/orm_django_sql.py +662 -0
  53. codecop/discover/orm_ent.py +565 -0
  54. codecop/discover/orm_ex_ecto.py +2138 -0
  55. codecop/discover/orm_go.py +2134 -0
  56. codecop/discover/orm_go_bun.py +602 -0
  57. codecop/discover/orm_go_run.py +636 -0
  58. codecop/discover/orm_go_types.py +1082 -0
  59. codecop/discover/orm_java.py +1450 -0
  60. codecop/discover/orm_jdbi.py +743 -0
  61. codecop/discover/orm_jooq.py +806 -0
  62. codecop/discover/orm_jpa.py +1307 -0
  63. codecop/discover/orm_mybatis.py +730 -0
  64. codecop/discover/orm_py.py +557 -0
  65. codecop/discover/orm_py_peewee.py +1266 -0
  66. codecop/discover/orm_py_prisma.py +298 -0
  67. codecop/discover/orm_rb_activerecord.py +1906 -0
  68. codecop/discover/orm_rust.py +1248 -0
  69. codecop/discover/orm_rust_seaorm.py +734 -0
  70. codecop/discover/orm_sqlalchemy.py +2475 -0
  71. codecop/discover/orm_stats.py +307 -0
  72. codecop/discover/orm_tables.py +29 -0
  73. codecop/discover/orm_ts.py +503 -0
  74. codecop/discover/orm_ts_drizzle.py +697 -0
  75. codecop/discover/orm_ts_knex.py +1117 -0
  76. codecop/discover/orm_ts_kysely.py +861 -0
  77. codecop/discover/orm_ts_prisma.py +1045 -0
  78. codecop/discover/orm_ts_schema.py +169 -0
  79. codecop/discover/orm_ts_sequelize.py +1401 -0
  80. codecop/discover/orm_ts_typeorm.py +1067 -0
  81. codecop/discover/probes.py +323 -0
  82. codecop/discover/python.py +595 -0
  83. codecop/discover/ruby.py +793 -0
  84. codecop/discover/rust.py +2378 -0
  85. codecop/discover/schema.py +520 -0
  86. codecop/discover/schema_ent.py +145 -0
  87. codecop/discover/schema_ts.py +420 -0
  88. codecop/discover/tsresolve.py +257 -0
  89. codecop/discover/typescript.py +1728 -0
  90. codecop/discover/xml_mapper.py +526 -0
  91. codecop/engines/__init__.py +515 -0
  92. codecop/engines/base.py +498 -0
  93. codecop/engines/clickhouse.py +1558 -0
  94. codecop/engines/pg_ddl.py +444 -0
  95. codecop/engines/pg_hints.py +137 -0
  96. codecop/engines/postgres.py +1060 -0
  97. codecop/engines/sqlite.py +742 -0
  98. codecop/families/__init__.py +3 -0
  99. codecop/families/build.py +280 -0
  100. codecop/families/cli.py +177 -0
  101. codecop/families/coverage_hook.py +62 -0
  102. codecop/families/driver.py +221 -0
  103. codecop/families/goslice.py +229 -0
  104. codecop/families/goslice_tool/go.mod +3 -0
  105. codecop/families/goslice_tool/main.go +403 -0
  106. codecop/families/holes.py +451 -0
  107. codecop/families/images/Dockerfile.go +5 -0
  108. codecop/families/images/Dockerfile.python +4 -0
  109. codecop/families/images/Dockerfile.rust +4 -0
  110. codecop/families/isolate.py +171 -0
  111. codecop/families/locate.py +270 -0
  112. codecop/families/model.py +301 -0
  113. codecop/families/plangate.py +271 -0
  114. codecop/families/tagpatch.py +174 -0
  115. codecop/fidelity.py +671 -0
  116. codecop/fixgroups.py +130 -0
  117. codecop/formerly.py +91 -0
  118. codecop/grantscript.py +254 -0
  119. codecop/groupbench.py +1375 -0
  120. codecop/groups.py +594 -0
  121. codecop/groups_view.py +186 -0
  122. codecop/heat.py +1405 -0
  123. codecop/heatcli.py +219 -0
  124. codecop/joins.py +1749 -0
  125. codecop/joins_view.py +127 -0
  126. codecop/kinds/__init__.py +507 -0
  127. codecop/kinds/calls/__init__.py +501 -0
  128. codecop/kinds/calls/extract.py +1097 -0
  129. codecop/kinds/calls/harness.py +408 -0
  130. codecop/kinds/calls/measure.py +342 -0
  131. codecop/kinds/calls/rules.py +139 -0
  132. codecop/kinds/calls/runners/RunCalls.java +167 -0
  133. codecop/kinds/calls/runners/run_go.go +141 -0
  134. codecop/kinds/calls/runners/run_node.js +186 -0
  135. codecop/kinds/calls/runners/run_python.py +319 -0
  136. codecop/kinds/calls/runners/run_rust.rs +200 -0
  137. codecop/kinds/calls/standin.py +340 -0
  138. codecop/kinds/pipeline.py +288 -0
  139. codecop/kinds/regex/__init__.py +1167 -0
  140. codecop/kinds/regex/engines/RegexHarness.java +129 -0
  141. codecop/kinds/regex/engines/run_go.go +294 -0
  142. codecop/kinds/regex/engines/run_node.js +99 -0
  143. codecop/kinds/regex/engines/run_python.py +295 -0
  144. codecop/kinds/regex/engines/run_rust.rs +149 -0
  145. codecop/kinds/regex/extract.py +1438 -0
  146. codecop/kinds/regex/harness.py +235 -0
  147. codecop/kinds/regex/measure.py +270 -0
  148. codecop/kinds/regex/shapes.py +418 -0
  149. codecop/kinds/regex/syntax.py +1721 -0
  150. codecop/kinds/testkind.py +107 -0
  151. codecop/kinds/transaction/__init__.py +228 -0
  152. codecop/kinds/transaction/bind.py +355 -0
  153. codecop/kinds/transaction/measure.py +264 -0
  154. codecop/kinds/transaction/plan.py +462 -0
  155. codecop/kinds/transaction/rules.py +540 -0
  156. codecop/kinds/transaction/sandbox.py +94 -0
  157. codecop/kinds/transaction/scenarios.py +520 -0
  158. codecop/kinds/transaction/schedule.py +483 -0
  159. codecop/kinds/transaction/shapes.py +418 -0
  160. codecop/kinds/transaction/verify.py +293 -0
  161. codecop/live.py +237 -0
  162. codecop/loopbench.py +2071 -0
  163. codecop/loopschema.py +591 -0
  164. codecop/mcpserver.py +120 -0
  165. codecop/mechanism.py +214 -0
  166. codecop/members.py +200 -0
  167. codecop/multi.py +443 -0
  168. codecop/observed.py +1868 -0
  169. codecop/parts.py +102 -0
  170. codecop/patterns.py +830 -0
  171. codecop/patterns_view.py +559 -0
  172. codecop/plangate.py +242 -0
  173. codecop/profile.py +439 -0
  174. codecop/prompts/areas.md +19 -0
  175. codecop/prompts/observed_variants.md +20 -0
  176. codecop/prompts/profile.md +60 -0
  177. codecop/prompts/profile_postgres.md +68 -0
  178. codecop/prompts/profile_sizes.md +26 -0
  179. codecop/prompts/profile_sqlite.md +69 -0
  180. codecop/prompts/rank.md +84 -0
  181. codecop/prompts/rank_postgres.md +96 -0
  182. codecop/prompts/rank_sqlite.md +94 -0
  183. codecop/prompts/scenario_variants.md +20 -0
  184. codecop/rank.py +1473 -0
  185. codecop/realdb/__init__.py +688 -0
  186. codecop/realdb/clickhouse.py +1223 -0
  187. codecop/realdb/facts.py +815 -0
  188. codecop/realdb/locality.py +964 -0
  189. codecop/realdb/locks.py +355 -0
  190. codecop/realdb/match.py +531 -0
  191. codecop/realdb/postgres.py +643 -0
  192. codecop/realdb/ratios.py +77 -0
  193. codecop/realdb/sample.py +126 -0
  194. codecop/relations.py +227 -0
  195. codecop/report.py +1854 -0
  196. codecop/resources.py +332 -0
  197. codecop/resources_view.py +266 -0
  198. codecop/rules/entry_points.toml +1013 -0
  199. codecop/rules/sinks.toml +362 -0
  200. codecop/runsonce.py +8 -0
  201. codecop/sandboxschema.py +555 -0
  202. codecop/scenario_agent.py +172 -0
  203. codecop/scenario_bind.py +507 -0
  204. codecop/scenario_sql.py +971 -0
  205. codecop/scenarios.py +675 -0
  206. codecop/scenarios_view.py +274 -0
  207. codecop/schemacli.py +67 -0
  208. codecop/schemas/areas_output.schema.json +21 -0
  209. codecop/schemas/profile_output.schema.json +362 -0
  210. codecop/schemas/rank_output.schema.json +385 -0
  211. codecop/sizes.py +200 -0
  212. codecop/sqlinfo.py +558 -0
  213. codecop/typedparams.py +576 -0
  214. codecop/verdicts.py +212 -0
  215. codecop/writebench.py +720 -0
  216. codecop/writecost.py +440 -0
  217. codecop/writes.py +1208 -0
  218. codecop-0.1.0.dist-info/METADATA +42 -0
  219. codecop-0.1.0.dist-info/RECORD +222 -0
  220. codecop-0.1.0.dist-info/WHEEL +4 -0
  221. codecop-0.1.0.dist-info/entry_points.txt +2 -0
  222. codecop-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,403 @@
1
+ // slicer: for one Go package directory, cut out every string-returning function whose transitive closure of
2
+ // package-level declarations uses only an allowlist of standard packages (a "pure slice"), and write a standalone
3
+ // program that calls each over its enumerable arguments (bools, constants of a named type) and prints JSON.
4
+ // The slicer only PARSES the repository; the program it writes is run elsewhere (container, no network).
5
+ package main
6
+
7
+ import (
8
+ "bytes"
9
+ "encoding/json"
10
+ "fmt"
11
+ "go/ast"
12
+ "go/parser"
13
+ "go/printer"
14
+ "go/token"
15
+ "os"
16
+ "path/filepath"
17
+ "sort"
18
+ "strings"
19
+ )
20
+
21
+ var allow = map[string]bool{"fmt": true, "strings": true, "strconv": true, "sort": true, "slices": true, "maps": true, "unicode": true,
22
+ "unicode/utf8": true, "bytes": true, "math": true, "errors": true, "time": true, "regexp": true, "encoding/json": true, "encoding/hex": true,
23
+ "crypto/sha256": true, "crypto/md5": true, "crypto/sha1": true, "hash/fnv": true, "cmp": true, "text/template": true, "embed": true, "math/bits": true, "iter": true}
24
+
25
+ type decl struct {
26
+ name string
27
+ node ast.Node // *ast.FuncDecl or *ast.GenDecl(spec wrapped)
28
+ file *ast.File
29
+ isFunc bool
30
+ recv string
31
+ refs map[string]bool
32
+ sels map[string]bool // selector names used (possible methods)
33
+ imports map[string]string
34
+ impure string
35
+ embed bool
36
+ }
37
+
38
+ func main() {
39
+ dir, out := os.Args[1], os.Args[2]
40
+ fset := token.NewFileSet()
41
+ pkgs, err := parser.ParseDir(fset, dir, func(fi os.FileInfo) bool { return !strings.HasSuffix(fi.Name(), "_test.go") }, parser.ParseComments)
42
+ if err != nil && len(pkgs) == 0 {
43
+ fmt.Println(`{"error":"parse"}`)
44
+ return
45
+ }
46
+ decls := map[string]*decl{}
47
+ methods := map[string][]*decl{}
48
+ enums := map[string][]string{} // type -> const names
49
+ for _, pkg := range pkgs {
50
+ if strings.HasSuffix(pkg.Name, "_test") {
51
+ continue
52
+ }
53
+ for _, f := range pkg.Files {
54
+ imps := map[string]string{}
55
+ for _, im := range f.Imports {
56
+ p := strings.Trim(im.Path.Value, `"`)
57
+ n := filepath.Base(p)
58
+ if im.Name != nil {
59
+ n = im.Name.Name
60
+ }
61
+ imps[n] = p
62
+ }
63
+ for _, d := range f.Decls {
64
+ switch x := d.(type) {
65
+ case *ast.FuncDecl:
66
+ dd := &decl{name: x.Name.Name, node: x, file: f, isFunc: true}
67
+ if x.Recv != nil && len(x.Recv.List) > 0 {
68
+ t := x.Recv.List[0].Type
69
+ if s, ok := t.(*ast.StarExpr); ok {
70
+ t = s.X
71
+ }
72
+ if ix, ok := t.(*ast.IndexExpr); ok {
73
+ t = ix.X
74
+ }
75
+ if id, ok := t.(*ast.Ident); ok {
76
+ dd.recv = id.Name
77
+ }
78
+ methods[dd.name] = append(methods[dd.name], dd)
79
+ } else {
80
+ decls[dd.name] = dd
81
+ }
82
+ scan(dd, imps)
83
+ case *ast.GenDecl:
84
+ if x.Tok == token.IMPORT {
85
+ continue
86
+ }
87
+ var lastType string
88
+ for _, sp := range x.Specs {
89
+ one := &ast.GenDecl{Tok: x.Tok, Specs: []ast.Spec{sp}, Doc: x.Doc}
90
+ switch s := sp.(type) {
91
+ case *ast.TypeSpec:
92
+ dd := &decl{name: s.Name.Name, node: one, file: f}
93
+ decls[dd.name] = dd
94
+ scan(dd, imps)
95
+ case *ast.ValueSpec:
96
+ if x.Tok == token.CONST {
97
+ if id, ok := s.Type.(*ast.Ident); ok {
98
+ lastType = id.Name
99
+ } else if s.Type != nil || len(s.Values) > 0 {
100
+ if len(s.Values) > 0 {
101
+ if c, ok := s.Values[0].(*ast.CallExpr); ok {
102
+ if id, ok := c.Fun.(*ast.Ident); ok {
103
+ lastType = id.Name
104
+ } else {
105
+ lastType = ""
106
+ }
107
+ } else if s.Type == nil {
108
+ lastType = ""
109
+ }
110
+ }
111
+ }
112
+ }
113
+ whole := one
114
+ iota := false
115
+ ast.Inspect(x, func(n ast.Node) bool {
116
+ if id, ok := n.(*ast.Ident); ok && id.Name == "iota" {
117
+ iota = true
118
+ }
119
+ return true
120
+ })
121
+ if iota {
122
+ whole = x
123
+ }
124
+ for _, n := range s.Names {
125
+ if n.Name == "_" {
126
+ continue
127
+ }
128
+ dd := &decl{name: n.Name, node: whole, file: f}
129
+ if s.Doc != nil && strings.Contains(s.Doc.Text(), "go:embed") || x.Doc != nil && hasEmbed(x.Doc) || s.Doc != nil && hasEmbed(s.Doc) {
130
+ dd.embed = true
131
+ }
132
+ decls[dd.name] = dd
133
+ scan(dd, imps)
134
+ if x.Tok == token.CONST && lastType != "" {
135
+ enums[lastType] = append(enums[lastType], n.Name)
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ // closure per target
145
+ type target struct {
146
+ d *decl
147
+ close []*decl
148
+ }
149
+ var targets []target
150
+ var embeds []*decl
151
+ report := map[string]string{}
152
+ names := make([]string, 0, len(decls))
153
+ for n := range decls {
154
+ names = append(names, n)
155
+ }
156
+ sort.Strings(names)
157
+ for _, n := range names {
158
+ d := decls[n]
159
+ if !d.isFunc {
160
+ continue
161
+ }
162
+ fd := d.node.(*ast.FuncDecl)
163
+ if fd.Type.Results == nil || len(fd.Type.Results.List) == 0 || fd.Type.TypeParams != nil {
164
+ continue
165
+ }
166
+ if id, ok := fd.Type.Results.List[0].Type.(*ast.Ident); !ok || id.Name != "string" {
167
+ continue
168
+ }
169
+ seen := map[*decl]bool{}
170
+ why := ""
171
+ var walk func(x *decl)
172
+ walk = func(x *decl) {
173
+ if seen[x] || why != "" {
174
+ return
175
+ }
176
+ seen[x] = true
177
+ if x.impure != "" {
178
+ why = x.name + " uses " + x.impure
179
+ return
180
+ }
181
+ if x.embed {
182
+ embeds = append(embeds, x)
183
+ }
184
+ for r := range x.refs {
185
+ if y, ok := decls[r]; ok {
186
+ walk(y)
187
+ }
188
+ }
189
+ for s := range x.sels {
190
+ for _, m := range methods[s] {
191
+ if m.impure == "" {
192
+ walk(m)
193
+ }
194
+ }
195
+ }
196
+ }
197
+ walk(d)
198
+ if why != "" {
199
+ report[n] = "impure: " + why
200
+ continue
201
+ }
202
+ var cl []*decl
203
+ for x := range seen {
204
+ cl = append(cl, x)
205
+ }
206
+ targets = append(targets, target{d, cl})
207
+ }
208
+ // embedded data files (SQL text, never code) are copied beside the program
209
+ for _, e := range embeds {
210
+ gd := e.node.(*ast.GenDecl)
211
+ if gd.Doc == nil { continue }
212
+ for _, c := range gd.Doc.List {
213
+ if !strings.HasPrefix(c.Text, "//go:embed") { continue }
214
+ for _, pat := range strings.Fields(c.Text)[1:] {
215
+ ms, _ := filepath.Glob(filepath.Join(dir, pat))
216
+ for _, m := range ms {
217
+ filepath.Walk(m, func(pth string, fi os.FileInfo, err error) error {
218
+ if err != nil || fi.IsDir() { return nil }
219
+ ext := filepath.Ext(pth)
220
+ if ext != ".sql" && ext != ".tmpl" && ext != ".txt" && ext != ".json" && ext != ".tpl" { return nil }
221
+ rel, _ := filepath.Rel(dir, pth)
222
+ b, _ := os.ReadFile(pth)
223
+ os.MkdirAll(filepath.Join(out, filepath.Dir(rel)), 0o755)
224
+ os.WriteFile(filepath.Join(out, rel), b, 0o644)
225
+ return nil
226
+ })
227
+ }
228
+ }
229
+ }
230
+ }
231
+ // one program for the package
232
+ used := map[*decl]bool{}
233
+ imps := map[string]string{"encoding/json": "json", "fmt": "fmt", "os": "os"}
234
+ if len(embeds) > 0 { imps["embed"] = "_" }
235
+ for _, t := range targets {
236
+ for _, x := range t.close {
237
+ used[x] = true
238
+ }
239
+ }
240
+ var buf bytes.Buffer
241
+ printed := map[ast.Node]bool{}
242
+ var ds []*decl
243
+ for x := range used {
244
+ ds = append(ds, x)
245
+ }
246
+ sort.Slice(ds, func(i, j int) bool { return ds[i].name+ds[i].recv < ds[j].name+ds[j].recv })
247
+ for _, x := range ds {
248
+ if printed[x.node] {
249
+ continue
250
+ }
251
+ printed[x.node] = true
252
+ for k, v := range x.imports {
253
+ imps[v] = k
254
+ }
255
+ printer.Fprint(&buf, fset, x.node)
256
+ buf.WriteString("\n\n")
257
+ }
258
+ var drv bytes.Buffer
259
+ drv.WriteString("type zzRow struct{ Fn string `json:\"fn\"`; Args []string `json:\"args\"`; Out string `json:\"out\"`; Panic bool `json:\"panic,omitempty\"` }\nfunc zzCall(fn string, args []string, f func() string) { r := zzRow{Fn: fn, Args: args}; func() { defer func() { if recover() != nil { r.Panic = true } }(); r.Out = f() }(); b, _ := json.Marshal(r); fmt.Fprintln(os.Stdout, string(b)) }\nfunc main() {\n")
260
+ for _, t := range targets {
261
+ fd := t.d.node.(*ast.FuncDecl)
262
+ type par struct {
263
+ name string
264
+ vals []string
265
+ }
266
+ var ps []par
267
+ ok := true
268
+ i := 0
269
+ for _, f := range fd.Type.Params.List {
270
+ var tb bytes.Buffer
271
+ printer.Fprint(&tb, fset, f.Type)
272
+ ts := tb.String()
273
+ n := len(f.Names)
274
+ if n == 0 {
275
+ n = 1
276
+ }
277
+ for k := 0; k < n; k++ {
278
+ i++
279
+ var vals []string
280
+ switch {
281
+ case ts == "bool":
282
+ vals = []string{"false", "true"}
283
+ case ts == "string":
284
+ vals = []string{fmt.Sprintf("\"ZZARG%d\"", i)}
285
+ case strings.HasPrefix(ts, "..."):
286
+ vals = []string{""}
287
+ case len(enums[ts]) > 0:
288
+ vals = enums[ts]
289
+ if len(vals) > 12 {
290
+ vals = vals[:12]
291
+ }
292
+ case strings.HasPrefix(ts, "[]") && len(enums[ts[2:]]) > 0:
293
+ vals = []string{ts + "{" + strings.Join(enums[ts[2:]], ", ") + "}", ts + "{" + enums[ts[2:]][0] + "}"}
294
+ case ts == "[]string":
295
+ vals = []string{fmt.Sprintf("[]string{\"ZZARG%d\"}", i)}
296
+ case ts == "int" || ts == "int64" || ts == "int32" || ts == "uint64" || ts == "uint" || ts == "float64":
297
+ vals = []string{"1"}
298
+ case strings.HasPrefix(ts, "*") && decls[ts[1:]] != nil:
299
+ vals = []string{"nil", "new(" + ts[1:] + ")"}
300
+ case strings.HasPrefix(ts, "func"):
301
+ ok = false
302
+ default:
303
+ vals = []string{"*new(" + ts + ")"}
304
+ }
305
+ ps = append(ps, par{"", vals})
306
+ }
307
+ }
308
+ if !ok {
309
+ report[t.d.name] = "param: func"
310
+ continue
311
+ }
312
+ combos := [][]string{{}}
313
+ for _, p := range ps {
314
+ var nx [][]string
315
+ for _, c := range combos {
316
+ for _, v := range p.vals {
317
+ if len(nx) >= 64 {
318
+ break
319
+ }
320
+ nx = append(nx, append(append([]string{}, c...), v))
321
+ }
322
+ }
323
+ combos = nx
324
+ }
325
+ nres := 0
326
+ for _, r := range fd.Type.Results.List {
327
+ if len(r.Names) == 0 {
328
+ nres++
329
+ } else {
330
+ nres += len(r.Names)
331
+ }
332
+ }
333
+ for _, c := range combos {
334
+ var args []string
335
+ for _, a := range c {
336
+ if a != "" {
337
+ args = append(args, a)
338
+ }
339
+ }
340
+ qs := make([]string, len(args))
341
+ for qi, a := range args { qs[qi] = fmt.Sprintf("%q", a) }
342
+ lit := "[]string{" + strings.Join(qs, ", ") + "}"
343
+ lhs := "r"
344
+ for k := 1; k < nres; k++ {
345
+ lhs += ", _"
346
+ }
347
+ fmt.Fprintf(&drv, "\tzzCall(%q, %s, func() string { %s := %s(%s); return r })\n", t.d.name, lit, lhs, t.d.name, strings.Join(args, ", "))
348
+ }
349
+ report[t.d.name] = fmt.Sprintf("ok: %d calls", len(combos))
350
+ }
351
+ drv.WriteString("}\n")
352
+ var head bytes.Buffer
353
+ head.WriteString("package main\n\nimport (\n")
354
+ for p, n := range imps {
355
+ if filepath.Base(p) == n {
356
+ fmt.Fprintf(&head, "\t%q\n", p)
357
+ } else {
358
+ fmt.Fprintf(&head, "\t%s %q\n", n, p)
359
+ }
360
+ }
361
+ head.WriteString(")\n\n")
362
+ os.MkdirAll(out, 0o755)
363
+ os.WriteFile(filepath.Join(out, "main.go"), append(append(head.Bytes(), buf.Bytes()...), drv.Bytes()...), 0o644)
364
+ os.WriteFile(filepath.Join(out, "go.mod"), []byte("module slice\ngo 1.24\n"), 0o644)
365
+ rb, _ := json.MarshalIndent(report, "", " ")
366
+ os.WriteFile(filepath.Join(out, "report.json"), rb, 0o644)
367
+ }
368
+
369
+ func hasEmbed(cg *ast.CommentGroup) bool {
370
+ for _, c := range cg.List {
371
+ if strings.Contains(c.Text, "go:embed") {
372
+ return true
373
+ }
374
+ }
375
+ return false
376
+ }
377
+
378
+ func scan(d *decl, imps map[string]string) {
379
+ d.refs, d.sels, d.imports = map[string]bool{}, map[string]bool{}, map[string]string{}
380
+ ast.Inspect(d.node, func(n ast.Node) bool {
381
+ switch x := n.(type) {
382
+ case *ast.SelectorExpr:
383
+ if id, ok := x.X.(*ast.Ident); ok {
384
+ if p, isImp := imps[id.Name]; isImp && id.Obj == nil {
385
+ d.imports[id.Name] = p
386
+ if !allow[p] {
387
+ d.impure = p
388
+ }
389
+ return false
390
+ }
391
+ }
392
+ d.sels[x.Sel.Name] = true
393
+ case *ast.Ident:
394
+ d.refs[x.Name] = true
395
+ case *ast.GoStmt:
396
+ d.impure = "go statement"
397
+ }
398
+ return true
399
+ })
400
+ if fd, ok := d.node.(*ast.FuncDecl); ok && fd.Body == nil {
401
+ d.impure = "no body"
402
+ }
403
+ }