Skip to content

gantry: delete unused fakes, options and the unadopted log vocabulary - #677

Open
Philip Lombardi (plombardi89) wants to merge 2 commits into
mainfrom
chore/deadcode-gantry
Open

gantry: delete unused fakes, options and the unadopted log vocabulary#677
Philip Lombardi (plombardi89) wants to merge 2 commits into
mainfrom
chore/deadcode-gantry

Conversation

@plombardi89

Copy link
Copy Markdown
Collaborator

Part of the #670 dead-code sweep, split by component. The tooling that produced these findings is #673; this PR is deletions only and is independent of the other eight — the file sets are disjoint, so they can be reviewed and merged in any order and in parallel.

Why two analyzers were needed to find this

unused cannot see dead exported code under internal/. That is a documented design decision, not a gap: unused/unused.go:48-62 holds that a package uses its exported named types and a named type uses its exported methods, so every method on an exported type is transitively live because the type is exported.

x/tools/cmd/deadcode does not close that gap on its own either. x/tools/go/callgraph/rta/rta.go:281-287,433-437 — converting a value to an interface materializes its runtime type and marks every exported method of that type reachable, because reflection could call any of them. One var i any = x anywhere buys all of x's exported methods a clean bill of health.

So #673 adds both deadcode and hack/cmd/unreferenced, which resolves identifiers instead of tracing reachability. Neither subsumes the other, and findings below are attributed to whichever one saw them.


gantry/log: delete the unadopted attribute vocabulary

Eight of the nine attribute constructors have no caller: Digest, Peer,
Registry, Repo, Class, NodeID, Err and Context, plus the private safeString
they share. Subsystem is the one that was adopted, and it stays.

The file's own comment said these existed "so callers don't keep typing the key
name and so a refactor of the vocabulary only has to touch this file". Callers
did keep typing the key name. A vocabulary nobody speaks is not a vocabulary,
and keeping the constructors on the strength of the comment would be preferring
the intent in the prose to what the code does.

The package doc still lists the standard attribute keys, because the keys are
real and the WARN-line contract the design docs describe still depends on them.
Only the claim that helper constructors set them is gone.

Refs #670

gantry: delete unused fakes, options and dead lifecycle code

The whole Coordinator fake goes: NewCoordinator, ProgramIntent,
ProgramPleasePull, PullIntentQuery, PleasePull, the Coordinator type, the
private key type it was the only user of, and the compile-time assertion that
kept the type referenced. Nothing constructs it. coord's own tests use the real
Server.

Three affordances on fakes that are still in use had no caller either, and each
left state behind:

  • OriginPuller.HeadCount, with the headCount map, its initializer and the
    increment in Head. Its comment pointed at
    TestMirror_OriginSuccessMetric_FiresOnlyOnCacheCommit as the caller; that
    test exists but counts through mirror.WithOriginSuccessMetric instead, so
    the comment outlived the arrangement it described.
  • PeerDialer.FailOn, with the failOn map and the branch in FetchFromPeer it
    fed. With no writer the branch could never be taken. The mirror tests that
    model an unreachable peer declare their own dialer doubles
    (countingPeerDialer, resumingPeerDialer) rather than using this one.
  • DHT.SetHealth. Health is still read; only the setter was dead.

walk_test.go's digestSet helper was held up by an explicit var _ = digestSet
block commented "silence digestSet linter when unused in this file", which is
what kept unused quiet about it for as long as it has been dead. The block
and the regexp.Compile placeholder next to it go with it.

Subscriber.Close closed a closed channel that nothing ever selected on, so
the method, the channel and the sync.Once guarding it all go together. coord's
nopAddr existed only to satisfy a net.Addr assertion about itself.

Unused functional options: WithProvideTimeout and WithWithdrawTimeout
(advertise), WithContainerdConnectTimeout, WithRefPrefix,
WithMaxConcurrentStreams, WithDialTimeout, WithRPCTimeout (coord),
WithProviderFailureCacheTTL, WithReadIdleTimeout. Each configured a field that
keeps its default in every caller.

Refs #670


Verification

go build ./..., go vet ./..., golangci-lint over the touched trees (0 issues), make fmt producing no diff, and go build -tags e2e,integrationtest,storageboundary ./.... Full suite runs in CI.

The eight deletion branches were reassembled onto the tooling commits and diffed against the original combined branch: byte-identical, so nothing was lost or duplicated in the split.

Eight of the nine attribute constructors have no caller: Digest, Peer,
Registry, Repo, Class, NodeID, Err and Context, plus the private safeString
they share. Subsystem is the one that was adopted, and it stays.

The file's own comment said these existed "so callers don't keep typing the key
name and so a refactor of the vocabulary only has to touch this file". Callers
did keep typing the key name. A vocabulary nobody speaks is not a vocabulary,
and keeping the constructors on the strength of the comment would be preferring
the intent in the prose to what the code does.

The package doc still lists the standard attribute keys, because the keys are
real and the WARN-line contract the design docs describe still depends on them.
Only the claim that helper constructors set them is gone.

Refs #670
The whole Coordinator fake goes: NewCoordinator, ProgramIntent,
ProgramPleasePull, PullIntentQuery, PleasePull, the Coordinator type, the
private key type it was the only user of, and the compile-time assertion that
kept the type referenced. Nothing constructs it. coord's own tests use the real
Server.

Three affordances on fakes that are still in use had no caller either, and each
left state behind:

  - OriginPuller.HeadCount, with the headCount map, its initializer and the
    increment in Head. Its comment pointed at
    TestMirror_OriginSuccessMetric_FiresOnlyOnCacheCommit as the caller; that
    test exists but counts through mirror.WithOriginSuccessMetric instead, so
    the comment outlived the arrangement it described.
  - PeerDialer.FailOn, with the failOn map and the branch in FetchFromPeer it
    fed. With no writer the branch could never be taken. The mirror tests that
    model an unreachable peer declare their own dialer doubles
    (countingPeerDialer, resumingPeerDialer) rather than using this one.
  - DHT.SetHealth. Health is still read; only the setter was dead.

walk_test.go's digestSet helper was held up by an explicit `var _ = digestSet`
block commented "silence digestSet linter when unused in this file", which is
what kept `unused` quiet about it for as long as it has been dead. The block
and the regexp.Compile placeholder next to it go with it.

Subscriber.Close closed a `closed` channel that nothing ever selected on, so
the method, the channel and the sync.Once guarding it all go together. coord's
nopAddr existed only to satisfy a net.Addr assertion about itself.

Unused functional options: WithProvideTimeout and WithWithdrawTimeout
(advertise), WithContainerdConnectTimeout, WithRefPrefix,
WithMaxConcurrentStreams, WithDialTimeout, WithRPCTimeout (coord),
WithProviderFailureCacheTTL, WithReadIdleTimeout. Each configured a field that
keeps its default in every caller.

Refs #670
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