interp: fix data race for composite literal creation

This change fixes two data races related to composite literal creation.

The first one isn't controversial as it is just about initializing the
variable that contains the values in the right place, i.e. within the
n.exec, so that this variable is local to each potential goroutine,
instead of being racily shared by all goroutines.

The second one is more worrying, i.e. having to protect the node typ
with a mutex, because a call to func (t *itype) refType actually
modifies the itype itself, which means it is not concurrent safe.
The change seems to work, and does not seem to introduce regression, but
it is still a concern as it probably is a sign that more similar
guarding has to be done in several other places.
This commit is contained in:
mpl
2020-09-14 16:22:04 +02:00
committed by GitHub
parent 42abedb25d
commit a2f56431ea
5 changed files with 98 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"path/filepath"
"reflect"
"strconv"
"sync"
)
// tcat defines interpreter type categories.
@@ -104,6 +105,7 @@ type structField struct {
// itype defines the internal representation of types in the interpreter.
type itype struct {
mu *sync.Mutex
cat tcat // Type category
field []structField // Array of struct fields if structT or interfaceT
key *itype // Type of key element if MapT or nil