Skip to content

Commit 52f76ce

Browse files
committed
refactor coroutine lowering and tasks
1 parent c8a4994 commit 52f76ce

40 files changed

+1829
-1514
lines changed

compiler/compiler.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,22 @@ const tinygoPath = "github.com/tinygo-org/tinygo"
4040
var functionsUsedInTransforms = []string{
4141
"runtime.alloc",
4242
"runtime.free",
43-
"runtime.scheduler",
4443
"runtime.nilPanic",
4544
}
4645

47-
var taskFunctionsUsedInTransforms = []string{
48-
"runtime.startGoroutine",
49-
}
46+
var taskFunctionsUsedInTransforms = []string{}
5047

5148
var coroFunctionsUsedInTransforms = []string{
52-
"runtime.avrSleep",
53-
"runtime.getFakeCoroutine",
54-
"runtime.setTaskStatePtr",
55-
"runtime.getTaskStatePtr",
56-
"runtime.activateTask",
57-
"runtime.noret",
58-
"runtime.getParentHandle",
59-
"runtime.getCoroutine",
60-
"runtime.llvmCoroRefHolder",
49+
"internal/task.start",
50+
"internal/task.Pause",
51+
"internal/task.fake",
52+
"internal/task.Current",
53+
"internal/task.createTask",
54+
"(*internal/task.Task).setState",
55+
"(*internal/task.Task).returnTo",
56+
"(*internal/task.Task).returnCurrent",
57+
"(*internal/task.Task).setReturnPtr",
58+
"(*internal/task.Task).getReturnPtr",
6159
}
6260

6361
type Compiler struct {
@@ -161,6 +159,7 @@ func (c *Compiler) Module() llvm.Module {
161159
func (c *Compiler) getFunctionsUsedInTransforms() []string {
162160
fnused := functionsUsedInTransforms
163161
switch c.Scheduler() {
162+
case "none":
164163
case "coroutines":
165164
fnused = append(append([]string{}, fnused...), coroFunctionsUsedInTransforms...)
166165
case "tasks":
@@ -217,7 +216,7 @@ func (c *Compiler) Compile(mainPath string) []error {
217216
path = path[len(tinygoPath+"/src/"):]
218217
}
219218
switch path {
220-
case "machine", "os", "reflect", "runtime", "runtime/interrupt", "runtime/volatile", "sync", "testing", "internal/reflectlite":
219+
case "machine", "os", "reflect", "runtime", "runtime/interrupt", "runtime/volatile", "sync", "testing", "internal/reflectlite", "internal/task":
221220
return path
222221
default:
223222
if strings.HasPrefix(path, "device/") || strings.HasPrefix(path, "examples/") {
@@ -1041,7 +1040,7 @@ func (c *Compiler) parseInstr(frame *Frame, instr ssa.Instruction) {
10411040
funcPtr, context := c.decodeFuncValue(c.getValue(frame, instr.Call.Value), instr.Call.Value.Type().(*types.Signature))
10421041
params = append(params, context) // context parameter
10431042
switch c.Scheduler() {
1044-
case "coroutines":
1043+
case "none", "coroutines":
10451044
// There are no additional parameters needed for the goroutine start operation.
10461045
case "tasks":
10471046
// Add the function pointer as a parameter to start the goroutine.

compiler/func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (c *Compiler) funcImplementation() funcValueImplementation {
3535
// Always pick the switch implementation, as it allows the use of blocking
3636
// inside a function that is used as a func value.
3737
switch c.Scheduler() {
38-
case "coroutines":
38+
case "none", "coroutines":
3939
return funcValueSwitch
4040
case "tasks":
4141
return funcValueDoubleword

0 commit comments

Comments
 (0)