Skip to content

refactor(tools,repl): replace hand-rolled sorted-unique helpers with slices.Sort and slices.Compact - #1489

Merged
HuiJun merged 1 commit into
developfrom
refactor/stdlib-dedupe
Oct 25, 2026
Merged

HuiJun merged 1 commit into
developfrom
refactor/stdlib-dedupe

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Four packages each carried a private dedupe that spelled sort-then-drop-adjacent-duplicates by hand, which the standard library's slices.Sort/slices.Sorted + slices.Compact already provide. Each site now calls the standard library directly, preserving the result shape the helper had, and the helpers are deleted:

  • internal/frontend/repl/compare.go: dedupe(failures) (seen-map then sort, fresh slice) → slices.Compact(slices.Sorted(slices.Values(failures))); failures is still untouched for the later len check.
  • tools/referee/xpect/compare.go + resourceset.go: the adjacent-duplicate dedupe after sort.Strings → slices.Sort + slices.Compact on set.missing and set.libraryRoots (both overwritten, so in-place compaction is unobservable; Missing is omitempty, so nil vs empty does not change the JSON). In matches, the at clause's needle is now squeeze([]byte(text)).Text instead of an inline FieldsFunc closure listing the same four bytes as isSpace, so needle and haystack share one definition of whitespace.
  • tools/bench/llm/fidelity.go: the in-place dedupe → slices.Sort + slices.Compact at both callers (same backing array, same first-of-run survivor).
  • tools/census/grammar/classify.go: the seen-map dedupe (nil on empty, fresh sorted slice) → slices.Compact(slices.Sorted(slices.Values(literals))), which is also nil on empty and leaves the input alone.

Net: 16 insertions, 65 deletions; no behaviour change.

How it was verified

gofmt -l .                       # (nothing)
go build ./... && go build -C tools ./...
go vet ./... && go vet -C tools ./...
python3 scripts/changelog.py check
go test -count=1 ./internal/frontend/repl/                              ok  29.954s
go test -C tools -count=1 ./referee/xpect/ ./bench/llm/ ./census/grammar/
                                                                          ok  0.143s / 170.447s / 0.005s
go test -count=1 ./...                 120 ok; tests/codegen hit Go's 10m default under full-suite load
go test -count=1 -timeout 40m ./tests/codegen                            ok  353.948s (rerun alone)
go test -C tools -count=1 ./...        28 ok
make lint                              ✓ Lint passed (staticcheck + gosec, both modules)

Checklist

  • make test and make lint pass locally (go build, go vet, gofmt -l, go test ./... in both modules as above; make lint ✓)
  • Tests added or updated for the change — none needed: the existing package suites cover every call site and the helpers were not test-only
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md) — not applicable
  • Changelog entry added as changes/unreleased/stdlib-dedupe.changed.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved — no count moved
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/6bdfc22599a64e188b0b5e3a1fd0d050
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/6bdfc22599a64e188b0b5e3a1fd0d050?variant=devin
Requested by: @HuiJun

…slices.Sort and slices.Compact

The REPL comparison, the Xpect referee, the LLM fidelity bench and the grammar census each spelled sort-then-drop-adjacent-duplicates by hand. Call the standard library at each site instead, keeping the in-place or fresh-slice result each had, and strip the Xpect at-clause needle through squeeze so needle and haystack share one definition of whitespace.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review October 25, 2026 03:55

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@HuiJun
HuiJun merged commit 546283f into develop Oct 25, 2026
56 checks passed
@HuiJun
HuiJun deleted the refactor/stdlib-dedupe branch October 25, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant