Skip to content

Blocking for Function Instances #1347

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 3 commits into from
Oct 23, 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
78 changes: 0 additions & 78 deletions compiler/analysis/info_test.go

This file was deleted.

8 changes: 4 additions & 4 deletions compiler/decls.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sort"
"strings"

"github.com/gopherjs/gopherjs/compiler/analysis"
"github.com/gopherjs/gopherjs/compiler/internal/analysis"
"github.com/gopherjs/gopherjs/compiler/internal/dce"
"github.com/gopherjs/gopherjs/compiler/internal/symbol"
"github.com/gopherjs/gopherjs/compiler/internal/typeparams"
Expand Down Expand Up @@ -317,7 +317,7 @@ func (fc *funcContext) newFuncDecl(fun *ast.FuncDecl, inst typeparams.Instance)
o := fc.pkgCtx.Defs[fun.Name].(*types.Func)
d := &Decl{
FullName: o.FullName(),
Blocking: fc.pkgCtx.IsBlocking(o),
Blocking: fc.pkgCtx.IsBlocking(inst),
LinkingName: symbol.New(o),
}
d.Dce().SetName(o)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (fc *funcContext) newFuncDecl(fun *ast.FuncDecl, inst typeparams.Instance)
func (fc *funcContext) callInitFunc(init *types.Func) ast.Stmt {
id := fc.newIdentFor(init)
call := &ast.CallExpr{Fun: id}
if fc.pkgCtx.IsBlocking(init) {
if fc.pkgCtx.IsBlocking(typeparams.Instance{Object: init}) {
fc.Blocking[call] = true
}
return &ast.ExprStmt{X: call}
Expand All @@ -373,7 +373,7 @@ func (fc *funcContext) callMainFunc(main *types.Func) ast.Stmt {
},
},
}
if fc.pkgCtx.IsBlocking(main) {
if fc.pkgCtx.IsBlocking(typeparams.Instance{Object: main}) {
fc.Blocking[call] = true
fc.Flattened[ifStmt] = true
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strconv"
"strings"

"github.com/gopherjs/gopherjs/compiler/analysis"
"github.com/gopherjs/gopherjs/compiler/astutil"
"github.com/gopherjs/gopherjs/compiler/internal/analysis"
"github.com/gopherjs/gopherjs/compiler/internal/typeparams"
"github.com/gopherjs/gopherjs/compiler/typesutil"
)
Expand Down
16 changes: 8 additions & 8 deletions compiler/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"sort"
"strings"

"github.com/gopherjs/gopherjs/compiler/analysis"
"github.com/gopherjs/gopherjs/compiler/astutil"
"github.com/gopherjs/gopherjs/compiler/internal/analysis"
"github.com/gopherjs/gopherjs/compiler/internal/typeparams"
"github.com/gopherjs/gopherjs/compiler/typesutil"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (fc *funcContext) nestedFunctionContext(info *analysis.FuncInfo, inst typep
// namedFuncContext creates a new funcContext for a named Go function
// (standalone or method).
func (fc *funcContext) namedFuncContext(inst typeparams.Instance) *funcContext {
info := fc.pkgCtx.FuncDeclInfos[inst.Object.(*types.Func)]
info := fc.pkgCtx.FuncInfo(inst)
c := fc.nestedFunctionContext(info, inst)

return c
Expand All @@ -82,7 +82,7 @@ func (fc *funcContext) namedFuncContext(inst typeparams.Instance) *funcContext {
// go/types doesn't generate *types.Func objects for function literals, we
// generate a synthetic one for it.
func (fc *funcContext) literalFuncContext(fun *ast.FuncLit) *funcContext {
info := fc.pkgCtx.FuncLitInfos[fun]
info := fc.pkgCtx.FuncLitInfo(fun)
sig := fc.pkgCtx.TypeOf(fun).(*types.Signature)
o := types.NewFunc(fun.Pos(), fc.pkgCtx.Pkg, fc.newLitFuncName(), sig)
inst := typeparams.Instance{Object: o}
Expand Down Expand Up @@ -237,7 +237,7 @@ func (fc *funcContext) translateFunctionBody(typ *ast.FuncType, recv *ast.Ident,
}

bodyOutput := string(fc.CatchOutput(1, func() {
if len(fc.Blocking) != 0 {
if fc.IsBlocking() {
fc.pkgCtx.Scopes[body] = fc.pkgCtx.Scopes[typ]
fc.handleEscapingVars(body)
}
Expand Down Expand Up @@ -283,14 +283,14 @@ func (fc *funcContext) translateFunctionBody(typ *ast.FuncType, recv *ast.Ident,
if fc.HasDefer {
fc.localVars = append(fc.localVars, "$deferred")
suffix = " }" + suffix
if len(fc.Blocking) != 0 {
if fc.IsBlocking() {
suffix = " }" + suffix
}
}

localVarDefs := "" // Function-local var declaration at the top.

if len(fc.Blocking) != 0 {
if fc.IsBlocking() {
localVars := append([]string{}, fc.localVars...)
// There are several special variables involved in handling blocking functions:
// $r is sometimes used as a temporary variable to store blocking call result.
Expand All @@ -314,7 +314,7 @@ func (fc *funcContext) translateFunctionBody(typ *ast.FuncType, recv *ast.Ident,
if fc.HasDefer {
prefix = prefix + " var $err = null; try {"
deferSuffix := " } catch(err) { $err = err;"
if len(fc.Blocking) != 0 {
if fc.IsBlocking() {
deferSuffix += " $s = -1;"
}
if fc.resultNames == nil && fc.sig.HasResults() {
Expand All @@ -324,7 +324,7 @@ func (fc *funcContext) translateFunctionBody(typ *ast.FuncType, recv *ast.Ident,
if fc.resultNames != nil {
deferSuffix += fmt.Sprintf(" if (!$curGoroutine.asleep) { return %s; }", fc.translateResults(fc.resultNames))
}
if len(fc.Blocking) != 0 {
if fc.IsBlocking() {
deferSuffix += " if($curGoroutine.asleep) {"
}
suffix = deferSuffix + suffix
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading