Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: consistently defer module path checks (including major-version matching) until import or build-list resolution #31662

Open
bcmills opened this issue Apr 24, 2019 · 2 comments
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Apr 24, 2019

At the moment, we validate that the major version through which a module was resolved matches the major-version suffix of the path declared in its go.mod file.

However, we perform that validation only sporadically (#31428), the resulting failure message (if any) can be difficult to understand in context (#30499, #30636), and a mismatch — even one involving mismatched major-version components — isn't even obviously correct if the module is involved in a replace directive (#26904, #27171 (comment)).

I suspect that we should simply not validate module paths at all when fetching a module, and instead do the validation consistently only at loading time (when we resolve explicit package imports).

At that point:

  • If a module is used to replace the source code of another module, we should ensure that its path — including the major-version component — matches the module whose code it replaces.
    • Due to existing replace usage, we might need to relax this to allow the module path to also match the path and version from which the source code was fetched, but ideally only if the go.mod file specifies go 1.12 or earlier.
  • If a module is used as an alias from another module path and version (cmd/go: allow replacement modules to alias other active modules #26904), then we should resolve it at the path to which the alias points during package loading, and thus the module path and major version should match that path (and the major version at which it is required).
  • If a module is downloaded using go mod download, we don't know how it is going to be used, and thus should not validate anything about its path.

CC @rsc @jayconrod @heschik @hyangah @katiehockman @leitzler @tbpg

@tbpg
Copy link
Contributor

tbpg commented Apr 26, 2019

If a module is downloaded using go mod download, we don't know how it is going to be used, and thus should not validate anything about its path.

Can we validate a given module's path and version (with an explicit go.mod) to see if there is a mis-matched major version?

@katiehockman katiehockman added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Apr 30, 2019
@bcmills
Copy link
Contributor Author

bcmills commented Apr 30, 2019

Can we validate a given module's path and version (with an explicit go.mod) to see if there is a mis-matched major version?

I don't think so, no. It seems entirely reasonable to replace, say, github.com/utensil/spoon/v25 with utensil.dev/fork at v1.0.0, since the two modules have otherwise-distinct import paths and the renaming may have the explicit goal of resetting the major-version numbering.

@bcmills bcmills changed the title cmd/go: consistently defer module path checks (including major-version matching) until import resolution cmd/go: consistently defer module path checks (including major-version matching) until import or build-list resolution May 6, 2019
@bcmills bcmills added this to the Go1.13 milestone May 14, 2019
@jayconrod jayconrod modified the milestones: Go1.13, Go1.14 May 28, 2019
@bcmills bcmills added the early-in-cycle A change that should be done early in the 3 month dev cycle. label May 30, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants