Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Merge go1.19 branch to master #1269

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

Merged
merged 50 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a0b7135
Update Go version to 1.19.13 to begin work on Go 1.19 support.
nevkontakte Nov 12, 2023
c146af0
updated reflect and reflectlite
grantnelson-wf Nov 14, 2023
5090ba1
Merge pull request #1250 from Workiva/reflectUpdate
nevkontakte Nov 14, 2023
a76a603
Fixing a mistake found in reflect
grantnelson-wf Dec 4, 2023
528f1c8
Merge branch 'master' of github.com:gopherjs/gopherjs into reflectFix
grantnelson-wf Dec 4, 2023
0eb9c04
Merge pull request #1253 from Workiva/reflectFix
nevkontakte Dec 6, 2023
5edefc6
Update FuncKey and fix Http native
grantnelson-wf Dec 18, 2023
17263fa
Broke up parseAndAugment
grantnelson-wf Dec 18, 2023
6e1ec66
Extending Directives
grantnelson-wf Dec 18, 2023
9bcf242
Merge branch 'breakupAugment' of github.com:Workiva/gopherjs into add…
grantnelson-wf Dec 18, 2023
295da69
Merge branch 'extendDirectives' of github.com:Workiva/gopherjs into a…
grantnelson-wf Dec 18, 2023
27e1297
Adding purge directive
grantnelson-wf Dec 18, 2023
022eb64
Merge pull request #1255 from Workiva/updateFuncKey
nevkontakte Dec 19, 2023
f34e28b
Merge pull request #1256 from Workiva/breakupAugment
nevkontakte Dec 19, 2023
84774ae
Changed to use Inspect
grantnelson-wf Dec 19, 2023
b13f4d5
Merge branch 'go1.19' of github.com:gopherjs/gopherjs into addPurgeDi…
grantnelson-wf Dec 19, 2023
40bddb9
Merge branch 'extendDirectives' of github.com:Workiva/gopherjs into a…
grantnelson-wf Dec 19, 2023
7758c0d
Updated to use Inspect and srctesting
grantnelson-wf Dec 19, 2023
8ea6531
Merge pull request #1257 from Workiva/extendDirectives
nevkontakte Dec 21, 2023
bf0e797
Merge branch 'go1.19' of github.com:gopherjs/gopherjs into addPurgeDi…
grantnelson-wf Dec 29, 2023
38b4d3b
Merge pull request #1258 from Workiva/addPurgeDirective
nevkontakte Dec 29, 2023
e03bfea
Update compiler for go1.19
grantnelson-wf Jan 16, 2024
5f9eeb8
Fix Build Issue
grantnelson-wf Jan 16, 2024
a83c5fa
Updating natives for go1.19
grantnelson-wf Jan 16, 2024
cd17b90
Merge pull request #1261 from Workiva/updateCompiler19
nevkontakte Jan 19, 2024
5a98043
Updating documentation for build directives
grantnelson-wf Jan 19, 2024
1faba3b
Merge pull request #1260 from Workiva/fixBuildIssue
nevkontakte Jan 19, 2024
dea4768
Merge pull request #1262 from Workiva/updateNatives19
nevkontakte Jan 19, 2024
12a247d
Fix problem where import is named but source is augmented to only nee…
grantnelson-wf Jan 30, 2024
4b5b077
Fix chocolatey go version
grantnelson-wf Jan 30, 2024
d7abc77
Update known fails list of fixed bugs
grantnelson-wf Jan 30, 2024
95c01fa
Merge pull request #1263 from Workiva/go1.19BuildFix
nevkontakte Jan 30, 2024
91f1d44
Updated crypto natives
grantnelson-wf Jan 31, 2024
f5c911a
Fix natives for debug/pe
grantnelson-wf Jan 31, 2024
ff493e4
Update to go/token/position
grantnelson-wf Jan 31, 2024
cd055c9
Update hash/maphash
grantnelson-wf Jan 31, 2024
5437642
Update to reflect and reflectlite
grantnelson-wf Jan 31, 2024
8151b28
Update for fastrand
grantnelson-wf Jan 31, 2024
014360b
Updated net/netip
grantnelson-wf Jan 31, 2024
db5d7b3
Updating sync/atomic
grantnelson-wf Jan 31, 2024
710fdb7
Merge branch 'go1.19' of github.com:gopherjs/gopherjs into go1.19Nati…
grantnelson-wf Jan 31, 2024
a6b98dd
Update syscall/js
grantnelson-wf Jan 31, 2024
967ffcc
Fixed a copy/paste mistake
grantnelson-wf Jan 31, 2024
9e28c32
Merge pull request #1264 from Workiva/go1.19NativesUpdate
nevkontakte Jan 31, 2024
c08b7bf
Fixed chocolatey go version
grantnelson-wf Feb 13, 2024
02aea33
Limit augmentation and prune imports to natives that need it
grantnelson-wf Feb 13, 2024
c852920
Merge pull request #1266 from Workiva/forceChocolateyGoVersion
nevkontakte Feb 13, 2024
5d25518
Merge branch 'go1.19' of github.com:gopherjs/gopherjs into limitAugme…
grantnelson-wf Feb 13, 2024
a533e78
Merge pull request #1267 from Workiva/limitAugmentation
nevkontakte Feb 13, 2024
1011858
Update GopherJS version to 1.19.0-beta1 in perparation for release.
nevkontakte Feb 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Limit augmentation and prune imports to natives that need it
  • Loading branch information
