-
Notifications
You must be signed in to change notification settings - Fork 570
compiler: remove dependency on legacy gcimporter15 #803
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This is a follow up to #789 that removes the sticking plaster in that PR, and switches the compiler to using golang.org/x/tools/go/gcexportdata as directed here https://github.com/golang/tools/blob/14d5b80f954f510ba9bcd241821b6f4828498e1a/go/gcimporter15/gcimporter.go#L13-L14. This means we can also remove the temporary vendor of gcimporter15.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import ( | |
|
||
"github.com/gopherjs/gopherjs/compiler/analysis" | ||
"github.com/neelance/astrewrite" | ||
"golang.org/x/tools/go/gcimporter15" | ||
"golang.org/x/tools/go/gcexportdata" | ||
"golang.org/x/tools/go/types/typeutil" | ||
) | ||
|
||
|
@@ -164,7 +164,10 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor | |
} | ||
importContext.Packages[importPath] = typesPkg | ||
|
||
exportData := gcimporter.BExportData(nil, typesPkg) | ||
exportData := new(bytes.Buffer) | ||
if err := gcexportdata.Write(exportData, nil, typesPkg); err != nil { | ||
return nil, fmt.Errorf("failed to write export data: %v", err) | ||
} | ||
encodedFileSet := bytes.NewBuffer(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line uses a very outdated style of initializing a new
It's not surprising because this line was written 4 years ago. I know it's not your code, but it's the line directly following your code, and I think it's not nice how just 4 lines above it is a different style is used to do the same thing: exportData := new(bytes.Buffer)
// ... 3 lines
encodedFileSet := bytes.NewBuffer(nil) Let's make this better by updating it so they both use the same style. I would slightly prefer the var exportData bytes.Buffer
if err := gcexportdata.Write(&exportData, nil, typesPkg); err != nil {
return nil, fmt.Errorf("failed to write export data: %v", err)
}
var encodedFileSet bytes.Buffer
if err := fileSet.Write(json.NewEncoder(&encodedFileSet).Encode); err != nil { But if you feel strongly about using Also, I know this file has yet another instance of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if err := fileSet.Write(json.NewEncoder(encodedFileSet).Encode); err != nil { | ||
return nil, err | ||
|
@@ -541,7 +544,7 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor | |
ImportPath: importPath, | ||
Name: typesPkg.Name(), | ||
Imports: importedPaths, | ||
ExportData: exportData, | ||
ExportData: exportData.Bytes(), | ||
Declarations: allDecls, | ||
FileSet: encodedFileSet.Bytes(), | ||
Minified: minify, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b
is not a descriptive variable name. That's often okay in short functions, but it doesn't work well in this context. It's also typically associated with[]byte
type, notio.Reader
. I seer
is already taken and I don't think it's a good idea to reuse it.I think it's better to either use a longer descriptive name here:
Which would mirror the
gcexportdata.Write
code below.But I think this line is not that long, that it's even better to just inline it:
Either of those is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.