authzed / spicedb

Open Source, Google Zanzibar-inspired database for scalably storing and querying fine-grained authorization data
https://authzed.com/docs
Apache License 2.0
5.1k stars 278 forks source link

Remove statically analyzable dead-code #1719

Open jzelinskie opened 9 months ago

jzelinskie commented 9 months ago

What platforms are affected?

linux, macos, windows, others

What architectures are affected?

amd64, arm64, others

What SpiceDB version are you using?

main

Steps to Reproduce

  1. go install golang.org/x/tools/cmd/deadcode@latest
  2. deadcode -test ./...

Expected Result

No output

Actual Result

internal/datasets/subjectset.go:39:22: unreachable func: SubjectSet.UnionWithSet
internal/datasets/subjectsetbytype.go:86:28: unreachable func: SubjectByTypeSet.Len
internal/datastore/common/jitter.go:12:6: unreachable func: WithJitter
internal/datastore/mysql/options.go:204:6: unreachable func: DebugAnalyzeBeforeStatistics
internal/datastore/postgres/options.go:315:6: unreachable func: DebugAnalyzeBeforeStatistics
internal/datastore/postgres/options.go:322:6: unreachable func: WithQueryInterceptor
internal/developmentmembership/trackingsubjectset.go:59:32: unreachable func: TrackingSubjectSet.RemoveFrom
internal/dispatch/combined/combined.go:119:6: unreachable func: RemoteDispatchTimeout
internal/graph/errors.go:59:6: unreachable func: NewAlwaysFailErr
internal/graph/errors.go:73:32: unreachable func: ErrRelationNotFound.NamespaceName
internal/graph/errors.go:78:32: unreachable func: ErrRelationNotFound.NotFoundRelationName
internal/graph/errors.go:82:32: unreachable func: ErrRelationNotFound.MarshalZerologObject
internal/graph/errors.go:87:32: unreachable func: ErrRelationNotFound.DetailsMetadata
internal/graph/errors.go:95:6: unreachable func: NewRelationNotFoundErr
internal/graph/errors.go:136:6: unreachable func: NewRelationMissingTypeInfoErr
internal/graph/errors.go:166:6: unreachable func: NewUnimplementedErr
internal/graph/graph.go:51:6: unreachable func: AlwaysFailExpand
internal/logging/logger.go:39:6: unreachable func: Log
internal/logging/logger.go:43:6: unreachable func: Print
internal/logging/logger.go:47:6: unreachable func: Printf
internal/middleware/dispatcher/dispatcher.go:28:6: unreachable func: FromContext
internal/middleware/dispatcher/dispatcher.go:38:6: unreachable func: MustFromContext
internal/services/shared/errors.go:109:6: unreachable func: AsValidationError
internal/services/shared/interceptor.go:16:50: unreachable func: WithUnaryServiceSpecificInterceptor.UnaryInterceptor
internal/services/v0/developer.go:26:6: unreachable func: RegisterDeveloperServer
internal/testfixtures/generator.go:18:6: unreachable func: RandomObjectID
pkg/caveats/types/types.go:48:6: unreachable func: TypeKeywords
pkg/cmd/server/middleware.go:280:41: unreachable func: StreamOrderEnforcerBuilder.EnsureWrapperNotExecuted
pkg/cmd/server/middleware.go:290:41: unreachable func: StreamOrderEnforcerBuilder.EnsureInterceptorNotExecuted
pkg/cmd/server/middleware.go:371:40: unreachable func: UnaryOrderEnforcerBuilder.EnsureNotExecuted
pkg/datastore/relationshipquerytree.go:17:6: unreachable func: NewRelationshipQueryTree
pkg/datastore/revisionparsing/revisionparsing.go:27:6: unreachable func: MustParseRevisionForTest
pkg/datastore/test/datastore.go:32:30: unreachable func: DatastoreTesterFunc.New
pkg/datastore/test/datastore.go:154:6: unreachable func: All
pkg/development/devcontext.go:168:23: unreachable func: DevContext.Dispose
pkg/genutil/slicez/slicez.go:4:6: unreachable func: Concat
pkg/middleware/datastore/datastore.go:12:6: unreachable func: FromContext
pkg/middleware/datastore/datastore.go:18:6: unreachable func: MustFromContext
pkg/middleware/dispatcher/dispatcher.go:12:6: unreachable func: FromContext
pkg/middleware/dispatcher/dispatcher.go:18:6: unreachable func: MustFromContext
pkg/middleware/requestid/requestid.go:37:6: unreachable func: WithIDGenerator
pkg/middleware/requestid/requestid.go:50:6: unreachable func: GetOrGenerateRequestID
pkg/middleware/usagemetrics/usagemetrics.go:11:6: unreachable func: FromContext
pkg/proto/core/v1/util.go:8:6: unreachable func: ToCoreRelationTuple
pkg/proto/core/v1/util.go:16:6: unreachable func: ToCoreRelationTuples
pkg/proto/core/v1/util.go:25:6: unreachable func: ToCoreObjectAndRelation
pkg/proto/core/v1/util.go:34:6: unreachable func: ToCoreRelationReference
pkg/proto/core/v1/util.go:42:6: unreachable func: ToV0RelationTuple
pkg/proto/core/v1/util.go:62:6: unreachable func: ToV0RelationTuples
pkg/releases/releases.go:17:6: unreachable func: GetSourceRepository
pkg/schemadsl/compiler/compiler.go:55:6: unreachable func: RequirePrefixedObjectType
pkg/schemadsl/input/sourcepositionmapper.go:21:6: unreachable func: EmptySourcePositionMapper
pkg/schemadsl/lexer/lex_def.go:84:6: unreachable func: IsKeyword
pkg/schemautil/schemautil.go:15:6: unreachable func: ValidateSchemaChanges
pkg/schemautil/schemautil.go:22:6: unreachable func: ApplySchemaChanges
pkg/spiceerrors/bug.go:23:6: unreachable func: MustPanic
pkg/spiceerrors/termination.go:51:25: unreachable func: ErrorBuilder.Timestamp
pkg/tuple/tuple.go:444:6: unreachable func: MustFromRelationships
pkg/typesystem/errors.go:201:32: unreachable func: ErrPermissionsCycle.MarshalZerologObject
pkg/typesystem/errors.go:206:32: unreachable func: ErrPermissionsCycle.DetailsMetadata
pkg/typesystem/errors.go:243:37: unreachable func: ErrUnusedCaveatParameter.MarshalZerologObject
pkg/typesystem/errors.go:248:37: unreachable func: ErrUnusedCaveatParameter.DetailsMetadata
pkg/typesystem/errors.go:338:6: unreachable func: NewPermissionsCycleErr
pkg/typesystem/errors.go:347:6: unreachable func: NewUnusedCaveatParameterErr
pkg/typesystem/reachabilitygraph.go:126:30: unreachable func: ReachabilityGraph.RelationsEncountered
pkg/typesystem/resolver.go:55:6: unreachable func: ResolverForSchema
Linkinlog commented 8 months ago

I think I can help, could I be assigned to this?

jzelinskie commented 8 months ago

There are a few instances here that are actually being used by external projects. Let one of the maintainers filter down the list and then you can absolutely help out!

jzelinskie commented 8 months ago

cc @ecordell @vroldanbet

vroldanbet commented 8 months ago

@jzelinskie I think the best course of action here would be to open a PR with the fix, and then gather the list that breaks our internal usages, and fix the PR.

I also noticed the linter identifies code that is only used on tests as dead code

josephschorr commented 2 months ago

We should likely mark anything in pkg as being ignored, since any removal will require a proper deprecation process