grantnelson-wf committed Feb 13, 2024
commit 02aea33b76248f0a35eb7c7044c880fdadf8ee6c
42 changes: 34 additions & 8 deletions 42 build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke

for _, file := range originalFiles {
augmentOriginalImports(pkg.ImportPath, file)
augmentOriginalFile(file, overrides)
pruneImports(file)
}

if len(overrides) > 0 {
for _, file := range originalFiles {
augmentOriginalFile(file, overrides)
}
}

return append(overlayFiles, originalFiles...), jsFiles, nil
Expand Down Expand Up @@ -275,6 +279,7 @@ func parserOriginalFiles(pkg *PackageData, fileSet *token.FileSet) ([]*ast.File,
// an overlay file AST to collect information such as compiler directives
// and perform any initial augmentation needed to the overlay.
func augmentOverlayFile(file *ast.File, overrides map[string]overrideInfo) {
anyChange := false
for i, decl := range file.Decls {
purgeDecl := astutil.Purge(decl)
switch d := decl.(type) {
Expand Down Expand Up @@ -302,15 +307,20 @@ func augmentOverlayFile(file *ast.File, overrides map[string]overrideInfo) {
}
}
if purgeSpec {
anyChange = true
d.Specs[j] = nil
}
}
}
if purgeDecl {
anyChange = true
file.Decls[i] = nil
}
}
finalizeRemovals(file)
if anyChange {
finalizeRemovals(file)
pruneImports(file)
}
}

// augmentOriginalImports is the part of parseAndAugment that processes
Expand All @@ -334,10 +344,12 @@ func augmentOriginalImports(importPath string, file *ast.File) {
// original file AST to augment the source code using the overrides from
// the overlay files.
func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
anyChange := false
for i, decl := range file.Decls {
switch d := decl.(type) {
case *ast.FuncDecl:
if info, ok := overrides[astutil.FuncKey(d)]; ok {
anyChange = true
removeFunc := true
if info.keepOriginal {
// Allow overridden function calls
Expand All @@ -358,6 +370,7 @@ func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
} else if recvKey := astutil.FuncReceiverKey(d); len(recvKey) > 0 {
// check if the receiver has been purged, if so, remove the method too.
if info, ok := overrides[recvKey]; ok && info.purgeMethods {
anyChange = true
file.Decls[i] = nil
}
}
Expand All @@ -366,6 +379,7 @@ func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
switch s := spec.(type) {
case *ast.TypeSpec:
if _, ok := overrides[s.Name.Name]; ok {
anyChange = true
d.Specs[j] = nil
}
case *ast.ValueSpec:
Expand All @@ -378,6 +392,7 @@ func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
// to be run, add the call into the overlay.
for k, name := range s.Names {
if _, ok := overrides[name.Name]; ok {
anyChange = true
s.Names[k] = nil
s.Values[k] = nil
}
Expand Down Expand Up @@ -405,6 +420,7 @@ func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
}
}
if removeSpec {
anyChange = true
d.Specs[j] = nil
}
}
Expand All @@ -413,7 +429,10 @@ func augmentOriginalFile(file *ast.File, overrides map[string]overrideInfo) {
}
}
}
finalizeRemovals(file)
if anyChange {
finalizeRemovals(file)
pruneImports(file)
}
}

// isOnlyImports determines if this file is empty except for imports.
Expand All @@ -437,6 +456,14 @@ func isOnlyImports(file *ast.File) bool {
// If the removal of code causes an import to be removed, the init's from that
// import may not be run anymore. If we still need to run an init for an import
// which is no longer used, add it to the overlay as a blank (`_`) import.
//
// This uses the given name or guesses at the name using the import path,
// meaning this doesn't work for packages which have a different package name
// from the path, including those paths which are versioned
// (e.g. `github.com/foo/bar/v2` where the package name is `bar`)
// or if the import is defined using a relative path (e.g. `./..`).
// Those cases don't exist in the native for Go, so we should only run
// this pruning when we have native overlays, but not for unknown packages.
func pruneImports(file *ast.File) {
if isOnlyImports(file) && !astutil.HasDirectivePrefix(file, `//go:linkname `) {
// The file is empty, remove all imports including any `.` or `_` imports.
Expand Down Expand Up @@ -478,12 +505,11 @@ func pruneImports(file *ast.File) {
// since the import is otherwise unused set the name to blank.
in.Name = ast.NewIdent(`_`)
delete(unused, name)
if len(unused) == 0 {
return
}
break
}
}
if len(unused) == 0 {
return
}

// Remove all unused import specifications
isUnusedSpec := map[*ast.ImportSpec]bool{}
Expand Down
33 changes: 33 additions & 0 deletions 33 build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,39 @@ func TestOriginalAugmentation(t *testing.T) {
import _ "unsafe"`,
want: `//go:linkname foo bar
import _ "unsafe"`,
}, {
desc: `multiple imports for directives`,
info: map[string]overrideInfo{
`A`: {},
`C`: {},
},
src: `import "unsafe"
import "embed"

//go:embed hello.txt
var A embed.FS

//go:embed goodbye.txt
var B string

var C unsafe.Pointer

// override Now with hardcoded time for testing
//go:linkname timeNow time.Now
func timeNow() time.Time {
return time.Date(2012, 8, 6, 0, 0, 0, 0, time.UTC)
}`,
want: `import _ "unsafe"
import _ "embed"

//go:embed goodbye.txt
var B string

// override Now with hardcoded time for testing
//go:linkname timeNow time.Now
func timeNow() time.Time {
return time.Date(2012, 8, 6, 0, 0, 0, 0, time.UTC)
}`,
},
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.