Skip to content

Commit

Permalink
interp: do not register runtime timers during interp
Browse files Browse the repository at this point in the history
The runtime hasn't been initialized yet so this leads to problems.

This fixes #4123.
  • Loading branch information
aykevl authored and deadprogram committed Feb 19, 2024
1 parent 5557e97 commit f529b60
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion interp/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// already be emitted in initAll.
continue
case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" ||
callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current":
callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" ||
callFn.name == "time.startTimer" || callFn.name == "time.stopTimer" || callFn.name == "time.resetTimer":
// These functions should be run at runtime. Specifically:
// * Print and panic functions are best emitted directly without
// interpreting them, otherwise we get a ton of putchar (etc.)
Expand All @@ -252,6 +253,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// at runtime.
// * internal/task.start, internal/task.Current: start and read shcheduler state,
// which is modified elsewhere.
// * Timer functions access runtime internal state which may
// not be initialized.
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
if err != nil {
return nil, mem, err
Expand Down
2 changes: 2 additions & 0 deletions testdata/timers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import "time"

var timer = time.NewTimer(time.Millisecond)

func main() {
// Test ticker.
ticker := time.NewTicker(time.Millisecond * 500)
Expand Down

0 comments on commit f529b60

Please sign in to comment.