dslice

command module
v0.0.0-...-a61a0ae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 6 Imported by: 0

README

dslice

dslice computes a static program slice of Go source code. Given a set of root symbols (functions, types, methods, constants, or variables), it extracts the minimal syntactic subset of the program required to compile those roots.

Dependencies on internal packages are resolved recursively and inlined into the output.

Example

$ dslice bytes.Equal
package bytes

// Equal reports whether a and b
// are the same length and contain the same bytes.
// A nil argument is equivalent to an empty slice.
func Equal(a, b []byte) bool {
	return string(a) == string(b)
}

Install

go install git.sr.ht/~bwsd0/dslice@latest

Usage

dslice [flags] <symbol>

Flags:
  -o string      output file (default: stdout)
  -name string   output package name (default: inferred)
  -private string comma-separated glob patterns of private module paths (sets GOPRIVATE)

Symbols are fully qualified: package/path.Symbol or package/path.Type.Method.

$ dslice fmt.Println
$ dslice strings.Builder.Cap
$ dslice golang.org/x/tools/go/packages.Load
$ dslice -o slice.go encoding/json.Marshal
External and private modules

When the target symbol belongs to a module that is not a dependency of the current working directory's go.mod, dslice automatically fetches it into a temporary module workspace:

$ dslice github.com/pkg/errors.New

For private modules that are not available on the public module proxy, use the -private flag to bypass the proxy and checksum database:

$ dslice -private 'github.com/corp/*' github.com/corp/lib.Func

This sets GOPRIVATE, GONOPROXY, and GONOSUMDB for all Go toolchain invocations, including the automatic module fetch.

Multiple patterns are comma-separated, using the same syntax as GOPRIVATE:

$ dslice -private 'github.com/corp/*,github.com/internal/*' github.com/corp/auth.Verify

Limitations

Static analysis only. No guarantees for reflection, interface dispatch, or plugins.

References

M. Weiser, "Program Slicing," Proceedings of the 5th International Conference on Software Engineering, pp. 439-449, IEEE Press, 1981. https://dl.acm.org/doi/10.5555/800078.802557

Documentation

Overview

dslice extracts minimal dependency slices from Go packages.

Usage:

dslice [flags] <symbol>

The symbol is a fully qualified Go symbol in the form:

package/path.Name
package/path.Type.Method

For private modules that are not available on the public module proxy, use the -private flag with comma-separated glob patterns:

dslice -private 'github.com/corp/*' github.com/corp/lib.Func

This sets GOPRIVATE, GONOPROXY, and GONOSUMDB so the Go toolchain fetches modules directly from their origin.

Examples:

dslice golang.org/x/tools/go/packages.Package
dslice golang.org/x/tools/go/packages.Load
dslice net/http.Client.Do

Directories

Path Synopsis
Package slice computes minimal dependency slices for Go declarations.
Package slice computes minimal dependency slices for Go declarations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL