From 1286a4add73723646d76eb510c8ec2a063c254ce Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Tue, 12 Mar 2024 19:23:02 +0530 Subject: [PATCH] fixups --- examples/gno.land/r/demo/tests/tests_test.gno | 4 ++-- gnovm/cmd/gno/lint.go | 1 + gnovm/pkg/gnolang/gno_test.go | 8 ++++---- gnovm/pkg/gnolang/machine.go | 13 +++++++----- gnovm/pkg/gnolang/machine_test.go | 2 +- gnovm/pkg/gnolang/nodes.go | 2 +- gnovm/pkg/gnolang/preprocess.go | 20 +++++++++++-------- gnovm/pkg/gnolang/types.go | 2 +- gnovm/pkg/gnolang/uverse_test.go | 2 +- gnovm/tests/file.go | 1 + 10 files changed, 32 insertions(+), 23 deletions(-) diff --git a/examples/gno.land/r/demo/tests/tests_test.gno b/examples/gno.land/r/demo/tests/tests_test.gno index 3dcbeecf18c..f428f6b1dd7 100644 --- a/examples/gno.land/r/demo/tests/tests_test.gno +++ b/examples/gno.land/r/demo/tests/tests_test.gno @@ -34,8 +34,8 @@ func TestAssertOriginCall(t *testing.T) { func TestPrevRealm(t *testing.T) { var ( - user1Addr = std.DerivePkgAddr("user1.gno") - rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") + user1Addr = std.DerivePkgAddr("user1.gno", "") + rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests", "v0.0.1") ) // When a single realm in the frames, PrevRealm returns the user if addr := GetPrevRealm().Addr(); addr != user1Addr { diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index e2a7e53fb69..d643aa33371 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -129,6 +129,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { } } + // TODO(hariom): gno lint is failing because of this? tm.RunFiles(testfiles.Files...) }) diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 861b98b4427..6a11fbe7d76 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -21,7 +21,7 @@ import ( func TestRunEmptyMain(t *testing.T) { t.Parallel() - m := NewMachine("test", nil) + m := NewMachine("test", "", nil) // []Stmt{} != nil, as nil means that in the source code not even the // brackets are present and is reserved for external (ie. native) functions. main := FuncD("main", nil, nil, []Stmt{}) @@ -33,7 +33,7 @@ func TestRunEmptyMain(t *testing.T) { func TestRunLoopyMain(t *testing.T) { t.Parallel() - m := NewMachine("test", nil) + m := NewMachine("test", "", nil) c := `package test func main() { for i:=0; i<1000; i++ { @@ -48,7 +48,7 @@ func main() { } func TestDoOpEvalBaseConversion(t *testing.T) { - m := NewMachine("test", nil) + m := NewMachine("test", "", nil) type testCase struct { input string @@ -119,7 +119,7 @@ func TestDoOpEvalBaseConversion(t *testing.T) { func TestEval(t *testing.T) { t.Parallel() - m := NewMachine("test", nil) + m := NewMachine("test", "", nil) c := `package test func next(i int) int { return i+1 diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 6a010e4c8f2..6f1eb3b9a7b 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -56,11 +56,12 @@ type Machine struct { // // Like for [NewMachineWithOptions], Machines initialized through this // constructor must be finalized with [Machine.Release]. -func NewMachine(pkgPath string, store Store) *Machine { +func NewMachine(pkgPath, pkgVersion string, store Store) *Machine { return NewMachineWithOptions( MachineOptions{ - PkgPath: pkgPath, - Store: store, + PkgPath: pkgPath, + PkgVersion: pkgVersion, + Store: store, }) } @@ -251,9 +252,11 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* // make and set package if doesn't exist. pn := (*PackageNode)(nil) pv := (*PackageValue)(nil) + // panic("stop: " + memPkg.ModFile.ImportPath + " " + memPkg.ModFile.Version) if m.Package != nil && - m.Package.ModFile.Path == memPkg.ModFile.ImportPath && - m.Package.ModFile.Version == memPkg.ModFile.Version { + m.Package.ModFile.Path == memPkg.ModFile.ImportPath { + // m.Package.ModFile.Version == memPkg.ModFile.Version { + fmt.Println() pv = m.Package loc := PackageNodeLocation(memPkg.ModFile.ImportPath, memPkg.ModFile.Version) pn = m.Store.GetBlockNode(loc).(*PackageNode) diff --git a/gnovm/pkg/gnolang/machine_test.go b/gnovm/pkg/gnolang/machine_test.go index edd1dca4421..3668a6cc739 100644 --- a/gnovm/pkg/gnolang/machine_test.go +++ b/gnovm/pkg/gnolang/machine_test.go @@ -26,7 +26,7 @@ func TestRunMemPackageWithOverrides_revertToOld(t *testing.T) { baseStore := dbadapter.StoreConstructor(db, stypes.StoreOptions{}) iavlStore := iavl.StoreConstructor(db, stypes.StoreOptions{}) store := NewStore(nil, baseStore, iavlStore) - m := NewMachine("std", store) + m := NewMachine("std", "", store) m.RunMemPackageWithOverrides(&std.MemPackage{ Name: "std", ModFile: &std.MemMod{ diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index c512e44369f..c72952afa38 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -1356,7 +1356,7 @@ func (x *PackageNode) NewPackage() *PackageValue { Source: x, }, PkgName: x.PkgName, - ModFile: x.ModFile, + ModFile: x.ModFile.Copy(), FNames: nil, FBlocks: nil, fBlocksMap: make(map[Name]*Block), diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index eda417d6247..403c93c15c1 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2028,7 +2028,7 @@ func evalStaticType(store Store, last BlockNode, x Expr) Type { store = store.Fork() store.SetCachePackage(pv) } - m := NewMachine(pn.ModFile.Path, store) + m := NewMachine(pn.ModFile.Path, pn.ModFile.Version, store) tv := m.EvalStatic(last, x) m.Release() if _, ok := tv.V.(TypeValue); !ok { @@ -2102,7 +2102,7 @@ func evalStaticTypeOfRaw(store Store, last BlockNode, x Expr) (t Type) { store = store.Fork() store.SetCachePackage(pv) } - m := NewMachine(pn.ModFile.Path, store) + m := NewMachine(pn.ModFile.Path, pn.ModFile.Version, store) t = m.EvalStaticTypeOf(last, x) m.Release() x.SetAttribute(ATTR_TYPEOF_VALUE, t) @@ -2198,7 +2198,7 @@ func getResultTypedValues(cx *CallExpr) []TypedValue { func evalConst(store Store, last BlockNode, x Expr) *ConstExpr { // TODO: some check or verification for ensuring x // is constant? From the machine? - cv := NewMachine(".dontcare", store) + cv := NewMachine(".dontcare", "", store) tv := cv.EvalStatic(last, x) cv.Release() cx := &ConstExpr{ @@ -3044,11 +3044,15 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) { break } } - if version == "" { - panic(fmt.Sprintf( - "cannot get version for package %s", - d.PkgPath)) - } + // TODO(hariom): uncomment? + // It may cause problems in few cases + // - If package doen't contain gno.mod + // - Testing _filetest. Currently imports are covered by gno.mod + // if version == "" { + // panic(fmt.Sprintf( + // "cannot get version for package %s", + // d.PkgPath)) + // } } // TODO(hariom): create helper diff --git a/gnovm/pkg/gnolang/types.go b/gnovm/pkg/gnolang/types.go index 4929c625dc4..4f7a7c0b46b 100644 --- a/gnovm/pkg/gnolang/types.go +++ b/gnovm/pkg/gnolang/types.go @@ -2530,7 +2530,7 @@ func applySpecifics(lookup map[Name]Type, tmpl Type) (Type, bool) { gx := MustParseExpr(string(generic)) gx = Preprocess(nil, bs, gx).(Expr) // Evaluate type from generic expression. - m := NewMachine("", nil) + m := NewMachine("", "", nil) tv := m.EvalStatic(bs, gx) m.Release() if isElem { diff --git a/gnovm/pkg/gnolang/uverse_test.go b/gnovm/pkg/gnolang/uverse_test.go index 7280d131ec5..1090f0c7b25 100644 --- a/gnovm/pkg/gnolang/uverse_test.go +++ b/gnovm/pkg/gnolang/uverse_test.go @@ -150,7 +150,7 @@ func TestIssue1337PrintNilSliceAsUndefined(t *testing.T) { for _, tc := range test { t.Run(tc.name, func(t *testing.T) { - m := NewMachine("test", nil) + m := NewMachine("test", "", nil) n := MustParseFile("main.go", tc.code) m.RunFiles(n) m.RunMain() diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index 1b24f4dd4ee..eb18b36767a 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -180,6 +180,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { Name: string(pkgName), ModFile: &std.MemMod{ ImportPath: pkgPath, + Version: pkgVersion, }, Files: []*std.MemFile{ {