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

proposal: cmd/fix: allow third party packages to migrate using go fix #40162

Open
lu4p opened this issue Jul 10, 2020 · 6 comments
Open

proposal: cmd/fix: allow third party packages to migrate using go fix #40162

lu4p opened this issue Jul 10, 2020 · 6 comments
Labels
Projects
Milestone

Comments

@lu4p
Copy link

@lu4p lu4p commented Jul 10, 2020

After I read most recent blog post https://blog.golang.org/module-compatibility.
I wondered if many of the issues couldn't be avoided by allowing modules to provide fixes to automatically upgrade between major versions using go fix.

I'm currently not sure how this can be achieved exactly.

@gopherbot gopherbot added this to the Proposal milestone Jul 10, 2020
@gopherbot gopherbot added the Proposal label Jul 10, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 10, 2020

It seems fairly difficult to make that work with third party modules that you didn't write. The go fix would have to be perfect, which is quite difficult except in the very simplest of cases.

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Jul 10, 2020
@thepudds
Copy link

@thepudds thepudds commented Jul 11, 2020

See also the "Automatic API Updates" section of the initial vgo blog series, as well as #32816.

@lu4p
Copy link
Author

@lu4p lu4p commented Jul 11, 2020

@ianlancetaylor The fix doesn't have to be perfect.

In the case of a changed function signature:

Find all affected references to that function.

The maintainer provides fixes for specific usages of this function e.g. in a ast.CallExpr.

Warn about all other uses which couldn't be fixed automatically, and describe what exactly needs to be changed.

Edit: Also module/v1 and module/v2 can coexist in the same package so maybe go/fix can convert all uses which still need the old API to oldmodule.Func then import the different versions like this:

import (
     oldmodule "module/v1"
     "module/v2"
)

(I don't propose prefixing the old version with "old", just for illustration.)

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 11, 2020

@lu4p I understand that the maintainer provides the fix. If it doesn't have to be perfect, then I'm not sure why it needs any particular support from the Go toolchain. The maintainer can just say: this is what you have to change, and here is a program that can do most of the changes for you. That program can be a go fix module.

What do you think should change in the Go toolchain?

@ianlancetaylor ianlancetaylor changed the title proposal: cmd/fix/ Allow third party packages to migrate using go fix proposal: cmd/fix: allow third party packages to migrate using go fix Jul 11, 2020
@lu4p
Copy link
Author

@lu4p lu4p commented Jul 11, 2020

@ianlancetaylor You are right it would probably only make sense to provide "perfect" fixes.

Maybe we can have some code generation tool which can outline all the possible cases so no case is missed. Another approach would be to force the implementation of a FuncFixer interface.

Something like go fix new func

Which would generate a file like %time_func.fix.go

There probably needs to be a seperate directory where all fixfiles are stored, because reserving a directory name like fixes is not hard make this configurable in the modfile with a new directive like fixdir.

The fixfiles should be normal go files, but they probably need a standard layout (version, affected subpackage, description), therfore a go fix new command.

@dgryski
Copy link
Contributor

@dgryski dgryski commented Jul 15, 2020

Go-ruleguard provides some capabilities for detecting and rewriting deprecated APIs. A more powerful language (starlark?) might make more complex rewrites possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.