Repository navigation
refactor(tools,repl): replace hand-rolled sorted-unique helpers with slices.Sort and slices.Compact - #1489
Merged
Conversation
…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>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Four packages each carried a private
dedupethat spelled sort-then-drop-adjacent-duplicates by hand, which the standard library'sslices.Sort/slices.Sorted+slices.Compactalready 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)));failuresis still untouched for the laterlencheck.tools/referee/xpect/compare.go+resourceset.go: the adjacent-duplicatededupeaftersort.Strings→slices.Sort+slices.Compactonset.missingandset.libraryRoots(both overwritten, so in-place compaction is unobservable;Missingisomitempty, so nil vs empty does not change the JSON). Inmatches, theatclause's needle is nowsqueeze([]byte(text)).Textinstead of an inlineFieldsFuncclosure listing the same four bytes asisSpace, so needle and haystack share one definition of whitespace.tools/bench/llm/fidelity.go: the in-placededupe→slices.Sort+slices.Compactat both callers (same backing array, same first-of-run survivor).tools/census/grammar/classify.go: the seen-mapdedupe(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
Checklist
make testandmake lintpass locally (go build,go vet,gofmt -l,go test ./...in both modules as above;make lint✓)changes/unreleased/stdlib-dedupe.changed.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved — no count movedF4,K5) in the body, docs, or changelogLink 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