elvish/pkg/eval/deprecation.go
Qi Xiao 6c764d31d5 pkg/eval: Add mutex to Evaler, and remove that of deprecationRegistry.
The Evaler keeps global states and needs to be accessed concurrently. Mutations
to global states have fairly low throughput, so it makes sense to use a single
mutex.

On the other hand, the compiler is always used on a single thread, so it does
not need any mutex protection, so there is no need to put the mutex inside
deprecationRegistry.
2021-01-04 15:55:26 +00:00

30 lines
603 B
Go

package eval
import (
"github.com/elves/elvish/pkg/diag"
)
type deprecationRegistry struct {
registered map[deprecation]struct{}
}
func newDeprecationRegistry() deprecationRegistry {
return deprecationRegistry{registered: make(map[deprecation]struct{})}
}
type deprecation struct {
srcName string
location diag.Ranging
message string
}
// Registers a deprecation, and returns whether it was registered for the first
// time.
func (r *deprecationRegistry) register(dep deprecation) bool {
if _, ok := r.registered[dep]; ok {
return false
}
r.registered[dep] = struct{}{}
return true
}