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

unconvert: use x/tools/go/packages #32

Merged
merged 3 commits into from
Jan 10, 2019
Merged

unconvert: use x/tools/go/packages #32

merged 3 commits into from
Jan 10, 2019

Conversation

egonelbre
Copy link
Contributor

@egonelbre egonelbre commented Sep 11, 2018

About 2x faster and handles go modules better.

However there are still some upstream problems with x/tools/go/packages. So still need to wait for those fixes. Example issue caused by upstream kisielk/errcheck#150

@nmiyake nmiyake mentioned this pull request Jan 9, 2019
unconvert.go Outdated
fmt.Println("Missing type for function")
return
}
if !ft.IsType() {
// Function call; not a conversion.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you get rid of this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To elaborate, I think this is necessary to prevent unconvert from mishandling edge cases like:

type T func(T)
var f T
_ = f(f)

Without checking that call.Fun is a type expression, I expect unconvert would rewrite the last line into just _ = f.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I honestly cannot exactly remember at this point anymore. But what I can gather from context is that, TypesInfo.TypeOf should always return a type. But I'll verify tomorrow.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeOf will always return a type, yes. But this check was distinguishing whether an expression was a value or a type. This is important for distinguishing functionName(x) (function call) from typeName(x) (conversion).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

unconvert.go Outdated
pkg *loader.PackageInfo
file *token.File
pkg *packages.Package
file *ast.File
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR can be a lot less invasive if you change pkg's type to *types.Info (and then a subsequent PR to rename pkg to info), and leave file as *token.File.

Copy link
Owner

@mdempsky mdempsky Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a side benefit: if we stick to just *types.Info, then we can potentially make computeEdits conditionally use go/loader or go/packages based on a compile-time or run-time flag in case users have problems with go/packages. (No need to proactively implement this though. We can implement that if users report issues.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look tomorrow to that approach.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed pkg *loader.PackageInfo to info *types.Info at master, so you should be able to get rid of these changes now and focus just on the go/loader to go/packages change in computeEdits. Cheers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was much nicer thanks.

@mdempsky mdempsky merged commit b40e604 into mdempsky:master Jan 10, 2019
@mdempsky
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants