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

feat(Optimize Go imports): run goimports on Go target code #4777

Merged
merged 35 commits into from
Jan 24, 2024

Conversation

ShubhamChaturvedi7
Copy link
Collaborator

Description

This PR adds support to optimize imports in the generated Go target code. It runs the goimports tool to do the optimization.

How has this been tested?

  • Manual Testing and the existing Integrating Tests

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Love how simple this solution is. :)

@@ -87,6 +87,22 @@ jobs:
with:
java-version: 18
distribution: corretto
- name: Set up newest supported Go
if: matrix.target-language-version == 'newest'
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, we aren't currently ever populating matrix.target-language-version, because running the entire suite twice for the sake of a small percentage of tests wasn't frugal. See #1983 for more background, especially my latest comment on how I think we should solve this problem.

Copy link
Member

Choose a reason for hiding this comment

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

This might be the reason the CI is still failing for you in fact.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's why I wasn't seeing the Go 1.20 execution, I thought it was skipped due to Go 1.11 failures! I have removed the check for newest and Go 1.20. Added Go 1.15 (min Go version supported by Aws Sdk) as the version to test against instead of older 1.11.

/// </summary>
public virtual void OnPostCompile() { }
public abstract bool OnPostCompile(string dafnyProgramName, string targetFilename, TextWriter outputWriter);
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes more sense to keep this as an empty virtual method, so implementing classes don't have to do anything if they don't need this hook.

Copy link
Member

Choose a reason for hiding this comment

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

Also targetFilename should probably be targetDirectory, since you're passing targetPaths.SourceDirectory for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed a return type to convey if the method OnPostCompile has succeeded or not. But with a return type on a virtual method, I’m forced to return true on the base virtual method. It might be a bit better to have the person implementing OnPostCompile reason about what to do OnPostCompile than we biasing them towards doing nothing.

Yup, I prototyped with a file first and hence the name. Fixed.

@@ -205,7 +205,8 @@ To set up Dafny to compile to Go:
* Install Go from [https://golang.org/dl](https://golang.org/dl) or
* Linux: `sudo apt install golang`
* Mac: `brew install golang`
* Make sure `go` is on your path
* Install `goimports` from [https://pkg.go.dev/golang.org/x/tools/cmd/goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports)
Copy link
Member

Choose a reason for hiding this comment

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

An explicit command to execute as well would be slightly friendlier

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added go install golang.org/x/tools/cmd/goimports@latest . This installs the latest goimports based on the latest go installation from previous command.

@ShubhamChaturvedi7 ShubhamChaturvedi7 marked this pull request as ready for review December 1, 2023 00:07
@@ -4,47 +4,47 @@
package _System

import (
_dafny "dafny"
os "os"
_dafny "dafny"
Copy link
Member

Choose a reason for hiding this comment

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

I take it these changes are because goimports applies auto-formatting as well?

No issues with that and in fact that's kind of a nice side-effect of this change!

robin-aws
robin-aws previously approved these changes Dec 1, 2023
Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

🚀

robin-aws
robin-aws previously approved these changes Dec 1, 2023
@robin-aws robin-aws enabled auto-merge (squash) January 24, 2024 17:57
@robin-aws robin-aws merged commit cbd1812 into dafny-lang:master Jan 24, 2024
20 checks passed
robin-aws added a commit that referenced this pull request Jan 25, 2024
### Description
Should fix nightly build break caused by
#4777

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
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.

2 participants