Skip to content

compiler: break functions related to Decls out of Compile(). #1311

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 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions compiler/analysis/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,26 @@ func (info *Info) newFuncInfo(n ast.Node) *FuncInfo {
return funcInfo
}

// IsBlocking returns true if the function may contain blocking calls or operations.
func (info *Info) IsBlocking(fun *types.Func) bool {
if funInfo := info.FuncDeclInfos[fun]; funInfo != nil {
return len(funInfo.Blocking) > 0
}
panic(fmt.Errorf(`info did not have function declaration for %s`, fun.FullName()))
}

// VarsWithInitializers returns a set of package-level variables that have
// explicit initializers.
func (info *Info) VarsWithInitializers() map[*types.Var]bool {
result := map[*types.Var]bool{}
for _, init := range info.InitOrder {
for _, o := range init.Lhs {
result[o] = true
}
}
return result
}

func AnalyzePkg(files []*ast.File, fileSet *token.FileSet, typesInfo *types.Info, typesPkg *types.Package, isBlocking func(*types.Func) bool) *Info {
info := &Info{
Info: typesInfo,
Expand Down
51 changes: 0 additions & 51 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"strings"
"time"

"github.com/gopherjs/gopherjs/compiler/internal/symbol"
"github.com/gopherjs/gopherjs/compiler/prelude"
"golang.org/x/tools/go/gcexportdata"
)
Expand Down Expand Up @@ -85,56 +84,6 @@ func (a *Archive) RegisterTypes(packages map[string]*types.Package) error {
return err
}

// Decl represents a package-level symbol (e.g. a function, variable or type).
//
// It contains code generated by the compiler for this specific symbol, which is
// grouped by the execution stage it belongs to in the JavaScript runtime.
type Decl struct {
// The package- or receiver-type-qualified name of function or method obj.
// See go/types.Func.FullName().
FullName string
// A logical equivalent of a symbol name in an object file in the traditional
// Go compiler/linker toolchain. Used by GopherJS to support go:linkname
// directives. Must be set for decls that are supported by go:linkname
// implementation.
LinkingName symbol.Name
// A list of package-level JavaScript variable names this symbol needs to declare.
Vars []string
// A JS expression by which the object represented by this decl may be
// referenced within the package context. Empty if the decl represents no such
// object.
RefExpr string
// NamedRecvType is method named recv declare.
NamedRecvType string
// JavaScript code that declares basic information about a symbol. For a type
// it configures basic information about the type and its identity. For a function
// or method it contains its compiled body.
DeclCode []byte
// JavaScript code that initializes reflection metadata about type's method list.
MethodListCode []byte
// JavaScript code that initializes the rest of reflection metadata about a type
// (e.g. struct fields, array type sizes, element types, etc.).
TypeInitCode []byte
// JavaScript code that needs to be executed during the package init phase to
// set the symbol up (e.g. initialize package-level variable value).
InitCode []byte
// Symbol's identifier used by the dead-code elimination logic, not including
// package path. If empty, the symbol is assumed to be alive and will not be
// eliminated. For methods it is the same as its receiver type identifier.
DceObjectFilter string
// The second part of the identified used by dead-code elimination for methods.
// Empty for other types of symbols.
DceMethodFilter string
// List of fully qualified (including package path) DCE symbol identifiers the
// symbol depends on for dead code elimination purposes.
DceDeps []string
// Set to true if a function performs a blocking operation (I/O or
// synchronization). The compiler will have to generate function code such
// that it can be resumed after a blocking operation completes without
// blocking the main thread in the meantime.
Blocking bool
}

type Dependency struct {
Pkg string
Type string
Expand Down
Loading
Loading