Skip to content

Commit ee5bc65

Browse files
aykevldeadprogram
authored andcommitted
compiler: move some code around to make the next bugfix easier
This just makes the next fix easier to read.
1 parent 4f1b698 commit ee5bc65

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

compiler/goroutine.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,7 @@ import (
1313

1414
// createGo emits code to start a new goroutine.
1515
func (b *builder) createGo(instr *ssa.Go) {
16-
// Get all function parameters to pass to the goroutine.
17-
var params []llvm.Value
18-
for _, param := range instr.Call.Args {
19-
params = append(params, b.getValue(param, getPos(instr)))
20-
}
21-
22-
var prefix string
23-
var funcPtr llvm.Value
24-
var funcType llvm.Type
25-
hasContext := false
26-
if callee := instr.Call.StaticCallee(); callee != nil {
27-
// Static callee is known. This makes it easier to start a new
28-
// goroutine.
29-
var context llvm.Value
30-
switch value := instr.Call.Value.(type) {
31-
case *ssa.Function:
32-
// Goroutine call is regular function call. No context is necessary.
33-
case *ssa.MakeClosure:
34-
// A goroutine call on a func value, but the callee is trivial to find. For
35-
// example: immediately applied functions.
36-
funcValue := b.getValue(value, getPos(instr))
37-
context = b.extractFuncContext(funcValue)
38-
default:
39-
panic("StaticCallee returned an unexpected value")
40-
}
41-
if !context.IsNil() {
42-
params = append(params, context) // context parameter
43-
hasContext = true
44-
}
45-
funcType, funcPtr = b.getFunction(callee)
46-
} else if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok {
16+
if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok {
4717
// We cheat. None of the builtins do any long or blocking operation, so
4818
// we might as well run these builtins right away without the program
4919
// noticing the difference.
@@ -74,6 +44,38 @@ func (b *builder) createGo(instr *ssa.Go) {
7444
}
7545
b.createBuiltin(argTypes, argValues, builtin.Name(), instr.Pos())
7646
return
47+
}
48+
49+
// Get all function parameters to pass to the goroutine.
50+
var params []llvm.Value
51+
for _, param := range instr.Call.Args {
52+
params = append(params, b.getValue(param, getPos(instr)))
53+
}
54+
55+
var prefix string
56+
var funcPtr llvm.Value
57+
var funcType llvm.Type
58+
hasContext := false
59+
if callee := instr.Call.StaticCallee(); callee != nil {
60+
// Static callee is known. This makes it easier to start a new
61+
// goroutine.
62+
var context llvm.Value
63+
switch value := instr.Call.Value.(type) {
64+
case *ssa.Function:
65+
// Goroutine call is regular function call. No context is necessary.
66+
case *ssa.MakeClosure:
67+
// A goroutine call on a func value, but the callee is trivial to find. For
68+
// example: immediately applied functions.
69+
funcValue := b.getValue(value, getPos(instr))
70+
context = b.extractFuncContext(funcValue)
71+
default:
72+
panic("StaticCallee returned an unexpected value")
73+
}
74+
if !context.IsNil() {
75+
params = append(params, context) // context parameter
76+
hasContext = true
77+
}
78+
funcType, funcPtr = b.getFunction(callee)
7779
} else if instr.Call.IsInvoke() {
7880
// This is a method call on an interface value.
7981
itf := b.getValue(instr.Call.Value, getPos(instr))

0 commit comments

Comments
 (0)