From bdb44bd604ad0c96af9a7006b17e5aa36205a378 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:36:26 -0700 Subject: [PATCH 01/21] test(gnovm): add test for bounding issue --- examples/gno.land/r/demo/foo20/foo20.gno | 6 +++++ .../r/demo/tests/crossrealm/crossrealm.gno | 7 +++++ gnovm/tests/files/zrealm_crossrealm15.gno | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm15.gno diff --git a/examples/gno.land/r/demo/foo20/foo20.gno b/examples/gno.land/r/demo/foo20/foo20.gno index 162454800e8..efdd0cacbb3 100644 --- a/examples/gno.land/r/demo/foo20/foo20.gno +++ b/examples/gno.land/r/demo/foo20/foo20.gno @@ -14,12 +14,18 @@ import ( var ( foo *grc20.AdminToken admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" // TODO: helper to change admin + pub grc20.IGRC20 ) func init() { foo = grc20.NewAdminToken("Foo", "FOO", 4) foo.Mint(admin, 1000000*10000) // @administrator (1M) foo.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10000*10000) // @manfred (10k) +<<<<<<< Updated upstream +======= + pub = foo.GRC20() + grc20reg.Register(pub, "") +>>>>>>> Stashed changes } // method proxies as public functions. diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno index 97273f642de..0fdb5ff2308 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno @@ -27,3 +27,10 @@ func Make1() *p_crossrealm.Container { B: local, } } + +type Fooer interface{ Foo() } + +var fooer Fooer + +func SetFooer(f Fooer) { fooer = f } +func CallFoo() { fooer.Foo() } diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno new file mode 100644 index 00000000000..16f01cf2701 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello") } + +var f *fooer + +func init() { + f = &fooer{} + crossrealm.SetFooer(f) + crossrealm.CallFoo() +} + +func main() { + print(".") +} + +// Output: +// hello +// . From 7cba9cab9f2b2f3ed8ec52883fc8185356ced9c7 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:37:39 -0700 Subject: [PATCH 02/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/demo/foo20/foo20.gno | 6 ------ gnovm/pkg/gnolang/realm.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/gno.land/r/demo/foo20/foo20.gno b/examples/gno.land/r/demo/foo20/foo20.gno index efdd0cacbb3..162454800e8 100644 --- a/examples/gno.land/r/demo/foo20/foo20.gno +++ b/examples/gno.land/r/demo/foo20/foo20.gno @@ -14,18 +14,12 @@ import ( var ( foo *grc20.AdminToken admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" // TODO: helper to change admin - pub grc20.IGRC20 ) func init() { foo = grc20.NewAdminToken("Foo", "FOO", 4) foo.Mint(admin, 1000000*10000) // @administrator (1M) foo.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10000*10000) // @manfred (10k) -<<<<<<< Updated upstream -======= - pub = foo.GRC20() - grc20reg.Register(pub, "") ->>>>>>> Stashed changes } // method proxies as public functions. diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 3710524130a..8ecdb3f4904 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -567,6 +567,24 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { + /* + println("@@@@@@@@1") + fmt.Printf("po: %v\n", po) + fmt.Printf("po.Info: %v\n", po.GetObjectInfo()) + fmt.Printf("po.Owner: %v\n", po.GetOwner()) + fmt.Printf("po.Hash: %v\n", po.GetHash()) + fmt.Printf("po.IsDeleted: %v\n", po.GetIsDeleted()) + fmt.Printf("po.IsDirty: %v\n", po.GetIsDirty()) + fmt.Printf("po.IsEscaped: %v\n", po.GetIsEscaped()) + fmt.Printf("po.IsNewDeleted: %v\n", po.GetIsNewDeleted()) + fmt.Printf("po.IsNewEscaped: %v\n", po.GetIsNewEscaped()) + fmt.Printf("po.IsOwned: %v\n", po.GetIsOwned()) + fmt.Printf("po.IsReal: %v\n", po.GetIsReal()) + fmt.Printf("po.IsNewReal: %v\n", po.GetIsNewReal()) + fmt.Printf("po.IsTransient: %v\n", po.GetIsTransient()) + println("@@@@@@@@2") + os.Exit(1) + */ panic("new escaped mark has no object ID") } // escaped has no owner. From 4ba7490ba18c2b6c35d4a984c571075dcdefcc1a Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:38:11 -0700 Subject: [PATCH 03/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/pkg/gnolang/realm.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 8ecdb3f4904..3710524130a 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -567,24 +567,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { - /* - println("@@@@@@@@1") - fmt.Printf("po: %v\n", po) - fmt.Printf("po.Info: %v\n", po.GetObjectInfo()) - fmt.Printf("po.Owner: %v\n", po.GetOwner()) - fmt.Printf("po.Hash: %v\n", po.GetHash()) - fmt.Printf("po.IsDeleted: %v\n", po.GetIsDeleted()) - fmt.Printf("po.IsDirty: %v\n", po.GetIsDirty()) - fmt.Printf("po.IsEscaped: %v\n", po.GetIsEscaped()) - fmt.Printf("po.IsNewDeleted: %v\n", po.GetIsNewDeleted()) - fmt.Printf("po.IsNewEscaped: %v\n", po.GetIsNewEscaped()) - fmt.Printf("po.IsOwned: %v\n", po.GetIsOwned()) - fmt.Printf("po.IsReal: %v\n", po.GetIsReal()) - fmt.Printf("po.IsNewReal: %v\n", po.GetIsNewReal()) - fmt.Printf("po.IsTransient: %v\n", po.GetIsTransient()) - println("@@@@@@@@2") - os.Exit(1) - */ panic("new escaped mark has no object ID") } // escaped has no owner. From 621d59957e6e0380c74ed2160b7722d3b5682a61 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:59:04 -0700 Subject: [PATCH 04/21] chore: fixup --- gnovm/tests/files/zrealm_crossrealm15.gno | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index 16f01cf2701..f4e3d57b0fb 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -22,5 +22,7 @@ func main() { } // Output: -// hello -// . + +// Error: + +// Realm: From b0a1e1ffbbc1a5d641eb18e7816c12a76a5aedaa Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sat, 6 Jul 2024 16:22:38 -0700 Subject: [PATCH 05/21] allow passing in an object about to be persisted in the previous realm --- .../r/demo/tests/crossrealm/crossrealm.gno | 7 + gnovm/pkg/gnolang/realm.go | 20 +- gnovm/pkg/gnomod/file_test.go | 1 + gnovm/tests/file.go | 1 - gnovm/tests/files/zrealm_crossrealm15.gno | 30 + gnovm/tests/files/zrealm_crossrealm16.gno | 597 ++++++++++++++++++ 6 files changed, 653 insertions(+), 3 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm15.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm16.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno index 97273f642de..0fdb5ff2308 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno @@ -27,3 +27,10 @@ func Make1() *p_crossrealm.Container { B: local, } } + +type Fooer interface{ Foo() } + +var fooer Fooer + +func SetFooer(f Fooer) { fooer = f } +func CallFoo() { fooer.Foo() } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 3710524130a..df6100ee72f 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -171,6 +171,13 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { + if !co.GetIsReal() { + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + co.SetIsNewReal(false) + rlm.MarkNewReal(co) + } rlm.MarkNewEscaped(co) } } else if co.GetIsReal() { @@ -375,6 +382,15 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo.SetIsNewReal(false) // skip if became deleted. continue + } else if oo.GetIsReal() && oo.GetObjectID().PkgID != rlm.ID { + // the object was new real in this realm, + // but another realm saved it before + // this realm started finalizing. + // if debug { XXX uncomment in the future + if oo.GetObjectID().PkgID == rlm.ID { + panic("should have been saved in another realm") + } + // } } else { rlm.incRefCreatedDescendants(store, oo) } @@ -442,7 +458,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // NOTE: do not unset owner here, // may become unescaped later // in processNewEscapedMarks(). - // NOTE: may already be escaped. rlm.MarkNewEscaped(child) } } else { @@ -569,6 +584,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { if eo.GetObjectID().IsZero() { panic("new escaped mark has no object ID") } + // escaped has no owner. eo.SetOwner(nil) } @@ -1471,7 +1487,7 @@ func toRefValue(val Value) RefValue { } else if oo.GetIsEscaped() { if debug { if !oo.GetOwnerID().IsZero() { - panic("cannot convert escaped object to ref value without an owner ID") + panic("cannot convert escaped object to ref value with an owner ID") } } return RefValue{ diff --git a/gnovm/pkg/gnomod/file_test.go b/gnovm/pkg/gnomod/file_test.go index 7abfe16f340..7790e213c2f 100644 --- a/gnovm/pkg/gnomod/file_test.go +++ b/gnovm/pkg/gnomod/file_test.go @@ -16,6 +16,7 @@ import ( const testRemote string = "test3.gno.land:26657" +// XXX this test fails when the network is offline. func TestFetchDeps(t *testing.T) { for _, tc := range []struct { desc string diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index 8ab60145bd5..347a61ec8ee 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -307,7 +307,6 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { panic(fmt.Sprintf("fail on %s: got unexpected debug error(s): %v", path, gno.GetDebugErrors())) } // pnc is nil, errWanted empty, no gno debug errors - return nil } case "Output": // panic if got unexpected error diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno new file mode 100644 index 00000000000..dc081dfc771 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -0,0 +1,30 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello") } + +var f *fooer + +func init() { + f = &fooer{} + crossrealm.SetFooer(f) + crossrealm.CallFoo() +} + +func main() { + print(".") +} + +// Output: +// hello +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno new file mode 100644 index 00000000000..db924432271 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -0,0 +1,597 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello") } + +var f *fooer + +func main() { + f = &fooer{} + crossrealm.SetFooer(f) + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ +// "Fields": [], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "RefCount": "1" +// } +// } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "IsEscaped": true, +// "ModTime": "0", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "2aec554d4aaa9a1c37af933f8ca8d000088e4e7c", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// } +// } +// } +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "0", +// "File": "", +// "Line": "0", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "A", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ls", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm.gno", +// "IsMethod": true, +// "Name": "String", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ls", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "LocalStruct", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.InterfaceType", +// "Generic": "", +// "Methods": [ +// { +// "Embedded": false, +// "Name": "Foo", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "Fooer", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "init.2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "19", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "Make1", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "24", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "SetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "35", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "CallFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "36", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "a75fdb389fedfcbbaa7f446d528c1e149726347c", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ] +// } +// switchrealm["gno.land/r/crossrealm_test"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "IsEscaped": true, +// "ModTime": "3", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "0", +// "File": "", +// "Line": "0", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "main.gno", +// "IsMethod": true, +// "Name": "Foo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "main.gno", +// "Line": "10", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// } +// ], +// "Results": [] +// } +// } +// } +// ], +// "Name": "fooer", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "FileName": "main.gno", +// "IsMethod": false, +// "Name": "main", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "main.gno", +// "Line": "14", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ] +// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] From cbf27535a6741619eb9f0e41567a0e8a0a860f45 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 09:46:12 -0700 Subject: [PATCH 06/21] remove spurious lines --- gnovm/pkg/gnolang/realm.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index df6100ee72f..41a5e787667 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -382,15 +382,6 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo.SetIsNewReal(false) // skip if became deleted. continue - } else if oo.GetIsReal() && oo.GetObjectID().PkgID != rlm.ID { - // the object was new real in this realm, - // but another realm saved it before - // this realm started finalizing. - // if debug { XXX uncomment in the future - if oo.GetObjectID().PkgID == rlm.ID { - panic("should have been saved in another realm") - } - // } } else { rlm.incRefCreatedDescendants(store, oo) } From 5f647fbcaf8893085a3f7d29b8e19544af450822 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 10:12:08 -0700 Subject: [PATCH 07/21] fix for all cases --- gnovm/pkg/gnolang/realm.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 41a5e787667..56b7fe458fb 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -171,13 +171,6 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - if !co.GetIsReal() { - // this can happen if a ref +1 - // new object gets passed into - // an external realm function. - co.SetIsNewReal(false) - rlm.MarkNewReal(co) - } rlm.MarkNewEscaped(co) } } else if co.GetIsReal() { @@ -573,7 +566,10 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { - panic("new escaped mark has no object ID") + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + rlm.assignNewObjectID(eo) } // escaped has no owner. From bd889f712e32a2f9dc55f0d061ec69ca37c033db Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 10:23:27 -0700 Subject: [PATCH 08/21] reset new escape for both cases --- gnovm/pkg/gnolang/realm.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 56b7fe458fb..a1b7798ed46 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -171,6 +171,13 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { + if !co.GetIsReal() { + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + co.SetIsNewReal(false) + rlm.MarkNewReal(co) + } rlm.MarkNewEscaped(co) } } else if co.GetIsReal() { @@ -442,6 +449,13 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // NOTE: do not unset owner here, // may become unescaped later // in processNewEscapedMarks(). + if !child.GetIsReal() { + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + child.SetIsNewReal(false) + rlm.MarkNewReal(child) + } rlm.MarkNewEscaped(child) } } else { From 00a2779d09981803e94379f4b97cff94158e67b2 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 10:53:31 -0700 Subject: [PATCH 09/21] optimized fix --- gnovm/pkg/gnolang/ownership.go | 35 ++++++++++++++------------- gnovm/pkg/gnolang/realm.go | 44 +++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 511b44bfc73..a4a3a8dcf74 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -140,11 +140,12 @@ type ObjectInfo struct { RefCount int // for persistence. deleted/gc'd if 0. IsEscaped bool `json:",omitempty"` // hash in iavl. // MemRefCount int // consider for optimizations. - isDirty bool - isDeleted bool - isNewReal bool - isNewEscaped bool - isNewDeleted bool + isDirty bool + isDeleted bool + isNewReal bool + isNewEscaped bool + isNewDeleted bool + lastNewRealRealm PkgID // XXX huh? owner Object // mem reference to owner. @@ -154,17 +155,19 @@ type ObjectInfo struct { // Note that "owner" is nil. func (oi *ObjectInfo) Copy() ObjectInfo { return ObjectInfo{ - ID: oi.ID, - Hash: oi.Hash.Copy(), - OwnerID: oi.OwnerID, - ModTime: oi.ModTime, - RefCount: oi.RefCount, - IsEscaped: oi.IsEscaped, - isDirty: oi.isDirty, - isDeleted: oi.isDeleted, - isNewReal: oi.isNewReal, - isNewEscaped: oi.isNewEscaped, - isNewDeleted: oi.isNewDeleted, + ID: oi.ID, + Hash: oi.Hash.Copy(), + OwnerID: oi.OwnerID, + ModTime: oi.ModTime, + RefCount: oi.RefCount, + IsEscaped: oi.IsEscaped, + // XXX do the following need copying too? + isDirty: oi.isDirty, + isDeleted: oi.isDeleted, + isNewReal: oi.isNewReal, + isNewEscaped: oi.isNewEscaped, + isNewDeleted: oi.isNewDeleted, + lastNewRealRealm: oi.lastNewRealRealm, } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index a1b7798ed46..082b6297b17 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -171,14 +171,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - if !co.GetIsReal() { - // this can happen if a ref +1 - // new object gets passed into - // an external realm function. - co.SetIsNewReal(false) - rlm.MarkNewReal(co) - } - rlm.MarkNewEscaped(co) + rlm.MarkNewEscapedCheckCrossRealm(co) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -272,6 +265,24 @@ func (rlm *Realm) MarkNewDeleted(oo Object) { rlm.newDeleted = append(rlm.newDeleted, oo) } +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { + oi := oo.GetObjectInfo() + if !oi.GetIsReal() { + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + if oi.lastNewRealRealm == rlm.ID { + // we already marked as new real here + // and appended to newCreated, skip. + } else { + oi.lastNewRealRealm = rlm.ID + oi.SetIsNewReal(false) + rlm.MarkNewReal(oo) + } + } + rlm.MarkNewEscaped(oo) +} + func (rlm *Realm) MarkNewEscaped(oo Object) { if debug { if !oo.GetIsNewReal() && !oo.GetIsReal() { @@ -366,7 +377,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { // Create new objects and their new descendants. - for _, oo := range rlm.newCreated { + // NOTE: the following range does not work + // because incRefCreatedDescendants may append to newCreated + // for the case when new escapes are found to have crossed. + // XXX write test. + // for _, oo := range rlm.newCreated { + for i := 0; i < len(rlm.newCreated); i++ { + oo := rlm.newCreated[i] if debug { if oo.GetIsDirty() { panic("new created mark cannot be dirty") @@ -449,14 +466,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // NOTE: do not unset owner here, // may become unescaped later // in processNewEscapedMarks(). - if !child.GetIsReal() { - // this can happen if a ref +1 - // new object gets passed into - // an external realm function. - child.SetIsNewReal(false) - rlm.MarkNewReal(child) - } - rlm.MarkNewEscaped(child) + rlm.MarkNewEscapedCheckCrossRealm(child) } } else { panic("child reference count should be greater than zero after increasing") From 3a498f69bf209a1c279e5bb05033aac1007cfb10 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 11:08:06 -0700 Subject: [PATCH 10/21] optimize --- gnovm/pkg/gnolang/ownership.go | 28 +++++++++++++++------------- gnovm/pkg/gnolang/realm.go | 28 ++++++++++------------------ 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index a4a3a8dcf74..015d7a59907 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -140,12 +140,12 @@ type ObjectInfo struct { RefCount int // for persistence. deleted/gc'd if 0. IsEscaped bool `json:",omitempty"` // hash in iavl. // MemRefCount int // consider for optimizations. - isDirty bool - isDeleted bool - isNewReal bool - isNewEscaped bool - isNewDeleted bool - lastNewRealRealm PkgID + isDirty bool + isDeleted bool + isNewReal bool + isNewEscaped bool + isNewDeleted bool + lastNewRealEscapedRealm PkgID // XXX huh? owner Object // mem reference to owner. @@ -161,13 +161,15 @@ func (oi *ObjectInfo) Copy() ObjectInfo { ModTime: oi.ModTime, RefCount: oi.RefCount, IsEscaped: oi.IsEscaped, - // XXX do the following need copying too? - isDirty: oi.isDirty, - isDeleted: oi.isDeleted, - isNewReal: oi.isNewReal, - isNewEscaped: oi.isNewEscaped, - isNewDeleted: oi.isNewDeleted, - lastNewRealRealm: oi.lastNewRealRealm, + /* + // XXX do the following need copying too? + isDirty: oi.isDirty, + isDeleted: oi.isDeleted, + isNewReal: oi.isNewReal, + isNewEscaped: oi.isNewEscaped, + isNewDeleted: oi.isNewDeleted, + lastNewRealEscapedRealm: oi.lastNewRealEscapedRealm, + */ } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 082b6297b17..5eedb36bbd9 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -102,7 +102,6 @@ type Realm struct { created []Object // about to become real. updated []Object // real objects that were modified. deleted []Object // real objects that became deleted. - escaped []Object // real objects with refcount > 1. } // Creates a blank new realm with counter 0. @@ -267,18 +266,18 @@ func (rlm *Realm) MarkNewDeleted(oo Object) { func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { oi := oo.GetObjectInfo() + if oi.lastNewRealEscapedRealm == rlm.ID { + // already processed for this realm, + // see below. + return + } if !oi.GetIsReal() { // this can happen if a ref +1 // new object gets passed into // an external realm function. - if oi.lastNewRealRealm == rlm.ID { - // we already marked as new real here - // and appended to newCreated, skip. - } else { - oi.lastNewRealRealm = rlm.ID - oi.SetIsNewReal(false) - rlm.MarkNewReal(oo) - } + oi.lastNewRealEscapedRealm = rlm.ID + oi.SetIsNewReal(false) + rlm.MarkNewReal(oo) } rlm.MarkNewEscaped(oo) } @@ -318,8 +317,7 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { len(rlm.newDeleted) > 0 || len(rlm.created) > 0 || len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.deleted) > 0 { panic("realm updates in readonly transaction") } return @@ -335,8 +333,7 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.updated) if false || rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.deleted != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -355,7 +352,6 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { rlm.markDirtyAncestors(store) if debug { ensureUniq(rlm.created, rlm.updated, rlm.deleted) - ensureUniq(rlm.escaped) } // save all the created and updated objects. // hash calculation is done along the way, @@ -546,7 +542,6 @@ func (rlm *Realm) decRefDeletedDescendants(store Store, oo Object) { // objects get their original owners marked dirty (to be further // marked via markDirtyAncestors). func (rlm *Realm) processNewEscapedMarks(store Store) { - escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, // but is always newly escaped, @@ -572,7 +567,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // we do that upon actually persisting // the hash index. // eo.SetIsNewEscaped(false) - escaped = append(escaped, eo) // add to escaped, and mark dirty previous owner. po := getOwner(store, eo) @@ -601,7 +595,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { } } } - rlm.escaped = escaped // XXX is this actually used? } //---------------------------------------- @@ -816,7 +809,6 @@ func (rlm *Realm) clearMarks() { rlm.created = nil rlm.updated = nil rlm.deleted = nil - rlm.escaped = nil } //---------------------------------------- From 60b99ccec391ea420a8806b1d744719dfbd69009 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 11:33:51 -0700 Subject: [PATCH 11/21] add test for crossrealm new escaped internal objects --- gnovm/pkg/gnolang/realm.go | 9 +- gnovm/tests/files/zrealm_crossrealm17.gno | 680 ++++++++++++++++++++++ 2 files changed, 683 insertions(+), 6 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm17.gno diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 5eedb36bbd9..5b046da53ac 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -376,8 +376,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // NOTE: the following range does not work // because incRefCreatedDescendants may append to newCreated // for the case when new escapes are found to have crossed. - // XXX write test. - // for _, oo := range rlm.newCreated { + // BAD: for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] if debug { @@ -583,11 +582,9 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // exists, mark dirty. rlm.MarkDirty(po) } + // TODO: move to if debug { } once proven. if eo.GetObjectID().IsZero() { - // this can happen if a ref +1 - // new object gets passed into - // an external realm function. - rlm.assignNewObjectID(eo) + panic("new escaped object has no object ID") } // escaped has no owner. diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno new file mode 100644 index 00000000000..cb794c380d3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -0,0 +1,680 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type container struct{ *fooer } + +func (container) Foo() { println("hello container") } + +type fooer struct{} + +var f *fooer + +func main() { + f = &fooer{} + c := &container{f} + crossrealm.SetFooer(c) + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello container +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "RefCount": "1" +// } +// } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "2e88a06ae991c0b638c9dd94a2d80b19e476d114", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// } +// } +// } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:9]={ +// "Fields": [], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", +// "RefCount": "1" +// } +// } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:8]={ +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", +// "IsEscaped": true, +// "ModTime": "0", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "e521635fd7846ccea2a330e7c114af77db07ee27", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// } +// } +// } +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "0", +// "File": "", +// "Line": "0", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "A", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ls", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm.gno", +// "IsMethod": true, +// "Name": "String", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ls", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "LocalStruct", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.InterfaceType", +// "Generic": "", +// "Methods": [ +// { +// "Embedded": false, +// "Name": "Foo", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "Fooer", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "init.2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "19", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "Make1", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "24", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "SetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "35", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm.gno", +// "IsMethod": false, +// "Name": "CallFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm.gno", +// "Line": "36", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "a75fdb389fedfcbbaa7f446d528c1e149726347c", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "7041ec66b0edbe5faaa7e8e9baa1b2a862887964", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ] +// } +// switchrealm["gno.land/r/crossrealm_test"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "IsEscaped": true, +// "ModTime": "3", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "0", +// "File": "", +// "Line": "0", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": true, +// "Name": "fooer", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// } +// } +// ], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "main.gno", +// "IsMethod": true, +// "Name": "Foo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "main.gno", +// "Line": "10", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// } +// } +// ], +// "Results": [] +// } +// } +// } +// ], +// "Name": "container", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [], +// "Name": "fooer", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "FileName": "main.gno", +// "IsMethod": false, +// "Name": "main", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "main.gno", +// "Line": "16", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ] +// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] From 03e838bfc0d7db06e2f36367f7068c5af9a57fd9 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:49:58 -0500 Subject: [PATCH 12/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../r/demo/tests/crossrealm/crossrealm.gno | 7 ++-- gnovm/tests/files/zrealm_crossrealm16.gno | 26 +++++++++++++-- gnovm/tests/files/zrealm_crossrealm17.gno | 26 +++++++++++++-- gnovm/tests/files/zrealm_crossrealm18.gno | 33 +++++++++++++++++++ 4 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm18.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno index 0fdb5ff2308..acb040c1ca8 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno @@ -32,5 +32,8 @@ type Fooer interface{ Foo() } var fooer Fooer -func SetFooer(f Fooer) { fooer = f } -func CallFoo() { fooer.Foo() } +func SetFooer(f Fooer) Fooer { + fooer = f + return fooer +} +func CallFoo() { fooer.Foo() } diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index db924432271..f2720c54769 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -325,7 +325,17 @@ func main() { // } // } // ], -// "Results": [] +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] // }, // "V": { // "@type": "/gno.FuncValue", @@ -363,7 +373,17 @@ func main() { // } // } // ], -// "Results": [] +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] // } // } // }, @@ -392,7 +412,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm.gno", -// "Line": "36", +// "Line": "39", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } // }, diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index cb794c380d3..298655f7291 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -376,7 +376,17 @@ func main() { // } // } // ], -// "Results": [] +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] // }, // "V": { // "@type": "/gno.FuncValue", @@ -414,7 +424,17 @@ func main() { // } // } // ], -// "Results": [] +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] // } // } // }, @@ -443,7 +463,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm.gno", -// "Line": "36", +// "Line": "39", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } // }, diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno new file mode 100644 index 00000000000..45441d4572d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello") } + +var f crossrealm.Fooer = crossrealm.SetFooer(&fooer{}) + +func init() { + crossrealm.CallFoo() +} + +func main() { + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello +// hello +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] From 71b74f42c918ec6e44e50ef299e322efb003d07f Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:53:22 -0500 Subject: [PATCH 13/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/files/zrealm_crossrealm15.gno | 6 ++++-- gnovm/tests/files/zrealm_crossrealm16.gno | 10 ++++++---- gnovm/tests/files/zrealm_crossrealm17.gno | 10 ++++++---- gnovm/tests/files/zrealm_crossrealm18.gno | 8 +++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index dc081dfc771..c2c5575bfcd 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -2,12 +2,14 @@ package crossrealm_test import ( + "std" + crossrealm "gno.land/r/demo/tests/crossrealm" ) type fooer struct{} -func (fooer) Foo() { println("hello") } +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f *fooer @@ -22,7 +24,7 @@ func main() { } // Output: -// hello +// hello gno.land/r/crossrealm_test // . // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index f2720c54769..47797631975 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -2,12 +2,14 @@ package crossrealm_test import ( + "std" + crossrealm "gno.land/r/demo/tests/crossrealm" ) type fooer struct{} -func (fooer) Foo() { println("hello") } +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f *fooer @@ -19,7 +21,7 @@ func main() { } // Output: -// hello +// hello gno.land/r/crossrealm_test // . // Error: @@ -529,7 +531,7 @@ func main() { // "Location": { // "Column": "1", // "File": "main.gno", -// "Line": "10", +// "Line": "12", // "PkgPath": "gno.land/r/crossrealm_test" // } // }, @@ -581,7 +583,7 @@ func main() { // "Location": { // "Column": "1", // "File": "main.gno", -// "Line": "14", +// "Line": "16", // "PkgPath": "gno.land/r/crossrealm_test" // } // }, diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 298655f7291..d0f488d86b2 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -2,12 +2,14 @@ package crossrealm_test import ( + "std" + crossrealm "gno.land/r/demo/tests/crossrealm" ) type container struct{ *fooer } -func (container) Foo() { println("hello container") } +func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } type fooer struct{} @@ -22,7 +24,7 @@ func main() { } // Output: -// hello container +// hello container gno.land/r/crossrealm_test // . // Error: @@ -593,7 +595,7 @@ func main() { // "Location": { // "Column": "1", // "File": "main.gno", -// "Line": "10", +// "Line": "12", // "PkgPath": "gno.land/r/crossrealm_test" // } // }, @@ -664,7 +666,7 @@ func main() { // "Location": { // "Column": "1", // "File": "main.gno", -// "Line": "16", +// "Line": "18", // "PkgPath": "gno.land/r/crossrealm_test" // } // }, diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno index 45441d4572d..cc46e3df514 100644 --- a/gnovm/tests/files/zrealm_crossrealm18.gno +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -2,12 +2,14 @@ package crossrealm_test import ( + "std" + crossrealm "gno.land/r/demo/tests/crossrealm" ) type fooer struct{} -func (fooer) Foo() { println("hello") } +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f crossrealm.Fooer = crossrealm.SetFooer(&fooer{}) @@ -21,8 +23,8 @@ func main() { } // Output: -// hello -// hello +// hello gno.land/r/crossrealm_test +// hello gno.land/r/crossrealm_test // . // Error: From 4ca57af51b3a0350c9204478999bbf76c036313d Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:46:49 -0500 Subject: [PATCH 14/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/stdlibs/math/overflow/overflow.gno | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/stdlibs/math/overflow/overflow.gno b/gnovm/stdlibs/math/overflow/overflow.gno index 9bdeff0720f..0bc2e03a522 100644 --- a/gnovm/stdlibs/math/overflow/overflow.gno +++ b/gnovm/stdlibs/math/overflow/overflow.gno @@ -223,7 +223,7 @@ func Div8p(a, b int8) int8 { func Quo8(a, b int8) (int8, int8, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == math.MinInt8 { + } else if b == -1 && a == int8(math.MinInt8) { return 0, 0, false } c := a / b @@ -313,7 +313,7 @@ func Div16p(a, b int16) int16 { func Quo16(a, b int16) (int16, int16, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == math.MinInt16 { + } else if b == -1 && a == int16(math.MinInt16) { return 0, 0, false } c := a / b @@ -403,7 +403,7 @@ func Div32p(a, b int32) int32 { func Quo32(a, b int32) (int32, int32, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == math.MinInt32 { + } else if b == -1 && a == int32(math.MinInt32) { return 0, 0, false } c := a / b From 19c2e796e5608bf42e9250b79ca25079ceb7739b Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:16:26 -0500 Subject: [PATCH 15/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/files/zrealm_crossrealm19.gno | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm19.gno diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno new file mode 100644 index 00000000000..867dbbd071f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -0,0 +1,35 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + s string +} + +func (f *fooer) Foo() { + f.s = "B" + println("hello " + f.s + " " + std.CurrentRealm().PkgPath()) +} + +var f *fooer + +func init() { + f = &fooer{s: "A"} + crossrealm.SetFooer(f) + crossrealm.CallFoo() +} + +func main() { + print(".") +} + +// Output: + +// Error: + +// Realm: From 8014a85bcb68ae60c223e477e2af2003da19b5a9 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:16:26 -0500 Subject: [PATCH 16/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/files/zrealm_crossrealm19.gno | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm19.gno diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno new file mode 100644 index 00000000000..867dbbd071f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -0,0 +1,35 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + s string +} + +func (f *fooer) Foo() { + f.s = "B" + println("hello " + f.s + " " + std.CurrentRealm().PkgPath()) +} + +var f *fooer + +func init() { + f = &fooer{s: "A"} + crossrealm.SetFooer(f) + crossrealm.CallFoo() +} + +func main() { + print(".") +} + +// Output: + +// Error: + +// Realm: From 8e69d3ad96f04cbdde007895fb248a57281dbb90 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:02:06 -0500 Subject: [PATCH 17/21] Revert "chore: fixup" This reverts commit 4ca57af51b3a0350c9204478999bbf76c036313d. --- gnovm/stdlibs/math/overflow/overflow.gno | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/stdlibs/math/overflow/overflow.gno b/gnovm/stdlibs/math/overflow/overflow.gno index 0bc2e03a522..9bdeff0720f 100644 --- a/gnovm/stdlibs/math/overflow/overflow.gno +++ b/gnovm/stdlibs/math/overflow/overflow.gno @@ -223,7 +223,7 @@ func Div8p(a, b int8) int8 { func Quo8(a, b int8) (int8, int8, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == int8(math.MinInt8) { + } else if b == -1 && a == math.MinInt8 { return 0, 0, false } c := a / b @@ -313,7 +313,7 @@ func Div16p(a, b int16) int16 { func Quo16(a, b int16) (int16, int16, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == int16(math.MinInt16) { + } else if b == -1 && a == math.MinInt16 { return 0, 0, false } c := a / b @@ -403,7 +403,7 @@ func Div32p(a, b int32) int32 { func Quo32(a, b int32) (int32, int32, bool) { if b == 0 { return 0, 0, false - } else if b == -1 && a == int32(math.MinInt32) { + } else if b == -1 && a == math.MinInt32 { return 0, 0, false } c := a / b From e206804b3c3d56a80ccc7f108ec8b4d798694d3e Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:04:47 -0500 Subject: [PATCH 18/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../{zrealm_crossrealm14.gno => zrealm_crossrealm14_stdlibs.gno} | 0 .../{zrealm_crossrealm15.gno => zrealm_crossrealm15_stdlibs.gno} | 0 .../{zrealm_crossrealm16.gno => zrealm_crossrealm16_stdlibs.gno} | 0 .../{zrealm_crossrealm17.gno => zrealm_crossrealm17_stdlibs.gno} | 0 .../{zrealm_crossrealm18.gno => zrealm_crossrealm18_stdlibs.gno} | 0 .../{zrealm_crossrealm19.gno => zrealm_crossrealm19_stdlibs.gno} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm14.gno => zrealm_crossrealm14_stdlibs.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm15.gno => zrealm_crossrealm15_stdlibs.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm16.gno => zrealm_crossrealm16_stdlibs.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm17.gno => zrealm_crossrealm17_stdlibs.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm18.gno => zrealm_crossrealm18_stdlibs.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm19.gno => zrealm_crossrealm19_stdlibs.gno} (100%) diff --git a/gnovm/tests/files/zrealm_crossrealm14.gno b/gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm14.gno rename to gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm15.gno rename to gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm16.gno rename to gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm17.gno rename to gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm18.gno rename to gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm19.gno rename to gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno From a91c84a6c67e4cf3c4b1e159b560c1adceb5b0bf Mon Sep 17 00:00:00 2001 From: jaekwon Date: Sun, 7 Jul 2024 16:05:33 -0700 Subject: [PATCH 19/21] change realm to receiver's --- examples/gno.land/r/demo/tests/tests.gno | 2 + gnovm/pkg/gnolang/machine.go | 54 +++++++++----- gnovm/tests/files/zrealm_crossrealm16.gno | 3 +- gnovm/tests/files/zrealm_crossrealm17.gno | 3 +- .../files/zrealm_crossrealm19_stdlibs.gno | 37 ++++++++++ .../files/zrealm_crossrealm3_stdlibs.gno | 11 ++- .../files/zrealm_crossrealm4_stdlibs.gno | 12 ++-- .../files/zrealm_crossrealm5_stdlibs.gno | 8 +-- gnovm/tests/files/zrealm_tests0_stdlibs.gno | 70 +++++++++++-------- 9 files changed, 133 insertions(+), 67 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index 773412c3db9..2489a2214ba 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -49,6 +49,8 @@ type TestRealmObject struct { Field string } +var TestRealmObjectValue TestRealmObject + func ModifyTestRealmObject(t *TestRealmObject) { t.Field += "_modified" } diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 850da3d3c0f..c8afd774ab9 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -36,8 +36,8 @@ func (e Exception) Sprint(m *Machine) string { type Machine struct { // State - Ops []Op // main operations - NumOps int + Ops []Op // operations stack + NumOps int // number of operations Values []TypedValue // buffer of values to be operated on NumValues int // number of values Exprs []Expr // pending expressions @@ -47,9 +47,9 @@ type Machine struct { Package *PackageValue // active package Realm *Realm // active realm Alloc *Allocator // memory allocations - Exceptions []Exception - NumResults int // number of results returned - Cycles int64 // number of "cpu" cycles + Exceptions []Exception // exceptions stack + NumResults int // number of results returned + Cycles int64 // number of "cpu" cycles performed Debugger Debugger @@ -199,6 +199,7 @@ func (m *Machine) Release() { machinePool.Put(m) } +// Convenience for initial setup of the machine. func (m *Machine) SetActivePackage(pv *PackageValue) { if err := m.CheckEmpty(); err != nil { panic(errors.Wrap(err, "set package when machine not empty")) @@ -210,6 +211,14 @@ func (m *Machine) SetActivePackage(pv *PackageValue) { } } +func (m *Machine) setCurrentPackage(pv *PackageValue) { + m.Package = pv + rlm := pv.GetRealm() + if rlm != nil { + m.Realm = rlm + } +} + //---------------------------------------- // top level Run* methods. @@ -1797,29 +1806,36 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { m.Printf("+F %#v\n", fr) } m.Frames = append(m.Frames, fr) - pv := fv.GetPackage(m.Store) - if pv == nil { - panic(fmt.Sprintf("package value missing in store: %s", fv.PkgPath)) - } - rlm := pv.GetRealm() - if rlm == nil && recv.IsDefined() { + if recv.IsDefined() { + // If the receiver is defined, we enter the receiver's realm. obj := recv.GetFirstObject(m.Store) if obj == nil { // could be a nil receiver. - // just ignore. + // set package and realm of function. + pv := fv.GetPackage(m.Store) + if pv == nil { + panic(fmt.Sprintf("package value missing in store: %s", fv.PkgPath)) + } + m.setCurrentPackage(pv) // maybe new realm } else { recvOID := obj.GetObjectInfo().ID - if !recvOID.IsZero() { + if recvOID.IsZero() { + // receiver isn't owned yet. + // just continue with current package and realm. + // XXX is this reasonable? + } else { // override the pv and rlm with receiver's. recvPkgOID := ObjectIDFromPkgID(recvOID.PkgID) - pv = m.Store.GetObject(recvPkgOID).(*PackageValue) - rlm = pv.GetRealm() // done + pv := m.Store.GetObject(recvPkgOID).(*PackageValue) + m.setCurrentPackage(pv) // maybe new realm } } - } - m.Package = pv - if rlm != nil && m.Realm != rlm { - m.Realm = rlm // enter new realm + } else { + pv := fv.GetPackage(m.Store) + if pv == nil { + panic(fmt.Sprintf("package value missing in store: %s", fv.PkgPath)) + } + m.setCurrentPackage(pv) // maybe new realm } } diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index db924432271..0fef0148b7d 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -443,6 +443,7 @@ func main() { // } // ] // } +// switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ // "Blank": {}, @@ -593,5 +594,3 @@ func main() { // } // ] // } -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index cb794c380d3..b3cdfc885ca 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -494,6 +494,7 @@ func main() { // } // ] // } +// switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ // "Blank": {}, @@ -676,5 +677,3 @@ func main() { // } // ] // } -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno new file mode 100644 index 00000000000..6a51623f7bc --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm19_stdlibs.gno @@ -0,0 +1,37 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + s string +} + +func (f *fooer) Foo() { + f.s = "B" + println("hello " + f.s + " " + std.CurrentRealm().PkgPath()) +} + +var f *fooer + +func init() { + f = &fooer{s: "A"} + crossrealm.SetFooer(f) + crossrealm.CallFoo() +} + +func main() { + print(".") +} + +// Output: +// hello B gno.land/r/demo/tests/crossrealm +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno index 6aa9c5247d8..105066c5ba7 100644 --- a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno @@ -13,10 +13,15 @@ func init() { } func main() { - // NOTE: but it is invalid to modify it using an external realm function. + // NOTE: it is valid to modify it using an external realm function, + // because the receiver makes the function run under this realm. somevalue.Modify() println(somevalue) + // we can even modify it directly. + somevalue.Field = "test_modified_directly" + println(somevalue) } -// Error: -// cannot modify external-realm or non-realm object +// Output: +// (struct{("test_modified" string)} gno.land/r/demo/tests.TestRealmObject) +// (struct{("test_modified_directly" string)} gno.land/r/demo/tests.TestRealmObject) diff --git a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno index 6aa9c5247d8..ed73b7ad6bb 100644 --- a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno @@ -5,18 +5,18 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. -var somevalue tests.TestRealmObject +// NOTE: it is valid to persist a pointer to an external object +var somevalue *tests.TestRealmObject func init() { - somevalue.Field = "test" + somevalue = &tests.TestRealmObjectValue } func main() { - // NOTE: but it is invalid to modify it using an external realm function. + // NOTE: it is valid to modify it using the external realm function. somevalue.Modify() println(somevalue) } -// Error: -// cannot modify external-realm or non-realm object +// Output: +// &(struct{("_modified" string)} gno.land/r/demo/tests.TestRealmObject) diff --git a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno index 6aa9c5247d8..c7560b21463 100644 --- a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno @@ -6,15 +6,15 @@ import ( ) // NOTE: it is valid to persist external realm types. -var somevalue tests.TestRealmObject +var somevalue *tests.TestRealmObject func init() { - somevalue.Field = "test" + somevalue = &tests.TestRealmObjectValue } func main() { - // NOTE: but it is invalid to modify it using an external realm function. - somevalue.Modify() + // NOTE: but it is invalid to modify it directly. + somevalue.Field = "test" println(somevalue) } diff --git a/gnovm/tests/files/zrealm_tests0_stdlibs.gno b/gnovm/tests/files/zrealm_tests0_stdlibs.gno index 70ac3dd810d..5cd57c71a4a 100644 --- a/gnovm/tests/files/zrealm_tests0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_tests0_stdlibs.gno @@ -23,7 +23,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests"] -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19]={ // "Fields": [ // { // "T": { @@ -37,17 +37,17 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19", // "ModTime": "0", -// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", +// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18", // "RefCount": "1" // } // } -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18]={ // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18", // "ModTime": "0", -// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:16", +// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", // "RefCount": "1" // }, // "Value": { @@ -57,12 +57,12 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "d3d6ffa52602f2bc976051d79294d219750aca64", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18" +// "Hash": "6b9b731f6118c2419f23ba57e1481679f17f4a8f", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19" // } // } // } -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:16]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17]={ // "Data": null, // "List": [ // { @@ -77,8 +77,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "4ea1e08156f3849b74a0f41f92cd4b48fb94926b", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:11" +// "Hash": "148d314678615253ee2032d7ecff6b144b474baf", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:12" // }, // "Index": "0", // "TV": null @@ -96,8 +96,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "ce86ea1156e75a44cd9d7ba2261819b100aa4ed1", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14" +// "Hash": "fa414e1770821b8deb8e6d46d97828c47f7d5fa5", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:15" // }, // "Index": "0", // "TV": null @@ -115,8 +115,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "b66192fbd8a8dde79b6f854b5cc3c4cc965cfd92", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17" +// "Hash": "aaa64d049cf8660d689780acac9f546f270eaa4e", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18" // }, // "Index": "0", // "TV": null @@ -124,7 +124,7 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:16", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", // "ModTime": "0", // "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "RefCount": "1" @@ -135,7 +135,7 @@ func main() { // "ObjectInfo": { // "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "IsEscaped": true, -// "ModTime": "15", +// "ModTime": "16", // "RefCount": "5" // }, // "Parent": null, @@ -400,7 +400,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "56", +// "Line": "58", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1197,7 +1197,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "52", +// "Line": "54", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1246,7 +1246,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "74", +// "Line": "76", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1282,7 +1282,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "79", +// "Line": "81", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1318,7 +1318,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "87", +// "Line": "89", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1364,7 +1364,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "91", +// "Line": "93", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1420,7 +1420,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "95", +// "Line": "97", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1477,7 +1477,7 @@ func main() { // "Location": { // "Column": "1", // "File": "tests.gno", -// "Line": "99", +// "Line": "101", // "PkgPath": "gno.land/r/demo/tests" // } // }, @@ -1512,8 +1512,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "ad25f70f66c8c53042afd1377e5ff5ab744bf1a5", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:16" +// "Hash": "3c58838c5667649add1ff8ee48a1cdc187fcd2ef", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17" // }, // "Length": "3", // "Maxcap": "3", @@ -1563,6 +1563,17 @@ func main() { // }, // { // "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.TestRealmObject" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "5e56ba76fc0add1a3a67f7a8b6709f4f27215f93", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:10" +// } +// }, +// { +// "T": { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", @@ -1590,10 +1601,7 @@ func main() { // } // ] // } -// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13] -// switchrealm["gno.land/r/demo/tests_foo"] -// switchrealm["gno.land/r/demo/tests_foo"] -// switchrealm["gno.land/r/demo/tests_foo"] +// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14] // switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests"] // switchrealm["gno.land/r/demo/tests_test"] From 91134caedeedf6bf3df7be4292d19f8aa3fe1ee1 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:09:37 -0500 Subject: [PATCH 20/21] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno index c2c5575bfcd..32b4edd566e 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_stdlibs.gno @@ -24,7 +24,7 @@ func main() { } // Output: -// hello gno.land/r/crossrealm_test +// hello gno.land/r/demo/tests/crossrealm // . // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno index 7b766ba1a88..d67dc7a7aa7 100644 --- a/gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm16_stdlibs.gno @@ -21,7 +21,7 @@ func main() { } // Output: -// hello gno.land/r/crossrealm_test +// hello gno.land/r/demo/tests/crossrealm // . // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno index d52541bb653..ce6f59bcf8c 100644 --- a/gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm17_stdlibs.gno @@ -24,7 +24,7 @@ func main() { } // Output: -// hello container gno.land/r/crossrealm_test +// hello container gno.land/r/demo/tests/crossrealm // . // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno index cc46e3df514..a1c8888fb7d 100644 --- a/gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm18_stdlibs.gno @@ -23,13 +23,12 @@ func main() { } // Output: -// hello gno.land/r/crossrealm_test -// hello gno.land/r/crossrealm_test +// hello gno.land/r/demo/tests/crossrealm +// hello gno.land/r/demo/tests/crossrealm // . // Error: // Realm: -// switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] From c15ff5885cbaf36b79257084d0fb33d71368fe41 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:44:11 +0200 Subject: [PATCH 21/21] chore: add new cross realm test Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../files/zrealm_crossrealm20_stdlibs.gno | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm20_stdlibs.gno diff --git a/gnovm/tests/files/zrealm_crossrealm20_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm20_stdlibs.gno new file mode 100644 index 00000000000..73eb8e09dc0 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20_stdlibs.gno @@ -0,0 +1,37 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +var ( + a int = 10 + f *fooer = &fooer{} +) + +func (f *fooer) Foo() { a *= 2 } + +func init() { + a++ // a=11 + crossrealm.SetFooer(f) // a=11 + a++ // a=12 +} + +func main() { + a++ // a=13 + crossrealm.CallFoo() // a=26 + a++ // a=27 + println(a) +} + +// Output: +// 27 + +// Error: + +// Realm: