Skip to content

Commit

Permalink
chore: s/NativeStore/NativeResolver/g (#3262)
Browse files Browse the repository at this point in the history
It's not a "store", this was a misnomer from the beginning.
  • Loading branch information
thehowl authored Dec 4, 2024
1 parent 8c660ac commit a7a38b6
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (vm *VMKeeper) Initialize(

alloc := gno.NewAllocator(maxAllocTx)
vm.gnoStore = gno.NewStore(alloc, baseStore, iavlStore)
vm.gnoStore.SetNativeStore(stdlibs.NativeStore)
vm.gnoStore.SetNativeResolver(stdlibs.NativeResolver)

if vm.gnoStore.NumMemPackages() > 0 {
// for now, all mem packages must be re-run after reboot.
Expand Down Expand Up @@ -146,7 +146,7 @@ func (vm *VMKeeper) LoadStdlibCached(ctx sdk.Context, stdlibDir string) {
}

gs := gno.NewStore(nil, cachedStdlib.base, cachedStdlib.iavl)
gs.SetNativeStore(stdlibs.NativeStore)
gs.SetNativeResolver(stdlibs.NativeResolver)
loadStdlib(gs, stdlibDir)
cachedStdlib.gno = gs
})
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ func copyValueWithRefs(val Value) Value {
if cv.Closure != nil {
closure = toRefValue(cv.Closure)
}
// nativeBody funcs which don't come from NativeStore (and thus don't
// nativeBody funcs which don't come from NativeResolver (and thus don't
// have NativePkg/Name) can't be persisted, and should not be able
// to get here anyway.
if cv.nativeBody != nil && cv.NativePkg == "" {
Expand Down
24 changes: 12 additions & 12 deletions gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
// cause writes to happen to the store, such as MemPackages to iavlstore.
type PackageGetter func(pkgPath string, store Store) (*PackageNode, *PackageValue)

// NativeStore is a function which can retrieve native bodies of native functions.
type NativeStore func(pkgName string, name Name) func(m *Machine)
// NativeResolver is a function which can retrieve native bodies of native functions.
type NativeResolver func(pkgName string, name Name) func(m *Machine)

// Store is the central interface that specifies the communications between the
// GnoVM and the underlying data store; currently, generally the gno.land
Expand Down Expand Up @@ -62,7 +62,7 @@ type Store interface {
GetMemFile(path string, name string) *gnovm.MemFile
IterMemPackage() <-chan *gnovm.MemPackage
ClearObjectCache() // run before processing a message
SetNativeStore(NativeStore) // for "new" natives XXX
SetNativeResolver(NativeResolver) // for "new" natives XXX
GetNative(pkgPath string, name Name) func(m *Machine) // for "new" natives XXX
SetLogStoreOps(enabled bool)
SprintStoreOps() string
Expand Down Expand Up @@ -95,7 +95,7 @@ type defaultStore struct {
// store configuration; cannot be modified in a transaction
pkgGetter PackageGetter // non-realm packages
cacheNativeTypes map[reflect.Type]Type // reflect doc: reflect.Type are comparable
nativeStore NativeStore // for injecting natives
nativeResolver NativeResolver // for injecting natives

// transient
opslog []StoreOp // for debugging and testing.
Expand All @@ -116,7 +116,7 @@ func NewStore(alloc *Allocator, baseStore, iavlStore store.Store) *defaultStore
// store configuration
pkgGetter: nil,
cacheNativeTypes: make(map[reflect.Type]Type),
nativeStore: nil,
nativeResolver: nil,
}
InitStoreCaches(ds)
return ds
Expand Down Expand Up @@ -144,7 +144,7 @@ func (ds *defaultStore) BeginTransaction(baseStore, iavlStore store.Store) Trans
// store configuration
pkgGetter: ds.pkgGetter,
cacheNativeTypes: ds.cacheNativeTypes,
nativeStore: ds.nativeStore,
nativeResolver: ds.nativeResolver,

// transient
current: nil,
Expand Down Expand Up @@ -174,8 +174,8 @@ func (transactionStore) SetPackageGetter(pg PackageGetter) {
// panic("Go2GnoType may not be called in a transaction store")
// }

func (transactionStore) SetNativeStore(ns NativeStore) {
panic("SetNativeStore may not be called in a transaction store")
func (transactionStore) SetNativeResolver(ns NativeResolver) {
panic("SetNativeResolver may not be called in a transaction store")
}

// CopyCachesFromStore allows to copy a store's internal object, type and
Expand Down Expand Up @@ -685,13 +685,13 @@ func (ds *defaultStore) ClearObjectCache() {
ds.SetCachePackage(Uverse())
}

func (ds *defaultStore) SetNativeStore(ns NativeStore) {
ds.nativeStore = ns
func (ds *defaultStore) SetNativeResolver(ns NativeResolver) {
ds.nativeResolver = ns
}

func (ds *defaultStore) GetNative(pkgPath string, name Name) func(m *Machine) {
if ds.nativeStore != nil {
return ds.nativeStore(pkgPath, name)
if ds.nativeResolver != nil {
return ds.nativeResolver(pkgPath, name)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestTransactionStore_blockedMethods(t *testing.T) {
// These methods should panic as they modify store settings, which should
// only be changed in the root store.
assert.Panics(t, func() { transactionStore{}.SetPackageGetter(nil) })
assert.Panics(t, func() { transactionStore{}.SetNativeStore(nil) })
assert.Panics(t, func() { transactionStore{}.SetNativeResolver(nil) })
}

func TestCopyFromCachedStore(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ type FuncValue struct {
Captures []TypedValue `json:",omitempty"` // HeapItemValues captured from closure.
FileName Name // file name where declared
PkgPath string
NativePkg string // for native bindings through NativeStore
NativePkg string // for native bindings through NativeResolver
NativeName Name // not redundant with Name; this cannot be changed in userspace

body []Stmt // function body
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/test/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func Store(
// Make a new store.
resStore = gno.NewStore(nil, baseStore, baseStore)
resStore.SetPackageGetter(getPackage)
resStore.SetNativeStore(teststdlibs.NativeStore)
resStore.SetNativeResolver(teststdlibs.NativeResolver)
return
}

Expand Down
4 changes: 2 additions & 2 deletions gnovm/stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func FindNative(pkgPath string, name gno.Name) *NativeFunc {
return nil
}

// NativeStore is used by the GnoVM to determine if the given function,
// NativeResolver is used by the GnoVM to determine if the given function,
// specified by its pkgPath and name, has a native implementation; and if so
// retrieve it.
func NativeStore(pkgPath string, name gno.Name) func(*gno.Machine) {
func NativeResolver(pkgPath string, name gno.Name) func(*gno.Machine) {
nt := FindNative(pkgPath, name)
if nt == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

//go:generate go run github.com/gnolang/gno/misc/genstd

func NativeStore(pkgPath string, name gno.Name) func(*gno.Machine) {
func NativeResolver(pkgPath string, name gno.Name) func(*gno.Machine) {
for _, nf := range nativeFuncs {
if nf.gnoPkg == pkgPath && name == nf.gnoFunc {
return nf.f
}
}
return stdlibs.NativeStore(pkgPath, name)
return stdlibs.NativeResolver(pkgPath, name)
}

0 comments on commit a7a38b6

Please sign in to comment.