Skip to content

[WIP] Extract type checking and analysis from compiler #1363

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0c6d66d
starting migration
grantnelson-wf Feb 27, 2025
4c537e7
starting migration
grantnelson-wf Feb 27, 2025
6c48e04
moved linkname to its own package
grantnelson-wf Feb 27, 2025
f97e44c
Merge branch 'sourceInsteadOfParsedPackage' of github.com:Workiva/gop…
grantnelson-wf Feb 27, 2025
fb52990
Working on import context
grantnelson-wf Feb 27, 2025
cbf9b58
Working on import context
grantnelson-wf Feb 28, 2025
36c8c11
Working on package analysis
grantnelson-wf Feb 28, 2025
cd071c1
Moving propagate
grantnelson-wf Feb 28, 2025
f5f1968
Merge branch 'sourceInsteadOfParsedPackage' of github.com:Workiva/gop…
grantnelson-wf Feb 28, 2025
3def5f3
Reworking preparing and analyzing sources
grantnelson-wf Feb 28, 2025
731f220
Trying to debug the funcLit pointer issue
grantnelson-wf Mar 3, 2025
ae7afcd
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
ccb500b
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
a79a574
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
471fbf5
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
b5ab57e
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
04ab0c0
Fixing the funclit pointer problem
grantnelson-wf Mar 4, 2025
54e2572
Merge branch 'master' of github.com:gopherjs/gopherjs into breakupCom…
grantnelson-wf Mar 4, 2025
35e4013
Fixing remaining bugs
grantnelson-wf Mar 4, 2025
a1122c5
Fixing remaining bugs
grantnelson-wf Mar 4, 2025
e57c7aa
Some cleanup
grantnelson-wf Mar 4, 2025
c3f2ffe
Some cleanup
grantnelson-wf Mar 5, 2025
aae9e0a
Some cleanup
grantnelson-wf Mar 5, 2025
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
Fixing the funclit pointer problem
  • Loading branch information
grantnelson-wf committed Mar 4, 2025
commit ae7afcd044690aab24f93ef233d30fee6334c77a
24 changes: 1 addition & 23 deletions compiler/internal/analysis/info.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package analysis

import (
"bytes"
"fmt"
"go/ast"
"go/printer"
"go/token"
"go/types"
"strings"
Expand Down Expand Up @@ -100,13 +98,6 @@ func (info *Info) newFuncInfo(n ast.Node, obj types.Object, typeArgs typesutil.T

case *ast.FuncLit:
info.funcLitInfos[n] = append(info.funcLitInfos[n], funcInfo)

// TODO(grantnelson-wf): Remove below
buf := &bytes.Buffer{}
fSet := token.NewFileSet()
printer.Fprint(buf, fSet, n)
fmt.Printf(">>|<< Adding %q with [%v] in package %s\n", buf.String(), typeArgs, info.Pkg.Path())
fmt.Printf(">>|<< \tHad: %v\n", info.funcLitInfos[n])
}

// And add it to the list of all functions.
Expand Down Expand Up @@ -175,15 +166,7 @@ func (info *Info) FuncLitInfo(fun *ast.FuncLit, typeArgs typesutil.TypeList) *Fu
return fi
}
}

// TODO(grantnelson-wf): Remove below
buf := &bytes.Buffer{}
fSet := token.NewFileSet()
printer.Fprint(buf, fSet, fun)
fmt.Printf(">>|<< Failed to find %q (%p) with [%v] in package %s\n", buf.String(), fun, typeArgs, info.Pkg.Path())
fmt.Printf(">>|<< \tHad: %v\n\n", lits)
panic("BOOM!")
//return nil
return nil
}

// VarsWithInitializers returns a set of package-level variables that have
Expand Down Expand Up @@ -273,11 +256,6 @@ func (info *Info) propagateFunctionBlocking() bool {
}
}
}

// TODO(grantnelson-wf): Remove below
fmt.Printf(">>|<< propagateFunctionBlocking package %s\n", info.Pkg.Path())
fmt.Printf(">>|<< \tHad: %v\n", info.funcLitInfos)

return done
}

Expand Down
5 changes: 0 additions & 5 deletions compiler/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ func PrepareAllSources(root *sources.Sources, allSources map[string]*sources.Sou
allInfo = append(allInfo, src.TypeInfo)
}
analysis.PropagateAnalysis(allInfo)

// Simplify the source files.
for _, srcs := range allSources {
srcs.Simplify()
}
return nil
}

Expand Down
27 changes: 19 additions & 8 deletions compiler/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,20 @@ func (s *Sources) Prepare(importer Importer, sizes types.Sizes, tContext *types.
}
}

// Extract all go:linkname compiler directives from the package source.
err = s.parseGoLinknames()
if err != nil {
return err
}

// Simply the source files.
s.simplify(typesInfo)

// Analyze the package to determine type parameters instances, blocking,
// and other type information. This will not populate the information.
s.analyze(typesInfo, importer, tContext)

// Extract all go:linkname compiler directives from the package source.
return s.parseGoLinknames()
return nil
}

// sort the Go files slice by the original source name to ensure consistent order
Expand All @@ -112,17 +120,20 @@ func (s *Sources) sort() {
// simplify processed each Files entry with astrewrite.Simplify.
//
// Note this function mutates the original Files slice.
// This must be called after TypeCheck.
func (s *Sources) Simplify() {
// This must be called after TypeCheck and before analyze since
// this will change the pointers in the AST, for example the pointers
// to function literals will change making it impossible to find them
// in the type information if analyze is called first.
func (s *Sources) simplify(typesInfo *types.Info) {
for i, file := range s.Files {
s.Files[i] = astrewrite.Simplify(file, s.TypeInfo.Info, false)
s.Files[i] = astrewrite.Simplify(file, typesInfo, false)
}
}

// typeCheck the sources. Returns information about declared package types and
// type information for the supplied AST.
//
// This must be called prior to Simplify.
// This must be called prior to simplify.
func (s *Sources) typeCheck(importer Importer, sizes types.Sizes, tContext *types.Context) (*types.Info, error) {
const errLimit = 10 // Max number of type checking errors to return.

Expand Down Expand Up @@ -174,7 +185,7 @@ func (s *Sources) typeCheck(importer Importer, sizes types.Sizes, tContext *type
// analyze will determine the type parameters instances, blocking,
// and other type information for the package.
//
// This must be called prior to Simplify.
// This must be called after to simplify.
// Note that at the end of this call the analysis information
// has NOT been propagated across packages yet.
func (s *Sources) analyze(typesInfo *types.Info, importer Importer, tContext *types.Context) {
Expand All @@ -201,7 +212,7 @@ func (s *Sources) analyze(typesInfo *types.Info, importer Importer, tContext *ty
// parseGoLinknames extracts all //go:linkname compiler directive from the sources.
//
// This will set the GoLinknames field on the Sources struct.
// This must be called prior to Simplify.
// This must be called prior to simplify.
func (s *Sources) parseGoLinknames() error {
goLinknames := []linkname.GoLinkname{}
var errs errorList.ErrorList
Expand Down
Loading