Skip to content

cmd/go: module graph pruning and lazy module loading #36460

@bcmills

Description

@bcmills
Contributor

I propose to change cmd/go to avoid loading transitive module dependencies
that have no observable effect on the packages to be built.

The key insights that lead to this approach are:

  1. If no package in a given dependency module is ever (even transitively)
    imported by any package loaded by an invocation of the go command, then an
    incompatibility between any package in that dependency and any other package
    has no observable effect in the resulting program(s). Therefore, we can
    safely ignore the (transitive) requirements of any module that does not
    contribute any package to the build.

  2. We can use the explicit requirements of the main module as a coarse filter
    on the set of modules relevant to the main module and to previous
    invocations of the go command.

Based on those insights, I propose to change the go command to retain more
transitive dependencies in go.mod files and to avoid loading go.mod files
for “irrelevant” modules, while still maintaining high reproducibility for build
and test operations.

Design doc: http://golang.org/design/36460-lazy-module-loading.

Activity

added
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on Jan 8, 2020
added this to the Go1.15 milestone on Jan 8, 2020
gopherbot

gopherbot commented on Feb 3, 2020

@gopherbot
Contributor

Change https://golang.org/cl/217557 mentions this issue: cmd/go: add a regression test for package import cycles guarded by build tags

gopherbot

gopherbot commented on Feb 19, 2020

@gopherbot
Contributor

Change https://golang.org/cl/220080 mentions this issue: design/36460: add design for lazy module loading

removed
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on Feb 19, 2020
bcmills

bcmills commented on Feb 19, 2020

@bcmills
ContributorAuthor

A detailed design is in CL 220080.

(You can view the rendered Markdown by opening the .md file at the latest patch set and clicking the gitiles link.)

added
early-in-cycleA change that should be done early in the 3 month dev cycle.
on Feb 19, 2020
ChrisHines

ChrisHines commented on Feb 20, 2020

@ChrisHines
Contributor

For modules that are tidy:

The module versions recorded in the go.mod file would be exactly those listed in vendor/modules.txt, if present.

👍 I think that is a nice property to have. I have some projects for which go mod vendor is sane, but go mod tidy updates the go.mod file in undesirable ways due to test-of-test dependencies. If I understand this proposal correctly that problem would go away.

bcmills

bcmills commented on Feb 20, 2020

@bcmills
ContributorAuthor

I added a few examples (in our usual cmd/go script test format) to the design doc.

@ChrisHines, the third example explicitly covers the behavior for test-of-test dependencies.

bcmills

bcmills commented on Feb 21, 2020

@bcmills
ContributorAuthor

CC @julieqiu since this may affect how we display dependencies on pkg.go.dev.

CC @heschik, @dmitshur because this may affect the package search algorithms used by goimports and godoc.

CC @bep because I seem to recall that Hugo is doing something unusual with module dependencies independent of Go package imports. (But note that we are unlikely to actively support the use of Go modules for purposes other than compiling Go source code.)

383 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Proposal-Acceptedearly-in-cycleA change that should be done early in the 3 month dev cycle.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @frioux@rsc@dolmen@andybons@bep

        Issue actions

          cmd/go: module graph pruning and lazy module loading · Issue #36460 · golang/go