From 2dcdfd55cfa7fab0ddb438b6d0046ec4013054a2 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 24 Jun 2024 16:52:58 +0800 Subject: [PATCH 01/88] naive fix --- gnovm/pkg/gnolang/gno_test.go | 84 +++++++++++++++++------------------ gnovm/pkg/gnolang/uverse.go | 5 ++- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 54d808faefc..583a3a244ab 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -159,37 +159,37 @@ func main() { m.RunMain() } -func BenchmarkPreprocessForLoop(b *testing.B) { - m := NewMachine("test", nil) - c := `package test -func main() { - for i:=0; i<10000; i++ {} -}` - n := MustParseFile("main.go", c) - m.RunFiles(n) - - for i := 0; i < b.N; i++ { - m.RunMain() - } -} - -func BenchmarkIfStatement(b *testing.B) { - m := NewMachine("test", nil) - c := `package test -func main() { - for i:=0; i<10000; i++ { - if i > 10 { - - } - } -}` - n := MustParseFile("main.go", c) - m.RunFiles(n) - - for i := 0; i < b.N; i++ { - m.RunMain() - } -} +//func BenchmarkPreprocessForLoop(b *testing.B) { +// m := NewMachine("test", nil) +// c := `package test +//func main() { +// for i:=0; i<10000; i++ {} +//}` +// n := MustParseFile("main.go", c) +// m.RunFiles(n) +// +// for i := 0; i < b.N; i++ { +// m.RunMain() +// } +//} + +//func BenchmarkIfStatement(b *testing.B) { +// m := NewMachine("test", nil) +// c := `package test +//func main() { +// for i:=0; i<10000; i++ { +// if i > 10 { +// +// } +// } +//}` +// n := MustParseFile("main.go", c) +// m.RunFiles(n) +// +// for i := 0; i < b.N; i++ { +// m.RunMain() +// } +//} func TestDoOpEvalBaseConversion(t *testing.T) { m := NewMachine("test", nil) @@ -401,17 +401,17 @@ func BenchmarkBenchdata(b *testing.B) { name += "_param:" + param } b.Run(name, func(b *testing.B) { - if strings.HasPrefix(name, "matrix.gno_param") { - // CGO_ENABLED=0 go test -bench . -benchmem ./... -short -run=^$ -cpu 1,2 -count=1 ./... - // That is not just exposing test and benchmark traces as output, but these benchmarks are failing - // making the output unparseable: - /* - BenchmarkBenchdata/matrix.gno_param:3 panic: runtime error: index out of range [31] with length 25 [recovered] - panic: runtime error: index out of range [31] with length 25: - ... - */ - b.Skip("it panics causing an error when parsing benchmark results") - } + //if strings.HasPrefix(name, "matrix.gno_param") { + // // CGO_ENABLED=0 go test -bench . -benchmem ./... -short -run=^$ -cpu 1,2 -count=1 ./... + // // That is not just exposing test and benchmark traces as output, but these benchmarks are failing + // // making the output unparseable: + // /* + // BenchmarkBenchdata/matrix.gno_param:3 panic: runtime error: index out of range [31] with length 25 [recovered] + // panic: runtime error: index out of range [31] with length 25: + // ... + // */ + // b.Skip("it panics causing an error when parsing benchmark results") + //} // Gen template with N and param. var buf bytes.Buffer diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index 880a75396ca..ad886958adc 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -65,9 +65,11 @@ var ( const uversePkgPath = ".uverse" +var done bool + // Always returns a new copy from the latest state of source. func Uverse() *PackageValue { - if uverseValue == nil { + if uverseValue == nil || !done { pn := UverseNode() uverseValue = pn.NewPackage() } @@ -1017,6 +1019,7 @@ func UverseNode() *PackageNode { m.Exceptions = nil }, ) + done = true return uverseNode } From fb2f40842a52b8e26e6b58196273879806a675ea Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 22 Aug 2024 23:39:02 +0800 Subject: [PATCH 02/88] fix untyped bool --- gnovm/pkg/gnolang/preprocess.go | 3 +++ gnovm/tests/files/types/eql_0f49.gno | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gnovm/tests/files/types/eql_0f49.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index ba60ead28f6..d7b52e3eed9 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1207,6 +1207,9 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { "incompatible types in binary expression: %v %v %v", lt.TypeID(), n.Op, rt.TypeID())) } + // convert untyped to typed + checkOrConvertType(store, last, &n.Left, defaultTypeOf(lt), false) + checkOrConvertType(store, last, &n.Right, defaultTypeOf(rt), false) } else { // left untyped, right typed checkOrConvertType(store, last, &n.Left, rt, false) } diff --git a/gnovm/tests/files/types/eql_0f49.gno b/gnovm/tests/files/types/eql_0f49.gno new file mode 100644 index 00000000000..b5a4bf4ed05 --- /dev/null +++ b/gnovm/tests/files/types/eql_0f49.gno @@ -0,0 +1,21 @@ +package main + +func main() { + a := "1234" + b := "1234" + + cond := a == b + println(cond) + println(cond == (a == b)) + println((a == b) == cond) + println((a == b) == (a == b)) + println(cond && (a == b)) + println(cond || (a > b)) + +} + +// true +// true +// true +// true +// true From 22f973f97d5825455ed2eebd57aec01d802ec8ff Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 27 Aug 2024 10:02:11 +0800 Subject: [PATCH 03/88] revert un-intentional change --- gnovm/pkg/gnolang/gno_test.go | 84 +++++++++++++++++------------------ gnovm/pkg/gnolang/uverse.go | 5 +-- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 583a3a244ab..2c1ed2f003d 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -159,37 +159,37 @@ func main() { m.RunMain() } -//func BenchmarkPreprocessForLoop(b *testing.B) { -// m := NewMachine("test", nil) -// c := `package test -//func main() { -// for i:=0; i<10000; i++ {} -//}` -// n := MustParseFile("main.go", c) -// m.RunFiles(n) -// -// for i := 0; i < b.N; i++ { -// m.RunMain() -// } -//} - -//func BenchmarkIfStatement(b *testing.B) { -// m := NewMachine("test", nil) -// c := `package test -//func main() { -// for i:=0; i<10000; i++ { -// if i > 10 { -// -// } -// } -//}` -// n := MustParseFile("main.go", c) -// m.RunFiles(n) -// -// for i := 0; i < b.N; i++ { -// m.RunMain() -// } -//} +func BenchmarkPreprocessForLoop(b *testing.B) { + m := NewMachine("test", nil) + c := `package test +func main() { + for i:=0; i<10000; i++ {} +}` + n := MustParseFile("main.go", c) + m.RunFiles(n) + + for i := 0; i < b.N; i++ { + m.RunMain() + } +} + +func BenchmarkIfStatement(b *testing.B) { + m := NewMachine("test", nil) + c := `package test +func main() { + for i:=0; i<10000; i++ { + if i > 10 { + + } + } +}` + n := MustParseFile("main.go", c) + m.RunFiles(n) + + for i := 0; i < b.N; i++ { + m.RunMain() + } +} func TestDoOpEvalBaseConversion(t *testing.T) { m := NewMachine("test", nil) @@ -401,17 +401,17 @@ func BenchmarkBenchdata(b *testing.B) { name += "_param:" + param } b.Run(name, func(b *testing.B) { - //if strings.HasPrefix(name, "matrix.gno_param") { - // // CGO_ENABLED=0 go test -bench . -benchmem ./... -short -run=^$ -cpu 1,2 -count=1 ./... - // // That is not just exposing test and benchmark traces as output, but these benchmarks are failing - // // making the output unparseable: - // /* - // BenchmarkBenchdata/matrix.gno_param:3 panic: runtime error: index out of range [31] with length 25 [recovered] - // panic: runtime error: index out of range [31] with length 25: - // ... - // */ - // b.Skip("it panics causing an error when parsing benchmark results") - //} + if strings.HasPrefix(name, "matrix.gno_param") { + // CGO_ENABLED=0 go test -bench . -benchmem ./... -short -run=^$ -cpu 1,2 -count=1 ./... + // That is not just exposing test and benchmark traces as output, but these benchmarks are failing + // making the output unparseable: + /* + BenchmarkBenchdata/matrix.gno_param:3 panic: runtime error: index out of range [31] with length 25 [recovered] + panic: runtime error: index out of range [31] with length 25: + ... + */ + b.Skip("it panics causing an error when parsing benchmark results") + } // Gen template with N and param. var buf bytes.Buffer diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index ad886958adc..880a75396ca 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -65,11 +65,9 @@ var ( const uversePkgPath = ".uverse" -var done bool - // Always returns a new copy from the latest state of source. func Uverse() *PackageValue { - if uverseValue == nil || !done { + if uverseValue == nil { pn := UverseNode() uverseValue = pn.NewPackage() } @@ -1019,7 +1017,6 @@ func UverseNode() *PackageNode { m.Exceptions = nil }, ) - done = true return uverseNode } From 2926b3d2fdeb39eac6e6da0d58a8d0ccda3f2dbd Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 23 Sep 2024 01:30:37 +0800 Subject: [PATCH 04/88] test files --- .../r/demo/tests/crossrealm/crossrealm2.gno | 27 ++++++++++++ .../r/demo/tests/crossrealm/crossrealm3.gno | 17 ++++++++ gnovm/tests/files/zrealm_crossrealm15.gno | 35 ++++++++++++++++ gnovm/tests/files/zrealm_crossrealm16.gno | 24 +++++++++++ gnovm/tests/files/zrealm_crossrealm17.gno | 31 ++++++++++++++ gnovm/tests/files/zrealm_crossrealm18.gno | 34 +++++++++++++++ gnovm/tests/files/zrealm_crossrealm19.gno | 33 +++++++++++++++ gnovm/tests/files/zrealm_crossrealm20.gno | 33 +++++++++++++++ gnovm/tests/files/zrealm_crossrealm21.gno | 24 +++++++++++ gnovm/tests/files/zrealm_crossrealm22.gno | 22 ++++++++++ gnovm/tests/files/zrealm_crossrealm23.gno | 22 ++++++++++ gnovm/tests/files/zrealm_crossrealm23a.gno | 22 ++++++++++ gnovm/tests/files/zrealm_crossrealm24.gno | 22 ++++++++++ gnovm/tests/files/zrealm_crossrealm25.gno | 39 ++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm25a.gno | 41 +++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm26.gno | 32 +++++++++++++++ gnovm/tests/files/zrealm_crossrealm27.gno | 29 +++++++++++++ gnovm/tests/files/zrealm_crossrealm27a.gno | 33 +++++++++++++++ 18 files changed, 520 insertions(+) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm15.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm16.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm17.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm18.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm19.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm20.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm21.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm24.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm25.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm25a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm26.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm27.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm27a.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno new file mode 100644 index 00000000000..8f12ec1322d --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno @@ -0,0 +1,27 @@ +package crossrealm + +// XXX, how about not interface +type Fooer interface{ Foo() } + +var fooer Fooer + +func SetFooer(f Fooer) Fooer { + fooer = f + return fooer +} + +func CallFoo() { fooer.Foo() } + +// container in external realm +type Container struct { + f Fooer +} + +var container Container // TODO, check does this attach or not + +func AttachContainer() { + container = Container{} +} +func SetContainer(f Fooer) { + container.f = f +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno new file mode 100644 index 00000000000..6fb1b958baf --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno @@ -0,0 +1,17 @@ +package crossrealm + +type Bar struct { + A int +} + +var bar *Bar + +func SetBar(b *Bar) *Bar { + bar = b + return bar +} + +func CallBar() { + bar.A += 1 + println(bar.A) +} diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno new file mode 100644 index 00000000000..fd870731c0e --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm15.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{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f *fooer + +// XXX, this attach a heapItem to current realm +func init() { + f = &fooer{} +} + +func main() { + // XXX, this associate a pointer to a value(already attached to local realm) + // to external realm, no attachment happens to the external realm. + crossrealm.SetFooer(f) + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello gno.land/r/demo/tests/crossrealm +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno new file mode 100644 index 00000000000..fd9f9889c38 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 crossrealm.Bar + +func init() { + b0 = crossrealm.Bar{A: 1} // attach to this realm +} + +func main() { + crossrealm.SetBar(&b0) // set reference to external realm + crossrealm.CallBar() + print(".") +} + +// Output: +// 1 +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno new file mode 100644 index 00000000000..2cc82b960d5 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -0,0 +1,31 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type container struct{ *fooer } + +func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } + +type fooer struct{} + +var f *fooer + +func main() { + // not finalize yet, so this reference can not be attached to external realm, + // can only be associated to un-attached objects, only until the un-attached + // objects has not been attached to the external realm yet. + f = &fooer{} + c := &container{f} + crossrealm.SetFooer(c) + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello container 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..a1c8888fb7d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -0,0 +1,34 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f crossrealm.Fooer = crossrealm.SetFooer(&fooer{}) + +func init() { + crossrealm.CallFoo() +} + +func main() { + crossrealm.CallFoo() + print(".") +} + +// Output: +// hello gno.land/r/demo/tests/crossrealm +// hello gno.land/r/demo/tests/crossrealm +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno new file mode 100644 index 00000000000..62b6d08c78f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 = crossrealm.Bar{A: 1} + +// un-attached package level var +// is this attached? or not? another function to attach? +//var b *crossrealm.Bar = crossrealm.SetBar(&b0) + +func init() { + // crossrealm.CallFoo() + crossrealm.SetBar(&b0) +} + +func main() { + crossrealm.CallBar() + print(".") +} + +// Output: +// hello gno.land/r/demo/tests/crossrealm +// hello gno.land/r/demo/tests/crossrealm +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno new file mode 100644 index 00000000000..62b6d08c78f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 = crossrealm.Bar{A: 1} + +// un-attached package level var +// is this attached? or not? another function to attach? +//var b *crossrealm.Bar = crossrealm.SetBar(&b0) + +func init() { + // crossrealm.CallFoo() + crossrealm.SetBar(&b0) +} + +func main() { + crossrealm.CallBar() + print(".") +} + +// Output: +// hello gno.land/r/demo/tests/crossrealm +// hello gno.land/r/demo/tests/crossrealm +// . + +// Error: + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno new file mode 100644 index 00000000000..5babaff955b --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 crossrealm.Bar + +// XXX, this should fail while trying to attach +// value of type defined in another realm. +// NOTE: the check can be in runtime or in preprocess. +func init() { + b0 = crossrealm.Bar{A: 1} +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno new file mode 100644 index 00000000000..8e294e969d3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type Bar struct { + A int +} + +var b0 Bar + +// XXX this works attach value with type defined in same realm +func init() { + b0 = Bar{A: 1} +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm23.gno b/gnovm/tests/files/zrealm_crossrealm23.gno new file mode 100644 index 00000000000..ec2f19a9351 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import "gno.land/p/demo/tests/p_crossrealm" + +var b0 p_crossrealm.Container + +// XXX, this works attach value with type defined in p +func init() { + b0 = p_crossrealm.Container{ + A: 1, + } +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno new file mode 100644 index 00000000000..21416cdde8f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import "gno.land/p/demo/tests/p_crossrealm" + +var b0 *p_crossrealm.Container + +// XXX, this works, attach reference with type defined in p +func init() { + b0 = &p_crossrealm.Container{ + A: 1, + } +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno new file mode 100644 index 00000000000..e6c7d8d2e3c --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 *crossrealm.Bar + +// XXX, should work to attach by reference +func init() { + b0 = &crossrealm.Bar{A: 1} +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno new file mode 100644 index 00000000000..5ea5e4a520f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -0,0 +1,39 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +// When an association occurs by reference to an object already +// attached to an external realm, no attachment occurs. For example, +// pointers to external realm attached objects may be associated +// with a realm object (whether attached or not), such as assigned +// to the field of a struct, but this does not attach the external +// realm object to the container, in this case the struct. +func init() { + f = fooer{} +} + +func main() { + // XXX, this associate a pointer to a value(already attached to local realm) + // to external realm, no attachment happens to the external realm. + crossrealm.AttachContainer() // this attach container first + crossrealm.SetContainer(&f) + print(".") +} + +// Output: +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno new file mode 100644 index 00000000000..1700e72b25f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -0,0 +1,41 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +// When an association occurs by reference to an object already +// attached to an external realm, no attachment occurs. For example, +// pointers to external realm attached objects may be associated +// with a realm object (whether attached or not), such as assigned +// to the field of a struct, but this does not attach the external +// realm object to the container, in this case the struct. +func init() { + f = fooer{} +} + +func main() { + // XXX, this associate a pointer to a value(not attached) + // to external realm, no attachment happens to the external realm. + + // XXX, attach to un-attached external realm + //crossrealm.AttachContainer() // this attach container first + crossrealm.SetContainer(&f) + print(".") +} + +// Output: +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm26.gno b/gnovm/tests/files/zrealm_crossrealm26.gno new file mode 100644 index 00000000000..6fff7ac6b96 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm26.gno @@ -0,0 +1,32 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +// Pointers to external realm objects that are not yet +// attached to the external realm may not be associated +// with an attached object. + +func main() { + crossrealm.AttachContainer() // this attach container first + f = fooer{} // not attached to local realm yet, cannot be able to attach to external attached even by reference + crossrealm.SetContainer(&f) + print(".") +} + +// Output: +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno new file mode 100644 index 00000000000..28a091d7e7c --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -0,0 +1,29 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +// XXX, this should work when reference to not attached local object +// associated to external realm *NOT* attached object. +func main() { + f = fooer{} + crossrealm.SetContainer(&f) + print(".") +} + +// Output: +// . + +// Error: + +// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm27a.gno new file mode 100644 index 00000000000..6d29277240e --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm27a.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +// XXX, this should work when reference to not attached local object +// associated to external realm *NOT* attached object. +// XXX, panic should happen when the attachment happen in external realm + +// In this way, all references to external realm objects that are reachable +// from a realm’s package global variables must already be attached to the external realm. +func main() { + f = fooer{} + crossrealm.SetContainer(&f) + print(".") +} + +// Output: +// . + +// Error: + +// Realm: From c3e3bdd6cc403e6e1d91e63bf44685f8f018982e Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 23 Sep 2024 10:06:52 +0200 Subject: [PATCH 05/88] debug --- gnovm/pkg/gnolang/machine.go | 83 +++++++++++++++----- gnovm/pkg/gnolang/op_assign.go | 3 + gnovm/pkg/gnolang/op_call.go | 7 ++ gnovm/pkg/gnolang/op_eval.go | 3 + gnovm/pkg/gnolang/op_exec.go | 2 + gnovm/pkg/gnolang/op_expressions.go | 3 + gnovm/pkg/gnolang/ownership.go | 51 ++++++++---- gnovm/pkg/gnolang/realm.go | 116 +++++++++++++++++++++++++++- gnovm/pkg/gnolang/store.go | 5 ++ gnovm/pkg/gnolang/values.go | 22 ++++++ 10 files changed, 255 insertions(+), 40 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 24f94abc10b..ad3fbeee7f2 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -47,8 +47,8 @@ func (e UnhandledPanicError) Error() 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 @@ -58,9 +58,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 @@ -210,17 +210,28 @@ func (m *Machine) Release() { machinePool.Put(m) } +// Convenience for initial setup of the machine. func (m *Machine) SetActivePackage(pv *PackageValue) { + //fmt.Println("---SetActivePackage, pv: ", pv) if err := m.CheckEmpty(); err != nil { panic(errors.Wrap(err, "set package when machine not empty")) } m.Package = pv m.Realm = pv.GetRealm() + //fmt.Println("---SetActivePackage, m.Realm", m.Realm) m.Blocks = []*Block{ pv.GetBlock(m.Store), } } +func (m *Machine) setCurrentPackage(pv *PackageValue) { + m.Package = pv + rlm := pv.GetRealm() + if rlm != nil { + m.Realm = rlm + } +} + //---------------------------------------- // top level Run* methods. @@ -275,6 +286,7 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *std.MemPackage, save bool) } func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { + fmt.Println("---runMemPackage, save: ", save) // parse files. files := ParseMemPackage(memPkg) if !overrides && checkDuplicates(files) { @@ -296,6 +308,7 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* m.SetActivePackage(pv) // run files. updates := m.RunFileDecls(files.Files...) + fmt.Println("---updates: ", updates) // save package value and mempackage. // XXX save condition will be removed once gonative is removed. var throwaway *Realm @@ -305,6 +318,7 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* if throwaway != nil { m.Realm = throwaway } + fmt.Println("---save, throwaway: ", throwaway) } // run init functions m.runInitFromUpdates(pv, updates) @@ -714,13 +728,16 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // multiple files belonging to the same package in // lexical file name order to a compiler." func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { + fmt.Println("---runInitFromUpdates") for _, tv := range updates { + fmt.Println("---tv: ", tv) if tv.IsDefined() && tv.T.Kind() == FuncKind && tv.V != nil { fv, ok := tv.V.(*FuncValue) if !ok { continue // skip native functions. } if strings.HasPrefix(string(fv.Name), "init.") { + fmt.Println("---fv.Name: ", fv.Name) fb := pv.GetFileBlock(m.Store, fv.FileName) m.PushBlock(fb) m.RunFunc(fv.Name) @@ -767,10 +784,12 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { + fmt.Println("---resavePackageValues, realm: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { rlm = pv.Realm + fmt.Println("---rlm: ", rlm) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // re-save package realm info. m.Store.SetPackageRealm(rlm) @@ -1832,6 +1851,7 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { + fmt.Printf("---PushFrameCall---, cx: %v, fv: %v, recv: %v\n", cx, fv, recv) fr := &Frame{ Source: cx, NumOps: m.NumOps, @@ -1857,29 +1877,54 @@ 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() { + fmt.Println("---recv: ", recv) + if recv.IsDefined() { + // If the receiver is defined, we enter the receiver's realm. obj := recv.GetFirstObject(m.Store) + fmt.Println("---obj, rt of obj: ", obj, reflect.TypeOf(obj)) + fmt.Println("---obj.GetObjectID: ", obj.GetObjectID()) + fmt.Printf("---obj addr: %p\n", obj) 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() { + fmt.Println("---recvOID is: ", recvOID) + if recvOID.IsZero() { + //panic("!!!should not happen!!!") + fmt.Println("!!! recvOID is ZERO!!!") + // TODO: object reference by external realm must first be attached, + // check here... + // NOTE: the reference has two types: + // 1. if associated with global or child of global, panic; + // 2. if associated with un-attached object directly/indirectly, ok, + // when the un-attached object is attached, check if the target + // object has been attached(become real), if not, panic. + + fmt.Println("---recv is ZERO, it's not owned, recv: ", recv) + fmt.Println("---recv is ZERO, m.realm: ", m.Realm) + + // 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/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index eb67ffcc351..a10429367ae 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -1,5 +1,7 @@ package gnolang +import "fmt" + func (m *Machine) doOpDefine() { s := m.PopStmt().(*AssignStmt) // Define each value evaluated for Lhs. @@ -25,6 +27,7 @@ func (m *Machine) doOpDefine() { } func (m *Machine) doOpAssign() { + fmt.Println("---doOpAssign, m.Realm: ", m.Realm) s := m.PopStmt().(*AssignStmt) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 15531ec610d..d148457bd89 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -7,6 +7,7 @@ import ( ) func (m *Machine) doOpPrecall() { + fmt.Println("---doOpPrecall---") cx := m.PopExpr().(*CallExpr) v := m.PeekValue(1 + cx.NumArgs).V if debug { @@ -19,9 +20,13 @@ func (m *Machine) doOpPrecall() { } switch fv := v.(type) { case *FuncValue: + fmt.Println("---FuncValue, fv: ", fv) m.PushFrameCall(cx, fv, TypedValue{}) m.PushOp(OpCall) case *BoundMethodValue: + fmt.Println("---BoundMethodValue, fv: ", fv) + fmt.Println("---BoundMethodValue, fv.Func: ", fv.Func) + fmt.Println("---BoundMethodValue, fv.Receiver: ", fv.Receiver) m.PushFrameCall(cx, fv.Func, fv.Receiver) m.PushOp(OpCall) case TypeValue: @@ -46,6 +51,7 @@ func (m *Machine) doOpPrecall() { var gReturnStmt = &ReturnStmt{} func (m *Machine) doOpCall() { + fmt.Println("---doOpCall---") // NOTE: Frame won't be popped until the statement is complete, to // discard the correct number of results for func calls in ExprStmts. fr := m.LastFrame() @@ -199,6 +205,7 @@ func (m *Machine) doOpReturn() { finalize = true } if finalize { + fmt.Println("---going to finalizeRealmTransaction at return after call") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 701615fff13..3ef6da71210 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -37,6 +37,7 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerTo(m.Store, nx.Path) + fmt.Println("---ptr: ", ptr) m.PushValue(ptr.Deref()) return } @@ -242,6 +243,7 @@ func (m *Machine) doOpEval() { m.PushOp(OpEval) } case *CallExpr: + fmt.Println("---Eval, CallExpr, x: ", x) m.PushOp(OpPrecall) // Eval args. args := x.Args @@ -265,6 +267,7 @@ func (m *Machine) doOpEval() { m.PushExpr(x.X) m.PushOp(OpEval) case *SelectorExpr: + fmt.Println("---Eval, SelectorExpr, x: ", x) m.PushOp(OpSelector) // evaluate x m.PushExpr(x.X) diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index c7e8ffd600c..a0f84f82e66 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -56,6 +56,7 @@ func (m *Machine) doOpExec(op Op) { debug.Printf("PEEK STMT: %v\n", s) debug.Printf("%v\n", m) } + fmt.Printf("PEEK STMT: %v\n", s) // NOTE this could go in the switch statement, and we could // use the EXEC_SWITCH to jump back, rather than putting this @@ -485,6 +486,7 @@ EXEC_SWITCH: // All expressions push 1 value except calls, // which push as many as there are results. if _, ok := cs.X.(*CallExpr); ok { + fmt.Println("---CallExpr: ", cs.X) m.PushOp(OpPopResults) } else { m.PushOp(OpPopValue) diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index 8ff0b5bd538..7492a5f1ec7 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -76,9 +76,12 @@ func (m *Machine) doOpIndex2() { } func (m *Machine) doOpSelector() { + fmt.Println("---doOpSelector---") sx := m.PopExpr().(*SelectorExpr) xv := m.PeekValue(1) + fmt.Println("---xv: ", xv) res := xv.GetPointerTo(m.Alloc, m.Store, sx.Path).Deref() + fmt.Println("---res: ", res) if debug { m.Printf("-v[S] %v\n", xv) m.Printf("+v[S] %v\n", res) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 511b44bfc73..f46ba335a41 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -3,6 +3,7 @@ package gnolang import ( "encoding/hex" "fmt" + "reflect" "strconv" "strings" @@ -112,6 +113,8 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) + GetIsCrossRealm() bool + SetIsCrossRealm(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -140,31 +143,36 @@ 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 + isCrossRealm bool + isNewEscaped bool + isNewDeleted bool + lastNewRealEscapedRealm PkgID // realm attached and escaped // XXX huh? owner Object // mem reference to owner. } -// Copy used for serialization of objects. // 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, + lastNewRealEscapedRealm: oi.lastNewRealEscapedRealm, + */ } } @@ -305,6 +313,14 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { oi.isNewReal = x } +func (oi *ObjectInfo) GetIsCrossRealm() bool { + return oi.isCrossRealm +} + +func (oi *ObjectInfo) SetIsCrossRealm(x bool) { + oi.isCrossRealm = x +} + func (oi *ObjectInfo) GetIsNewEscaped() bool { return oi.isNewEscaped } @@ -326,6 +342,7 @@ func (oi *ObjectInfo) GetIsTransient() bool { } func (tv *TypedValue) GetFirstObject(store Store) Object { + fmt.Println("---GetFirstObject---, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: return cv.GetBase(store) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 3710524130a..606375d06f9 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -134,6 +134,41 @@ func (rlm *Realm) String() string { // xo or co is nil if the element value is undefined or has no // associated object. func (rlm *Realm) DidUpdate(po, xo, co Object) { + fmt.Println("---DidUpdate---") + fmt.Println("---xo: ", xo, reflect.TypeOf(xo)) + fmt.Println("---co: ", co, reflect.TypeOf(co)) + fmt.Println("---po: ", po, reflect.TypeOf(po)) + + if co != nil { + fmt.Println("co.GetObjectInfo:", co.GetObjectInfo()) + } + + if sv, ok := po.(*StructValue); ok { + fmt.Println("---sv: ", sv) + fmt.Println("---sv.ID: ", sv.ObjectInfo.ID) + fmt.Println("---sv.Fields: ", sv.Fields) + fmt.Println("---sv.OwnerID: ", sv.ObjectInfo.OwnerID) + } else if bv, ok := po.(*Block); ok { + for _, tv := range bv.Values { + fmt.Println("----tv.T: ", tv.T) + fmt.Println("----tv.V: ", tv.V) + if csv, ok := co.(*StructValue); ok { + if csv == tv.V { + fmt.Println("---eql, csv: ", csv) + fmt.Println("---eql, T: ", tv.T, reflect.TypeOf(tv.T)) + if dt, ok := tv.T.(*DeclaredType); ok { + fmt.Println("---dt: ", dt, dt.PkgPath) + if IsRealmPath(dt.PkgPath) && dt.PkgPath != rlm.Path { + co.SetIsCrossRealm(true) + //panic("!!!") + } + } + } + } + } + } + + fmt.Println("---realm: ", rlm) if rlm == nil { return } @@ -148,10 +183,12 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { panic("cannot attach to a deleted object") } } - if po == nil || !po.GetIsReal() { + if po == nil || !po.GetIsReal() { // XXX, make sure po is attached return // do nothing. } + fmt.Println("---po.GetObjectID(): ", po.GetObjectID()) if po.GetObjectID().PkgID != rlm.ID { + fmt.Printf("po.GetObjectID().PkgID: %v, rlm.ID: %v\n", po.GetObjectID().PkgID, rlm.ID) panic("cannot modify external-realm or non-realm object") } @@ -166,18 +203,23 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkDirty(po) if co != nil { + fmt.Println("---co: ", co) + fmt.Println("---co.GetRefCount: ", co.GetRefCount()) co.IncRefCount() if co.GetRefCount() > 1 { if co.GetIsEscaped() { // already escaped } else { - rlm.MarkNewEscaped(co) + rlm.MarkNewEscapedCheckCrossRealm(co) + //rlm.MarkNewEscaped(co) } } else if co.GetIsReal() { + println("---co is real") rlm.MarkDirty(co) } else { + println("---else") co.SetOwner(po) - rlm.MarkNewReal(co) + rlm.MarkNewReal(co) // co will be attached when finalize } } @@ -194,7 +236,35 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { //---------------------------------------- // mark* +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { + fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) + oi := oo.GetObjectInfo() + fmt.Println("----oi: ", oi) + fmt.Println("----oi.lastNewRealEscapedRealm: ", oi.lastNewRealEscapedRealm) + fmt.Println("----rlm.ID: ", rlm.ID) + + if oi.lastNewRealEscapedRealm == rlm.ID { + // already processed for this realm, + // see below. + return + } + if !oi.GetIsReal() { // e.g. attach object initialized in 'init', mark it as new real/attached, thus it has an object ID. + fmt.Println("---oi Not real, oi: ", oi.ID) + // this can happen if a ref +1 + // new object gets passed into + // an external realm function. + oi.lastNewRealEscapedRealm = rlm.ID + oi.SetIsNewReal(false) + rlm.MarkNewReal(oo) + } else { + fmt.Println("---oo is real, oi:", oi.ID) + // TODO: set last escape realm? + } + rlm.MarkNewEscaped(oo) +} + func (rlm *Realm) MarkNewReal(oo Object) { + fmt.Println("---markNewReal---, oo: ", oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -215,6 +285,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { } } if oo.GetIsNewReal() { + println("---markNewReal---, oo: ", oo) return // already marked. } oo.SetIsNewReal(true) @@ -226,6 +297,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { } func (rlm *Realm) MarkDirty(oo Object) { + fmt.Printf("rlm: %v MarkDirty: %v\n", rlm, oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -266,6 +338,7 @@ func (rlm *Realm) MarkNewDeleted(oo Object) { } func (rlm *Realm) MarkNewEscaped(oo Object) { + fmt.Println("---MarkNewEscaped---, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsReal() { panic("cannot mark unreal object as new escaped") @@ -293,6 +366,10 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { + fmt.Println("---FinalizeRealmTransaction---") + defer func() { + fmt.Println("---done FinalizeRealmTransaction---") + }() if readonly { if true || len(rlm.newCreated) > 0 || @@ -358,8 +435,16 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // All newly created objects become appended to .created, // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { + fmt.Println("---processNewCreatedMarks---") // Create new objects and their new descendants. - for _, oo := range rlm.newCreated { + //for _, oo := range rlm.newCreated { + for i := 0; i < len(rlm.newCreated); i++ { + oo := rlm.newCreated[i] + fmt.Println("---oo: ", oo) + if oo.GetIsCrossRealm() { + fmt.Println("---should not attach value with type defined in other realm") + //panic("---!!!") + } if debug { if oo.GetIsDirty() { panic("new created mark cannot be dirty") @@ -387,6 +472,8 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { + fmt.Println("---incRefCreatedDescendants---, oo: ", oo) + fmt.Println("---incRefCreatedDescendants---, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -409,7 +496,10 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) + fmt.Println("---more: ", more) for _, child := range more { + fmt.Println("---child: ", child) + fmt.Printf("---child addr: %p\n", child) if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -421,12 +511,16 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() + fmt.Println("---rc: ", rc) if rc == 1 { + fmt.Println("---rc == 1") if child.GetIsReal() { + fmt.Println("---child is real, child: ", child) // a deleted real became undeleted. child.SetOwner(oo) rlm.MarkDirty(child) } else { + fmt.Println("---child NOT real, child: ", child) // a (possibly pre-existing) new object // became real (again). // NOTE: may already be marked for first gen @@ -443,6 +537,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // may become unescaped later // in processNewEscapedMarks(). // NOTE: may already be escaped. + fmt.Println("---in recursive, mark new escaped, child: ", child) rlm.MarkNewEscaped(child) } } else { @@ -460,6 +555,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // to rlm.deleted. // Must run *after* processNewCreatedMarks(). func (rlm *Realm) processNewDeletedMarks(store Store) { + fmt.Println("---processNewDeletedMarks---") for _, oo := range rlm.newDeleted { if debug { if oo.GetObjectID().IsZero() { @@ -523,6 +619,7 @@ 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) { + fmt.Println("---processNewEscapedMarks---") escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, @@ -531,6 +628,8 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // except for new-reals that get demoted // because ref-count isn't >= 2. for _, eo := range rlm.newEscaped { + fmt.Println("---processNewEscapedMarks, eo, eo.GetRefCount: ", eo, eo.GetRefCount()) + fmt.Println("---processNewEscapedMarks, eo, eo.GetObjectID: ", eo, eo.GetObjectID()) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -584,6 +683,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (ancestors) must be marked as dirty to update the // hash tree. func (rlm *Realm) markDirtyAncestors(store Store) { + fmt.Println("---markDirtyAncestors---") markAncestorsOne := func(oo Object) { for { if pv, ok := oo.(*PackageValue); ok { @@ -652,6 +752,7 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { + fmt.Println("---saveUnsavedObjects---") for _, co := range rlm.created { // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] @@ -755,6 +856,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) { // removeDeletedObjects func (rlm *Realm) removeDeletedObjects(store Store) { + fmt.Println("---removeDeletedObjects---") for _, do := range rlm.deleted { store.DelObject(do) } @@ -1061,6 +1163,7 @@ func copyTypeWithRefs(typ Type) Type { // Also checks for integrity of immediate children -- they must already be // persistent (real), and not dirty, or else this function panics. func copyValueWithRefs(val Value) Value { + fmt.Println("---copyValueWithRefs, val: ", val) switch cv := val.(type) { case nil: return nil @@ -1423,11 +1526,14 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { + fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v\n", rlm, oo) oid := oo.GetObjectID() + fmt.Println("---oid: ", oid) if !oid.IsZero() { panic("unexpected non-zero object id") } noid := rlm.nextObjectID() + fmt.Println("---noid: ", noid) oo.SetObjectID(noid) return noid } @@ -1443,6 +1549,7 @@ func toRefNode(bn BlockNode) RefNode { } func toRefValue(val Value) RefValue { + fmt.Println("---toRefValue", val) // TODO use type switch stmt. if ref, ok := val.(RefValue); ok { return ref @@ -1516,6 +1623,7 @@ func ensureUniq(oozz ...[]Object) { } func refOrCopyValue(tv TypedValue) TypedValue { + fmt.Println("---refOrCopyValue:", tv) if tv.T != nil { tv.T = refOrCopyType(tv.T) } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 038f4ba894b..30443032d12 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -324,9 +324,11 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { + fmt.Println("---SetObject---,oo: ", oo) oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) + fmt.Println("---o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) // set hash. @@ -361,8 +363,10 @@ func (ds *defaultStore) SetObject(oo Object) { if ds.opslog != nil { var op StoreOpType if oo.GetIsNewReal() { + fmt.Println("---oo is new real, oo: ", oo) op = StoreOpNew } else { + fmt.Println("---oo is mod, oo: ", oo) op = StoreOpMod } ds.opslog = append(ds.opslog, @@ -378,6 +382,7 @@ func (ds *defaultStore) SetObject(oo Object) { } func (ds *defaultStore) DelObject(oo Object) { + fmt.Println("---DelObject, oo: ", oo) oid := oo.GetObjectID() // delete from cache. delete(ds.cacheObjects, oid) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 5da7c15bb05..009f253e0e2 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -193,14 +193,17 @@ const ( ) func (pv *PointerValue) GetBase(store Store) Object { + fmt.Printf("GetBase, pv.Base: %v\n", pv.Base) switch cbase := pv.Base.(type) { case nil: return nil case RefValue: + println("---RefValue") base := store.GetObject(cbase.ObjectID).(Object) pv.Base = base return base case Object: + fmt.Println("---Object, cbase: ", cbase) return cbase default: panic(fmt.Sprintf("unexpected pointer base type %T", cbase)) @@ -211,6 +214,9 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { + fmt.Println("---Assign2, pv: ", pv) + fmt.Println("---Assign2, tv2: ", tv2) + fmt.Println("---Assign2, realm: ", rlm) // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -1701,6 +1707,7 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { // allocated, *Allocator.AllocatePointer() is called separately, // as in OpRef. func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath) PointerValue { + fmt.Println("---GetPointerTo, tv, rt of tv: ", tv, reflect.TypeOf(tv)) if debug { if tv.IsUndefined() { panic("GetPointerTo() on undefined value") @@ -1867,11 +1874,18 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath panic("should not happen") } } + fmt.Println("---dtv: ", dtv) + fmt.Printf("---dtv addr: %p\n", dtv) dtv2 := dtv.Copy(alloc) + + fmt.Println("---dtv2: ", dtv2) + fmt.Printf("---dtv2 addr: %p\n", dtv2) + alloc.AllocateBoundMethod() bmv := &BoundMethodValue{ Func: mv, Receiver: dtv2, + //Receiver: *dtv, } return PointerValue{ TV: &TypedValue{ @@ -2431,7 +2445,9 @@ func (b *Block) GetParent(store Store) *Block { } func (b *Block) GetPointerToInt(store Store, index int) PointerValue { + fmt.Println("---GetPointerToInt") vv := fillValueTV(store, &b.Values[index]) + fmt.Println("---vv: ", vv) return PointerValue{ TV: vv, Base: b, @@ -2440,7 +2456,9 @@ func (b *Block) GetPointerToInt(store Store, index int) PointerValue { } func (b *Block) GetPointerTo(store Store, path ValuePath) PointerValue { + fmt.Println("---GetPointerTo, path: ", path) if path.IsBlockBlankPath() { + println("---isBlockBlankPath") if debug { if path.Name != blankIdentifier { panic(fmt.Sprintf( @@ -2621,13 +2639,17 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { + fmt.Println("---fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: + println("---tv.V RefValue") + fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) + fmt.Println("---tv.V: ", tv.V) } case PointerValue: // As a special case, cv.Base is filled From 72b28d76c55debe902e4c992663092370bac4fec Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Fri, 27 Sep 2024 11:21:02 +0200 Subject: [PATCH 06/88] debug --- gnovm/pkg/gnolang/ownership.go | 3 ++- gnovm/pkg/gnolang/realm.go | 16 +++++++----- gnovm/tests/files/zrealm_crossrealm21.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 29 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm21a.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index f46ba335a41..700f2e55dfb 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -113,7 +113,7 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) - GetIsCrossRealm() bool + GetIsCrossRealm() bool // XXX, does escape imply this? SetIsCrossRealm(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) @@ -341,6 +341,7 @@ func (oi *ObjectInfo) GetIsTransient() bool { return false } +// XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { fmt.Println("---GetFirstObject---, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 606375d06f9..f41553250ed 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -186,6 +186,8 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if po == nil || !po.GetIsReal() { // XXX, make sure po is attached return // do nothing. } + + // XXX, cross realm check fmt.Println("---po.GetObjectID(): ", po.GetObjectID()) if po.GetObjectID().PkgID != rlm.ID { fmt.Printf("po.GetObjectID().PkgID: %v, rlm.ID: %v\n", po.GetObjectID().PkgID, rlm.ID) @@ -205,15 +207,16 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if co != nil { fmt.Println("---co: ", co) fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + // XXX, inc ref count everytime assignment happens co.IncRefCount() - if co.GetRefCount() > 1 { + if co.GetRefCount() > 1 { // XXX, associated more the once? how this happen? if co.GetIsEscaped() { // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(co) + rlm.MarkNewEscapedCheckCrossRealm(co) // XXX, track which realm escape from //rlm.MarkNewEscaped(co) } - } else if co.GetIsReal() { + } else if co.GetIsReal() { // XXX, attached in .init? println("---co is real") rlm.MarkDirty(co) } else { @@ -248,12 +251,12 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { // see below. return } - if !oi.GetIsReal() { // e.g. attach object initialized in 'init', mark it as new real/attached, thus it has an object ID. + if !oi.GetIsReal() { // XXX, this seems to be wrong -- an object escapes to other realm before it's attached(no objectID) fmt.Println("---oi Not real, oi: ", oi.ID) // this can happen if a ref +1 // new object gets passed into // an external realm function. - oi.lastNewRealEscapedRealm = rlm.ID + oi.lastNewRealEscapedRealm = rlm.ID // XXX, where the object escape from. oi.SetIsNewReal(false) rlm.MarkNewReal(oo) } else { @@ -296,6 +299,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { rlm.newCreated = append(rlm.newCreated, oo) } +// mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { fmt.Printf("rlm: %v MarkDirty: %v\n", rlm, oo) if debug { @@ -491,7 +495,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { return } rlm.assignNewObjectID(oo) - rlm.created = append(rlm.created, oo) + rlm.created = append(rlm.created, oo) // XXX, here it becomes real. // RECURSE GUARD END // recurse for children. diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 5babaff955b..44e40636e5a 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -9,7 +9,7 @@ var b0 crossrealm.Bar // XXX, this should fail while trying to attach // value of type defined in another realm. -// NOTE: the check can be in runtime or in preprocess. +// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). func init() { b0 = crossrealm.Bar{A: 1} } diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno new file mode 100644 index 00000000000..90783036a62 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -0,0 +1,29 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type Container struct { + b crossrealm.Bar +} + +var c Container + +// XXX, this should fail while trying to attach +// value of type defined in another realm. +// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). +func init() { + b0 := crossrealm.Bar{A: 1} + c = Container{b: b0} +} + +func main() { + print(".") +} + +// Output: +// . + +// Error: From 00a59e7f5563395db7250f8772b31ac59dd29d3c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 7 Oct 2024 13:11:09 +0800 Subject: [PATCH 07/88] save --- examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21.gno | 8 +++----- gnovm/tests/files/zrealm_crossrealm21a.gno | 9 ++++----- gnovm/tests/files/zrealm_crossrealm22.gno | 7 +++---- gnovm/tests/files/zrealm_crossrealm23.gno | 7 +++---- gnovm/tests/files/zrealm_crossrealm23a.gno | 7 +++---- gnovm/tests/files/zrealm_crossrealm24.gno | 6 +++--- gnovm/tests/files/zrealm_crossrealm25a.gno | 2 +- 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno index 97273f642de..4ed3c8cc128 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno @@ -17,7 +17,7 @@ func (ls *LocalStruct) String() string { var local *LocalStruct func init() { - local = &LocalStruct{A: 123} + local = &LocalStruct{A: 123} // this is attached first } // Make1 returns a local object wrapped by a p struct diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 44e40636e5a..11093213162 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -7,9 +7,6 @@ import ( var b0 crossrealm.Bar -// XXX, this should fail while trying to attach -// value of type defined in another realm. -// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). func init() { b0 = crossrealm.Bar{A: 1} } @@ -18,7 +15,8 @@ func main() { print(".") } -// Output: -// . +// XXX, this should fail while trying to attach +// value of type defined in another realm. +// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index 90783036a62..c8afe72843c 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -5,15 +5,13 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) +// associate to a containing object type Container struct { b crossrealm.Bar } var c Container -// XXX, this should fail while trying to attach -// value of type defined in another realm. -// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). func init() { b0 := crossrealm.Bar{A: 1} c = Container{b: b0} @@ -23,7 +21,8 @@ func main() { print(".") } -// Output: -// . +// XXX, this should fail while trying to attach +// value of type defined in another realm. +// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 8e294e969d3..14c3dbd5311 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -7,7 +7,6 @@ type Bar struct { var b0 Bar -// XXX this works attach value with type defined in same realm func init() { b0 = Bar{A: 1} } @@ -16,7 +15,7 @@ func main() { print(".") } -// Output: -// . +// XXX this works. attach value with type defined in same realm -// Error: +// Output: +//. diff --git a/gnovm/tests/files/zrealm_crossrealm23.gno b/gnovm/tests/files/zrealm_crossrealm23.gno index ec2f19a9351..554bd41ceb0 100644 --- a/gnovm/tests/files/zrealm_crossrealm23.gno +++ b/gnovm/tests/files/zrealm_crossrealm23.gno @@ -5,7 +5,6 @@ import "gno.land/p/demo/tests/p_crossrealm" var b0 p_crossrealm.Container -// XXX, this works attach value with type defined in p func init() { b0 = p_crossrealm.Container{ A: 1, @@ -16,7 +15,7 @@ func main() { print(".") } -// Output: -// . +// XXX, this works attach value with type defined in p -// Error: +// Output: +//. diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index 21416cdde8f..61d8f0ec291 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -5,7 +5,6 @@ import "gno.land/p/demo/tests/p_crossrealm" var b0 *p_crossrealm.Container -// XXX, this works, attach reference with type defined in p func init() { b0 = &p_crossrealm.Container{ A: 1, @@ -16,7 +15,7 @@ func main() { print(".") } -// Output: -// . +// XXX, this works, attach reference with type defined in p -// Error: +// Output: +//. diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index e6c7d8d2e3c..01934436225 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -7,7 +7,6 @@ import ( var b0 *crossrealm.Bar -// XXX, should work to attach by reference func init() { b0 = &crossrealm.Bar{A: 1} } @@ -16,7 +15,8 @@ func main() { print(".") } +// XXX, should work to attach by reference to +// type defined in another realm. + // Output: // . - -// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno index 1700e72b25f..cfdef023b31 100644 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -27,7 +27,7 @@ func main() { // XXX, this associate a pointer to a value(not attached) // to external realm, no attachment happens to the external realm. - // XXX, attach to un-attached external realm + // XXX, associate to un-attached external realm //crossrealm.AttachContainer() // this attach container first crossrealm.SetContainer(&f) print(".") From 71c6fed12b3e63612267ab06b823ae124aa73c14 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 8 Oct 2024 23:48:06 +0800 Subject: [PATCH 08/88] external type --- gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno index 5bf34c2c852..241338a4739 100644 --- a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno index 686468b40c7..f89747c29c5 100644 --- a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno index cfcd4e6898c..2e9f3b30637 100644 --- a/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno index 6aa9c5247d8..9dc099b3c43 100644 --- a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno index 6aa9c5247d8..9dc099b3c43 100644 --- a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno index 6aa9c5247d8..9dc099b3c43 100644 --- a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is *invalid* to persist external realm types. var somevalue tests.TestRealmObject func init() { From 07d902957cc24ce1b7f19ac618edb1369579b620 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 10 Oct 2024 23:59:39 +0800 Subject: [PATCH 09/88] save --- .../r/demo/tests/crossrealm/crossrealm2.gno | 9 ++- gnovm/pkg/gnolang/machine.go | 1 + gnovm/pkg/gnolang/ownership.go | 7 ++ gnovm/pkg/gnolang/realm.go | 71 ++++++++++++++++--- gnovm/pkg/gnolang/values.go | 10 ++- gnovm/tests/files/zrealm_crossrealm21a.gno | 7 +- gnovm/tests/files/zrealm_crossrealm25.gno | 16 ++--- gnovm/tests/files/zrealm_crossrealm25a.gno | 13 +--- gnovm/tests/files/zrealm_crossrealm25b.gno | 33 +++++++++ gnovm/tests/files/zrealm_crossrealm25c.gno | 33 +++++++++ gnovm/tests/files/zrealm_crossrealm25d.gno | 36 ++++++++++ gnovm/tests/files/zrealm_crossrealm26.gno | 20 ++---- gnovm/tests/files/zrealm_crossrealm26a.gno | 24 +++++++ gnovm/tests/files/zrealm_crossrealm26b.gno | 21 ++++++ gnovm/tests/files/zrealm_crossrealm26c.gno | 19 +++++ 15 files changed, 270 insertions(+), 50 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm25b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm25c.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm25d.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm26a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm26b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm26c.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno index 8f12ec1322d..76cf0eef100 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno @@ -14,14 +14,19 @@ func CallFoo() { fooer.Foo() } // container in external realm type Container struct { - f Fooer + name string + f Fooer } var container Container // TODO, check does this attach or not func AttachContainer() { - container = Container{} + container = Container{name: "external_container"} } func SetContainer(f Fooer) { container.f = f } + +func SetContainer2(f Fooer) { + ff := f +} diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index ad3fbeee7f2..2a7323c3a3c 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -753,6 +753,7 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { + fmt.Println("---saveNewPackageValuesAndTypes") // save package value and dependencies. pv := m.Package if pv.IsRealm() { diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 700f2e55dfb..c622149a5b8 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -346,12 +346,19 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { fmt.Println("---GetFirstObject---, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: + println("---pointer value, get base") + if v, ok := cv.TV.V.(Object); ok { + fmt.Println("---v: ", v) + rc := v.GetRefCount() + fmt.Println("---rc: ", rc) + } return cv.GetBase(store) case *ArrayValue: return cv case *SliceValue: return cv.GetBase(store) case *StructValue: + println("---struct value") return cv case *FuncValue: return cv.GetClosure(store) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index f41553250ed..02b2f66e752 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -135,14 +135,27 @@ func (rlm *Realm) String() string { // associated object. func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---DidUpdate---") - fmt.Println("---xo: ", xo, reflect.TypeOf(xo)) - fmt.Println("---co: ", co, reflect.TypeOf(co)) - fmt.Println("---po: ", po, reflect.TypeOf(po)) + fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) + fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + + fmt.Printf("xo: %p\n", xo) + if co != nil && co.GetIsCrossRealm() { + panic("!!!cross realm") + } + + if co != nil { + fmt.Println("--co isReal(attached): ", co.GetIsReal()) + fmt.Println("---co objectID: ", co.GetObjectID()) + } if co != nil { fmt.Println("co.GetObjectInfo:", co.GetObjectInfo()) + fmt.Printf("co: %p\n", co) } + // XXX, these can be improved by attach type info with co. + // the following does not work if sv, ok := po.(*StructValue); ok { fmt.Println("---sv: ", sv) fmt.Println("---sv.ID: ", sv.ObjectInfo.ID) @@ -159,6 +172,8 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if dt, ok := tv.T.(*DeclaredType); ok { fmt.Println("---dt: ", dt, dt.PkgPath) if IsRealmPath(dt.PkgPath) && dt.PkgPath != rlm.Path { + fmt.Println("---set co to be cross realm object, co: ", co) + fmt.Printf("---%p\n", co) co.SetIsCrossRealm(true) //panic("!!!") } @@ -183,6 +198,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { panic("cannot attach to a deleted object") } } + fmt.Println("---po.GetIsReal: ", po.GetIsReal()) if po == nil || !po.GetIsReal() { // XXX, make sure po is attached return // do nothing. } @@ -209,8 +225,10 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() - if co.GetRefCount() > 1 { // XXX, associated more the once? how this happen? + fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) + if co.GetRefCount() > 1 { // XXX, associated more the once? how this happens? if co.GetIsEscaped() { + println("---already escaped, should check cross realm?") // already escaped } else { rlm.MarkNewEscapedCheckCrossRealm(co) // XXX, track which realm escape from @@ -228,6 +246,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if xo != nil { xo.DecRefCount() + fmt.Println("---xo refCount after dec: ", xo.GetRefCount()) if xo.GetRefCount() == 0 { if xo.GetIsReal() { rlm.MarkNewDeleted(xo) @@ -243,8 +262,17 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) oi := oo.GetObjectInfo() fmt.Println("----oi: ", oi) + fmt.Println("----oi: ", oi) fmt.Println("----oi.lastNewRealEscapedRealm: ", oi.lastNewRealEscapedRealm) fmt.Println("----rlm.ID: ", rlm.ID) + fmt.Println("oi.GetIsReal: ", oi.GetIsReal()) + if oi.GetIsReal() { + lastRealmID := oi.GetObjectID().PkgID + fmt.Println("lastRealmID: ", lastRealmID) + if lastRealmID != rlm.ID { + panic("should not happen, cross realm!!!") + } + } if oi.lastNewRealEscapedRealm == rlm.ID { // already processed for this realm, @@ -262,6 +290,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { } else { fmt.Println("---oo is real, oi:", oi.ID) // TODO: set last escape realm? + println("---set last escape realm?") } rlm.MarkNewEscaped(oo) } @@ -288,7 +317,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { } } if oo.GetIsNewReal() { - println("---markNewReal---, oo: ", oo) + println("---isNewReal---, oo: ", oo) return // already marked. } oo.SetIsNewReal(true) @@ -296,7 +325,9 @@ func (rlm *Realm) MarkNewReal(oo Object) { if rlm.newCreated == nil { rlm.newCreated = make([]Object, 0, 256) } + fmt.Println("---append oo to newCreated object: ", oo) rlm.newCreated = append(rlm.newCreated, oo) + fmt.Println("---len of new created: ", len(rlm.newCreated)) } // mark dirty == updated @@ -444,7 +475,19 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - fmt.Println("---oo: ", oo) + fmt.Printf("---oo[%d] is %v:\n", i, oo) + // TODO: here check embedded object cross + more := getChildObjects2(store, oo) + fmt.Println("---children of oo: ", more) + for _, c := range more { + fmt.Printf("---%p\n", c) + if c.GetIsCrossRealm() { + panic("---cross realm") + } else { + println("---not cross realm") + } + } + fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) if oo.GetIsCrossRealm() { fmt.Println("---should not attach value with type defined in other realm") //panic("---!!!") @@ -502,7 +545,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { more := getChildObjects2(store, oo) fmt.Println("---more: ", more) for _, child := range more { - fmt.Println("---child: ", child) + fmt.Printf("---child: %v, type of child: %v \n", child, reflect.TypeOf(child)) fmt.Printf("---child addr: %p\n", child) if _, ok := child.(*PackageValue); ok { if debug { @@ -561,6 +604,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { func (rlm *Realm) processNewDeletedMarks(store Store) { fmt.Println("---processNewDeletedMarks---") for _, oo := range rlm.newDeleted { + fmt.Println("---oo: ", oo, oo.GetRefCount()) if debug { if oo.GetObjectID().IsZero() { panic("new deleted mark should have an object ID") @@ -905,9 +949,12 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { + fmt.Println("---getSelfOrChildObjects, val: ", val) if _, ok := val.(RefValue); ok { + println("---ref value") return append(more, val) } else if _, ok := val.(Object); ok { + println("---not ref value") return append(more, val) } else { return getChildObjects(val, more) @@ -917,6 +964,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { + fmt.Println("---getChildObjects, val: ", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -943,7 +991,10 @@ func getChildObjects(val Value, more []Value) []Value { more = getSelfOrChildObjects(cv.Base, more) return more case *StructValue: + println("---struct value") for _, ctv := range cv.Fields { + // TODO: we have type infos here, so check check cross realm logic + fmt.Println("---ctv: ", ctv) more = getSelfOrChildObjects(ctv.V, more) } return more @@ -993,13 +1044,17 @@ func getChildObjects(val Value, more []Value) []Value { // like getChildObjects() but loads RefValues into objects. func getChildObjects2(store Store, val Value) []Object { + fmt.Println("---getChildObjects2, val: ", val) chos := getChildObjects(val, nil) + fmt.Println("---chos: ", chos) objs := make([]Object, 0, len(chos)) for _, child := range chos { if ref, ok := child.(RefValue); ok { + println("---ref value") oo := store.GetObject(ref.ObjectID) objs = append(objs, oo) } else if oo, ok := child.(Object); ok { + println("---not ref value") objs = append(objs, oo) } } @@ -1530,7 +1585,7 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { - fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v\n", rlm, oo) + fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) oid := oo.GetObjectID() fmt.Println("---oid: ", oid) if !oid.IsZero() { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 009f253e0e2..7231f1f4f74 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -290,8 +290,10 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) + fmt.Println("---oo1: ", oo1) pv.TV.Assign(alloc, tv2, cu) oo2 := pv.TV.GetFirstObject(store) + fmt.Println("---oo2: ", oo2) rlm.DidUpdate(pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) @@ -508,6 +510,7 @@ func (sv *StructValue) GetSubrefPointerTo(store Store, st *StructType, path Valu } func (sv *StructValue) Copy(alloc *Allocator) *StructValue { + fmt.Println("---StructValue copy, sv: ", sv) /* TODO consider second refcount field if sv.GetRefCount() == 0 { return sv @@ -523,7 +526,10 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { fields[i] = field.Copy(alloc) } - return alloc.NewStruct(fields) + nsv := alloc.NewStruct(fields) + nsv.ObjectInfo = sv.ObjectInfo.Copy() + return nsv + //return alloc.NewStruct(fields) } // ---------------------------------------- @@ -1695,7 +1701,7 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { panic("should not happen") } } - *tv = tv2.Copy(alloc) + *tv = tv2.Copy(alloc) // TODO: why copy? if cu && isUntyped(tv.T) { ConvertUntypedTo(tv, defaultTypeOf(tv.T)) } diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index c8afe72843c..e77837400e3 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -7,14 +7,15 @@ import ( // associate to a containing object type Container struct { - b crossrealm.Bar + name string + b crossrealm.Bar } var c Container func init() { - b0 := crossrealm.Bar{A: 1} - c = Container{b: b0} + b0 := crossrealm.Bar{A: 1} // this is valid association + c = Container{name: "container", b: b0} // XXX, check recursively while finalize here } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno index 5ea5e4a520f..10b37896c8f 100644 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -7,7 +7,7 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct{ name string } func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } @@ -20,20 +20,14 @@ var f fooer // to the field of a struct, but this does not attach the external // realm object to the container, in this case the struct. func init() { - f = fooer{} + f = fooer{name: "local_fooer"} // f attached to current realm } func main() { - // XXX, this associate a pointer to a value(already attached to local realm) - // to external realm, no attachment happens to the external realm. - crossrealm.AttachContainer() // this attach container first + crossrealm.AttachContainer() // this attaches container first crossrealm.SetContainer(&f) print(".") } -// Output: -// . - -// Error: - -// Realm: +// XXX, this associate a pointer to a value(already attached to local realm) +// to external realm, no attachment happens to the external realm. diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno index cfdef023b31..7064b364d3d 100644 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -24,18 +24,11 @@ func init() { } func main() { - // XXX, this associate a pointer to a value(not attached) - // to external realm, no attachment happens to the external realm. - // XXX, associate to un-attached external realm - //crossrealm.AttachContainer() // this attach container first crossrealm.SetContainer(&f) print(".") } -// Output: -// . - -// Error: - -// Realm: +// this should work. +// XXX, this associate a pointer to a floating object(not attached) +// to external realm, no attachment happens to the external realm. diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno new file mode 100644 index 00000000000..57cfe2324ae --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25b.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +// pass pointer to an embedded object to external realm? + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +type localContainer struct { + name string + f fooer +} + +var lc localContainer + +func init() { + lc = localContainer{name: "local_container", f: fooer{name: "local_fooer"}} // attach +} + +func main() { + crossrealm.AttachContainer() // this attaches container first + crossrealm.SetContainer(&lc.f) + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno new file mode 100644 index 00000000000..9e8f961a21f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +// pass pointer to an embedded object to external realm? + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +type localContainer struct { + name string + f fooer +} + +var lc localContainer + +func init() { + lc = localContainer{name: "local_container", f: fooer{name: "local_fooer"}} // attach +} + +func main() { + crossrealm.AttachContainer() // this attaches container first + crossrealm.SetContainer(lc.f) // should work + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno new file mode 100644 index 00000000000..46ccf45dac7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -0,0 +1,36 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +// pass pointer to an embedded object to external realm? + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +type localContainer struct { + name string + ff fooer +} + +var lc localContainer + +func init() { + f = fooer{name: "local_fooer_global"} + lc = localContainer{name: "local_container", ff: f} // attach +} + +func main() { + crossrealm.AttachContainer() // this attaches container first + crossrealm.SetContainer(lc.ff) // this should not panic, lc.ff is not same with f(gloabl) + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm26.gno b/gnovm/tests/files/zrealm_crossrealm26.gno index 6fff7ac6b96..3dfabfd14fe 100644 --- a/gnovm/tests/files/zrealm_crossrealm26.gno +++ b/gnovm/tests/files/zrealm_crossrealm26.gno @@ -7,26 +7,18 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct{ name string } func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer -// Pointers to external realm objects that are not yet -// attached to the external realm may not be associated -// with an attached object. +func init() { + f = fooer{name: "local_fooer"} +} func main() { - crossrealm.AttachContainer() // this attach container first - f = fooer{} // not attached to local realm yet, cannot be able to attach to external attached even by reference - crossrealm.SetContainer(&f) + crossrealm.AttachContainer() // this attaches container first + crossrealm.SetContainer(f) print(".") } - -// Output: -// . - -// Error: - -// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm26a.gno b/gnovm/tests/files/zrealm_crossrealm26a.gno new file mode 100644 index 00000000000..1fbf476e917 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm26a.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{ name string } + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +func init() { + f = fooer{name: "local_fooer"} +} + +func main() { + crossrealm.AttachContainer() // this attaches container first + crossrealm.SetContainer(&f) + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm26b.gno b/gnovm/tests/files/zrealm_crossrealm26b.gno new file mode 100644 index 00000000000..de672d5cca3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm26b.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{ name string } + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer // this already attached + +func main() { + crossrealm.AttachContainer() // this attaches container first + f = fooer{name: "local_fooer"} // update to an already attached object + crossrealm.SetContainer(&f) + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm26c.gno b/gnovm/tests/files/zrealm_crossrealm26c.gno new file mode 100644 index 00000000000..3f7a92b33d0 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm26c.gno @@ -0,0 +1,19 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{ name string } + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +func main() { + crossrealm.AttachContainer() // this attaches container first + var f fooer = fooer{name: "local_fooer"} // this is not attached, should panic, even not escape + crossrealm.SetContainer(f) + print(".") +} From 8fdc399ab55c2caa5ee6108b7a2d9df6dd10a1af Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 14 Oct 2024 08:11:03 +0800 Subject: [PATCH 10/88] save --- .../r/demo/tests/crossrealm/crossrealm2.gno | 5 +- gnovm/pkg/gnolang/ownership.go | 5 +- gnovm/pkg/gnolang/realm.go | 69 +++++++++++-------- gnovm/pkg/gnolang/values.go | 2 +- gnovm/tests/files/zrealm_crossrealm26a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm26b.gno | 4 +- gnovm/tests/files/zrealm_crossrealm26c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm27.gno | 12 +--- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno index 76cf0eef100..784af2ab715 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno @@ -18,11 +18,12 @@ type Container struct { f Fooer } -var container Container // TODO, check does this attach or not +var container Container // XXX, not attached here func AttachContainer() { - container = Container{name: "external_container"} + container = Container{name: "external_container"} // attach after call } + func SetContainer(f Fooer) { container.f = f } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index c622149a5b8..82e1d33f1e7 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -351,14 +351,17 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { fmt.Println("---v: ", v) rc := v.GetRefCount() fmt.Println("---rc: ", rc) + fmt.Println("---v Owner: ", v.GetOwnerID()) + fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) } - return cv.GetBase(store) + return cv.GetBase(store) // TODO: this is not enough for pointers case *ArrayValue: return cv case *SliceValue: return cv.GetBase(store) case *StructValue: println("---struct value") + fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) return cv case *FuncValue: return cv.GetClosure(store) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 02b2f66e752..06ef3170578 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -133,6 +133,7 @@ func (rlm *Realm) String() string { // if rlm or po is nil, do nothing. // xo or co is nil if the element value is undefined or has no // associated object. +// TODO: func (rlm *Realm) DidUpdate(po, xo, co Object, attached bool) { func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---DidUpdate---") fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) @@ -154,34 +155,42 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Printf("co: %p\n", co) } - // XXX, these can be improved by attach type info with co. - // the following does not work - if sv, ok := po.(*StructValue); ok { - fmt.Println("---sv: ", sv) - fmt.Println("---sv.ID: ", sv.ObjectInfo.ID) - fmt.Println("---sv.Fields: ", sv.Fields) - fmt.Println("---sv.OwnerID: ", sv.ObjectInfo.OwnerID) - } else if bv, ok := po.(*Block); ok { - for _, tv := range bv.Values { - fmt.Println("----tv.T: ", tv.T) - fmt.Println("----tv.V: ", tv.V) - if csv, ok := co.(*StructValue); ok { - if csv == tv.V { - fmt.Println("---eql, csv: ", csv) - fmt.Println("---eql, T: ", tv.T, reflect.TypeOf(tv.T)) - if dt, ok := tv.T.(*DeclaredType); ok { - fmt.Println("---dt: ", dt, dt.PkgPath) - if IsRealmPath(dt.PkgPath) && dt.PkgPath != rlm.Path { - fmt.Println("---set co to be cross realm object, co: ", co) - fmt.Printf("---%p\n", co) - co.SetIsCrossRealm(true) - //panic("!!!") - } - } - } - } - } - } + //// XXX, these can be improved by attach type info with co. + //// the following does not work + //if sv, ok := po.(*StructValue); ok { + // fmt.Println("---sv: ", sv) + // fmt.Println("---sv.ID: ", sv.ObjectInfo.ID) + // fmt.Println("---sv.Fields: ", sv.Fields) + // fmt.Println("---sv.OwnerID: ", sv.ObjectInfo.OwnerID) + //} else if bv, ok := po.(*Block); ok { + // for _, tv := range bv.Values { + // fmt.Println("----tv.T: ", tv.T) + // fmt.Println("----tv.V: ", tv.V) + // if csv, ok := co.(*StructValue); ok { + // if csv == tv.V { + // fmt.Println("---eql, csv: ", csv) + // fmt.Println("---eql, T: ", tv.T, reflect.TypeOf(tv.T)) + // if dt, ok := tv.T.(*DeclaredType); ok { + // fmt.Println("---dt: ", dt, dt.PkgPath) + // if IsRealmPath(dt.PkgPath) && dt.PkgPath != rlm.Path { + // fmt.Println("---set co to be cross realm object, co: ", co) + // fmt.Printf("---%p\n", co) + // co.SetIsCrossRealm(true) + // //panic("!!!") + // } + // } + // } + // } + // } + //} + + // XXX, association happens here + // if is co is attached to external realm + // if xo is attached to realm, directly/indirectly; + // if associated with reference, ok + // else, panic("should not associate with value cross realm + // else if xo is not attached to realm, associate is ok too, check when finalize. + // else, panic when finalizing current realm. fmt.Println("---realm: ", rlm) if rlm == nil { @@ -246,7 +255,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if xo != nil { xo.DecRefCount() - fmt.Println("---xo refCount after dec: ", xo.GetRefCount()) + fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) if xo.GetRefCount() == 0 { if xo.GetIsReal() { rlm.MarkNewDeleted(xo) @@ -399,6 +408,8 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { //---------------------------------------- // transactions +// TODO: check cross realm, that might be objects not attached +// to a realm gets attached here, which should panic. // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { fmt.Println("---FinalizeRealmTransaction---") diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 7231f1f4f74..ad6bc85a4b2 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -527,7 +527,7 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - nsv.ObjectInfo = sv.ObjectInfo.Copy() + //nsv.ObjectInfo = sv.ObjectInfo.Copy() return nsv //return alloc.NewStruct(fields) } diff --git a/gnovm/tests/files/zrealm_crossrealm26a.gno b/gnovm/tests/files/zrealm_crossrealm26a.gno index 1fbf476e917..76f3bc4c93b 100644 --- a/gnovm/tests/files/zrealm_crossrealm26a.gno +++ b/gnovm/tests/files/zrealm_crossrealm26a.gno @@ -14,7 +14,7 @@ func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer func init() { - f = fooer{name: "local_fooer"} + f = fooer{name: "local_fooer"} // NOTE, from now on f is attached } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm26b.gno b/gnovm/tests/files/zrealm_crossrealm26b.gno index de672d5cca3..d2e2c33864b 100644 --- a/gnovm/tests/files/zrealm_crossrealm26b.gno +++ b/gnovm/tests/files/zrealm_crossrealm26b.gno @@ -11,11 +11,11 @@ type fooer struct{ name string } func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var f fooer // this already attached +var f fooer // this is NOT attached func main() { crossrealm.AttachContainer() // this attaches container first - f = fooer{name: "local_fooer"} // update to an already attached object + f = fooer{name: "local_fooer"} // XXX, still not attached, panic crossrealm.SetContainer(&f) print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm26c.gno b/gnovm/tests/files/zrealm_crossrealm26c.gno index 3f7a92b33d0..35885aa0cd4 100644 --- a/gnovm/tests/files/zrealm_crossrealm26c.gno +++ b/gnovm/tests/files/zrealm_crossrealm26c.gno @@ -14,6 +14,6 @@ func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } func main() { crossrealm.AttachContainer() // this attaches container first var f fooer = fooer{name: "local_fooer"} // this is not attached, should panic, even not escape - crossrealm.SetContainer(f) + crossrealm.SetContainer(&f) print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index 28a091d7e7c..f0bbfee07de 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -16,14 +16,8 @@ var f fooer // XXX, this should work when reference to not attached local object // associated to external realm *NOT* attached object. func main() { - f = fooer{} - crossrealm.SetContainer(&f) + f = fooer{} // this is not attached + crossrealm.SetContainer(&f) // XXX, here should work to associate *NOT* attached object to external container + crossrealm.AttachContainer() // XXX, here should panic, to attach external *NOT* attached object print(".") } - -// Output: -// . - -// Error: - -// Realm: From a604cdc64befd20b9ce50eb9a9d295430173948a Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 16 Oct 2024 18:18:11 +0800 Subject: [PATCH 11/88] more test --- .../r/demo/tests/crossrealm/crossrealm2.gno | 10 +- .../r/demo/tests/crossrealm/crossrealm3.gno | 1 + .../r/demo/tests/crossrealm/crossrealm4.gno | 7 + gnovm/pkg/gnolang/machine.go | 2 +- gnovm/pkg/gnolang/op_call.go | 1 + gnovm/pkg/gnolang/op_eval.go | 2 +- gnovm/pkg/gnolang/ownership.go | 3 +- gnovm/pkg/gnolang/realm.go | 124 +++++++++--------- gnovm/pkg/gnolang/store.go | 6 +- gnovm/pkg/gnolang/values.go | 17 +-- gnovm/tests/files/zrealm_crossrealm15.gno | 8 -- gnovm/tests/files/zrealm_crossrealm16.gno | 10 +- gnovm/tests/files/zrealm_crossrealm16a.gno | 16 +++ gnovm/tests/files/zrealm_crossrealm17.gno | 5 +- gnovm/tests/files/zrealm_crossrealm20.gno | 33 ----- gnovm/tests/files/zrealm_crossrealm21.gno | 2 - gnovm/tests/files/zrealm_crossrealm21a.gno | 8 +- gnovm/tests/files/zrealm_crossrealm22.gno | 3 - gnovm/tests/files/zrealm_crossrealm24.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25.gno | 33 ----- gnovm/tests/files/zrealm_crossrealm25a.gno | 6 - gnovm/tests/files/zrealm_crossrealm25b.gno | 4 +- gnovm/tests/files/zrealm_crossrealm25c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm26.gno | 2 +- gnovm/tests/files/zrealm_crossrealm27.gno | 9 +- gnovm/tests/files/zrealm_crossrealm27a.gno | 19 +-- gnovm/tests/files/zrealm_crossrealm28.gno | 27 ++++ gnovm/tests/files/zrealm_crossrealm33.gno | 16 +++ 29 files changed, 174 insertions(+), 206 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm16a.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm20.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm33.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno index 784af2ab715..a85778e00c6 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno @@ -18,16 +18,22 @@ type Container struct { f Fooer } -var container Container // XXX, not attached here +var container Container // attached func AttachContainer() { container = Container{name: "external_container"} // attach after call } func SetContainer(f Fooer) { - container.f = f + container.f = f // update } func SetContainer2(f Fooer) { ff := f + container.f = f +} + +func SetContainer3(f Fooer) { + ff := f // associate to non-attached object + SetContainer(ff) // attach container, while ff is not attached } diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno index 6fb1b958baf..1d1c0cf6f35 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno @@ -5,6 +5,7 @@ type Bar struct { } var bar *Bar +var Bar2 *Bar // exported func SetBar(b *Bar) *Bar { bar = b diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno new file mode 100644 index 00000000000..e7d86663094 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno @@ -0,0 +1,7 @@ +package crossrealm + +var S []Fooer + +func SetSlice(fs []Fooer) { + S = fs +} diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 2a7323c3a3c..0265b45ba5e 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -730,7 +730,7 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { fmt.Println("---runInitFromUpdates") for _, tv := range updates { - fmt.Println("---tv: ", tv) + fmt.Println("---runInitFromUpdates, tv: ", tv) if tv.IsDefined() && tv.T.Kind() == FuncKind && tv.V != nil { fv, ok := tv.V.(*FuncValue) if !ok { diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index d148457bd89..34e4f553dff 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -241,6 +241,7 @@ func (m *Machine) doOpReturnFromBlock() { finalize = true } if finalize { + fmt.Println("---going to finalize") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 3ef6da71210..b13f06212b7 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -37,7 +37,7 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerTo(m.Store, nx.Path) - fmt.Println("---ptr: ", ptr) + //fmt.Println("---ptr: ", ptr) m.PushValue(ptr.Deref()) return } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 82e1d33f1e7..908c4ed8715 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -353,8 +353,9 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { fmt.Println("---rc: ", rc) fmt.Println("---v Owner: ", v.GetOwnerID()) fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) + fmt.Println("---is Attached?", v.GetIsReal()) } - return cv.GetBase(store) // TODO: this is not enough for pointers + return cv.GetBase(store) case *ArrayValue: return cv case *SliceValue: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 06ef3170578..0244b0c2229 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -139,51 +139,19 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + fmt.Printf("---xo: %p\n", xo) - fmt.Printf("xo: %p\n", xo) - if co != nil && co.GetIsCrossRealm() { - panic("!!!cross realm") - } + //if co != nil && co.GetIsCrossRealm() { + // panic("!!!cross realm") + //} if co != nil { - fmt.Println("--co isReal(attached): ", co.GetIsReal()) + fmt.Println("---co isReal(attached): ", co.GetIsReal()) fmt.Println("---co objectID: ", co.GetObjectID()) + fmt.Println("---co.GetObjectInfo:", co.GetObjectInfo()) + fmt.Printf("---co: %p\n", co) } - if co != nil { - fmt.Println("co.GetObjectInfo:", co.GetObjectInfo()) - fmt.Printf("co: %p\n", co) - } - - //// XXX, these can be improved by attach type info with co. - //// the following does not work - //if sv, ok := po.(*StructValue); ok { - // fmt.Println("---sv: ", sv) - // fmt.Println("---sv.ID: ", sv.ObjectInfo.ID) - // fmt.Println("---sv.Fields: ", sv.Fields) - // fmt.Println("---sv.OwnerID: ", sv.ObjectInfo.OwnerID) - //} else if bv, ok := po.(*Block); ok { - // for _, tv := range bv.Values { - // fmt.Println("----tv.T: ", tv.T) - // fmt.Println("----tv.V: ", tv.V) - // if csv, ok := co.(*StructValue); ok { - // if csv == tv.V { - // fmt.Println("---eql, csv: ", csv) - // fmt.Println("---eql, T: ", tv.T, reflect.TypeOf(tv.T)) - // if dt, ok := tv.T.(*DeclaredType); ok { - // fmt.Println("---dt: ", dt, dt.PkgPath) - // if IsRealmPath(dt.PkgPath) && dt.PkgPath != rlm.Path { - // fmt.Println("---set co to be cross realm object, co: ", co) - // fmt.Printf("---%p\n", co) - // co.SetIsCrossRealm(true) - // //panic("!!!") - // } - // } - // } - // } - // } - //} - // XXX, association happens here // if is co is attached to external realm // if xo is attached to realm, directly/indirectly; @@ -192,7 +160,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { // else if xo is not attached to realm, associate is ok too, check when finalize. // else, panic when finalizing current realm. - fmt.Println("---realm: ", rlm) + fmt.Println("---current realm: ", rlm) if rlm == nil { return } @@ -207,8 +175,17 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { panic("cannot attach to a deleted object") } } + + // check if assignee is attached, if yes and assigner is not attached, panic + if xo != nil { + fmt.Println("---xo.GetIsReal: ", xo.GetIsReal()) + } else { + println("---xo is nil") + } fmt.Println("---po.GetIsReal: ", po.GetIsReal()) + if po == nil || !po.GetIsReal() { // XXX, make sure po is attached + fmt.Println("---po(Base) not real, do nothing!!!") return // do nothing. } @@ -251,6 +228,8 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { co.SetOwner(po) rlm.MarkNewReal(co) // co will be attached when finalize } + } else { + println("---co is nil, do nothing") } if xo != nil { @@ -261,6 +240,8 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkNewDeleted(xo) } } + } else { + println("---xo is nil, do nothing") } } @@ -306,6 +287,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { func (rlm *Realm) MarkNewReal(oo Object) { fmt.Println("---markNewReal---, oo: ", oo) + fmt.Println("---markNewReal---, type of oo: ", reflect.TypeOf(oo)) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -341,7 +323,8 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - fmt.Printf("rlm: %v MarkDirty: %v\n", rlm, oo) + fmt.Printf("---current rlm: %v: \n", rlm) + fmt.Printf("---Mark Dirty %v: \n", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -412,9 +395,9 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { // to a realm gets attached here, which should panic. // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { - fmt.Println("---FinalizeRealmTransaction---") + fmt.Println("-------------FinalizeRealmTransaction---------------") defer func() { - fmt.Println("---done FinalizeRealmTransaction---") + fmt.Println("================done FinalizeRealmTransaction==================") }() if readonly { if true || @@ -490,15 +473,17 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // TODO: here check embedded object cross more := getChildObjects2(store, oo) fmt.Println("---children of oo: ", more) - for _, c := range more { - fmt.Printf("---%p\n", c) + fmt.Println("---len of children: ", len(more)) + for i, c := range more { + fmt.Printf("[%d] of children is: %v\n", i, c) + //fmt.Printf("---%p\n", c) if c.GetIsCrossRealm() { panic("---cross realm") } else { println("---not cross realm") } } - fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) + fmt.Println("---processNewCreatedMarks, oo.GetRefCount(): ", oo.GetRefCount()) if oo.GetIsCrossRealm() { fmt.Println("---should not attach value with type defined in other realm") //panic("---!!!") @@ -530,7 +515,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - fmt.Println("---incRefCreatedDescendants---, oo: ", oo) + fmt.Println("---incRefCreatedDescendants from oo: ", oo) fmt.Println("---incRefCreatedDescendants---, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { @@ -554,10 +539,11 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) - fmt.Println("---more: ", more) - for _, child := range more { - fmt.Printf("---child: %v, type of child: %v \n", child, reflect.TypeOf(child)) - fmt.Printf("---child addr: %p\n", child) + fmt.Println("---incRefCreatedDescendants, more: ", more) + fmt.Println("---len of more: ", len(more)) + for i, child := range more { + fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) + //fmt.Printf("---child addr: %p\n", child) if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -569,7 +555,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - fmt.Println("---rc: ", rc) + fmt.Println("---rc after inc: ", rc) if rc == 1 { fmt.Println("---rc == 1") if child.GetIsReal() { @@ -589,6 +575,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } else if rc > 1 { if child.GetIsEscaped() { + fmt.Println("---child is escaped, child: ", child) // already escaped, do nothing. } else { // NOTE: do not unset owner here, @@ -686,9 +673,9 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (and never can be unescaped,) // except for new-reals that get demoted // because ref-count isn't >= 2. - for _, eo := range rlm.newEscaped { - fmt.Println("---processNewEscapedMarks, eo, eo.GetRefCount: ", eo, eo.GetRefCount()) - fmt.Println("---processNewEscapedMarks, eo, eo.GetObjectID: ", eo, eo.GetObjectID()) + for i, eo := range rlm.newEscaped { + fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) + fmt.Println("---processNewEscapedMarks, eo.GetObjectID: ", eo.GetRefCount()) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -811,19 +798,25 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - fmt.Println("---saveUnsavedObjects---") + fmt.Println("---saveUnsavedObjects, new created, new updated---") + fmt.Println("---len of new created: ", len(rlm.created)) + fmt.Println("---len of new updated: ", len(rlm.updated)) for _, co := range rlm.created { + fmt.Println("------saveUnsavedObject, co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { + println("---not new real") // might have happened already as child // of something else created. continue } else { + println("---new real") rlm.saveUnsavedObjectRecursively(store, co) } } for _, uo := range rlm.updated { + fmt.Println("---uo: ", uo) // for i := len(rlm.updated) - 1; i >= 0; i-- { // uo := rlm.updated[i] if !uo.GetIsDirty() { @@ -838,6 +831,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { + fmt.Println("---saveUnsavedObjectRecursively, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -856,8 +850,14 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // first, save unsaved children. unsaved := getUnsavedChildObjects(oo) + fmt.Println("---unsaved: ", unsaved) for _, uch := range unsaved { + fmt.Println("---uch: ", uch) + fmt.Println("---uch.GetOwnerID(): ", uch.GetOwnerID()) + fmt.Println("---uch.GetRefCount(): ", uch.GetRefCount()) + fmt.Println("---type of uch: ", reflect.TypeOf(uch)) if uch.GetIsEscaped() || uch.GetIsNewEscaped() { + fmt.Println("---uch is escaped or new escaped") // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) @@ -865,6 +865,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // then, save self. if oo.GetIsNewReal() { + fmt.Println("---oo is new real: ", oo) // save created object. if debug { if oo.GetIsDirty() { @@ -874,6 +875,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { rlm.saveObject(store, oo) oo.SetIsNewReal(false) } else { + fmt.Println("---oo is not new real, update it: ", oo) // update existing object. if debug { if !oo.GetIsDirty() { @@ -892,7 +894,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { + fmt.Println("---saveObject: ", oo) oid := oo.GetObjectID() + fmt.Println("---saveObject: ", oid) if oid.IsZero() { panic("unexpected zero object id") } @@ -962,10 +966,10 @@ func (rlm *Realm) clearMarks() { func getSelfOrChildObjects(val Value, more []Value) []Value { fmt.Println("---getSelfOrChildObjects, val: ", val) if _, ok := val.(RefValue); ok { - println("---ref value") + //println("---ref value") return append(more, val) } else if _, ok := val.(Object); ok { - println("---not ref value") + //println("---not ref value") return append(more, val) } else { return getChildObjects(val, more) @@ -1061,11 +1065,11 @@ func getChildObjects2(store Store, val Value) []Object { objs := make([]Object, 0, len(chos)) for _, child := range chos { if ref, ok := child.(RefValue); ok { - println("---ref value") + //println("---ref value") oo := store.GetObject(ref.ObjectID) objs = append(objs, oo) } else if oo, ok := child.(Object); ok { - println("---not ref value") + //println("---not ref value") objs = append(objs, oo) } } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 30443032d12..69302a23a6d 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -328,7 +328,7 @@ func (ds *defaultStore) SetObject(oo Object) { oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - fmt.Println("---o2: ", o2) + fmt.Println("---SetObject, o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) // set hash. @@ -363,10 +363,10 @@ func (ds *defaultStore) SetObject(oo Object) { if ds.opslog != nil { var op StoreOpType if oo.GetIsNewReal() { - fmt.Println("---oo is new real, oo: ", oo) + fmt.Println("---SetObject, oo is new real, oo: ", oo) op = StoreOpNew } else { - fmt.Println("---oo is mod, oo: ", oo) + fmt.Println("---SetObject, oo is mod, oo: ", oo) op = StoreOpMod } ds.opslog = append(ds.opslog, diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index ad6bc85a4b2..a98868fb956 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -294,6 +294,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty pv.TV.Assign(alloc, tv2, cu) oo2 := pv.TV.GetFirstObject(store) fmt.Println("---oo2: ", oo2) + // TODO: assert attached here? rlm.DidUpdate(pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) @@ -2451,9 +2452,9 @@ func (b *Block) GetParent(store Store) *Block { } func (b *Block) GetPointerToInt(store Store, index int) PointerValue { - fmt.Println("---GetPointerToInt") + //fmt.Println("---GetPointerToInt") vv := fillValueTV(store, &b.Values[index]) - fmt.Println("---vv: ", vv) + //fmt.Println("---vv: ", vv) return PointerValue{ TV: vv, Base: b, @@ -2462,9 +2463,9 @@ func (b *Block) GetPointerToInt(store Store, index int) PointerValue { } func (b *Block) GetPointerTo(store Store, path ValuePath) PointerValue { - fmt.Println("---GetPointerTo, path: ", path) + //fmt.Println("---GetPointerTo, path: ", path) if path.IsBlockBlankPath() { - println("---isBlockBlankPath") + //println("---isBlockBlankPath") if debug { if path.Name != blankIdentifier { panic(fmt.Sprintf( @@ -2645,17 +2646,17 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - fmt.Println("---fillValueTV, tv: ", tv) + //fmt.Println("---fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: - println("---tv.V RefValue") - fmt.Println("---cv: ", cv) + //println("---tv.V RefValue") + //fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) - fmt.Println("---tv.V: ", tv.V) + //fmt.Println("---tv.V: ", tv.V) } case PointerValue: // As a special case, cv.Base is filled diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index fd870731c0e..40b94662a70 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -25,11 +25,3 @@ func main() { crossrealm.CallFoo() print(".") } - -// Output: -// hello gno.land/r/demo/tests/crossrealm -// . - -// Error: - -// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index fd9f9889c38..50c695884c4 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -8,17 +8,11 @@ import ( var b0 crossrealm.Bar func init() { - b0 = crossrealm.Bar{A: 1} // attach to this realm + b0 = crossrealm.Bar{A: 1} // XXX, should be invalid to attach external type } func main() { - crossrealm.SetBar(&b0) // set reference to external realm + crossrealm.SetBar(&b0) crossrealm.CallBar() print(".") } - -// Output: -// 1 -// . - -// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm16a.gno b/gnovm/tests/files/zrealm_crossrealm16a.gno new file mode 100644 index 00000000000..5fbe6a072ab --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm16a.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 crossrealm.Bar + +func init() { + crossrealm.Bar2.A = 2 // this should be valid +} + +func main() { + print(".") +} diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 2cc82b960d5..e5587dedbee 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -16,10 +16,7 @@ type fooer struct{} var f *fooer func main() { - // not finalize yet, so this reference can not be attached to external realm, - // can only be associated to un-attached objects, only until the un-attached - // objects has not been attached to the external realm yet. - f = &fooer{} + f = &fooer{} // not attached c := &container{f} crossrealm.SetFooer(c) crossrealm.CallFoo() diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno deleted file mode 100644 index 62b6d08c78f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ /dev/null @@ -1,33 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -var b0 = crossrealm.Bar{A: 1} - -// un-attached package level var -// is this attached? or not? another function to attach? -//var b *crossrealm.Bar = crossrealm.SetBar(&b0) - -func init() { - // crossrealm.CallFoo() - crossrealm.SetBar(&b0) -} - -func main() { - crossrealm.CallBar() - print(".") -} - -// Output: -// hello gno.land/r/demo/tests/crossrealm -// hello gno.land/r/demo/tests/crossrealm -// . - -// Error: - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 11093213162..324f669805b 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -18,5 +18,3 @@ func main() { // XXX, this should fail while trying to attach // value of type defined in another realm. // NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). - -// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index e77837400e3..63e514b8f0f 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -15,15 +15,9 @@ var c Container func init() { b0 := crossrealm.Bar{A: 1} // this is valid association - c = Container{name: "container", b: b0} // XXX, check recursively while finalize here + c = Container{name: "container", b: b0} // XXX, should panic } func main() { print(".") } - -// XXX, this should fail while trying to attach -// value of type defined in another realm. -// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). - -// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 14c3dbd5311..02a612bea9a 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -16,6 +16,3 @@ func main() { } // XXX this works. attach value with type defined in same realm - -// Output: -//. diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 01934436225..a7697ffd980 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -16,7 +16,7 @@ func main() { } // XXX, should work to attach by reference to -// type defined in another realm. +// type defined in another realm??? // Output: // . diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno deleted file mode 100644 index 10b37896c8f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ /dev/null @@ -1,33 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -// When an association occurs by reference to an object already -// attached to an external realm, no attachment occurs. For example, -// pointers to external realm attached objects may be associated -// with a realm object (whether attached or not), such as assigned -// to the field of a struct, but this does not attach the external -// realm object to the container, in this case the struct. -func init() { - f = fooer{name: "local_fooer"} // f attached to current realm -} - -func main() { - crossrealm.AttachContainer() // this attaches container first - crossrealm.SetContainer(&f) - print(".") -} - -// XXX, this associate a pointer to a value(already attached to local realm) -// to external realm, no attachment happens to the external realm. diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno index 7064b364d3d..ba2b51e1fe8 100644 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -13,12 +13,6 @@ func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer -// When an association occurs by reference to an object already -// attached to an external realm, no attachment occurs. For example, -// pointers to external realm attached objects may be associated -// with a realm object (whether attached or not), such as assigned -// to the field of a struct, but this does not attach the external -// realm object to the container, in this case the struct. func init() { f = fooer{} } diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno index 57cfe2324ae..ac2e2dce401 100644 --- a/gnovm/tests/files/zrealm_crossrealm25b.gno +++ b/gnovm/tests/files/zrealm_crossrealm25b.gno @@ -1,8 +1,6 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -// pass pointer to an embedded object to external realm? - import ( "std" @@ -31,3 +29,5 @@ func main() { crossrealm.SetContainer(&lc.f) print(".") } + +// XXX? diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno index 9e8f961a21f..9a1d0e9cb1b 100644 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -27,7 +27,7 @@ func init() { } func main() { - crossrealm.AttachContainer() // this attaches container first + crossrealm.AttachContainer() crossrealm.SetContainer(lc.f) // should work print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno index 46ccf45dac7..7558c658b46 100644 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -30,7 +30,7 @@ func init() { } func main() { - crossrealm.AttachContainer() // this attaches container first + crossrealm.AttachContainer() crossrealm.SetContainer(lc.ff) // this should not panic, lc.ff is not same with f(gloabl) print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm26.gno b/gnovm/tests/files/zrealm_crossrealm26.gno index 3dfabfd14fe..5148cc0fefa 100644 --- a/gnovm/tests/files/zrealm_crossrealm26.gno +++ b/gnovm/tests/files/zrealm_crossrealm26.gno @@ -18,7 +18,7 @@ func init() { } func main() { - crossrealm.AttachContainer() // this attaches container first + crossrealm.AttachContainer() crossrealm.SetContainer(f) print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index f0bbfee07de..32f8dd834f8 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -7,7 +7,9 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct { + name string +} func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } @@ -16,8 +18,7 @@ var f fooer // XXX, this should work when reference to not attached local object // associated to external realm *NOT* attached object. func main() { - f = fooer{} // this is not attached - crossrealm.SetContainer(&f) // XXX, here should work to associate *NOT* attached object to external container - crossrealm.AttachContainer() // XXX, here should panic, to attach external *NOT* attached object + f = fooer{name: "local_fooer"} // this is not attached + crossrealm.SetContainer2(&f) // XXX, here should work to associate *NOT* attached object to external container print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm27a.gno index 6d29277240e..47ac14ecb04 100644 --- a/gnovm/tests/files/zrealm_crossrealm27a.gno +++ b/gnovm/tests/files/zrealm_crossrealm27a.gno @@ -7,27 +7,14 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct{ name string } func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer -// XXX, this should work when reference to not attached local object -// associated to external realm *NOT* attached object. -// XXX, panic should happen when the attachment happen in external realm - -// In this way, all references to external realm objects that are reachable -// from a realm’s package global variables must already be attached to the external realm. func main() { - f = fooer{} - crossrealm.SetContainer(&f) + f = fooer{name: "local_fooer"} + crossrealm.SetContainer3(&f) print(".") } - -// Output: -// . - -// Error: - -// Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno new file mode 100644 index 00000000000..65084d77c19 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var fs []crossrealm.Fooer + +func init() { + fs = append(fs, foo{name: "1"}) + fs = append(fs, foo{name: "2"}) + fs = append(fs, foo{name: "3"}) +} + +func main() { + println("ok") + crossrealm.SetSlice(fs) +} diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno new file mode 100644 index 00000000000..b9d6d5e9718 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +var ptr *int + +func init() { + ptr = new(int) +} + +func main() { + *ptr = 2 + println(*ptr) +} + +// Output: +// 2 From 2e6a97c27fb0bed8799e5f5583763ef245fa6d5f Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 6 Nov 2024 09:38:50 +0800 Subject: [PATCH 12/88] save --- gnovm/tests/files/zrealm_crossrealm23a.gno | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index 61d8f0ec291..b3f4f2ccd93 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -16,6 +16,4 @@ func main() { } // XXX, this works, attach reference with type defined in p - -// Output: -//. +// Attach pointer? From 7bedb54e4a6226fe1439fd4085c36b78dd477ad1 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 7 Nov 2024 07:32:51 +0800 Subject: [PATCH 13/88] save --- gnovm/pkg/gnolang/machine.go | 3 ++ gnovm/pkg/gnolang/realm.go | 44 ++++++++++++----------- gnovm/tests/files/zrealm_crossrealm21.gno | 2 +- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 0265b45ba5e..7d00e8f0bef 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -287,6 +287,8 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *std.MemPackage, save bool) func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { fmt.Println("---runMemPackage, save: ", save) + fmt.Println("---runMemPackage, memPkg: ", memPkg) + defer func() { fmt.Println("---done runMemPackage: ", memPkg) }() // parse files. files := ParseMemPackage(memPkg) if !overrides && checkDuplicates(files) { @@ -976,6 +978,7 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { + fmt.Println("---run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 0244b0c2229..49444d2f794 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -465,24 +465,25 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { fmt.Println("---processNewCreatedMarks---") + fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] fmt.Printf("---oo[%d] is %v:\n", i, oo) // TODO: here check embedded object cross - more := getChildObjects2(store, oo) - fmt.Println("---children of oo: ", more) - fmt.Println("---len of children: ", len(more)) - for i, c := range more { - fmt.Printf("[%d] of children is: %v\n", i, c) - //fmt.Printf("---%p\n", c) - if c.GetIsCrossRealm() { - panic("---cross realm") - } else { - println("---not cross realm") - } - } + //more := getChildObjects2(store, oo) + //fmt.Println("---children of oo: ", more) + //fmt.Println("---len of children: ", len(more)) + //for i, c := range more { + // fmt.Printf("[%d] of children is: %v\n", i, c) + // //fmt.Printf("---%p\n", c) + // if c.GetIsCrossRealm() { + // panic("---cross realm") + // } else { + // println("---not cross realm") + // } + //} fmt.Println("---processNewCreatedMarks, oo.GetRefCount(): ", oo.GetRefCount()) if oo.GetIsCrossRealm() { fmt.Println("---should not attach value with type defined in other realm") @@ -516,7 +517,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { fmt.Println("---incRefCreatedDescendants from oo: ", oo) - fmt.Println("---incRefCreatedDescendants---, oo.GetObjectID: ", oo.GetObjectID()) + fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -539,7 +540,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) - fmt.Println("---incRefCreatedDescendants, more: ", more) + //fmt.Println("---incRefCreatedDescendants, more: ", more) fmt.Println("---len of more: ", len(more)) for i, child := range more { fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) @@ -557,7 +558,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { rc := child.GetRefCount() fmt.Println("---rc after inc: ", rc) if rc == 1 { - fmt.Println("---rc == 1") if child.GetIsReal() { fmt.Println("---child is real, child: ", child) // a deleted real became undeleted. @@ -569,6 +569,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // became real (again). // NOTE: may already be marked for first gen // newCreated or updated. + //fmt.Println("---Set owner to be: ", oo) + println("---set owner") child.SetOwner(oo) rlm.incRefCreatedDescendants(store, child) child.SetIsNewReal(true) @@ -964,7 +966,7 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - fmt.Println("---getSelfOrChildObjects, val: ", val) + //fmt.Println("---getSelfOrChildObjects, val: ", val) if _, ok := val.(RefValue); ok { //println("---ref value") return append(more, val) @@ -979,7 +981,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - fmt.Println("---getChildObjects, val: ", val, reflect.TypeOf(val)) + //fmt.Println("---getChildObjects, val: ", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1006,10 +1008,10 @@ func getChildObjects(val Value, more []Value) []Value { more = getSelfOrChildObjects(cv.Base, more) return more case *StructValue: - println("---struct value") + //println("---struct value") for _, ctv := range cv.Fields { // TODO: we have type infos here, so check check cross realm logic - fmt.Println("---ctv: ", ctv) + //fmt.Println("---ctv: ", ctv) more = getSelfOrChildObjects(ctv.V, more) } return more @@ -1059,9 +1061,9 @@ func getChildObjects(val Value, more []Value) []Value { // like getChildObjects() but loads RefValues into objects. func getChildObjects2(store Store, val Value) []Object { - fmt.Println("---getChildObjects2, val: ", val) + //fmt.Println("---getChildObjects2, val: ", val) chos := getChildObjects(val, nil) - fmt.Println("---chos: ", chos) + //fmt.Println("---chos: ", chos) objs := make([]Object, 0, len(chos)) for _, child := range chos { if ref, ok := child.(RefValue); ok { diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 324f669805b..b065e31ee06 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -5,7 +5,7 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -var b0 crossrealm.Bar +var b0 crossrealm.Bar // run declarations func init() { b0 = crossrealm.Bar{A: 1} From eeb5bd8e5096504f5198278a51ec379fc9947a9a Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Fri, 8 Nov 2024 09:21:41 +0800 Subject: [PATCH 14/88] more obj info --- gnovm/pkg/gnolang/machine.go | 1 + gnovm/pkg/gnolang/ownership.go | 89 +++++++++++++++++++++-- gnovm/pkg/gnolang/realm.go | 20 +++-- gnovm/pkg/gnolang/values.go | 13 +++- gnovm/tests/files/zrealm_crossrealm20.gno | 16 ++++ 5 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm20.gno diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 7d00e8f0bef..0f5d705b7e1 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -985,6 +985,7 @@ func (m *Machine) runDeclaration(d Decl) { // closure and package already set // during PackageNode.NewPackage(). case *ValueDecl: + fmt.Println("---valueDecl, d.Type, type of d.Type: ", d.Type, reflect.TypeOf(d.Type)) m.PushOp(OpHalt) m.PushStmt(d) m.PushOp(OpExec) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 908c4ed8715..fa9955e9090 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -113,8 +113,8 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) - GetIsCrossRealm() bool // XXX, does escape imply this? - SetIsCrossRealm(bool) + GetLastNewEscapedRealm() PkgID // XXX, does escape imply this? + SetLastNewEscapedRealm(pkgID PkgID) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -208,6 +208,9 @@ func (oi *ObjectInfo) MustGetObjectID() ObjectID { func (oi *ObjectInfo) SetObjectID(oid ObjectID) { oi.ID = oid } +func (oi *ObjectInfo) SetLastEscapedRealm(pkgId PkgID) { + oi.lastNewRealEscapedRealm = pkgId +} func (oi *ObjectInfo) GetHash() ValueHash { return oi.Hash @@ -313,12 +316,12 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { oi.isNewReal = x } -func (oi *ObjectInfo) GetIsCrossRealm() bool { - return oi.isCrossRealm +func (oi *ObjectInfo) GetLastNewEscapedRealm() PkgID { + return oi.lastNewRealEscapedRealm } -func (oi *ObjectInfo) SetIsCrossRealm(x bool) { - oi.isCrossRealm = x +func (oi *ObjectInfo) SetLastNewEscapedRealm(pkgId PkgID) { + oi.lastNewRealEscapedRealm = pkgId } func (oi *ObjectInfo) GetIsNewEscaped() bool { @@ -344,6 +347,14 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { fmt.Println("---GetFirstObject---, tv: ", tv, reflect.TypeOf(tv.V)) + fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) + if dt, ok := tv.T.(*DeclaredType); ok { + fmt.Println("---dt: ", dt) + fmt.Println("---dt.Name: ", dt.Name) + fmt.Println("---dt.PkgPath: ", dt.PkgPath) + fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + fmt.Println("---dt.Base: ", dt.Base) + } switch cv := tv.V.(type) { case PointerValue: println("---pointer value, get base") @@ -387,3 +398,69 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { return nil } } + +// XXX, get first accessible object, maybe containing(parent) object, maybe itself. +func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID) { + fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) + fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) + var pkgId PkgID + if dt, ok := tv.T.(*DeclaredType); ok { + fmt.Println("---dt: ", dt) + fmt.Println("---dt.Name: ", dt.Name) + fmt.Println("---dt.PkgPath: ", dt.PkgPath) + fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + fmt.Println("---dt.Base: ", dt.Base) + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } + switch cv := tv.V.(type) { + case PointerValue: + println("---pointer value, get base") + if v, ok := cv.TV.V.(Object); ok { + fmt.Println("---v: ", v) + rc := v.GetRefCount() + fmt.Println("---rc: ", rc) + fmt.Println("---v Owner: ", v.GetOwnerID()) + fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) + fmt.Println("---is Attached?", v.GetIsReal()) + + if dt, ok := cv.TV.T.(*DeclaredType); ok { + fmt.Println("---dt: ", dt) + fmt.Println("---dt.Name: ", dt.Name) + fmt.Println("---dt.PkgPath: ", dt.PkgPath) + fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + fmt.Println("---dt.Base: ", dt.Base) + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } + } + return cv.GetBase(store), pkgId + case *ArrayValue: + return cv, pkgId + case *SliceValue: + return cv.GetBase(store), pkgId + case *StructValue: + println("---struct value") + fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) + return cv, pkgId + case *FuncValue: + return cv.GetClosure(store), pkgId + case *MapValue: + return cv, pkgId + case *BoundMethodValue: + return cv, pkgId + case *NativeValue: + // XXX allow PointerValue.Assign2 to pass nil for oo1/oo2. + // panic("realm logic for native values not supported") + return nil, pkgId + case *Block: + return cv, pkgId + case RefValue: + oo := store.GetObject(cv.ObjectID) + tv.V = oo + return oo, pkgId + case *HeapItemValue: + // should only appear in PointerValue.Base + panic("heap item value should only appear as a pointer's base") + default: + return nil, pkgId + } +} diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 49444d2f794..136d831983b 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -135,11 +135,17 @@ func (rlm *Realm) String() string { // associated object. // TODO: func (rlm *Realm) DidUpdate(po, xo, co Object, attached bool) { func (rlm *Realm) DidUpdate(po, xo, co Object) { - fmt.Println("---DidUpdate---") + fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - fmt.Printf("---xo: %p\n", xo) + //fmt.Printf("---xo: %p\n", xo) + if co != nil { + fmt.Println("co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) + if rlm.ID != co.GetLastNewEscapedRealm() { + panic("---cross realm!!!") + } + } //if co != nil && co.GetIsCrossRealm() { // panic("!!!cross realm") @@ -149,7 +155,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---co isReal(attached): ", co.GetIsReal()) fmt.Println("---co objectID: ", co.GetObjectID()) fmt.Println("---co.GetObjectInfo:", co.GetObjectInfo()) - fmt.Printf("---co: %p\n", co) + //fmt.Printf("---co: %p\n", co) } // XXX, association happens here @@ -485,10 +491,10 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // } //} fmt.Println("---processNewCreatedMarks, oo.GetRefCount(): ", oo.GetRefCount()) - if oo.GetIsCrossRealm() { - fmt.Println("---should not attach value with type defined in other realm") - //panic("---!!!") - } + //if oo.GetIsCrossRealm() { + // fmt.Println("---should not attach value with type defined in other realm") + // //panic("---!!!") + //} if debug { if oo.GetIsDirty() { panic("new created mark cannot be dirty") diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index a98868fb956..34b79de13c1 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -291,9 +291,20 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) fmt.Println("---oo1: ", oo1) + if oo1 != nil { + fmt.Println("---oo1.GetObjectID: ", oo1.GetObjectID()) + } pv.TV.Assign(alloc, tv2, cu) - oo2 := pv.TV.GetFirstObject(store) + oo2, pkgId := pv.TV.GetFirstObject2(store) fmt.Println("---oo2: ", oo2) + //fmt.Println("---oo2 objectInfo: ", oo2.GetObjectInfo()) + fmt.Println("---oo2 pkgId: ", pkgId) + //if oo2 != nil { + // fmt.Println("---oo2.GetObjectID: ", oo2.GetObjectID()) + //} + if oo2 != nil { + oo2.SetLastNewEscapedRealm(pkgId) + } // TODO: assert attached here? rlm.DidUpdate(pv.Base.(Object), oo1, oo2) } else { diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno new file mode 100644 index 00000000000..06c81304212 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type local struct{} + +var a local + +var b0 crossrealm.Bar // run declarations + +func main() { + print(".") +} From 9175b859e6facc83c32d22352f487ed56df36f1f Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sat, 9 Nov 2024 22:41:16 +0800 Subject: [PATCH 15/88] test --- gnovm/pkg/gnolang/machine.go | 27 ++++++----- gnovm/pkg/gnolang/op_assign.go | 2 + gnovm/pkg/gnolang/op_exec.go | 1 + gnovm/pkg/gnolang/ownership.go | 36 +++++++++------ gnovm/pkg/gnolang/realm.go | 54 +++++++++++++++++----- gnovm/pkg/gnolang/values.go | 4 +- gnovm/tests/files/zrealm_crossrealm20.gno | 3 ++ gnovm/tests/files/zrealm_crossrealm21.gno | 3 ++ gnovm/tests/files/zrealm_crossrealm21a.gno | 3 ++ gnovm/tests/files/zrealm_crossrealm22.gno | 3 ++ gnovm/tests/files/zrealm_crossrealm23.gno | 2 +- gnovm/tests/files/zrealm_crossrealm23a.gno | 3 ++ gnovm/tests/files/zrealm_crossrealm25.gno | 27 +++++++++++ 13 files changed, 127 insertions(+), 41 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm25.gno diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 0f5d705b7e1..276ddc94f5f 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -492,19 +492,22 @@ func (m *Machine) Stacktrace() (stacktrace Stacktrace) { } calls := make([]StacktraceCall, 0, len(m.Stmts)) - nextStmtIndex := len(m.Stmts) - 1 - for i := len(m.Frames) - 1; i >= 0; i-- { - if m.Frames[i].IsCall() { - stm := m.Stmts[nextStmtIndex] - bs := stm.(*bodyStmt) - stm = bs.Body[bs.NextBodyIndex-1] - calls = append(calls, StacktraceCall{ - Stmt: stm, - Frame: m.Frames[i], - }) + var nextStmtIndex int + if len(m.Stmts) > 0 { + nextStmtIndex = len(m.Stmts) - 1 + for i := len(m.Frames) - 1; i >= 0; i-- { + if m.Frames[i].IsCall() { + stm := m.Stmts[nextStmtIndex] + bs := stm.(*bodyStmt) + stm = bs.Body[bs.NextBodyIndex-1] + calls = append(calls, StacktraceCall{ + Stmt: stm, + Frame: m.Frames[i], + }) + } + // if the frame is a call, the next statement is the last statement of the frame. + nextStmtIndex = m.Frames[i].NumStmts - 1 } - // if the frame is a call, the next statement is the last statement of the frame. - nextStmtIndex = m.Frames[i].NumStmts - 1 } // if the stacktrace is too long, we trim it down to maxStacktraceSize diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index a10429367ae..5a65d9f1190 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -3,11 +3,13 @@ package gnolang import "fmt" func (m *Machine) doOpDefine() { + fmt.Println("---doOpDefine---") s := m.PopStmt().(*AssignStmt) // Define each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. rvs := m.PopValues(len(s.Lhs)) + fmt.Println("---rvs: ", rvs) lb := m.LastBlock() for i := 0; i < len(s.Lhs); i++ { // Get name and value of i'th term. diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index a0f84f82e66..a17f0203e1c 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -432,6 +432,7 @@ EXEC_SWITCH: if debug { debug.Printf("EXEC: %v\n", s) } + fmt.Printf("EXEC: %v\n", s) switch cs := s.(type) { case *AssignStmt: switch cs.Op { diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index fa9955e9090..0f2bfed10dd 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -158,12 +158,13 @@ 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, + ID: oi.ID, + Hash: oi.Hash.Copy(), + OwnerID: oi.OwnerID, + ModTime: oi.ModTime, + RefCount: oi.RefCount, + IsEscaped: oi.IsEscaped, + lastNewRealEscapedRealm: oi.lastNewRealEscapedRealm, /* // XXX do the following need copying too? isDirty: oi.isDirty, @@ -321,6 +322,7 @@ func (oi *ObjectInfo) GetLastNewEscapedRealm() PkgID { } func (oi *ObjectInfo) SetLastNewEscapedRealm(pkgId PkgID) { + fmt.Println("---SetLastNewEscapedRealm") oi.lastNewRealEscapedRealm = pkgId } @@ -410,7 +412,9 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID) { fmt.Println("---dt.PkgPath: ", dt.PkgPath) fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) fmt.Println("---dt.Base: ", dt.Base) - pkgId = PkgIDFromPkgPath(dt.PkgPath) + if IsRealmPath(dt.PkgPath) { + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } } switch cv := tv.V.(type) { case PointerValue: @@ -423,14 +427,16 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID) { fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) fmt.Println("---is Attached?", v.GetIsReal()) - if dt, ok := cv.TV.T.(*DeclaredType); ok { - fmt.Println("---dt: ", dt) - fmt.Println("---dt.Name: ", dt.Name) - fmt.Println("---dt.PkgPath: ", dt.PkgPath) - fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) - fmt.Println("---dt.Base: ", dt.Base) - pkgId = PkgIDFromPkgPath(dt.PkgPath) - } + //if dt, ok := cv.TV.T.(*DeclaredType); ok { + // fmt.Println("---dt: ", dt) + // fmt.Println("---dt.Name: ", dt.Name) + // fmt.Println("---dt.PkgPath: ", dt.PkgPath) + // fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + // fmt.Println("---dt.Base: ", dt.Base) + // if IsRealmPath(dt.PkgPath) { + // pkgId = PkgIDFromPkgPath(dt.PkgPath) + // } + //} } return cv.GetBase(store), pkgId case *ArrayValue: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 136d831983b..4fe9f3052ef 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -138,15 +138,15 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) //fmt.Printf("---xo: %p\n", xo) if co != nil { - fmt.Println("co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) - if rlm.ID != co.GetLastNewEscapedRealm() { - panic("---cross realm!!!") - } + fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) + //if rlm.ID != co.GetLastNewEscapedRealm() { + // panic("---cross realm!!!") + //} } + fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) //if co != nil && co.GetIsCrossRealm() { // panic("!!!cross realm") //} @@ -265,9 +265,9 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { if oi.GetIsReal() { lastRealmID := oi.GetObjectID().PkgID fmt.Println("lastRealmID: ", lastRealmID) - if lastRealmID != rlm.ID { - panic("should not happen, cross realm!!!") - } + //if lastRealmID != rlm.ID { + // panic("should not happen, cross realm!!!") + //} } if oi.lastNewRealEscapedRealm == rlm.ID { @@ -520,9 +520,18 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { } } +func isEmptyRealmID(pkgId PkgID) bool { + if pkgId.String() == "RID0000000000000000000000000000000000000000" { + return true + } + return false +} + // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - fmt.Println("---incRefCreatedDescendants from oo: ", oo) + fmt.Println("---incRefCreatedDescendants from oo: \n", oo) + fmt.Printf("addr of oo %p: ", oo) + fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { @@ -533,6 +542,19 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } + // make some pkgId logic while assign + _, ok1 := oo.(*PackageValue) + _, ok2 := oo.(*Block) + if !ok1 && !ok2 { + if !isEmptyRealmID(oo.GetLastNewEscapedRealm()) { // ! /p + if oo.GetLastNewEscapedRealm() != rlm.ID { + fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) + fmt.Println("---rlm.ID: ", rlm.ID) + panic("!!!cross realm while attach object") + } + } + } + // RECURSE GUARD // if id already set, skip. // this happens when a node marked created was already @@ -683,6 +705,14 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // because ref-count isn't >= 2. for i, eo := range rlm.newEscaped { fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) + fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) + fmt.Println("---rlm.ID: ", rlm.ID) + // only check object from another realm + if !isEmptyRealmID(eo.GetLastNewEscapedRealm()) { + if eo.GetLastNewEscapedRealm() != rlm.ID { + panic("!!!Cross realm update") + } + } fmt.Println("---processNewEscapedMarks, eo.GetObjectID: ", eo.GetRefCount()) if debug { if !eo.GetIsNewEscaped() { @@ -1014,10 +1044,10 @@ func getChildObjects(val Value, more []Value) []Value { more = getSelfOrChildObjects(cv.Base, more) return more case *StructValue: - //println("---struct value") + println("---struct value") for _, ctv := range cv.Fields { // TODO: we have type infos here, so check check cross realm logic - //fmt.Println("---ctv: ", ctv) + fmt.Println("---ctv: ", ctv) more = getSelfOrChildObjects(ctv.V, more) } return more @@ -1067,7 +1097,7 @@ func getChildObjects(val Value, more []Value) []Value { // like getChildObjects() but loads RefValues into objects. func getChildObjects2(store Store, val Value) []Object { - //fmt.Println("---getChildObjects2, val: ", val) + fmt.Println("---getChildObjects2, val: ", val) chos := getChildObjects(val, nil) //fmt.Println("---chos: ", chos) objs := make([]Object, 0, len(chos)) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 34b79de13c1..f9d76993793 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -303,6 +303,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // fmt.Println("---oo2.GetObjectID: ", oo2.GetObjectID()) //} if oo2 != nil { + fmt.Printf("addr of oo2: %p \n", oo2) oo2.SetLastNewEscapedRealm(pkgId) } // TODO: assert attached here? @@ -539,7 +540,8 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - //nsv.ObjectInfo = sv.ObjectInfo.Copy() + fmt.Println("---sv.ObjectInfo", sv.ObjectInfo) + nsv.ObjectInfo = sv.ObjectInfo.Copy() return nsv //return alloc.NewStruct(fields) } diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno index 06c81304212..53dd1b9d8a8 100644 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -14,3 +14,6 @@ var b0 crossrealm.Bar // run declarations func main() { print(".") } + +// Error: +// !!!cross realm while attach object diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index b065e31ee06..1933c54d8c2 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -18,3 +18,6 @@ func main() { // XXX, this should fail while trying to attach // value of type defined in another realm. // NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). + +// Error: +// !!!cross realm while attach object diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index 63e514b8f0f..bd9ae0186d0 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -21,3 +21,6 @@ func init() { func main() { print(".") } + +// Error: +// !!!cross realm while attach object diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 02a612bea9a..708e190c7f7 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -16,3 +16,6 @@ func main() { } // XXX this works. attach value with type defined in same realm + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm23.gno b/gnovm/tests/files/zrealm_crossrealm23.gno index 554bd41ceb0..2f0e9e1d6f2 100644 --- a/gnovm/tests/files/zrealm_crossrealm23.gno +++ b/gnovm/tests/files/zrealm_crossrealm23.gno @@ -18,4 +18,4 @@ func main() { // XXX, this works attach value with type defined in p // Output: -//. +// . diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index b3f4f2ccd93..18a9d1c324a 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -17,3 +17,6 @@ func main() { // XXX, this works, attach reference with type defined in p // Attach pointer? + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno new file mode 100644 index 00000000000..f451100e94a --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct{} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + +func init() { + f = fooer{} +} + +func main() { + + crossrealm.SetContainer(f) + print(".") +} + +// Error: +// !!!Cross realm update From c41caa3e50c6440086f375bb0127c0ee8eb90b02 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 12 Nov 2024 16:20:02 +0800 Subject: [PATCH 16/88] make test pass --- gnovm/pkg/gnolang/ownership.go | 47 ++--- gnovm/pkg/gnolang/realm.go | 204 +++++++++++---------- gnovm/pkg/gnolang/values.go | 9 +- gnovm/tests/files/zrealm_crossrealm20.gno | 6 +- gnovm/tests/files/zrealm_crossrealm21.gno | 12 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22.gno | 2 - gnovm/tests/files/zrealm_crossrealm23a.gno | 3 - gnovm/tests/files/zrealm_crossrealm24.gno | 8 + gnovm/tests/files/zrealm_crossrealm25.gno | 7 +- gnovm/tests/files/zrealm_crossrealm25a.gno | 6 +- gnovm/tests/files/zrealm_crossrealm25b.gno | 5 +- gnovm/tests/files/zrealm_crossrealm25c.gno | 8 +- gnovm/tests/files/zrealm_crossrealm25d.gno | 12 +- gnovm/tests/files/zrealm_crossrealm25e.gno | 32 ++++ gnovm/tests/files/zrealm_crossrealm26.gno | 24 --- gnovm/tests/files/zrealm_crossrealm26a.gno | 24 --- gnovm/tests/files/zrealm_crossrealm26b.gno | 21 --- gnovm/tests/files/zrealm_crossrealm26c.gno | 19 -- gnovm/tests/files/zrealm_crossrealm27.gno | 9 +- gnovm/tests/files/zrealm_crossrealm27a.gno | 13 +- 21 files changed, 212 insertions(+), 261 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm25e.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm26.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm26a.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm26b.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm26c.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 0f2bfed10dd..e4a51596b39 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -149,7 +149,7 @@ type ObjectInfo struct { isCrossRealm bool isNewEscaped bool isNewDeleted bool - lastNewRealEscapedRealm PkgID // realm attached and escaped + lastNewRealEscapedRealm PkgID // XXX huh? owner Object // mem reference to owner. @@ -402,7 +402,7 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } // XXX, get first accessible object, maybe containing(parent) object, maybe itself. -func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID) { +func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID, bool) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) var pkgId PkgID @@ -427,46 +427,47 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID) { fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) fmt.Println("---is Attached?", v.GetIsReal()) - //if dt, ok := cv.TV.T.(*DeclaredType); ok { - // fmt.Println("---dt: ", dt) - // fmt.Println("---dt.Name: ", dt.Name) - // fmt.Println("---dt.PkgPath: ", dt.PkgPath) - // fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) - // fmt.Println("---dt.Base: ", dt.Base) - // if IsRealmPath(dt.PkgPath) { - // pkgId = PkgIDFromPkgPath(dt.PkgPath) - // } - //} + if dt, ok := cv.TV.T.(*DeclaredType); ok { + // b0 = &crossrealm.Bar{A: 1} this is valid + // no need to check cross + // XXX, is it right? + if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { + if IsRealmPath(dt.PkgPath) { + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } + } + } } - return cv.GetBase(store), pkgId + return cv.GetBase(store), pkgId, true case *ArrayValue: - return cv, pkgId + return cv, pkgId, false case *SliceValue: - return cv.GetBase(store), pkgId + // TODO: XXX + return cv.GetBase(store), pkgId, false case *StructValue: println("---struct value") fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) - return cv, pkgId + return cv, pkgId, false case *FuncValue: - return cv.GetClosure(store), pkgId + return cv.GetClosure(store), pkgId, false case *MapValue: - return cv, pkgId + return cv, pkgId, false case *BoundMethodValue: - return cv, pkgId + return cv, pkgId, false case *NativeValue: // XXX allow PointerValue.Assign2 to pass nil for oo1/oo2. // panic("realm logic for native values not supported") - return nil, pkgId + return nil, pkgId, false case *Block: - return cv, pkgId + return cv, pkgId, false case RefValue: oo := store.GetObject(cv.ObjectID) tv.V = oo - return oo, pkgId + return oo, pkgId, false case *HeapItemValue: // should only appear in PointerValue.Base panic("heap item value should only appear as a pointer's base") default: - return nil, pkgId + return nil, pkgId, false } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 4fe9f3052ef..f9ce4fc84d3 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -138,35 +138,92 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - //fmt.Printf("---xo: %p\n", xo) + if co != nil { fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) - //if rlm.ID != co.GetLastNewEscapedRealm() { - // panic("---cross realm!!!") - //} + fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + fmt.Println("---co isReal(attached): ", co.GetIsReal()) + fmt.Println("---co objectID: ", co.GetObjectID()) } fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - //if co != nil && co.GetIsCrossRealm() { - // panic("!!!cross realm") - //} + + if rlm == nil { + return + } + if debug { + if co != nil && co.GetIsDeleted() { + panic("cannot attach a deleted object") + } + if po != nil && po.GetIsTransient() { + panic("cannot attach to a transient object") + } + if po != nil && po.GetIsDeleted() { + panic("cannot attach to a deleted object") + } + } + + if po == nil || !po.GetIsReal() { // XXX, make sure po is attached + fmt.Println("---po(Base) not real, do nothing!!!") + return // do nothing. + } + + // XXX check if this boosts performance + // XXX with broad integration benchmarking. + // XXX if co == xo { + // XXX } + + // From here on, po is real (not new-real). + // Updates to .newCreated/.newEscaped /.newDeleted made here. (first gen) + // More appends happen during FinalizeRealmTransactions(). (second+ gen) + rlm.MarkDirty(po) if co != nil { + fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + // XXX, inc ref count everytime assignment happens + co.IncRefCount() + fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) + if co.GetRefCount() > 1 { + if co.GetIsEscaped() { + // XXX, why packageBlock is automatically escaped? + println("---already escaped, should check cross realm?") + // already escaped + } else { + rlm.MarkNewEscapedCheckCrossRealm(co, false) + } + } else if co.GetIsReal() { + rlm.MarkDirty(co) + } else { + co.SetOwner(po) + rlm.MarkNewReal(co) // co will be attached when finalize + } + } + + if xo != nil { + xo.DecRefCount() + fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) + if xo.GetRefCount() == 0 { + if xo.GetIsReal() { + rlm.MarkNewDeleted(xo) + } + } + } +} + +func (rlm *Realm) DidUpdate2(po, xo, co Object, reference bool) { + fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) + fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) + + if co != nil { + fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) + fmt.Println("---co.GetRefCount: ", co.GetRefCount()) fmt.Println("---co isReal(attached): ", co.GetIsReal()) fmt.Println("---co objectID: ", co.GetObjectID()) - fmt.Println("---co.GetObjectInfo:", co.GetObjectInfo()) - //fmt.Printf("---co: %p\n", co) } - // XXX, association happens here - // if is co is attached to external realm - // if xo is attached to realm, directly/indirectly; - // if associated with reference, ok - // else, panic("should not associate with value cross realm - // else if xo is not attached to realm, associate is ok too, check when finalize. - // else, panic when finalizing current realm. + fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - fmt.Println("---current realm: ", rlm) if rlm == nil { return } @@ -182,26 +239,11 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } } - // check if assignee is attached, if yes and assigner is not attached, panic - if xo != nil { - fmt.Println("---xo.GetIsReal: ", xo.GetIsReal()) - } else { - println("---xo is nil") - } - fmt.Println("---po.GetIsReal: ", po.GetIsReal()) - if po == nil || !po.GetIsReal() { // XXX, make sure po is attached fmt.Println("---po(Base) not real, do nothing!!!") return // do nothing. } - // XXX, cross realm check - fmt.Println("---po.GetObjectID(): ", po.GetObjectID()) - if po.GetObjectID().PkgID != rlm.ID { - fmt.Printf("po.GetObjectID().PkgID: %v, rlm.ID: %v\n", po.GetObjectID().PkgID, rlm.ID) - panic("cannot modify external-realm or non-realm object") - } - // XXX check if this boosts performance // XXX with broad integration benchmarking. // XXX if co == xo { @@ -213,29 +255,24 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkDirty(po) if co != nil { - fmt.Println("---co: ", co) fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) - if co.GetRefCount() > 1 { // XXX, associated more the once? how this happens? + if co.GetRefCount() > 1 { if co.GetIsEscaped() { + // XXX, why packageBlock is automatically escaped? println("---already escaped, should check cross realm?") // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(co) // XXX, track which realm escape from - //rlm.MarkNewEscaped(co) + rlm.MarkNewEscapedCheckCrossRealm(co, reference) } - } else if co.GetIsReal() { // XXX, attached in .init? - println("---co is real") + } else if co.GetIsReal() { rlm.MarkDirty(co) } else { - println("---else") co.SetOwner(po) rlm.MarkNewReal(co) // co will be attached when finalize } - } else { - println("---co is nil, do nothing") } if xo != nil { @@ -246,54 +283,39 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkNewDeleted(xo) } } - } else { - println("---xo is nil, do nothing") } } //---------------------------------------- // mark* -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, reference bool) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) - oi := oo.GetObjectInfo() - fmt.Println("----oi: ", oi) - fmt.Println("----oi: ", oi) - fmt.Println("----oi.lastNewRealEscapedRealm: ", oi.lastNewRealEscapedRealm) - fmt.Println("----rlm.ID: ", rlm.ID) - fmt.Println("oi.GetIsReal: ", oi.GetIsReal()) - if oi.GetIsReal() { - lastRealmID := oi.GetObjectID().PkgID - fmt.Println("lastRealmID: ", lastRealmID) - //if lastRealmID != rlm.ID { - // panic("should not happen, cross realm!!!") - //} - } + fmt.Println("---rlm.ID: ", rlm.ID) + + fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) + fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) + fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) - if oi.lastNewRealEscapedRealm == rlm.ID { - // already processed for this realm, - // see below. + if oo.GetLastNewEscapedRealm() == rlm.ID { return } - if !oi.GetIsReal() { // XXX, this seems to be wrong -- an object escapes to other realm before it's attached(no objectID) - fmt.Println("---oi Not real, oi: ", oi.ID) - // this can happen if a ref +1 - // new object gets passed into - // an external realm function. - oi.lastNewRealEscapedRealm = rlm.ID // XXX, where the object escape from. - oi.SetIsNewReal(false) - rlm.MarkNewReal(oo) - } else { - fmt.Println("---oo is real, oi:", oi.ID) - // TODO: set last escape realm? - println("---set last escape realm?") + + if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm + if reference { + if !oo.GetIsReal() { // oo is not attached in the origin realm + panic("should not happen while attempting to attach unattached object by reference from external realm") + } + } else { + panic("should not happen while attempting to attach objects by value from external realm") + } } + rlm.MarkNewEscaped(oo) } func (rlm *Realm) MarkNewReal(oo Object) { fmt.Println("---markNewReal---, oo: ", oo) - fmt.Println("---markNewReal---, type of oo: ", reflect.TypeOf(oo)) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -520,18 +542,12 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { } } -func isEmptyRealmID(pkgId PkgID) bool { - if pkgId.String() == "RID0000000000000000000000000000000000000000" { - return true - } - return false -} - // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - fmt.Println("---incRefCreatedDescendants from oo: \n", oo) - fmt.Printf("addr of oo %p: ", oo) + fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) + + fmt.Println("---incRefCreatedDescendants from oo: ", oo) fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { @@ -544,13 +560,12 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // make some pkgId logic while assign _, ok1 := oo.(*PackageValue) - _, ok2 := oo.(*Block) - if !ok1 && !ok2 { - if !isEmptyRealmID(oo.GetLastNewEscapedRealm()) { // ! /p + if !ok1 { + if !oo.GetLastNewEscapedRealm().IsZero() { if oo.GetLastNewEscapedRealm() != rlm.ID { fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) fmt.Println("---rlm.ID: ", rlm.ID) - panic("!!!cross realm while attach object") + panic("should not happen while attempting to attach new real object from external realm") } } } @@ -569,7 +584,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) //fmt.Println("---incRefCreatedDescendants, more: ", more) - fmt.Println("---len of more: ", len(more)) + fmt.Println("---len of more: ", len(more)) for i, child := range more { fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) //fmt.Printf("---child addr: %p\n", child) @@ -706,13 +721,16 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { for i, eo := range rlm.newEscaped { fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) + fmt.Println("---eo.GetRefCount(): ", eo.GetRefCount()) fmt.Println("---rlm.ID: ", rlm.ID) - // only check object from another realm - if !isEmptyRealmID(eo.GetLastNewEscapedRealm()) { - if eo.GetLastNewEscapedRealm() != rlm.ID { - panic("!!!Cross realm update") - } - } + //// only check object from another realm + //if !eo.GetLastNewEscapedRealm().IsZero() { + // if eo.GetLastNewEscapedRealm() != rlm.ID { + // //if !eo.GetIsReal() { + // panic("!!!Cross realm update") + // //} + // } + //} fmt.Println("---processNewEscapedMarks, eo.GetObjectID: ", eo.GetRefCount()) if debug { if !eo.GetIsNewEscaped() { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index f9d76993793..661cf39fb24 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -295,19 +295,14 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty fmt.Println("---oo1.GetObjectID: ", oo1.GetObjectID()) } pv.TV.Assign(alloc, tv2, cu) - oo2, pkgId := pv.TV.GetFirstObject2(store) + oo2, pkgId, reference := pv.TV.GetFirstObject2(store) fmt.Println("---oo2: ", oo2) - //fmt.Println("---oo2 objectInfo: ", oo2.GetObjectInfo()) fmt.Println("---oo2 pkgId: ", pkgId) - //if oo2 != nil { - // fmt.Println("---oo2.GetObjectID: ", oo2.GetObjectID()) - //} if oo2 != nil { - fmt.Printf("addr of oo2: %p \n", oo2) oo2.SetLastNewEscapedRealm(pkgId) } // TODO: assert attached here? - rlm.DidUpdate(pv.Base.(Object), oo1, oo2) + rlm.DidUpdate2(pv.Base.(Object), oo1, oo2, reference) } else { pv.TV.Assign(alloc, tv2, cu) } diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno index 53dd1b9d8a8..f03e3b3af66 100644 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -5,10 +5,6 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type local struct{} - -var a local - var b0 crossrealm.Bar // run declarations func main() { @@ -16,4 +12,4 @@ func main() { } // Error: -// !!!cross realm while attach object +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 1933c54d8c2..ae8b58a44f6 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -5,19 +5,13 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -var b0 crossrealm.Bar // run declarations - func init() { - b0 = crossrealm.Bar{A: 1} + b0 := crossrealm.Bar{A: 1} } func main() { print(".") } -// XXX, this should fail while trying to attach -// value of type defined in another realm. -// NOTE: the check can be in runtime or in preprocess(by simply checkin edge cases). - -// Error: -// !!!cross realm while attach object +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index bd9ae0186d0..a50a6614920 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// !!!cross realm while attach object +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 708e190c7f7..e45db3510e0 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -15,7 +15,5 @@ func main() { print(".") } -// XXX this works. attach value with type defined in same realm - // Output: // . diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index 18a9d1c324a..10a2006a98b 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -15,8 +15,5 @@ func main() { print(".") } -// XXX, this works, attach reference with type defined in p -// Attach pointer? - // Output: // . diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index a7697ffd980..2f370d55b18 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -5,6 +5,14 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) +// XXX, this equals to: +// +// type LocalBar *crossrealm.Bar +// var b0 LocalBar +// +// both should be valid +// TODO: expand this + var b0 *crossrealm.Bar func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno index f451100e94a..68da79914b6 100644 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -7,21 +7,20 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct{ name string } func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer func init() { - f = fooer{} + f = fooer{name: "local fooer"} } func main() { - crossrealm.SetContainer(f) print(".") } // Error: -// !!!Cross realm update +// should not happen while attempting to attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno index ba2b51e1fe8..6b8a25e6dd3 100644 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -18,11 +18,9 @@ func init() { } func main() { - crossrealm.SetContainer(&f) print(".") } -// this should work. -// XXX, this associate a pointer to a floating object(not attached) -// to external realm, no attachment happens to the external realm. +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno index ac2e2dce401..112b4fe599f 100644 --- a/gnovm/tests/files/zrealm_crossrealm25b.gno +++ b/gnovm/tests/files/zrealm_crossrealm25b.gno @@ -21,13 +21,14 @@ type localContainer struct { var lc localContainer func init() { + // container attached, embedded object attached lc = localContainer{name: "local_container", f: fooer{name: "local_fooer"}} // attach } func main() { - crossrealm.AttachContainer() // this attaches container first crossrealm.SetContainer(&lc.f) print(".") } -// XXX? +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno index 9a1d0e9cb1b..74599ba2106 100644 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -1,8 +1,6 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -// pass pointer to an embedded object to external realm? - import ( "std" @@ -27,7 +25,9 @@ func init() { } func main() { - crossrealm.AttachContainer() - crossrealm.SetContainer(lc.f) // should work + crossrealm.SetContainer(lc.f) print(".") } + +// Error: +// should not happen while attempting to attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno index 7558c658b46..9d8af7decc1 100644 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -1,8 +1,6 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -// pass pointer to an embedded object to external realm? - import ( "std" @@ -15,8 +13,6 @@ type fooer struct { func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var f fooer - type localContainer struct { name string ff fooer @@ -25,12 +21,14 @@ type localContainer struct { var lc localContainer func init() { - f = fooer{name: "local_fooer_global"} + f := fooer{name: "local_fooer_global"} lc = localContainer{name: "local_container", ff: f} // attach } func main() { - crossrealm.AttachContainer() - crossrealm.SetContainer(lc.ff) // this should not panic, lc.ff is not same with f(gloabl) + crossrealm.SetContainer(lc.ff) print(".") } + +// Error: +// should not happen while attempting to attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25e.gno b/gnovm/tests/files/zrealm_crossrealm25e.gno new file mode 100644 index 00000000000..439839e8aa9 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25e.gno @@ -0,0 +1,32 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +type localContainer struct { + name string + f fooer +} + +var lc localContainer +var ff fooer + +func main() { + ff = fooer{name: "local_fooer"} // ref 1, unreal + lc = localContainer{name: "local_container", f: ff} + crossrealm.SetContainer(lc.f) + print(".") +} + +// Error: +// should not happen while attempting to attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm26.gno b/gnovm/tests/files/zrealm_crossrealm26.gno deleted file mode 100644 index 5148cc0fefa..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm26.gno +++ /dev/null @@ -1,24 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -func init() { - f = fooer{name: "local_fooer"} -} - -func main() { - crossrealm.AttachContainer() - crossrealm.SetContainer(f) - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm26a.gno b/gnovm/tests/files/zrealm_crossrealm26a.gno deleted file mode 100644 index 76f3bc4c93b..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm26a.gno +++ /dev/null @@ -1,24 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -func init() { - f = fooer{name: "local_fooer"} // NOTE, from now on f is attached -} - -func main() { - crossrealm.AttachContainer() // this attaches container first - crossrealm.SetContainer(&f) - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm26b.gno b/gnovm/tests/files/zrealm_crossrealm26b.gno deleted file mode 100644 index d2e2c33864b..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm26b.gno +++ /dev/null @@ -1,21 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer // this is NOT attached - -func main() { - crossrealm.AttachContainer() // this attaches container first - f = fooer{name: "local_fooer"} // XXX, still not attached, panic - crossrealm.SetContainer(&f) - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm26c.gno b/gnovm/tests/files/zrealm_crossrealm26c.gno deleted file mode 100644 index 35885aa0cd4..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm26c.gno +++ /dev/null @@ -1,19 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -func main() { - crossrealm.AttachContainer() // this attaches container first - var f fooer = fooer{name: "local_fooer"} // this is not attached, should panic, even not escape - crossrealm.SetContainer(&f) - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index 32f8dd834f8..9889cc194c7 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -15,10 +15,11 @@ func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer -// XXX, this should work when reference to not attached local object -// associated to external realm *NOT* attached object. func main() { - f = fooer{name: "local_fooer"} // this is not attached - crossrealm.SetContainer2(&f) // XXX, here should work to associate *NOT* attached object to external container + f = fooer{name: "local_fooer"} + crossrealm.SetContainer2(&f) print(".") } + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm27a.gno index 47ac14ecb04..8eb4d4686a1 100644 --- a/gnovm/tests/files/zrealm_crossrealm27a.gno +++ b/gnovm/tests/files/zrealm_crossrealm27a.gno @@ -7,14 +7,17 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{ name string } +type fooer struct { + name string +} func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var f fooer - func main() { - f = fooer{name: "local_fooer"} - crossrealm.SetContainer3(&f) + f := fooer{name: "local_fooer"} // f is "new real" cuz it's parent object is new real + crossrealm.SetContainer2(&f) // attach new real from external realm, panic print(".") } + +// Error: +// should not happen while attempting to attach new real object from external realm From 48eb8b97eccde72fcb202dd5c0e3d578ba16bb4f Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 12 Nov 2024 22:51:36 +0800 Subject: [PATCH 17/88] fixup --- gnovm/pkg/gnolang/ownership.go | 10 ++++++++- gnovm/pkg/gnolang/realm.go | 8 +++---- gnovm/pkg/gnolang/values.go | 16 +++++++------- gnovm/tests/files/zrealm_crossrealm29.gno | 25 ++++++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm29a.gno | 21 ++++++++++++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm29.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm29a.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index e4a51596b39..9dc3515e1d1 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -449,7 +449,15 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID, bool) { fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) return cv, pkgId, false case *FuncValue: - return cv.GetClosure(store), pkgId, false + fmt.Println("---FuncValue") + clo := cv.GetClosure(store) + fmt.Println("---clo: ", clo) + fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) + //if clo.GetObjectID().PkgID.IsZero() { + // p := clo.Source.GetParentNode(store) + // fmt.Println("---p: ", p) + //} + return cv.GetClosure(store), PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath), false case *MapValue: return cv, pkgId, false case *BoundMethodValue: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index f9ce4fc84d3..8eac3781547 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -210,7 +210,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } } -func (rlm *Realm) DidUpdate2(po, xo, co Object, reference bool) { +func (rlm *Realm) DidUpdate2(po, xo, co Object, isRef bool) { fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) @@ -265,7 +265,7 @@ func (rlm *Realm) DidUpdate2(po, xo, co Object, reference bool) { println("---already escaped, should check cross realm?") // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(co, reference) + rlm.MarkNewEscapedCheckCrossRealm(co, isRef) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -289,7 +289,7 @@ func (rlm *Realm) DidUpdate2(po, xo, co Object, reference bool) { //---------------------------------------- // mark* -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, reference bool) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, isRef bool) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) fmt.Println("---rlm.ID: ", rlm.ID) @@ -302,7 +302,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, reference bool) { } if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm - if reference { + if isRef { if !oo.GetIsReal() { // oo is not attached in the origin realm panic("should not happen while attempting to attach unattached object by reference from external realm") } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 661cf39fb24..dbd680860ba 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -291,18 +291,14 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) fmt.Println("---oo1: ", oo1) - if oo1 != nil { - fmt.Println("---oo1.GetObjectID: ", oo1.GetObjectID()) - } pv.TV.Assign(alloc, tv2, cu) - oo2, pkgId, reference := pv.TV.GetFirstObject2(store) + oo2, pkgId, isRef := pv.TV.GetFirstObject2(store) fmt.Println("---oo2: ", oo2) fmt.Println("---oo2 pkgId: ", pkgId) if oo2 != nil { - oo2.SetLastNewEscapedRealm(pkgId) + oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } - // TODO: assert attached here? - rlm.DidUpdate2(pv.Base.(Object), oo1, oo2, reference) + rlm.DidUpdate2(pv.Base.(Object), oo1, oo2, isRef) } else { pv.TV.Assign(alloc, tv2, cu) } @@ -1046,6 +1042,7 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { + fmt.Println("---Copy, type of tv.V: ", reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -1060,6 +1057,7 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: + println("---default") cp = tv } return @@ -1698,6 +1696,8 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { // cu: convert untyped after assignment. pass false // for const definitions, but true for all else. func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { + fmt.Println("---Assign, tv: ", tv) + fmt.Println("---Assign, tv2: ", tv2, reflect.TypeOf(tv2)) if debug { if tv.T == DataByteType { // assignment to data byte types should only @@ -1710,7 +1710,7 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { panic("should not happen") } } - *tv = tv2.Copy(alloc) // TODO: why copy? + *tv = tv2.Copy(alloc) if cu && isUntyped(tv.T) { ConvertUntypedTo(tv, defaultTypeOf(tv.T)) } diff --git a/gnovm/tests/files/zrealm_crossrealm29.gno b/gnovm/tests/files/zrealm_crossrealm29.gno new file mode 100644 index 00000000000..b2c7ede7d32 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29.gno @@ -0,0 +1,25 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +//var f1 = func() bool { +// println("callback") +// return true +//} + +func main() { + f := func() bool { + println("callback") + return true + } + crossrealm.SetCallback(f) + crossrealm.ExecuteCallback() +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29a.gno b/gnovm/tests/files/zrealm_crossrealm29a.gno new file mode 100644 index 00000000000..6688e9dd933 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29a.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var f = func() bool { + println("callback") + return true +} + +func main() { + crossrealm.SetCallback(f) + crossrealm.ExecuteCallback() +} + +// Output: +// callback From 0bef9078ad3c03a235c2a253675a900c328df429 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 12 Nov 2024 23:13:58 +0800 Subject: [PATCH 18/88] fixup --- gnovm/pkg/gnolang/ownership.go | 4 ---- gnovm/pkg/gnolang/realm.go | 13 ++++--------- .../files/zrealm_crossrealm0_stdlibs.gno | 4 ++-- .../files/zrealm_crossrealm1_stdlibs.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm29.gno | 5 ----- gnovm/tests/files/zrealm_crossrealm29b.gno | 19 +++++++++++++++++++ 6 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm29b.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 9dc3515e1d1..5a89556429f 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -453,10 +453,6 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID, bool) { clo := cv.GetClosure(store) fmt.Println("---clo: ", clo) fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) - //if clo.GetObjectID().PkgID.IsZero() { - // p := clo.Source.GetParentNode(store) - // fmt.Println("---p: ", p) - //} return cv.GetClosure(store), PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath), false case *MapValue: return cv, pkgId, false diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 8eac3781547..dd7c1e68226 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -559,15 +559,10 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } // make some pkgId logic while assign - _, ok1 := oo.(*PackageValue) - if !ok1 { - if !oo.GetLastNewEscapedRealm().IsZero() { - if oo.GetLastNewEscapedRealm() != rlm.ID { - fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) - fmt.Println("---rlm.ID: ", rlm.ID) - panic("should not happen while attempting to attach new real object from external realm") - } - } + if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID { + fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) + fmt.Println("---rlm.ID: ", rlm.ID) + panic("should not happen while attempting to attach new real object from external realm") } // RECURSE GUARD diff --git a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno index 241338a4739..0dd479d24e4 100644 --- a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno @@ -13,5 +13,5 @@ func main() { println(somevalue) } -// Output: -// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject) +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno index f89747c29c5..836c317b7dc 100644 --- a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno @@ -16,5 +16,5 @@ func main() { println(somevalue) } -// Output: -// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject) +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29.gno b/gnovm/tests/files/zrealm_crossrealm29.gno index b2c7ede7d32..cb4cbe050e1 100644 --- a/gnovm/tests/files/zrealm_crossrealm29.gno +++ b/gnovm/tests/files/zrealm_crossrealm29.gno @@ -7,11 +7,6 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -//var f1 = func() bool { -// println("callback") -// return true -//} - func main() { f := func() bool { println("callback") diff --git a/gnovm/tests/files/zrealm_crossrealm29b.gno b/gnovm/tests/files/zrealm_crossrealm29b.gno new file mode 100644 index 00000000000..62e90a9d988 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29b.gno @@ -0,0 +1,19 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +func main() { + crossrealm.SetCallback(func() bool { + println("callback") + return true + }) + crossrealm.ExecuteCallback() +} + +// Error: +// should not happen while attempting to attach new real object from external realm From 585b370fd81dcbb8f5a4b316c6a46c53d2371c00 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 13 Nov 2024 16:23:54 +0800 Subject: [PATCH 19/88] test array --- .../r/demo/tests/crossrealm/crossrealm2.gno | 9 ---- .../r/demo/tests/crossrealm/crossrealm4.gno | 3 ++ .../r/demo/tests/crossrealm/crossrealm5.gno | 13 ++++++ .../r/demo/tests/crossrealm/crossrealm6.gno | 41 +++++++++++++++++ gnovm/pkg/gnolang/alloc.go | 7 ++- gnovm/pkg/gnolang/op_assign.go | 1 + gnovm/pkg/gnolang/ownership.go | 46 +++++++++++++------ gnovm/pkg/gnolang/realm.go | 45 +++++++++++++++--- gnovm/pkg/gnolang/values.go | 4 +- gnovm/tests/files/zrealm_crossrealm28.gno | 8 ++-- gnovm/tests/files/zrealm_crossrealm28a.gno | 27 +++++++++++ gnovm/tests/files/zrealm_crossrealm28b.gno | 28 +++++++++++ gnovm/tests/files/zrealm_crossrealm28c.gno | 30 ++++++++++++ gnovm/tests/files/zrealm_crossrealm30.gno | 18 ++++++++ gnovm/tests/files/zrealm_crossrealm31.gno | 18 ++++++++ gnovm/tests/files/zrealm_crossrealm32.gno | 18 ++++++++ gnovm/tests/files/zrealm_crossrealm33.gno | 20 +++++--- 17 files changed, 294 insertions(+), 42 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm30.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm31.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm32.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno index a85778e00c6..528b8cba023 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno @@ -20,20 +20,11 @@ type Container struct { var container Container // attached -func AttachContainer() { - container = Container{name: "external_container"} // attach after call -} - func SetContainer(f Fooer) { container.f = f // update } func SetContainer2(f Fooer) { - ff := f - container.f = f -} - -func SetContainer3(f Fooer) { ff := f // associate to non-attached object SetContainer(ff) // attach container, while ff is not attached } diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno index e7d86663094..d58aba3553f 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno @@ -4,4 +4,7 @@ var S []Fooer func SetSlice(fs []Fooer) { S = fs + for _, f := range fs { + println(f) + } } diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno new file mode 100644 index 00000000000..a8d20091de5 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno @@ -0,0 +1,13 @@ +package crossrealm + +type F func() bool + +var f F + +func SetCallback(ff F) { + f = ff +} + +func ExecuteCallback() { + f() +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno new file mode 100644 index 00000000000..1ba3d9c6df4 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno @@ -0,0 +1,41 @@ +package crossrealm + +type XYZ struct{ name string } + +var s1 []XYZ +var s3 []XYZ +var s4 []XYZ + +func init() { + s1 = append(s1, XYZ{"1"}) + s1 = append(s1, XYZ{"2"}) + + s3 = append(s3, XYZ{"3"}) + s4 = append(s4, XYZ{"4"}) +} + +func GetSlice() []XYZ { + return s1[1:] +} + +// ------------------------------------------------------- +var e1 = XYZ{"1"} +var e2 = XYZ{"2"} + +func GetSlice2() []XYZ { + var s2 []XYZ + s2 = append(s2, e1) + s2 = append(s2, e2) + return s2 +} + +// ------------------------------------------------------ +func GetSlice3() []XYZ { + s3 = append(s3, XYZ{"0"}) // this is real after function + return s3 +} + +func GetSlice4(f func(s []XYZ)) { + s4 = append(s4, XYZ{"0"}) // this is real after this function + f(s4) // floating +} diff --git a/gnovm/pkg/gnolang/alloc.go b/gnovm/pkg/gnolang/alloc.go index 6fef5eda834..4088d9bc1f5 100644 --- a/gnovm/pkg/gnolang/alloc.go +++ b/gnovm/pkg/gnolang/alloc.go @@ -1,6 +1,9 @@ package gnolang -import "reflect" +import ( + "fmt" + "reflect" +) // Keeps track of in-memory allocations. // In the future, allocations within realm boundaries will be @@ -121,6 +124,7 @@ func (alloc *Allocator) AllocateDataArray(size int64) { } func (alloc *Allocator) AllocateListArray(items int64) { + fmt.Println("---AllocateListArray---") alloc.Allocate(allocArray + allocArrayItem*items) } @@ -225,6 +229,7 @@ func (alloc *Allocator) NewSlice(base Value, offset, length, maxcap int) *SliceV // NOTE: also allocates the underlying array from list. func (alloc *Allocator) NewSliceFromList(list []TypedValue) *SliceValue { + fmt.Println("---NewSliceFromList") alloc.AllocateSlice() alloc.AllocateListArray(int64(cap(list))) fullList := list[:cap(list)] diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index 5a65d9f1190..d8db20cac5f 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -31,6 +31,7 @@ func (m *Machine) doOpDefine() { func (m *Machine) doOpAssign() { fmt.Println("---doOpAssign, m.Realm: ", m.Realm) s := m.PopStmt().(*AssignStmt) + fmt.Println("---s: ", s) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 5a89556429f..e801c7cfb73 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -402,10 +402,9 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } // XXX, get first accessible object, maybe containing(parent) object, maybe itself. -func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID, bool) { +func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isRef bool, length int, offset int) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) - var pkgId PkgID if dt, ok := tv.T.(*DeclaredType); ok { fmt.Println("---dt: ", dt) fmt.Println("---dt.Name: ", dt.Name) @@ -438,40 +437,59 @@ func (tv *TypedValue) GetFirstObject2(store Store) (Object, PkgID, bool) { } } } - return cv.GetBase(store), pkgId, true + obj, isRef = cv.GetBase(store), true + return case *ArrayValue: - return cv, pkgId, false + fmt.Println("---array value, T: ", tv.T) + fmt.Println("---Elem PkgPath: ", tv.T.Elem().GetPkgPath()) + + obj, pkgId, isRef = cv, PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), false + return case *SliceValue: - // TODO: XXX - return cv.GetBase(store), pkgId, false + base := cv.GetBase(store) + fmt.Println("---SliceValue, base: ", base) + fmt.Printf("---SliceValue len: %d, cap:%d, offsetL:%d \n", cv.Length, cv.Maxcap, cv.Offset) + fmt.Println("---tv.T...PkgPath: ", tv.T.Elem().GetPkgPath()) + fmt.Println("---type of base: ", reflect.TypeOf(base)) + + obj, pkgId, isRef, length, offset = cv.GetBase(store), PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), true, cv.GetLength(), cv.Offset + return case *StructValue: println("---struct value") fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) - return cv, pkgId, false + obj, isRef = cv, false + return case *FuncValue: fmt.Println("---FuncValue") clo := cv.GetClosure(store) fmt.Println("---clo: ", clo) fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) - return cv.GetClosure(store), PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath), false + obj, pkgId, isRef = cv.GetClosure(store), PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath), false + return case *MapValue: - return cv, pkgId, false + obj, isRef = cv, false + return case *BoundMethodValue: - return cv, pkgId, false + obj, isRef = cv, false + return case *NativeValue: // XXX allow PointerValue.Assign2 to pass nil for oo1/oo2. // panic("realm logic for native values not supported") - return nil, pkgId, false + obj, isRef = nil, false + return case *Block: - return cv, pkgId, false + obj, isRef = cv, false + return case RefValue: oo := store.GetObject(cv.ObjectID) tv.V = oo - return oo, pkgId, false + obj, isRef = oo, false + return case *HeapItemValue: // should only appear in PointerValue.Base panic("heap item value should only appear as a pointer's base") default: - return nil, pkgId, false + obj, isRef = nil, false + return } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index dd7c1e68226..af85c35f2ec 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -189,7 +189,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { println("---already escaped, should check cross realm?") // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(co, false) + rlm.MarkNewEscapedCheckCrossRealm(nil, co, false, 0, 0) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -210,7 +210,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } } -func (rlm *Realm) DidUpdate2(po, xo, co Object, isRef bool) { +func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, offset int) { fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) @@ -265,7 +265,7 @@ func (rlm *Realm) DidUpdate2(po, xo, co Object, isRef bool) { println("---already escaped, should check cross realm?") // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(co, isRef) + rlm.MarkNewEscapedCheckCrossRealm(store, co, isRef, length, offset) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -289,7 +289,7 @@ func (rlm *Realm) DidUpdate2(po, xo, co Object, isRef bool) { //---------------------------------------- // mark* -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, isRef bool) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) fmt.Println("---rlm.ID: ", rlm.ID) @@ -303,8 +303,41 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(oo Object, isRef bool) { if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm if isRef { - if !oo.GetIsReal() { // oo is not attached in the origin realm - panic("should not happen while attempting to attach unattached object by reference from external realm") + fmt.Println("---length: ", length) + if length != 0 { // TODO: explicit array check + fmt.Println("---offset: ", offset) + fmt.Println("---escaped array, check if elements are real") + for i := offset; i < length; i++ { + e := oo.(*ArrayValue).List[i] + fmt.Println("---e: ", e, reflect.TypeOf(e.V)) + if _, ok := e.V.(RefValue); ok { // TODO: does this already enough + fmt.Println("---escaped: ", e.V.(RefValue).Escaped) + fmt.Println("---string: ", e.V.(RefValue).String()) + fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) + fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) + if store != nil { + oo := store.GetObject(e.V.(RefValue).ObjectID) + fmt.Println("---oo: ", oo) + fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) + if !oo.GetIsReal() { + panic("should not happen while reference unreal element from array of external realm") + } + } + } else { + fmt.Println("---e.V: ", e.V) + fmt.Println("---e.V: ", reflect.TypeOf(e.V)) + isreal := e.V.(Object).GetIsReal() + fmt.Println("---isreal: ", isreal) + fmt.Println("---objectID: ", e.V.(Object).GetObjectID()) + if !isreal { + panic("should not happen while reference unreal element from external realm") + } + } + } + } else { // other than array + if !oo.GetIsReal() { // oo is not attached in the origin realm + panic("should not happen while attempting to attach unattached object by reference from external realm") + } } } else { panic("should not happen while attempting to attach objects by value from external realm") diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index dbd680860ba..5028dc7fdc3 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -292,13 +292,13 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo1 := pv.TV.GetFirstObject(store) fmt.Println("---oo1: ", oo1) pv.TV.Assign(alloc, tv2, cu) - oo2, pkgId, isRef := pv.TV.GetFirstObject2(store) + oo2, pkgId, isRef, length, offset := pv.TV.GetFirstObject2(store) fmt.Println("---oo2: ", oo2) fmt.Println("---oo2 pkgId: ", pkgId) if oo2 != nil { oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } - rlm.DidUpdate2(pv.Base.(Object), oo1, oo2, isRef) + rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, isRef, length, offset) } else { pv.TV.Assign(alloc, tv2, cu) } diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno index 65084d77c19..7b9a9379ef7 100644 --- a/gnovm/tests/files/zrealm_crossrealm28.gno +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -13,15 +13,17 @@ type foo struct { func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var fs []crossrealm.Fooer +var fs []crossrealm.Fooer // panic func init() { - fs = append(fs, foo{name: "1"}) + fs = append(fs, foo{name: "1"}) // attached fs = append(fs, foo{name: "2"}) - fs = append(fs, foo{name: "3"}) } func main() { println("ok") crossrealm.SetSlice(fs) } + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28a.gno b/gnovm/tests/files/zrealm_crossrealm28a.gno new file mode 100644 index 00000000000..089b54c4209 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28a.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var arr []crossrealm.Fooer + +func main() { + arr = append(arr, foo{name: "1"}) + arr = append(arr, foo{name: "2"}) + arr = append(arr, foo{name: "3"}) + + println(".") +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28b.gno b/gnovm/tests/files/zrealm_crossrealm28b.gno new file mode 100644 index 00000000000..1cb7685ec3d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28b.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var arr [2]crossrealm.Fooer // panic + +func main() { + arr[0] = foo{name: "1"} + arr[1] = foo{name: "2"} + + fs := arr[1:] + println("ok") + crossrealm.SetSlice(fs) +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno new file mode 100644 index 00000000000..7dad77b41b2 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -0,0 +1,30 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +func main() { + var arr []crossrealm.Fooer // not attached here + arr = append(arr, foo{name: "1"}) + arr = append(arr, foo{name: "2"}) + arr = append(arr, foo{name: "3"}) + + fs := arr[1:] + println("ok") + crossrealm.SetSlice(fs) +} + +// Output: +// ok +// (struct{("2" string)} gno.land/r/crossrealm_test.foo) +// (struct{("3" string)} gno.land/r/crossrealm_test.foo) diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno new file mode 100644 index 00000000000..cac8dd6cd8e --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -0,0 +1,18 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []crossrealm.XYZ + +func main() { + SS = crossrealm.GetSlice() // this is valid if elem are all attached in origin realm + println(".") +} + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno new file mode 100644 index 00000000000..d3fab4041b9 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -0,0 +1,18 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []crossrealm.XYZ + +func main() { + SS = crossrealm.GetSlice2() // this is valid if elem are all attached in origin realm + println(".") +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno new file mode 100644 index 00000000000..5dd6dafbc20 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -0,0 +1,18 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []crossrealm.XYZ + +func main() { + SS = crossrealm.GetSlice3() + println(".") +} + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index b9d6d5e9718..1d892444305 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -1,16 +1,22 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -var ptr *int +import ( + "std" -func init() { - ptr = new(int) + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []crossrealm.XYZ + +var f = func(s []crossrealm.XYZ) { + SS = s } func main() { - *ptr = 2 - println(*ptr) + crossrealm.GetSlice4(f) + println(".") } -// Output: -// 2 +// Error: +// should not happen while reference unreal element from external realm From c8b24f597351c1d3d48cde4aeb489f3ea9e9b56c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 13 Nov 2024 18:08:31 +0800 Subject: [PATCH 20/88] add test --- .../r/demo/tests/crossrealm/crossrealm6.gno | 6 ++++++ gnovm/pkg/gnolang/realm.go | 11 ++--------- gnovm/tests/files/zrealm_crossrealm34.gno | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm34.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno index 1ba3d9c6df4..b01669d1d13 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno @@ -5,6 +5,7 @@ type XYZ struct{ name string } var s1 []XYZ var s3 []XYZ var s4 []XYZ +var s5 []*XYZ func init() { s1 = append(s1, XYZ{"1"}) @@ -12,6 +13,7 @@ func init() { s3 = append(s3, XYZ{"3"}) s4 = append(s4, XYZ{"4"}) + s5 = append(s5, &XYZ{"5"}) } func GetSlice() []XYZ { @@ -39,3 +41,7 @@ func GetSlice4(f func(s []XYZ)) { s4 = append(s4, XYZ{"0"}) // this is real after this function f(s4) // floating } + +func GetSlice5() []*XYZ { // TODO, unwrap + return s5 +} diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index af85c35f2ec..dea50778060 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -751,15 +751,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) fmt.Println("---eo.GetRefCount(): ", eo.GetRefCount()) fmt.Println("---rlm.ID: ", rlm.ID) - //// only check object from another realm - //if !eo.GetLastNewEscapedRealm().IsZero() { - // if eo.GetLastNewEscapedRealm() != rlm.ID { - // //if !eo.GetIsReal() { - // panic("!!!Cross realm update") - // //} - // } - //} - fmt.Println("---processNewEscapedMarks, eo.GetObjectID: ", eo.GetRefCount()) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -793,12 +784,14 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // will be saved regardless. } else { // exists, mark dirty. + fmt.Println("---exists, mark dirty, po: ", po) rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { panic("new escaped mark has no object ID") } // escaped has no owner. + println("---escaped has no owner") eo.SetOwner(nil) } } diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno new file mode 100644 index 00000000000..fc45616807a --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []*crossrealm.XYZ + +func main() { + SS = crossrealm.GetSlice5() + println(".") +} + +// Error: From ff95ddc435774367039fd76af1e5c35622ddff24 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sat, 16 Nov 2024 23:19:33 +0800 Subject: [PATCH 21/88] debug --- .../r/demo/tests/crossrealm/crossrealm6.gno | 3 ++- gnovm/pkg/gnolang/realm.go | 17 +++++++++++++++-- gnovm/pkg/gnolang/values.go | 4 ++++ gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34.gno | 2 ++ gnovm/tests/files/zrealm_crossrealm35.gno | 17 +++++++++++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm35.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno index b01669d1d13..7563a40be05 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno @@ -13,6 +13,7 @@ func init() { s3 = append(s3, XYZ{"3"}) s4 = append(s4, XYZ{"4"}) + s5 = append(s5, &XYZ{"5"}) } @@ -39,7 +40,7 @@ func GetSlice3() []XYZ { func GetSlice4(f func(s []XYZ)) { s4 = append(s4, XYZ{"0"}) // this is real after this function - f(s4) // floating + f(s4) // XYZ{"0"} is floating } func GetSlice5() []*XYZ { // TODO, unwrap diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index dea50778060..6eecb5810f6 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -216,6 +216,15 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) if co != nil { + if av, ok := co.(*ArrayValue); ok { + fmt.Println("---array value") + fmt.Println("---av: ", av) + fmt.Println("---av.Data: ", av.Data) + fmt.Println("---av.List: ", av.List, len(av.List)) + fmt.Println("---av.List[0]: ", av.List[0]) + } else { + println("not arrayvalue") + } fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) fmt.Println("---co.GetRefCount: ", co.GetRefCount()) fmt.Println("---co isReal(attached): ", co.GetIsReal()) @@ -289,6 +298,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, //---------------------------------------- // mark* +// TODO: move these crossrealm check logic before 'DidUpdate' func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) fmt.Println("---rlm.ID: ", rlm.ID) @@ -310,7 +320,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo for i := offset; i < length; i++ { e := oo.(*ArrayValue).List[i] fmt.Println("---e: ", e, reflect.TypeOf(e.V)) - if _, ok := e.V.(RefValue); ok { // TODO: does this already enough + if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough fmt.Println("---escaped: ", e.V.(RefValue).Escaped) fmt.Println("---string: ", e.V.(RefValue).String()) fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) @@ -326,6 +336,9 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo } else { fmt.Println("---e.V: ", e.V) fmt.Println("---e.V: ", reflect.TypeOf(e.V)) + if p, ok := e.V.(PointerValue); ok { + fmt.Println("---is nil? ", p.TV == nil) + } isreal := e.V.(Object).GetIsReal() fmt.Println("---isreal: ", isreal) fmt.Println("---objectID: ", e.V.(Object).GetObjectID()) @@ -591,7 +604,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } - // make some pkgId logic while assign + // XXX, oo must be new real here, it's not escaped if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID { fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) fmt.Println("---rlm.ID: ", rlm.ID) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 5028dc7fdc3..3f68543ed20 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -298,6 +298,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty if oo2 != nil { oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } + // TODO: make check happens in here? rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, isRef, length, offset) } else { pv.TV.Assign(alloc, tv2, cu) @@ -422,14 +423,17 @@ type SliceValue struct { } func (sv *SliceValue) GetBase(store Store) *ArrayValue { + fmt.Println("---GetBase") switch cv := sv.Base.(type) { case nil: return nil case RefValue: + fmt.Println("---RefValue, cv.ObjectID: ", cv.ObjectID) array := store.GetObject(cv.ObjectID).(*ArrayValue) sv.Base = array return array case *ArrayValue: + println("---ArrayValue") return cv default: panic("should not happen") diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index d3fab4041b9..366fafb377a 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -10,7 +10,7 @@ import ( var SS []crossrealm.XYZ func main() { - SS = crossrealm.GetSlice2() // this is valid if elem are all attached in origin realm + SS = crossrealm.GetSlice2() println(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index fc45616807a..d38d84eaa1c 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -15,3 +15,5 @@ func main() { } // Error: +// interface conversion: gnolang.PointerValue is not gnolang.Object: missing method DecRefCount +// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno new file mode 100644 index 00000000000..dd34eed2fc3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type XYZ struct{ name string } + +var S []*XYZ + +func init() { + S = append(S, &XYZ{"1"}) +} + +func main() { + println(S[0].name) +} + +// Output: +// 1 From ecad113a33205f4d5e8b34823cd02c0d15022fd4 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Fri, 22 Nov 2024 19:03:46 +0900 Subject: [PATCH 22/88] more embede tests --- .../r/demo/tests/crossrealm/crossrealm6.gno | 18 +++++ .../r/demo/tests/crossrealm/crossrealm7.gno | 36 ++++++++++ gnovm/pkg/gnolang/op_expressions.go | 6 +- gnovm/pkg/gnolang/realm.go | 72 ++++++++++++++++--- gnovm/pkg/gnolang/values.go | 29 ++++++-- gnovm/tests/files/zrealm_crossrealm34a.gno | 22 ++++++ gnovm/tests/files/zrealm_crossrealm34b.gno | 23 ++++++ gnovm/tests/files/zrealm_crossrealm35.gno | 3 +- gnovm/tests/files/zrealm_crossrealm36.gno | 17 +++++ 9 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm34a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm34b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm36.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno index 7563a40be05..ad4cad9ebac 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno @@ -6,6 +6,9 @@ var s1 []XYZ var s3 []XYZ var s4 []XYZ var s5 []*XYZ +var s6 = make([]*XYZ, 2) + +var s7 [2]XYZ func init() { s1 = append(s1, XYZ{"1"}) @@ -15,6 +18,11 @@ func init() { s4 = append(s4, XYZ{"4"}) s5 = append(s5, &XYZ{"5"}) + + s6[0] = &XYZ{"6"} + + s7[0] = XYZ{"7"} + s7[1] = XYZ{"7.1"} // should be real after this } func GetSlice() []XYZ { @@ -46,3 +54,13 @@ func GetSlice4(f func(s []XYZ)) { func GetSlice5() []*XYZ { // TODO, unwrap return s5 } + +func GetSlice6(f func(s []*XYZ)) { + s6[1] = &XYZ{"6.1"} // the initial value is deleted, so this is not real after append + f(s6) +} + +func GetSlice7(f func(s [2]XYZ)) { + //s7[1] = XYZ{"7.1"} + f(s7) +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno new file mode 100644 index 00000000000..2cb43b369ce --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno @@ -0,0 +1,36 @@ +package crossrealm + +type A struct { + name string +} + +type B struct { + name string +} + +type D struct { + name string +} + +type C struct { + A + B + D +} + +var a A = A{name: "a"} +var b B = B{name: "b"} + +var c *C + +func init() { + c = &C{} + c.A = a + c.B = b +} + +func GetStruct(cb func(v *C)) *C { + c.D = D{name: "d"} // this is not attached before return + cb(c) + return c +} diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index 7492a5f1ec7..72d428ae59c 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -16,6 +16,8 @@ func (m *Machine) doOpIndex1() { } iv := m.PopValue() // index xv := m.PeekValue(1) // x + fmt.Println("---doOpIndex1, iv: ", iv) + fmt.Println("---doOpIndex1, xv: ", xv) switch ct := baseOf(xv.T).(type) { case *MapType: mv := xv.V.(*MapValue) @@ -31,6 +33,7 @@ func (m *Machine) doOpIndex1() { } default: res := xv.GetPointerAtIndex(m.Alloc, m.Store, iv) + fmt.Println("---doOpIndex1, res: ", res.Deref()) *xv = res.Deref() // reuse as result } } @@ -44,6 +47,7 @@ func (m *Machine) doOpIndex2() { } iv := m.PeekValue(1) // index xv := m.PeekValue(2) // x + fmt.Println("---doOpIndex2: ", iv) switch ct := baseOf(xv.T).(type) { case *MapType: vt := ct.Value @@ -81,7 +85,7 @@ func (m *Machine) doOpSelector() { xv := m.PeekValue(1) fmt.Println("---xv: ", xv) res := xv.GetPointerTo(m.Alloc, m.Store, sx.Path).Deref() - fmt.Println("---res: ", res) + fmt.Println("---doOpSelector, res after Deref: ", res) if debug { m.Printf("-v[S] %v\n", xv) m.Printf("+v[S] %v\n", res) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 6eecb5810f6..9fafb42f5e3 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -313,6 +313,30 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm if isRef { + + if hiv, ok := oo.(*HeapItemValue); ok { + fmt.Println("---hiv: ", hiv) + r := fillValueTV(store, &hiv.Value) + fmt.Println("---r: ", r) + if sv, ok := hiv.Value.V.(*StructValue); ok { + fmt.Println("---sv: ", sv) + if !sv.GetIsReal() { + panic("---sv is not real!!!") + } + for _, fv := range sv.Fields { + rfv := fillValueTV(store, &fv) + fmt.Println("---rfv: ", rfv) + if oo, ok := rfv.V.(Object); ok { + if !oo.GetIsReal() { + panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) + } + } + } + } + } + + // ===================================================== + fmt.Println("---length: ", length) if length != 0 { // TODO: explicit array check fmt.Println("---offset: ", offset) @@ -336,15 +360,47 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo } else { fmt.Println("---e.V: ", e.V) fmt.Println("---e.V: ", reflect.TypeOf(e.V)) - if p, ok := e.V.(PointerValue); ok { - fmt.Println("---is nil? ", p.TV == nil) - } - isreal := e.V.(Object).GetIsReal() - fmt.Println("---isreal: ", isreal) - fmt.Println("---objectID: ", e.V.(Object).GetObjectID()) - if !isreal { - panic("should not happen while reference unreal element from external realm") + + res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + fmt.Println("---res: ", res) + fmt.Println("---type of res: ", reflect.TypeOf(res.V)) + if p, ok := res.V.(PointerValue); ok { + fmt.Println("---p.TV: ", p.TV) + fmt.Println("---p.Base: ", p.Base) + + rr := fillValueTV(store, p.TV) + fmt.Println("---rr: ", rr) + + if sv, ok := p.TV.V.(*StructValue); ok { + fmt.Println("---sv: ", sv) + fmt.Println("---sv.GetIsReal", sv.GetIsReal()) + if !sv.GetIsReal() { + panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) + } + fmt.Println("---sv.ObjectID", sv.GetObjectID()) + } } + + //if p, ok := e.V.(PointerValue); ok { + // fmt.Println("---is nil? ", p.TV == nil) + // r := fillValueTV(store, &e) + // fmt.Println("---r: ", r) + // if ref, ok := r.V.(RefValue); ok { + // base := store.GetObject(ref.ObjectID).(Value) + // fmt.Println("---base: ", base) + // } + // fmt.Println("---type of r: ", reflect.TypeOf(r.V)) + // if p, ok := r.V.(PointerValue); ok { + // fmt.Println("---p.TV: ", p.TV) + // fmt.Println("---p.Base: ", p.Base) + // } + //} + //isreal := e.V.(Object).GetIsReal() + //fmt.Println("---isreal: ", isreal) + //fmt.Println("---objectID: ", e.V.(Object).GetObjectID()) + //if !isreal { + // panic("should not happen while reference unreal element from external realm") + //} } } } else { // other than array diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 3f68543ed20..f4554fd8a89 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -372,6 +372,7 @@ func (av *ArrayValue) GetLength() int { // et is only required for .List byte-arrays. func (av *ArrayValue) GetPointerAtIndexInt2(store Store, ii int, et Type) PointerValue { + fmt.Println("----av, GetPointerAtIndexInt2: ", av) if av.Data == nil { ev := fillValueTV(store, &av.List[ii]) // by reference return PointerValue{ @@ -450,6 +451,7 @@ func (sv *SliceValue) GetLength() int { // et is only required for .List byte-slices. func (sv *SliceValue) GetPointerAtIndexInt2(store Store, ii int, et Type) PointerValue { + fmt.Println("---sv, GetPointerAtIndexInt2: ", sv) // Necessary run-time slice bounds check if ii < 0 { panic(fmt.Sprintf( @@ -472,6 +474,7 @@ type StructValue struct { // TODO handle unexported fields in debug, and also ensure in the preprocessor. func (sv *StructValue) GetPointerTo(store Store, path ValuePath) PointerValue { + fmt.Println("---sv GetPointerTo: ", sv) if debug { if path.Depth != 0 { panic(fmt.Sprintf( @@ -483,6 +486,8 @@ func (sv *StructValue) GetPointerTo(store Store, path ValuePath) PointerValue { } func (sv *StructValue) GetPointerToInt(store Store, index int) PointerValue { + fmt.Println("---sv, GetPointerToInt: ", sv) + fmt.Println("---index: ", index) fv := fillValueTV(store, &sv.Fields[index]) return PointerValue{ TV: fv, @@ -1726,7 +1731,10 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { // allocated, *Allocator.AllocatePointer() is called separately, // as in OpRef. func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath) PointerValue { - fmt.Println("---GetPointerTo, tv, rt of tv: ", tv, reflect.TypeOf(tv)) + fmt.Println("---GetPointerTo, tv: ", tv) + fmt.Println("---rt of tv: ", reflect.TypeOf(tv)) + fmt.Println("---path: ", path) + fmt.Println("---path.Type: ", path.Type) if debug { if tv.IsUndefined() { panic("GetPointerTo() on undefined value") @@ -1824,6 +1832,7 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath fillValueTV(store, dtv) } + fmt.Println("---2, path.Type: ", path.Type) switch path.Type { case VPBlock: switch dtv.T.(type) { @@ -1836,8 +1845,12 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath case VPField: switch baseOf(dtv.T).(type) { case *StructType: + println("---StructType") + fmt.Println("---dtv: ", dtv) + fmt.Println("---return pointer of dtv: ", dtv.V.(*StructValue).GetPointerTo(store, path)) return dtv.V.(*StructValue).GetPointerTo(store, path) case *TypeType: + println("---TypeType") switch t := dtv.V.(TypeValue).Type.(type) { case *PointerType: dt := t.Elt.(*DeclaredType) @@ -2054,6 +2067,7 @@ func (tv *TypedValue) GetPointerAtIndexInt(store Store, ii int) PointerValue { } func (tv *TypedValue) GetPointerAtIndex(alloc *Allocator, store Store, iv *TypedValue) PointerValue { + fmt.Println("---tv, GetPointerAtIndex: ", tv) switch bt := baseOf(tv.T).(type) { case PrimitiveType: if bt == StringType || bt == UntypedStringType { @@ -2658,19 +2672,20 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - //fmt.Println("---fillValueTV, tv: ", tv) + fmt.Println("---fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: - //println("---tv.V RefValue") - //fmt.Println("---cv: ", cv) + println("---tv.V RefValue") + fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) - //fmt.Println("---tv.V: ", tv.V) + fmt.Println("---tv.V: ", tv.V) } case PointerValue: + fmt.Println("---PointerValue") // As a special case, cv.Base is filled // and cv.TV set appropriately. // Alternatively, could implement @@ -2678,11 +2693,14 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { // but for execution speed traded off for // loading speed, we do the following for now: if ref, ok := cv.Base.(RefValue); ok { + fmt.Println("---cv.Base: ", ref) base := store.GetObject(ref.ObjectID).(Value) + fmt.Println("---base: ", base) cv.Base = base switch cb := base.(type) { case *ArrayValue: et := baseOf(tv.T).(*PointerType).Elt + fmt.Println("---et: ", et) epv := cb.GetPointerAtIndexInt2(store, cv.Index, et) cv.TV = epv.TV // TODO optimize? (epv.* ignored) case *StructValue: @@ -2696,6 +2714,7 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { vpv := cb.GetPointerToInt(store, cv.Index) cv.TV = vpv.TV // TODO optimize? case *HeapItemValue: + fmt.Println("---HeapItemValue: ", cb.Value) cv.TV = &cb.Value default: panic("should not happen") diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno new file mode 100644 index 00000000000..00dd06ba292 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS []*crossrealm.XYZ + +var f = func(s []*crossrealm.XYZ) { + SS = s +} + +func main() { + crossrealm.GetSlice6(f) + println(".") +} + +// Error: +// ---should not happen, struct{("6.1" string)}: is not real diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno new file mode 100644 index 00000000000..9f4a52019b0 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -0,0 +1,23 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var SS [2]crossrealm.XYZ + +var f = func(s [2]crossrealm.XYZ) { + SS = s +} + +func main() { + crossrealm.GetSlice7(f) + println(".") +} + +// Error: +// should not happen while attempting to attach new real object from external realm +// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno index dd34eed2fc3..3a223dca545 100644 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -10,7 +10,8 @@ func init() { } func main() { - println(S[0].name) + a := S[0].name + println(a) } // Output: diff --git a/gnovm/tests/files/zrealm_crossrealm36.gno b/gnovm/tests/files/zrealm_crossrealm36.gno new file mode 100644 index 00000000000..a4ce8f9497f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm36.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" + +var s *crossrealm.C + +func cb(c *crossrealm.C) { + s = c +} +func main() { + crossrealm.GetStruct(cb) + println(s) +} + +// Error: +// ---should not happen, struct{("d" string)}: is not real From e2670cc477b107e474d4073920a75bc860eae05c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 24 Nov 2024 17:59:25 +0900 Subject: [PATCH 23/88] start refactor --- gnovm/pkg/gnolang/realm.go | 46 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 9fafb42f5e3..d423bdba604 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -298,9 +298,27 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, //---------------------------------------- // mark* +// oo can can be base of the originType, like array for a slice type. +// originType may contain infos like len, cap for slice type, etc. +// XXX, oo coming here must be referenced type, since they already escaped. +// XXX, so oo has been persisted, thus fillValueTv.. +func checkCrossRealm(store Store, oo Object, originType Type) { + fmt.Println("---checkCrossReal, oo: ", oo) + fmt.Println("---originType: ", originType) + switch v := oo.(type) { + case *HeapItemValue: + fmt.Println("---heapItemValue: ", v) + case *ArrayValue: + fmt.Println("---ArrayValue: ", v) + default: + fmt.Println("---v :", v) + } +} + // TODO: move these crossrealm check logic before 'DidUpdate' func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) + checkCrossRealm(store, oo, nil) fmt.Println("---rlm.ID: ", rlm.ID) fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) @@ -403,7 +421,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo //} } } - } else { // other than array + } else { // other than array if !oo.GetIsReal() { // oo is not attached in the origin realm panic("should not happen while attempting to attach unattached object by reference from external realm") } @@ -531,13 +549,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -552,9 +570,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -988,9 +1006,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } From e28a2ba329440fe47c0b629531ba0a05ce9611fe Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 25 Nov 2024 10:42:49 +0900 Subject: [PATCH 24/88] save --- gnovm/pkg/gnolang/realm.go | 174 +++++++++++---------- gnovm/tests/files/zrealm_crossrealm34b.gno | 1 - 2 files changed, 89 insertions(+), 86 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index d423bdba604..ef2df487aae 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -301,15 +301,83 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, // oo can can be base of the originType, like array for a slice type. // originType may contain infos like len, cap for slice type, etc. // XXX, oo coming here must be referenced type, since they already escaped. -// XXX, so oo has been persisted, thus fillValueTv.. -func checkCrossRealm(store Store, oo Object, originType Type) { +// XXX, so oo has been persisted, thus fillValueTV +func checkCrossRealm(store Store, oo Object, offset, length int) { fmt.Println("---checkCrossReal, oo: ", oo) - fmt.Println("---originType: ", originType) switch v := oo.(type) { + case *StructValue: + fmt.Println("---StructValue...") + fmt.Println("---sv: ", v) + if !v.GetIsReal() { + panic("---sv is not real!!!") + } + for _, fv := range v.Fields { + fmt.Println("---fv: ", fv) + fmt.Println("---type of fv: ", reflect.TypeOf(fv.V)) + // XXX, consider this + //if _, ok := fv.V.(RefValue); !ok { + // panic("---sv is not ref value!!!") + //} + rfv := fillValueTV(store, &fv) + fmt.Println("---rfv: ", rfv) + if oo, ok := rfv.V.(Object); ok { + if !oo.GetIsReal() { + panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) + } + } + } + case *HeapItemValue: fmt.Println("---heapItemValue: ", v) + //r := fillValueTV(store, &v.Value) + //fmt.Println("---r: ", r) + + checkCrossRealm(store, v.Value.V.(Object), 0, 0) case *ArrayValue: fmt.Println("---ArrayValue: ", v) + fmt.Println("---offset: ", offset) + fmt.Println("---escaped array, check if elements are real") + for i := offset; i < length; i++ { + e := oo.(*ArrayValue).List[i] + fmt.Println("---e: ", e, reflect.TypeOf(e.V)) + if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough + fmt.Println("---escaped: ", e.V.(RefValue).Escaped) + fmt.Println("---string: ", e.V.(RefValue).String()) + fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) + fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) + if store != nil { + oo := store.GetObject(e.V.(RefValue).ObjectID) + fmt.Println("---oo: ", oo) + fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) + if !oo.GetIsReal() { + panic("should not happen while reference unreal element from array of external realm") + } + } + } else { + fmt.Println("---e.V: ", e.V) + fmt.Println("---e.V: ", reflect.TypeOf(e.V)) + + res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + fmt.Println("---res: ", res) + fmt.Println("---type of res: ", reflect.TypeOf(res.V)) + if p, ok := res.V.(PointerValue); ok { + fmt.Println("---p.TV: ", p.TV) + fmt.Println("---p.Base: ", p.Base) + + rr := fillValueTV(store, p.TV) + fmt.Println("---rr: ", rr) + + if sv, ok := p.TV.V.(*StructValue); ok { + fmt.Println("---sv: ", sv) + fmt.Println("---sv.GetIsReal", sv.GetIsReal()) + if !sv.GetIsReal() { + panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) + } + fmt.Println("---sv.ObjectID", sv.GetObjectID()) + } + } + } + } default: fmt.Println("---v :", v) } @@ -318,7 +386,7 @@ func checkCrossRealm(store Store, oo Object, originType Type) { // TODO: move these crossrealm check logic before 'DidUpdate' func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) - checkCrossRealm(store, oo, nil) + checkCrossRealm(store, oo, offset, length) fmt.Println("---rlm.ID: ", rlm.ID) fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) @@ -334,93 +402,29 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo if hiv, ok := oo.(*HeapItemValue); ok { fmt.Println("---hiv: ", hiv) - r := fillValueTV(store, &hiv.Value) - fmt.Println("---r: ", r) - if sv, ok := hiv.Value.V.(*StructValue); ok { - fmt.Println("---sv: ", sv) - if !sv.GetIsReal() { - panic("---sv is not real!!!") - } - for _, fv := range sv.Fields { - rfv := fillValueTV(store, &fv) - fmt.Println("---rfv: ", rfv) - if oo, ok := rfv.V.(Object); ok { - if !oo.GetIsReal() { - panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) - } - } - } - } + //r := fillValueTV(store, &hiv.Value) + //fmt.Println("---r: ", r) + //if sv, ok := hiv.Value.V.(*StructValue); ok { + // fmt.Println("---sv: ", sv) + // if !sv.GetIsReal() { + // panic("---sv is not real!!!") + // } + // for _, fv := range sv.Fields { + // rfv := fillValueTV(store, &fv) + // fmt.Println("---rfv: ", rfv) + // if oo, ok := rfv.V.(Object); ok { + // if !oo.GetIsReal() { + // panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) + // } + // } + // } + //} } // ===================================================== fmt.Println("---length: ", length) if length != 0 { // TODO: explicit array check - fmt.Println("---offset: ", offset) - fmt.Println("---escaped array, check if elements are real") - for i := offset; i < length; i++ { - e := oo.(*ArrayValue).List[i] - fmt.Println("---e: ", e, reflect.TypeOf(e.V)) - if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough - fmt.Println("---escaped: ", e.V.(RefValue).Escaped) - fmt.Println("---string: ", e.V.(RefValue).String()) - fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) - fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) - if store != nil { - oo := store.GetObject(e.V.(RefValue).ObjectID) - fmt.Println("---oo: ", oo) - fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) - if !oo.GetIsReal() { - panic("should not happen while reference unreal element from array of external realm") - } - } - } else { - fmt.Println("---e.V: ", e.V) - fmt.Println("---e.V: ", reflect.TypeOf(e.V)) - - res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - fmt.Println("---res: ", res) - fmt.Println("---type of res: ", reflect.TypeOf(res.V)) - if p, ok := res.V.(PointerValue); ok { - fmt.Println("---p.TV: ", p.TV) - fmt.Println("---p.Base: ", p.Base) - - rr := fillValueTV(store, p.TV) - fmt.Println("---rr: ", rr) - - if sv, ok := p.TV.V.(*StructValue); ok { - fmt.Println("---sv: ", sv) - fmt.Println("---sv.GetIsReal", sv.GetIsReal()) - if !sv.GetIsReal() { - panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) - } - fmt.Println("---sv.ObjectID", sv.GetObjectID()) - } - } - - //if p, ok := e.V.(PointerValue); ok { - // fmt.Println("---is nil? ", p.TV == nil) - // r := fillValueTV(store, &e) - // fmt.Println("---r: ", r) - // if ref, ok := r.V.(RefValue); ok { - // base := store.GetObject(ref.ObjectID).(Value) - // fmt.Println("---base: ", base) - // } - // fmt.Println("---type of r: ", reflect.TypeOf(r.V)) - // if p, ok := r.V.(PointerValue); ok { - // fmt.Println("---p.TV: ", p.TV) - // fmt.Println("---p.Base: ", p.Base) - // } - //} - //isreal := e.V.(Object).GetIsReal() - //fmt.Println("---isreal: ", isreal) - //fmt.Println("---objectID: ", e.V.(Object).GetObjectID()) - //if !isreal { - // panic("should not happen while reference unreal element from external realm") - //} - } - } } else { // other than array if !oo.GetIsReal() { // oo is not attached in the origin realm panic("should not happen while attempting to attach unattached object by reference from external realm") diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno index 9f4a52019b0..673d2538188 100644 --- a/gnovm/tests/files/zrealm_crossrealm34b.gno +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -20,4 +20,3 @@ func main() { // Error: // should not happen while attempting to attach new real object from external realm -// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** From 696e6dae67c16fae4a2ca735e8825401d4b9de9d Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 25 Nov 2024 10:48:04 +0900 Subject: [PATCH 25/88] save --- gnovm/pkg/gnolang/realm.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index ef2df487aae..a3fa623ce48 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -425,7 +425,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo fmt.Println("---length: ", length) if length != 0 { // TODO: explicit array check - } else { // other than array + } else { // other than array if !oo.GetIsReal() { // oo is not attached in the origin realm panic("should not happen while attempting to attach unattached object by reference from external realm") } @@ -553,13 +553,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -574,9 +574,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -1010,9 +1010,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } From 675355d55ea9248d268d5164812ded854ff26303 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 25 Nov 2024 17:16:40 +0900 Subject: [PATCH 26/88] clean --- .../r/demo/tests/crossrealm/crossrealm8.gno | 12 + .../r/demo/tests/crossrealm/crossrealm9.gno | 32 ++ gnovm/pkg/gnolang/alloc.go | 3 - gnovm/pkg/gnolang/machine.go | 35 ++- gnovm/pkg/gnolang/op_call.go | 14 +- gnovm/pkg/gnolang/op_eval.go | 4 +- gnovm/pkg/gnolang/op_exec.go | 6 +- gnovm/pkg/gnolang/op_expressions.go | 14 +- gnovm/pkg/gnolang/ownership.go | 56 ++-- gnovm/pkg/gnolang/realm.go | 273 +++++++----------- gnovm/pkg/gnolang/store.go | 10 +- gnovm/pkg/gnolang/values.go | 66 ++--- .../files/zrealm_crossrealm10_stdlibs.gno | 14 - .../files/zrealm_crossrealm11_stdlibs.gno | 146 ---------- .../files/zrealm_crossrealm12_stdlibs.gno | 37 --- .../files/zrealm_crossrealm13_stdlibs.gno | 48 --- .../files/zrealm_crossrealm13a_stdlibs.gno | 46 --- gnovm/tests/files/zrealm_crossrealm14.gno | 17 -- gnovm/tests/files/zrealm_crossrealm15.gno | 27 -- gnovm/tests/files/zrealm_crossrealm16.gno | 18 -- gnovm/tests/files/zrealm_crossrealm16a.gno | 16 - gnovm/tests/files/zrealm_crossrealm17.gno | 28 -- gnovm/tests/files/zrealm_crossrealm18.gno | 34 --- gnovm/tests/files/zrealm_crossrealm19.gno | 33 --- .../files/zrealm_crossrealm1_stdlibs.gno | 20 -- .../files/zrealm_crossrealm2_stdlibs.gno | 22 -- gnovm/tests/files/zrealm_crossrealm34.gno | 5 +- gnovm/tests/files/zrealm_crossrealm37.gno | 14 + gnovm/tests/files/zrealm_crossrealm38.gno | 13 + ...m0_stdlibs.gno => zrealm_crossrealm39.gno} | 11 +- .../files/zrealm_crossrealm3_stdlibs.gno | 22 -- gnovm/tests/files/zrealm_crossrealm40.gno | 13 + .../files/zrealm_crossrealm4_stdlibs.gno | 22 -- .../files/zrealm_crossrealm5_stdlibs.gno | 22 -- .../files/zrealm_crossrealm6_stdlibs.gno | 21 -- .../files/zrealm_crossrealm7_stdlibs.gno | 14 - .../files/zrealm_crossrealm8_stdlibs.gno | 14 - .../files/zrealm_crossrealm9_stdlibs.gno | 14 - 38 files changed, 291 insertions(+), 925 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm14.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm15.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm16.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm16a.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm17.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm18.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm19.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm37.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm38.gno rename gnovm/tests/files/{zrealm_crossrealm0_stdlibs.gno => zrealm_crossrealm39.gno} (50%) delete mode 100644 gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm40.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno new file mode 100644 index 00000000000..a3241dfe721 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno @@ -0,0 +1,12 @@ +package crossrealm + +var m map[string]int + +func init() { + m = make(map[string]int) + m["a"] = 1 +} + +func GetMap() map[string]int { + return m +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno new file mode 100644 index 00000000000..7961fe4a2ec --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno @@ -0,0 +1,32 @@ +package crossrealm + +var ff = func() string { return "a" } // parent object already escaped + +// XXX, this is special case, for ff, it's closure is referenced, +// so need to check all embedded items attached? +// see zrealm_crossrealm38.gno +func GetFunc() func() string { + return ff +} + +func GetFunc2() func() string { + return func() string { + return "b" + } +} + +type MyStruct struct{} + +func (sv *MyStruct) M() string { return "a" } + +var mysv *MyStruct = &MyStruct{} + +//var f_local func() string +// +//func init() { +// f_local = mysv.M +//} + +func GetMethod() func() string { + return mysv.M +} diff --git a/gnovm/pkg/gnolang/alloc.go b/gnovm/pkg/gnolang/alloc.go index 4088d9bc1f5..0c88f1383b2 100644 --- a/gnovm/pkg/gnolang/alloc.go +++ b/gnovm/pkg/gnolang/alloc.go @@ -1,7 +1,6 @@ package gnolang import ( - "fmt" "reflect" ) @@ -124,7 +123,6 @@ func (alloc *Allocator) AllocateDataArray(size int64) { } func (alloc *Allocator) AllocateListArray(items int64) { - fmt.Println("---AllocateListArray---") alloc.Allocate(allocArray + allocArrayItem*items) } @@ -229,7 +227,6 @@ func (alloc *Allocator) NewSlice(base Value, offset, length, maxcap int) *SliceV // NOTE: also allocates the underlying array from list. func (alloc *Allocator) NewSliceFromList(list []TypedValue) *SliceValue { - fmt.Println("---NewSliceFromList") alloc.AllocateSlice() alloc.AllocateListArray(int64(cap(list))) fullList := list[:cap(list)] diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 276ddc94f5f..9765d43b0db 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -286,9 +286,9 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *std.MemPackage, save bool) } func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { - fmt.Println("---runMemPackage, save: ", save) - fmt.Println("---runMemPackage, memPkg: ", memPkg) - defer func() { fmt.Println("---done runMemPackage: ", memPkg) }() + //fmt.Println("---runMemPackage, save: ", save) + //fmt.Println("---runMemPackage, memPkg: ", memPkg) + //defer func() { fmt.Println("---done runMemPackage: ", memPkg) }() // parse files. files := ParseMemPackage(memPkg) if !overrides && checkDuplicates(files) { @@ -310,7 +310,7 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* m.SetActivePackage(pv) // run files. updates := m.RunFileDecls(files.Files...) - fmt.Println("---updates: ", updates) + //fmt.Println("---updates: ", updates) // save package value and mempackage. // XXX save condition will be removed once gonative is removed. var throwaway *Realm @@ -320,7 +320,7 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* if throwaway != nil { m.Realm = throwaway } - fmt.Println("---save, throwaway: ", throwaway) + //fmt.Println("---save, throwaway: ", throwaway) } // run init functions m.runInitFromUpdates(pv, updates) @@ -733,16 +733,15 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // multiple files belonging to the same package in // lexical file name order to a compiler." func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { - fmt.Println("---runInitFromUpdates") for _, tv := range updates { - fmt.Println("---runInitFromUpdates, tv: ", tv) + //fmt.Println("---runInitFromUpdates, tv: ", tv) if tv.IsDefined() && tv.T.Kind() == FuncKind && tv.V != nil { fv, ok := tv.V.(*FuncValue) if !ok { continue // skip native functions. } if strings.HasPrefix(string(fv.Name), "init.") { - fmt.Println("---fv.Name: ", fv.Name) + //fmt.Println("---fv.Name: ", fv.Name) fb := pv.GetFileBlock(m.Store, fv.FileName) m.PushBlock(fb) m.RunFunc(fv.Name) @@ -758,7 +757,7 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { - fmt.Println("---saveNewPackageValuesAndTypes") + //fmt.Println("---saveNewPackageValuesAndTypes") // save package value and dependencies. pv := m.Package if pv.IsRealm() { @@ -790,12 +789,12 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { - fmt.Println("---resavePackageValues, realm: ", rlm) + //fmt.Println("---resavePackageValues, realm: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { rlm = pv.Realm - fmt.Println("---rlm: ", rlm) + //fmt.Println("---rlm: ", rlm) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // re-save package realm info. m.Store.SetPackageRealm(rlm) @@ -981,14 +980,14 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { - fmt.Println("---run declaration, d: ", d) + //fmt.Println("---run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. // closure and package already set // during PackageNode.NewPackage(). case *ValueDecl: - fmt.Println("---valueDecl, d.Type, type of d.Type: ", d.Type, reflect.TypeOf(d.Type)) + //fmt.Println("---valueDecl, d.Type, type of d.Type: ", d.Type, reflect.TypeOf(d.Type)) m.PushOp(OpHalt) m.PushStmt(d) m.PushOp(OpExec) @@ -1859,7 +1858,7 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { - fmt.Printf("---PushFrameCall---, cx: %v, fv: %v, recv: %v\n", cx, fv, recv) + //fmt.Printf("---PushFrameCall---, cx: %v, fv: %v, recv: %v\n", cx, fv, recv) fr := &Frame{ Source: cx, NumOps: m.NumOps, @@ -1885,13 +1884,13 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { m.Printf("+F %#v\n", fr) } m.Frames = append(m.Frames, fr) - fmt.Println("---recv: ", recv) + //fmt.Println("---recv: ", recv) if recv.IsDefined() { // If the receiver is defined, we enter the receiver's realm. obj := recv.GetFirstObject(m.Store) - fmt.Println("---obj, rt of obj: ", obj, reflect.TypeOf(obj)) - fmt.Println("---obj.GetObjectID: ", obj.GetObjectID()) - fmt.Printf("---obj addr: %p\n", obj) + //fmt.Println("---obj, rt of obj: ", obj, reflect.TypeOf(obj)) + //fmt.Println("---obj.GetObjectID: ", obj.GetObjectID()) + //fmt.Printf("---obj addr: %p\n", obj) if obj == nil { // could be a nil receiver. // set package and realm of function. diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 34e4f553dff..5bb9f3ec748 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -7,7 +7,7 @@ import ( ) func (m *Machine) doOpPrecall() { - fmt.Println("---doOpPrecall---") + //fmt.Println("---doOpPrecall---") cx := m.PopExpr().(*CallExpr) v := m.PeekValue(1 + cx.NumArgs).V if debug { @@ -20,13 +20,13 @@ func (m *Machine) doOpPrecall() { } switch fv := v.(type) { case *FuncValue: - fmt.Println("---FuncValue, fv: ", fv) + //fmt.Println("---FuncValue, fv: ", fv) m.PushFrameCall(cx, fv, TypedValue{}) m.PushOp(OpCall) case *BoundMethodValue: - fmt.Println("---BoundMethodValue, fv: ", fv) - fmt.Println("---BoundMethodValue, fv.Func: ", fv.Func) - fmt.Println("---BoundMethodValue, fv.Receiver: ", fv.Receiver) + //fmt.Println("---BoundMethodValue, fv: ", fv) + //fmt.Println("---BoundMethodValue, fv.Func: ", fv.Func) + //fmt.Println("---BoundMethodValue, fv.Receiver: ", fv.Receiver) m.PushFrameCall(cx, fv.Func, fv.Receiver) m.PushOp(OpCall) case TypeValue: @@ -51,7 +51,7 @@ func (m *Machine) doOpPrecall() { var gReturnStmt = &ReturnStmt{} func (m *Machine) doOpCall() { - fmt.Println("---doOpCall---") + //fmt.Println("---doOpCall---") // NOTE: Frame won't be popped until the statement is complete, to // discard the correct number of results for func calls in ExprStmts. fr := m.LastFrame() @@ -205,7 +205,6 @@ func (m *Machine) doOpReturn() { finalize = true } if finalize { - fmt.Println("---going to finalizeRealmTransaction at return after call") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -241,7 +240,6 @@ func (m *Machine) doOpReturnFromBlock() { finalize = true } if finalize { - fmt.Println("---going to finalize") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index b13f06212b7..d9a381bba96 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -243,7 +243,7 @@ func (m *Machine) doOpEval() { m.PushOp(OpEval) } case *CallExpr: - fmt.Println("---Eval, CallExpr, x: ", x) + //fmt.Println("---Eval, CallExpr, x: ", x) m.PushOp(OpPrecall) // Eval args. args := x.Args @@ -267,7 +267,7 @@ func (m *Machine) doOpEval() { m.PushExpr(x.X) m.PushOp(OpEval) case *SelectorExpr: - fmt.Println("---Eval, SelectorExpr, x: ", x) + //fmt.Println("---Eval, SelectorExpr, x: ", x) m.PushOp(OpSelector) // evaluate x m.PushExpr(x.X) diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index a17f0203e1c..3d50b4d8131 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -56,7 +56,7 @@ func (m *Machine) doOpExec(op Op) { debug.Printf("PEEK STMT: %v\n", s) debug.Printf("%v\n", m) } - fmt.Printf("PEEK STMT: %v\n", s) + //fmt.Printf("PEEK STMT: %v\n", s) // NOTE this could go in the switch statement, and we could // use the EXEC_SWITCH to jump back, rather than putting this @@ -432,7 +432,7 @@ EXEC_SWITCH: if debug { debug.Printf("EXEC: %v\n", s) } - fmt.Printf("EXEC: %v\n", s) + //fmt.Printf("EXEC: %v\n", s) switch cs := s.(type) { case *AssignStmt: switch cs.Op { @@ -487,7 +487,7 @@ EXEC_SWITCH: // All expressions push 1 value except calls, // which push as many as there are results. if _, ok := cs.X.(*CallExpr); ok { - fmt.Println("---CallExpr: ", cs.X) + //fmt.Println("---CallExpr: ", cs.X) m.PushOp(OpPopResults) } else { m.PushOp(OpPopValue) diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index 72d428ae59c..a95261909eb 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -16,8 +16,8 @@ func (m *Machine) doOpIndex1() { } iv := m.PopValue() // index xv := m.PeekValue(1) // x - fmt.Println("---doOpIndex1, iv: ", iv) - fmt.Println("---doOpIndex1, xv: ", xv) + //fmt.Println("---doOpIndex1, iv: ", iv) + //fmt.Println("---doOpIndex1, xv: ", xv) switch ct := baseOf(xv.T).(type) { case *MapType: mv := xv.V.(*MapValue) @@ -33,7 +33,7 @@ func (m *Machine) doOpIndex1() { } default: res := xv.GetPointerAtIndex(m.Alloc, m.Store, iv) - fmt.Println("---doOpIndex1, res: ", res.Deref()) + //fmt.Println("---doOpIndex1, res: ", res.Deref()) *xv = res.Deref() // reuse as result } } @@ -47,7 +47,7 @@ func (m *Machine) doOpIndex2() { } iv := m.PeekValue(1) // index xv := m.PeekValue(2) // x - fmt.Println("---doOpIndex2: ", iv) + //fmt.Println("---doOpIndex2: ", iv) switch ct := baseOf(xv.T).(type) { case *MapType: vt := ct.Value @@ -80,12 +80,12 @@ func (m *Machine) doOpIndex2() { } func (m *Machine) doOpSelector() { - fmt.Println("---doOpSelector---") + //fmt.Println("---doOpSelector---") sx := m.PopExpr().(*SelectorExpr) xv := m.PeekValue(1) - fmt.Println("---xv: ", xv) + //fmt.Println("---xv: ", xv) res := xv.GetPointerTo(m.Alloc, m.Store, sx.Path).Deref() - fmt.Println("---doOpSelector, res after Deref: ", res) + //fmt.Println("---doOpSelector, res after Deref: ", res) if debug { m.Printf("-v[S] %v\n", xv) m.Printf("+v[S] %v\n", res) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index e801c7cfb73..67352a7c93e 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -348,34 +348,14 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { - fmt.Println("---GetFirstObject---, tv: ", tv, reflect.TypeOf(tv.V)) - fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) - if dt, ok := tv.T.(*DeclaredType); ok { - fmt.Println("---dt: ", dt) - fmt.Println("---dt.Name: ", dt.Name) - fmt.Println("---dt.PkgPath: ", dt.PkgPath) - fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) - fmt.Println("---dt.Base: ", dt.Base) - } switch cv := tv.V.(type) { case PointerValue: - println("---pointer value, get base") - if v, ok := cv.TV.V.(Object); ok { - fmt.Println("---v: ", v) - rc := v.GetRefCount() - fmt.Println("---rc: ", rc) - fmt.Println("---v Owner: ", v.GetOwnerID()) - fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) - fmt.Println("---is Attached?", v.GetIsReal()) - } return cv.GetBase(store) case *ArrayValue: return cv case *SliceValue: return cv.GetBase(store) case *StructValue: - println("---struct value") - fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) return cv case *FuncValue: return cv.GetClosure(store) @@ -404,13 +384,13 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isRef bool, length int, offset int) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) - fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) + //fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) if dt, ok := tv.T.(*DeclaredType); ok { - fmt.Println("---dt: ", dt) - fmt.Println("---dt.Name: ", dt.Name) - fmt.Println("---dt.PkgPath: ", dt.PkgPath) - fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) - fmt.Println("---dt.Base: ", dt.Base) + //fmt.Println("---dt: ", dt) + //fmt.Println("---dt.Name: ", dt.Name) + //fmt.Println("---dt.PkgPath: ", dt.PkgPath) + //fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + //fmt.Println("---dt.Base: ", dt.Base) if IsRealmPath(dt.PkgPath) { pkgId = PkgIDFromPkgPath(dt.PkgPath) } @@ -420,11 +400,11 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isR println("---pointer value, get base") if v, ok := cv.TV.V.(Object); ok { fmt.Println("---v: ", v) - rc := v.GetRefCount() - fmt.Println("---rc: ", rc) - fmt.Println("---v Owner: ", v.GetOwnerID()) - fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) - fmt.Println("---is Attached?", v.GetIsReal()) + //rc := v.GetRefCount() + //fmt.Println("---rc: ", rc) + //fmt.Println("---v Owner: ", v.GetOwnerID()) + //fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) + //fmt.Println("---is Attached?", v.GetIsReal()) if dt, ok := cv.TV.T.(*DeclaredType); ok { // b0 = &crossrealm.Bar{A: 1} this is valid @@ -441,22 +421,22 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isR return case *ArrayValue: fmt.Println("---array value, T: ", tv.T) - fmt.Println("---Elem PkgPath: ", tv.T.Elem().GetPkgPath()) + //fmt.Println("---Elem PkgPath: ", tv.T.Elem().GetPkgPath()) obj, pkgId, isRef = cv, PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), false return case *SliceValue: - base := cv.GetBase(store) - fmt.Println("---SliceValue, base: ", base) - fmt.Printf("---SliceValue len: %d, cap:%d, offsetL:%d \n", cv.Length, cv.Maxcap, cv.Offset) - fmt.Println("---tv.T...PkgPath: ", tv.T.Elem().GetPkgPath()) - fmt.Println("---type of base: ", reflect.TypeOf(base)) + //base := cv.GetBase(store) + //fmt.Println("---SliceValue, base: ", base) + //fmt.Printf("---SliceValue len: %d, cap:%d, offsetL:%d \n", cv.Length, cv.Maxcap, cv.Offset) + //fmt.Println("---tv.T...PkgPath: ", tv.T.Elem().GetPkgPath()) + //fmt.Println("---type of base: ", reflect.TypeOf(base)) obj, pkgId, isRef, length, offset = cv.GetBase(store), PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), true, cv.GetLength(), cv.Offset return case *StructValue: println("---struct value") - fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) + //fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) obj, isRef = cv, false return case *FuncValue: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index a3fa623ce48..743200e0645 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -135,18 +135,18 @@ func (rlm *Realm) String() string { // associated object. // TODO: func (rlm *Realm) DidUpdate(po, xo, co Object, attached bool) { func (rlm *Realm) DidUpdate(po, xo, co Object) { - fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) - fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) - fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - - if co != nil { - fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) - fmt.Println("---co.GetRefCount: ", co.GetRefCount()) - fmt.Println("---co isReal(attached): ", co.GetIsReal()) - fmt.Println("---co objectID: ", co.GetObjectID()) - } - - fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + //fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) + //fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + //fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) + // + //if co != nil { + // fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) + // fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + // fmt.Println("---co isReal(attached): ", co.GetIsReal()) + // fmt.Println("---co objectID: ", co.GetObjectID()) + //} + + //fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) if rlm == nil { return @@ -179,14 +179,14 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkDirty(po) if co != nil { - fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() - fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) + //fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsEscaped() { // XXX, why packageBlock is automatically escaped? - println("---already escaped, should check cross realm?") + //println("---already escaped, should check cross realm?") // already escaped } else { rlm.MarkNewEscapedCheckCrossRealm(nil, co, false, 0, 0) @@ -201,7 +201,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if xo != nil { xo.DecRefCount() - fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) + //fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) if xo.GetRefCount() == 0 { if xo.GetIsReal() { rlm.MarkNewDeleted(xo) @@ -212,25 +212,8 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, offset int) { fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) - fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + //fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - - if co != nil { - if av, ok := co.(*ArrayValue); ok { - fmt.Println("---array value") - fmt.Println("---av: ", av) - fmt.Println("---av.Data: ", av.Data) - fmt.Println("---av.List: ", av.List, len(av.List)) - fmt.Println("---av.List[0]: ", av.List[0]) - } else { - println("not arrayvalue") - } - fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) - fmt.Println("---co.GetRefCount: ", co.GetRefCount()) - fmt.Println("---co isReal(attached): ", co.GetIsReal()) - fmt.Println("---co objectID: ", co.GetObjectID()) - } - fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) if rlm == nil { @@ -264,12 +247,12 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, rlm.MarkDirty(po) if co != nil { - fmt.Println("---co.GetRefCount: ", co.GetRefCount()) + //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { - if co.GetIsEscaped() { + if co.GetIsEscaped() { // XXX, this implies attached? // XXX, why packageBlock is automatically escaped? println("---already escaped, should check cross realm?") // already escaped @@ -326,7 +309,8 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { } } } - + case *MapValue: + println("---mapValue...") case *HeapItemValue: fmt.Println("---heapItemValue: ", v) //r := fillValueTV(store, &v.Value) @@ -338,7 +322,11 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { fmt.Println("---offset: ", offset) fmt.Println("---escaped array, check if elements are real") for i := offset; i < length; i++ { - e := oo.(*ArrayValue).List[i] + // XXX, difference between them? + //e := oo.(*ArrayValue).List[i] + //res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + fmt.Println("---e: ", e, reflect.TypeOf(e.V)) if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough fmt.Println("---escaped: ", e.V.(RefValue).Escaped) @@ -357,13 +345,13 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { fmt.Println("---e.V: ", e.V) fmt.Println("---e.V: ", reflect.TypeOf(e.V)) - res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - fmt.Println("---res: ", res) - fmt.Println("---type of res: ", reflect.TypeOf(res.V)) - if p, ok := res.V.(PointerValue); ok { + if p, ok := e.V.(PointerValue); ok { fmt.Println("---p.TV: ", p.TV) + fmt.Println("---p.Index: ", p.Index) fmt.Println("---p.Base: ", p.Base) + //r1 := fillValueTV(store, &p.Base) + rr := fillValueTV(store, p.TV) fmt.Println("---rr: ", rr) @@ -375,23 +363,27 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { } fmt.Println("---sv.ObjectID", sv.GetObjectID()) } + } else { + println("---e.V is not pointer") + if !e.V.(Object).GetIsReal() { + panic("should not happen while reference unreal element from external realm") + } } } } default: - fmt.Println("---v :", v) + //fmt.Println("---v :", v) } } -// TODO: move these crossrealm check logic before 'DidUpdate' +// escaped realm should be reference object func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { - fmt.Println("---MarkNewEscapedCheckCrossRealm---, oo: ", oo) - checkCrossRealm(store, oo, offset, length) - fmt.Println("---rlm.ID: ", rlm.ID) - - fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) - fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) - fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) + fmt.Println("---MarkNewEscapedCheckCrossRealm") + //fmt.Println("---isRef: ", isRef) + //fmt.Println("---rlm.ID: ", rlm.ID) + //fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) + //fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) + //fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) if oo.GetLastNewEscapedRealm() == rlm.ID { return @@ -399,37 +391,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm if isRef { - - if hiv, ok := oo.(*HeapItemValue); ok { - fmt.Println("---hiv: ", hiv) - //r := fillValueTV(store, &hiv.Value) - //fmt.Println("---r: ", r) - //if sv, ok := hiv.Value.V.(*StructValue); ok { - // fmt.Println("---sv: ", sv) - // if !sv.GetIsReal() { - // panic("---sv is not real!!!") - // } - // for _, fv := range sv.Fields { - // rfv := fillValueTV(store, &fv) - // fmt.Println("---rfv: ", rfv) - // if oo, ok := rfv.V.(Object); ok { - // if !oo.GetIsReal() { - // panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) - // } - // } - // } - //} - } - - // ===================================================== - - fmt.Println("---length: ", length) - if length != 0 { // TODO: explicit array check - } else { // other than array - if !oo.GetIsReal() { // oo is not attached in the origin realm - panic("should not happen while attempting to attach unattached object by reference from external realm") - } - } + checkCrossRealm(store, oo, offset, length) } else { panic("should not happen while attempting to attach objects by value from external realm") } @@ -439,7 +401,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo } func (rlm *Realm) MarkNewReal(oo Object) { - fmt.Println("---markNewReal---, oo: ", oo) + //fmt.Println("---markNewReal---, oo: ", oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -468,15 +430,15 @@ func (rlm *Realm) MarkNewReal(oo Object) { if rlm.newCreated == nil { rlm.newCreated = make([]Object, 0, 256) } - fmt.Println("---append oo to newCreated object: ", oo) + //fmt.Println("---append oo to newCreated object: ", oo) rlm.newCreated = append(rlm.newCreated, oo) - fmt.Println("---len of new created: ", len(rlm.newCreated)) + //fmt.Println("---len of new created: ", len(rlm.newCreated)) } // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - fmt.Printf("---current rlm: %v: \n", rlm) - fmt.Printf("---Mark Dirty %v: \n", oo) + //fmt.Printf("---current rlm: %v: \n", rlm) + //fmt.Printf("---Mark Dirty %v: \n", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -517,7 +479,7 @@ func (rlm *Realm) MarkNewDeleted(oo Object) { } func (rlm *Realm) MarkNewEscaped(oo Object) { - fmt.Println("---MarkNewEscaped---, oo: ", oo) + //fmt.Println("---MarkNewEscaped---, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsReal() { panic("cannot mark unreal object as new escaped") @@ -616,30 +578,15 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // All newly created objects become appended to .created, // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { - fmt.Println("---processNewCreatedMarks---") - fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) + //fmt.Println("---processNewCreatedMarks---") + //fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - fmt.Printf("---oo[%d] is %v:\n", i, oo) - // TODO: here check embedded object cross - //more := getChildObjects2(store, oo) - //fmt.Println("---children of oo: ", more) - //fmt.Println("---len of children: ", len(more)) - //for i, c := range more { - // fmt.Printf("[%d] of children is: %v\n", i, c) - // //fmt.Printf("---%p\n", c) - // if c.GetIsCrossRealm() { - // panic("---cross realm") - // } else { - // println("---not cross realm") - // } - //} - fmt.Println("---processNewCreatedMarks, oo.GetRefCount(): ", oo.GetRefCount()) - //if oo.GetIsCrossRealm() { - // fmt.Println("---should not attach value with type defined in other realm") - // //panic("---!!!") + //fmt.Printf("---oo[%d] is %v:\n", i, oo) + //if _, ok := oo.(*BoundMethodValue); ok { + // panic("should not happen persist bound method") //} if debug { if oo.GetIsDirty() { @@ -668,11 +615,11 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) - fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) + //fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) + //fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) + //fmt.Println("---incRefCreatedDescendants from oo: ", oo) + //fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) - fmt.Println("---incRefCreatedDescendants from oo: ", oo) - fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -684,8 +631,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // XXX, oo must be new real here, it's not escaped if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID { - fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) - fmt.Println("---rlm.ID: ", rlm.ID) + //fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) + //fmt.Println("---rlm.ID: ", rlm.ID) panic("should not happen while attempting to attach new real object from external realm") } @@ -703,9 +650,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) //fmt.Println("---incRefCreatedDescendants, more: ", more) - fmt.Println("---len of more: ", len(more)) - for i, child := range more { - fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) + //fmt.Println("---len of more: ", len(more)) + for _, child := range more { + //fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) //fmt.Printf("---child addr: %p\n", child) if _, ok := child.(*PackageValue); ok { if debug { @@ -718,35 +665,35 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - fmt.Println("---rc after inc: ", rc) + //fmt.Println("---rc after inc: ", rc) if rc == 1 { if child.GetIsReal() { - fmt.Println("---child is real, child: ", child) + //fmt.Println("---child is real, child: ", child) // a deleted real became undeleted. child.SetOwner(oo) rlm.MarkDirty(child) } else { - fmt.Println("---child NOT real, child: ", child) + //fmt.Println("---child NOT real, child: ", child) // a (possibly pre-existing) new object // became real (again). // NOTE: may already be marked for first gen // newCreated or updated. //fmt.Println("---Set owner to be: ", oo) - println("---set owner") + //println("---set owner") child.SetOwner(oo) rlm.incRefCreatedDescendants(store, child) child.SetIsNewReal(true) } } else if rc > 1 { if child.GetIsEscaped() { - fmt.Println("---child is escaped, child: ", child) + //fmt.Println("---child is escaped, child: ", child) // already escaped, do nothing. } else { // NOTE: do not unset owner here, // may become unescaped later // in processNewEscapedMarks(). // NOTE: may already be escaped. - fmt.Println("---in recursive, mark new escaped, child: ", child) + //fmt.Println("---in recursive, mark new escaped, child: ", child) rlm.MarkNewEscaped(child) } } else { @@ -764,9 +711,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // to rlm.deleted. // Must run *after* processNewCreatedMarks(). func (rlm *Realm) processNewDeletedMarks(store Store) { - fmt.Println("---processNewDeletedMarks---") + //fmt.Println("---processNewDeletedMarks---") for _, oo := range rlm.newDeleted { - fmt.Println("---oo: ", oo, oo.GetRefCount()) + //fmt.Println("---oo: ", oo, oo.GetRefCount()) if debug { if oo.GetObjectID().IsZero() { panic("new deleted mark should have an object ID") @@ -829,7 +776,7 @@ 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) { - fmt.Println("---processNewEscapedMarks---") + //fmt.Println("---processNewEscapedMarks---") escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, @@ -837,11 +784,11 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (and never can be unescaped,) // except for new-reals that get demoted // because ref-count isn't >= 2. - for i, eo := range rlm.newEscaped { - fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) - fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) - fmt.Println("---eo.GetRefCount(): ", eo.GetRefCount()) - fmt.Println("---rlm.ID: ", rlm.ID) + for _, eo := range rlm.newEscaped { + //fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) + //fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) + //fmt.Println("---eo.GetRefCount(): ", eo.GetRefCount()) + //fmt.Println("---rlm.ID: ", rlm.ID) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -875,14 +822,14 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // will be saved regardless. } else { // exists, mark dirty. - fmt.Println("---exists, mark dirty, po: ", po) + //fmt.Println("---exists, mark dirty, po: ", po) rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { panic("new escaped mark has no object ID") } // escaped has no owner. - println("---escaped has no owner") + //println("---escaped has no owner") eo.SetOwner(nil) } } @@ -897,7 +844,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (ancestors) must be marked as dirty to update the // hash tree. func (rlm *Realm) markDirtyAncestors(store Store) { - fmt.Println("---markDirtyAncestors---") + //fmt.Println("---markDirtyAncestors---") markAncestorsOne := func(oo Object) { for { if pv, ok := oo.(*PackageValue); ok { @@ -966,26 +913,26 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - fmt.Println("---saveUnsavedObjects, new created, new updated---") - fmt.Println("---len of new created: ", len(rlm.created)) - fmt.Println("---len of new updated: ", len(rlm.updated)) + //fmt.Println("---saveUnsavedObjects, new created, new updated---") + //fmt.Println("---len of new created: ", len(rlm.created)) + //fmt.Println("---len of new updated: ", len(rlm.updated)) for _, co := range rlm.created { - fmt.Println("------saveUnsavedObject, co: ", co) + //fmt.Println("------saveUnsavedObject, co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { - println("---not new real") + //println("---not new real") // might have happened already as child // of something else created. continue } else { - println("---new real") + //println("---new real") rlm.saveUnsavedObjectRecursively(store, co) } } for _, uo := range rlm.updated { - fmt.Println("---uo: ", uo) - // for i := len(rlm.updated) - 1; i >= 0; i-- { + //fmt.Println("---uo: ", uo) + // uo := rlm.updated[i] if !uo.GetIsDirty() { // might have happened already as child @@ -999,7 +946,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { - fmt.Println("---saveUnsavedObjectRecursively, oo: ", oo) + //fmt.Println("---saveUnsavedObjectRecursively, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -1018,14 +965,14 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // first, save unsaved children. unsaved := getUnsavedChildObjects(oo) - fmt.Println("---unsaved: ", unsaved) + //fmt.Println("---unsaved: ", unsaved) for _, uch := range unsaved { - fmt.Println("---uch: ", uch) - fmt.Println("---uch.GetOwnerID(): ", uch.GetOwnerID()) - fmt.Println("---uch.GetRefCount(): ", uch.GetRefCount()) - fmt.Println("---type of uch: ", reflect.TypeOf(uch)) + //fmt.Println("---uch: ", uch) + //fmt.Println("---uch.GetOwnerID(): ", uch.GetOwnerID()) + //fmt.Println("---uch.GetRefCount(): ", uch.GetRefCount()) + //fmt.Println("---type of uch: ", reflect.TypeOf(uch)) if uch.GetIsEscaped() || uch.GetIsNewEscaped() { - fmt.Println("---uch is escaped or new escaped") + //fmt.Println("---uch is escaped or new escaped") // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) @@ -1033,7 +980,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // then, save self. if oo.GetIsNewReal() { - fmt.Println("---oo is new real: ", oo) + //fmt.Println("---oo is new real: ", oo) // save created object. if debug { if oo.GetIsDirty() { @@ -1043,7 +990,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { rlm.saveObject(store, oo) oo.SetIsNewReal(false) } else { - fmt.Println("---oo is not new real, update it: ", oo) + //fmt.Println("---oo is not new real, update it: ", oo) // update existing object. if debug { if !oo.GetIsDirty() { @@ -1062,9 +1009,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - fmt.Println("---saveObject: ", oo) + //fmt.Println("---saveObject: ", oo) oid := oo.GetObjectID() - fmt.Println("---saveObject: ", oid) + //fmt.Println("---saveObject: ", oid) if oid.IsZero() { panic("unexpected zero object id") } @@ -1087,7 +1034,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) { // removeDeletedObjects func (rlm *Realm) removeDeletedObjects(store Store) { - fmt.Println("---removeDeletedObjects---") + //fmt.Println("---removeDeletedObjects---") for _, do := range rlm.deleted { store.DelObject(do) } @@ -1174,10 +1121,10 @@ func getChildObjects(val Value, more []Value) []Value { more = getSelfOrChildObjects(cv.Base, more) return more case *StructValue: - println("---struct value") + //println("---struct value") for _, ctv := range cv.Fields { // TODO: we have type infos here, so check check cross realm logic - fmt.Println("---ctv: ", ctv) + //fmt.Println("---ctv: ", ctv) more = getSelfOrChildObjects(ctv.V, more) } return more @@ -1227,7 +1174,7 @@ func getChildObjects(val Value, more []Value) []Value { // like getChildObjects() but loads RefValues into objects. func getChildObjects2(store Store, val Value) []Object { - fmt.Println("---getChildObjects2, val: ", val) + //fmt.Println("---getChildObjects2, val: ", val) chos := getChildObjects(val, nil) //fmt.Println("---chos: ", chos) objs := make([]Object, 0, len(chos)) @@ -1405,7 +1352,7 @@ func copyTypeWithRefs(typ Type) Type { // Also checks for integrity of immediate children -- they must already be // persistent (real), and not dirty, or else this function panics. func copyValueWithRefs(val Value) Value { - fmt.Println("---copyValueWithRefs, val: ", val) + //fmt.Println("---copyValueWithRefs, val: ", val) switch cv := val.(type) { case nil: return nil @@ -1768,14 +1715,14 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { - fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) + //fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) oid := oo.GetObjectID() - fmt.Println("---oid: ", oid) + //fmt.Println("---oid: ", oid) if !oid.IsZero() { panic("unexpected non-zero object id") } noid := rlm.nextObjectID() - fmt.Println("---noid: ", noid) + //fmt.Println("---noid: ", noid) oo.SetObjectID(noid) return noid } @@ -1791,7 +1738,7 @@ func toRefNode(bn BlockNode) RefNode { } func toRefValue(val Value) RefValue { - fmt.Println("---toRefValue", val) + //fmt.Println("---toRefValue", val) // TODO use type switch stmt. if ref, ok := val.(RefValue); ok { return ref @@ -1865,7 +1812,7 @@ func ensureUniq(oozz ...[]Object) { } func refOrCopyValue(tv TypedValue) TypedValue { - fmt.Println("---refOrCopyValue:", tv) + //fmt.Println("---refOrCopyValue:", tv) if tv.T != nil { tv.T = refOrCopyType(tv.T) } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 69302a23a6d..8db812ae333 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -324,11 +324,11 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - fmt.Println("---SetObject---,oo: ", oo) + //fmt.Println("---SetObject---,oo: ", oo) oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - fmt.Println("---SetObject, o2: ", o2) + //fmt.Println("---SetObject, o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) // set hash. @@ -363,10 +363,10 @@ func (ds *defaultStore) SetObject(oo Object) { if ds.opslog != nil { var op StoreOpType if oo.GetIsNewReal() { - fmt.Println("---SetObject, oo is new real, oo: ", oo) + //fmt.Println("---SetObject, oo is new real, oo: ", oo) op = StoreOpNew } else { - fmt.Println("---SetObject, oo is mod, oo: ", oo) + //fmt.Println("---SetObject, oo is mod, oo: ", oo) op = StoreOpMod } ds.opslog = append(ds.opslog, @@ -382,7 +382,7 @@ func (ds *defaultStore) SetObject(oo Object) { } func (ds *defaultStore) DelObject(oo Object) { - fmt.Println("---DelObject, oo: ", oo) + //fmt.Println("---DelObject, oo: ", oo) oid := oo.GetObjectID() // delete from cache. delete(ds.cacheObjects, oid) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index f4554fd8a89..5f4c527d800 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -214,9 +214,9 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { - fmt.Println("---Assign2, pv: ", pv) - fmt.Println("---Assign2, tv2: ", tv2) - fmt.Println("---Assign2, realm: ", rlm) + //fmt.Println("---Assign2, pv: ", pv) + //fmt.Println("---Assign2, tv2: ", tv2) + //fmt.Println("---Assign2, realm: ", rlm) // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -290,11 +290,11 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - fmt.Println("---oo1: ", oo1) + //fmt.Println("---oo1: ", oo1) pv.TV.Assign(alloc, tv2, cu) oo2, pkgId, isRef, length, offset := pv.TV.GetFirstObject2(store) - fmt.Println("---oo2: ", oo2) - fmt.Println("---oo2 pkgId: ", pkgId) + //fmt.Println("---oo2: ", oo2) + //fmt.Println("---oo2 pkgId: ", pkgId) if oo2 != nil { oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } @@ -523,7 +523,7 @@ func (sv *StructValue) GetSubrefPointerTo(store Store, st *StructType, path Valu } func (sv *StructValue) Copy(alloc *Allocator) *StructValue { - fmt.Println("---StructValue copy, sv: ", sv) + //fmt.Println("---StructValue copy, sv: ", sv) /* TODO consider second refcount field if sv.GetRefCount() == 0 { return sv @@ -1051,7 +1051,7 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { - fmt.Println("---Copy, type of tv.V: ", reflect.TypeOf(tv.V)) + //fmt.Println("---Copy, type of tv.V: ", reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -1066,7 +1066,7 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: - println("---default") + //println("---default") cp = tv } return @@ -1705,8 +1705,8 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { // cu: convert untyped after assignment. pass false // for const definitions, but true for all else. func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { - fmt.Println("---Assign, tv: ", tv) - fmt.Println("---Assign, tv2: ", tv2, reflect.TypeOf(tv2)) + //fmt.Println("---Assign, tv: ", tv) + //fmt.Println("---Assign, tv2: ", tv2, reflect.TypeOf(tv2)) if debug { if tv.T == DataByteType { // assignment to data byte types should only @@ -1731,10 +1731,10 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { // allocated, *Allocator.AllocatePointer() is called separately, // as in OpRef. func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath) PointerValue { - fmt.Println("---GetPointerTo, tv: ", tv) - fmt.Println("---rt of tv: ", reflect.TypeOf(tv)) - fmt.Println("---path: ", path) - fmt.Println("---path.Type: ", path.Type) + //fmt.Println("---GetPointerTo, tv: ", tv) + //fmt.Println("---rt of tv: ", reflect.TypeOf(tv)) + //fmt.Println("---path: ", path) + //fmt.Println("---path.Type: ", path.Type) if debug { if tv.IsUndefined() { panic("GetPointerTo() on undefined value") @@ -1832,7 +1832,7 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath fillValueTV(store, dtv) } - fmt.Println("---2, path.Type: ", path.Type) + //fmt.Println("---2, path.Type: ", path.Type) switch path.Type { case VPBlock: switch dtv.T.(type) { @@ -1845,12 +1845,12 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath case VPField: switch baseOf(dtv.T).(type) { case *StructType: - println("---StructType") - fmt.Println("---dtv: ", dtv) - fmt.Println("---return pointer of dtv: ", dtv.V.(*StructValue).GetPointerTo(store, path)) + //println("---StructType") + //fmt.Println("---dtv: ", dtv) + //fmt.Println("---return pointer of dtv: ", dtv.V.(*StructValue).GetPointerTo(store, path)) return dtv.V.(*StructValue).GetPointerTo(store, path) case *TypeType: - println("---TypeType") + //println("---TypeType") switch t := dtv.V.(TypeValue).Type.(type) { case *PointerType: dt := t.Elt.(*DeclaredType) @@ -1906,12 +1906,12 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath panic("should not happen") } } - fmt.Println("---dtv: ", dtv) - fmt.Printf("---dtv addr: %p\n", dtv) + //fmt.Println("---dtv: ", dtv) + //fmt.Printf("---dtv addr: %p\n", dtv) dtv2 := dtv.Copy(alloc) - fmt.Println("---dtv2: ", dtv2) - fmt.Printf("---dtv2 addr: %p\n", dtv2) + //fmt.Println("---dtv2: ", dtv2) + //fmt.Printf("---dtv2 addr: %p\n", dtv2) alloc.AllocateBoundMethod() bmv := &BoundMethodValue{ @@ -2067,7 +2067,7 @@ func (tv *TypedValue) GetPointerAtIndexInt(store Store, ii int) PointerValue { } func (tv *TypedValue) GetPointerAtIndex(alloc *Allocator, store Store, iv *TypedValue) PointerValue { - fmt.Println("---tv, GetPointerAtIndex: ", tv) + //fmt.Println("---tv, GetPointerAtIndex: ", tv) switch bt := baseOf(tv.T).(type) { case PrimitiveType: if bt == StringType || bt == UntypedStringType { @@ -2672,20 +2672,20 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - fmt.Println("---fillValueTV, tv: ", tv) + //fmt.Println("---fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: - println("---tv.V RefValue") - fmt.Println("---cv: ", cv) + //println("---tv.V RefValue") + //fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) - fmt.Println("---tv.V: ", tv.V) + //fmt.Println("---tv.V: ", tv.V) } case PointerValue: - fmt.Println("---PointerValue") + //fmt.Println("---PointerValue") // As a special case, cv.Base is filled // and cv.TV set appropriately. // Alternatively, could implement @@ -2693,9 +2693,9 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { // but for execution speed traded off for // loading speed, we do the following for now: if ref, ok := cv.Base.(RefValue); ok { - fmt.Println("---cv.Base: ", ref) + //fmt.Println("---cv.Base: ", ref) base := store.GetObject(ref.ObjectID).(Value) - fmt.Println("---base: ", base) + //fmt.Println("---base: ", base) cv.Base = base switch cb := base.(type) { case *ArrayValue: @@ -2714,7 +2714,7 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { vpv := cb.GetPointerToInt(store, cv.Index) cv.TV = vpv.TV // TODO optimize? case *HeapItemValue: - fmt.Println("---HeapItemValue: ", cb.Value) + //fmt.Println("---HeapItemValue: ", cb.Value) cv.TV = &cb.Value default: panic("should not happen") diff --git a/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno deleted file mode 100644 index 73ad3ea74d7..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/p/demo/tests" -) - -func main() { - tests.ModifyTestRealmObject2c() - println("done") -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno deleted file mode 100644 index e6f33c50654..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno +++ /dev/null @@ -1,146 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - ptests "gno.land/p/demo/tests" - "gno.land/p/demo/ufmt" - rtests "gno.land/r/demo/tests" - "std" -) - -func getPrevRealm() std.Realm { - return std.PrevRealm() -} - -func Exec(fn func()) { - fn() -} - -func main() { - // Create a map of the potential callers, this will give more understandable - // output than the bech32 addresses. - callersByAddr := make(map[std.Address]string) - for _, caller := range []string{ - "user1.gno", "gno.land/r/crossrealm_test", "gno.land/r/demo/tests", - } { - addr := std.DerivePkgAddr(caller) - callersByAddr[addr] = caller - } - - assertRealm := func(r std.Realm) { - pkgPath := callersByAddr[r.Addr()] - if r.IsUser() && pkgPath != "user1.gno" { - panic(ufmt.Sprintf("ERROR: expected: 'user1.gno', got:'%s'", pkgPath)) - } else if !r.IsUser() && pkgPath != r.PkgPath() { - panic(ufmt.Sprintf("ERROR: expected: '%s', got: '%s'", pkgPath, r.PkgPath())) - } - } - - tests := []struct { - callStackAdd string - callerFn func() std.Realm - }{ - { - callStackAdd: "", - callerFn: std.PrevRealm, - }, - { - callStackAdd: " -> r/crossrealm_test.getPrevRealm", - callerFn: getPrevRealm, - }, - { - callStackAdd: " -> p/demo/tests", - callerFn: ptests.GetPrevRealm, - }, - { - callStackAdd: " -> p/demo/tests -> p/demo/tests/subtests", - callerFn: ptests.GetPSubtestsPrevRealm, - }, - { - callStackAdd: " -> r/demo/tests", - callerFn: rtests.GetPrevRealm, - }, - { - callStackAdd: " -> r/demo/tests -> r/demo/tests/subtests", - callerFn: rtests.GetRSubtestsPrevRealm, - }, - { - callStackAdd: " -> p/demo/tests -> r/demo/tests", - callerFn: ptests.GetRTestsGetPrevRealm, - }, - } - - println("---") // needed to have space prefixes - printColumns("STACK", "std.PrevRealm") - printColumns("-----", "------------------") - - baseCallStack := "user1.gno -> r/crossrealm_test.main" - for i, tt := range tests { - printColumns(baseCallStack+tt.callStackAdd, callersByAddr[tt.callerFn().Addr()]) - Exec(func() { - r := tt.callerFn() - assertRealm(r) - printColumns(baseCallStack+" -> r/crossrealm_test.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) - }) - rtests.Exec(func() { - r := tt.callerFn() - assertRealm(r) - printColumns(baseCallStack+" -> r/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) - }) - ptests.Exec(func() { - r := tt.callerFn() - assertRealm(r) - printColumns(baseCallStack+" -> p/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) - }) - } -} - -func printColumns(left, right string) { - const w = 105 - - output := "" - padding := w - len(left) - - // strings.Repeat is not always available when using various imports modes. - for i := 0; i < padding; i++ { - output += " " - } - - output += left - output += " = " - output += right - println(output) -} - -// Output: -// --- -// STACK = std.PrevRealm -// ----- = ------------------ -// user1.gno -> r/crossrealm_test.main = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.getPrevRealm = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/crossrealm_test.getPrevRealm = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = user1.gno -// user1.gno -> r/crossrealm_test.main -> p/demo/tests = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests = user1.gno -// user1.gno -> r/crossrealm_test.main -> p/demo/tests -> p/demo/tests/subtests = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests -> p/demo/tests/subtests = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests -> p/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests -> p/demo/tests/subtests = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test diff --git a/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno deleted file mode 100644 index f2f229cd5de..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno +++ /dev/null @@ -1,37 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "fmt" - "std" - - psubtests "gno.land/p/demo/tests/subtests" - rsubtests "gno.land/r/demo/tests/subtests" -) - -func main() { - tests := []struct { - fn func() std.Realm - }{ - {std.CurrentRealm}, - {psubtests.GetCurrentRealm}, - {rsubtests.GetCurrentRealm}, - } - - for _, test := range tests { - r := test.fn() - - if std.DerivePkgAddr(r.PkgPath()) != r.Addr() { - panic(fmt.Sprintf("ERROR: expected: %v, got: %v", - std.DerivePkgAddr(r.PkgPath()), r.Addr(), - )) - } - - println(r.PkgPath(), r.Addr()) - } -} - -// Output: -// gno.land/r/crossrealm_test g1vla5mffzum6060t99u4xhm8mnhgxr0sz4k574p -// gno.land/r/crossrealm_test g1vla5mffzum6060t99u4xhm8mnhgxr0sz4k574p -// gno.land/r/demo/tests/subtests g13g48xnr7lzxsrvny0uf6lhx0cfaxy4n0n5geuf diff --git a/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno deleted file mode 100644 index 4daeb6de366..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "std" -) - -func main() { - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewUserRealm("g1user")) - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) -} - -func pad(s string) string { - for len(s) < 26 { - s += " " - } - return s -} - -func PrintRealm() { - println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) - println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) -} - -// Because this is the context of a package, using PrintRealm() -// should not change the output of the main function. - -// Output: -// PrintRealm: CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno deleted file mode 100644 index 2fc37804fce..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno +++ /dev/null @@ -1,46 +0,0 @@ -// PKGPATH: gno.land/r/demo/groups -package groups - -import ( - "std" -) - -func main() { - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewUserRealm("g1user")) - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) - PrintRealm() - println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) -} - -func pad(s string) string { - for len(s) < 26 { - s += " " - } - return s -} - -func PrintRealm() { - println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) - println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) -} - -// Output: -// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_crossrealm14.gno b/gnovm/tests/files/zrealm_crossrealm14.gno deleted file mode 100644 index 23451e6f5d1..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm14.gno +++ /dev/null @@ -1,17 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -func main() { - // even though we are running within a realm, - // we aren't storing the result of crossrealm.Make1(), - // so this should print fine. - crossrealm.Make1().Touch().Print() -} - -// Output: -// A: 2 -// B: LocalStruct{123} diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno deleted file mode 100644 index 40b94662a70..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ /dev/null @@ -1,27 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f *fooer - -// XXX, this attach a heapItem to current realm -func init() { - f = &fooer{} -} - -func main() { - // XXX, this associate a pointer to a value(already attached to local realm) - // to external realm, no attachment happens to the external realm. - crossrealm.SetFooer(f) - crossrealm.CallFoo() - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno deleted file mode 100644 index 50c695884c4..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ /dev/null @@ -1,18 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -var b0 crossrealm.Bar - -func init() { - b0 = crossrealm.Bar{A: 1} // XXX, should be invalid to attach external type -} - -func main() { - crossrealm.SetBar(&b0) - crossrealm.CallBar() - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm16a.gno b/gnovm/tests/files/zrealm_crossrealm16a.gno deleted file mode 100644 index 5fbe6a072ab..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm16a.gno +++ /dev/null @@ -1,16 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -var b0 crossrealm.Bar - -func init() { - crossrealm.Bar2.A = 2 // this should be valid -} - -func main() { - print(".") -} diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno deleted file mode 100644 index e5587dedbee..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ /dev/null @@ -1,28 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type container struct{ *fooer } - -func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } - -type fooer struct{} - -var f *fooer - -func main() { - f = &fooer{} // not attached - c := &container{f} - crossrealm.SetFooer(c) - crossrealm.CallFoo() - print(".") -} - -// Output: -// hello container gno.land/r/demo/tests/crossrealm -// . diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno deleted file mode 100644 index a1c8888fb7d..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm18.gno +++ /dev/null @@ -1,34 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type fooer struct{} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f crossrealm.Fooer = crossrealm.SetFooer(&fooer{}) - -func init() { - crossrealm.CallFoo() -} - -func main() { - crossrealm.CallFoo() - print(".") -} - -// Output: -// hello gno.land/r/demo/tests/crossrealm -// hello gno.land/r/demo/tests/crossrealm -// . - -// Error: - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno deleted file mode 100644 index 62b6d08c78f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ /dev/null @@ -1,33 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -var b0 = crossrealm.Bar{A: 1} - -// un-attached package level var -// is this attached? or not? another function to attach? -//var b *crossrealm.Bar = crossrealm.SetBar(&b0) - -func init() { - // crossrealm.CallFoo() - crossrealm.SetBar(&b0) -} - -func main() { - crossrealm.CallBar() - print(".") -} - -// Output: -// hello gno.land/r/demo/tests/crossrealm -// hello gno.land/r/demo/tests/crossrealm -// . - -// Error: - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno deleted file mode 100644 index 836c317b7dc..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno +++ /dev/null @@ -1,20 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/r/demo/tests" -) - -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject - -func init() { - somevalue.Field = "test" -} - -func main() { - println(somevalue) -} - -// Error: -// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno deleted file mode 100644 index 2e9f3b30637..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm2_stdlibs.gno +++ /dev/null @@ -1,22 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/r/demo/tests" -) - -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject - -func init() { - somevalue.Field = "test" -} - -func main() { - // NOTE: but it is invalid to modify it using an external realm function. - tests.ModifyTestRealmObject(&somevalue) - println(somevalue) -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index d38d84eaa1c..0cd5be053ff 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -14,6 +14,5 @@ func main() { println(".") } -// Error: -// interface conversion: gnolang.PointerValue is not gnolang.Object: missing method DecRefCount -// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm37.gno b/gnovm/tests/files/zrealm_crossrealm37.gno new file mode 100644 index 00000000000..65dc493b100 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm37.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" + +var m1 map[string]int + +func main() { + m1 = crossrealm.GetMap() + println(m1) +} + +// Error: +// should not happen while attempting to attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm38.gno b/gnovm/tests/files/zrealm_crossrealm38.gno new file mode 100644 index 00000000000..29b6c9f6670 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm38.gno @@ -0,0 +1,13 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" + +var f func() string + +func main() { + f = crossrealm.GetFunc() + println(f) +} + +// Output: diff --git a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm39.gno similarity index 50% rename from gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno rename to gnovm/tests/files/zrealm_crossrealm39.gno index 0dd479d24e4..f638eb67f4d 100644 --- a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm39.gno @@ -1,16 +1,13 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import ( - "gno.land/r/demo/tests" -) +import crossrealm "gno.land/r/demo/tests/crossrealm" -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject +var f func() string func main() { - somevalue.Field = "test" - println(somevalue) + f = crossrealm.GetFunc2() + println(f) } // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno deleted file mode 100644 index 9dc099b3c43..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm3_stdlibs.gno +++ /dev/null @@ -1,22 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/r/demo/tests" -) - -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject - -func init() { - somevalue.Field = "test" -} - -func main() { - // NOTE: but it is invalid to modify it using an external realm function. - somevalue.Modify() - println(somevalue) -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm40.gno b/gnovm/tests/files/zrealm_crossrealm40.gno new file mode 100644 index 00000000000..af9d89d59ac --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm40.gno @@ -0,0 +1,13 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" + +var f func() string + +func main() { + f = crossrealm.GetMethod() // XXX, this attach boundmethodvalue to current realm, shoud panic + println(f) +} + +// Error: diff --git a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno deleted file mode 100644 index 9dc099b3c43..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno +++ /dev/null @@ -1,22 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/r/demo/tests" -) - -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject - -func init() { - somevalue.Field = "test" -} - -func main() { - // NOTE: but it is invalid to modify it using an external realm function. - somevalue.Modify() - println(somevalue) -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno deleted file mode 100644 index 9dc099b3c43..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno +++ /dev/null @@ -1,22 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/r/demo/tests" -) - -// NOTE: it is *invalid* to persist external realm types. -var somevalue tests.TestRealmObject - -func init() { - somevalue.Field = "test" -} - -func main() { - // NOTE: but it is invalid to modify it using an external realm function. - somevalue.Modify() - println(somevalue) -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno deleted file mode 100644 index d2e7a4b096a..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno +++ /dev/null @@ -1,21 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/p/demo/tests" -) - -var somevalue tests.TestRealmObject2 - -func init() { - somevalue.Field = "test" -} - -func main() { - // this is OK because the method is declared in a non-realm package. - somevalue.Modify() - println(somevalue) -} - -// Output: -// (struct{("modified" string)} gno.land/p/demo/tests.TestRealmObject2) diff --git a/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno deleted file mode 100644 index 5a4dc3002cc..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/p/demo/tests" -) - -func main() { - tests.ModifyTestRealmObject2a() - println("done") -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno deleted file mode 100644 index f03085ff4c7..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/p/demo/tests" -) - -func main() { - tests.ModifyTestRealmObject2b() - println("done") -} - -// Error: -// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno deleted file mode 100644 index 96a7a3484d7..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "gno.land/p/demo/tests" -) - -func main() { - tests.SomeValue2.Field = "modified" - println("done") -} - -// Error: -// cannot modify external-realm or non-realm object From 4af9d458dbe6bad076228c978bafe09616d5d147 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 25 Nov 2024 19:55:03 +0900 Subject: [PATCH 27/88] save --- gnovm/pkg/gnolang/op_call.go | 3 -- gnovm/pkg/gnolang/op_eval.go | 4 -- gnovm/pkg/gnolang/op_expressions.go | 7 ---- gnovm/pkg/gnolang/realm.go | 48 +++++++---------------- gnovm/pkg/gnolang/uverse.go | 1 + gnovm/pkg/gnolang/values.go | 3 -- gnovm/tests/files/zrealm_crossrealm38.gno | 3 +- 7 files changed, 18 insertions(+), 51 deletions(-) diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 5bb9f3ec748..5bc54ec1f53 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -7,7 +7,6 @@ import ( ) func (m *Machine) doOpPrecall() { - //fmt.Println("---doOpPrecall---") cx := m.PopExpr().(*CallExpr) v := m.PeekValue(1 + cx.NumArgs).V if debug { @@ -20,7 +19,6 @@ func (m *Machine) doOpPrecall() { } switch fv := v.(type) { case *FuncValue: - //fmt.Println("---FuncValue, fv: ", fv) m.PushFrameCall(cx, fv, TypedValue{}) m.PushOp(OpCall) case *BoundMethodValue: @@ -51,7 +49,6 @@ func (m *Machine) doOpPrecall() { var gReturnStmt = &ReturnStmt{} func (m *Machine) doOpCall() { - //fmt.Println("---doOpCall---") // NOTE: Frame won't be popped until the statement is complete, to // discard the correct number of results for func calls in ExprStmts. fr := m.LastFrame() diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index d9a381bba96..1fe26555239 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -21,7 +21,6 @@ func (m *Machine) doOpEval() { x := m.PeekExpr(1) if debug { debug.Printf("EVAL: (%T) %v\n", x, x) - // fmt.Println(m.String()) } // This case moved out of switch for performance. // TODO: understand this better. @@ -37,7 +36,6 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerTo(m.Store, nx.Path) - //fmt.Println("---ptr: ", ptr) m.PushValue(ptr.Deref()) return } @@ -243,7 +241,6 @@ func (m *Machine) doOpEval() { m.PushOp(OpEval) } case *CallExpr: - //fmt.Println("---Eval, CallExpr, x: ", x) m.PushOp(OpPrecall) // Eval args. args := x.Args @@ -267,7 +264,6 @@ func (m *Machine) doOpEval() { m.PushExpr(x.X) m.PushOp(OpEval) case *SelectorExpr: - //fmt.Println("---Eval, SelectorExpr, x: ", x) m.PushOp(OpSelector) // evaluate x m.PushExpr(x.X) diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index a95261909eb..8ff0b5bd538 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -16,8 +16,6 @@ func (m *Machine) doOpIndex1() { } iv := m.PopValue() // index xv := m.PeekValue(1) // x - //fmt.Println("---doOpIndex1, iv: ", iv) - //fmt.Println("---doOpIndex1, xv: ", xv) switch ct := baseOf(xv.T).(type) { case *MapType: mv := xv.V.(*MapValue) @@ -33,7 +31,6 @@ func (m *Machine) doOpIndex1() { } default: res := xv.GetPointerAtIndex(m.Alloc, m.Store, iv) - //fmt.Println("---doOpIndex1, res: ", res.Deref()) *xv = res.Deref() // reuse as result } } @@ -47,7 +44,6 @@ func (m *Machine) doOpIndex2() { } iv := m.PeekValue(1) // index xv := m.PeekValue(2) // x - //fmt.Println("---doOpIndex2: ", iv) switch ct := baseOf(xv.T).(type) { case *MapType: vt := ct.Value @@ -80,12 +76,9 @@ func (m *Machine) doOpIndex2() { } func (m *Machine) doOpSelector() { - //fmt.Println("---doOpSelector---") sx := m.PopExpr().(*SelectorExpr) xv := m.PeekValue(1) - //fmt.Println("---xv: ", xv) res := xv.GetPointerTo(m.Alloc, m.Store, sx.Path).Deref() - //fmt.Println("---doOpSelector, res after Deref: ", res) if debug { m.Printf("-v[S] %v\n", xv) m.Printf("+v[S] %v\n", res) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 743200e0645..be5acee97eb 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -133,21 +133,7 @@ func (rlm *Realm) String() string { // if rlm or po is nil, do nothing. // xo or co is nil if the element value is undefined or has no // associated object. -// TODO: func (rlm *Realm) DidUpdate(po, xo, co Object, attached bool) { func (rlm *Realm) DidUpdate(po, xo, co Object) { - //fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) - //fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) - //fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - // - //if co != nil { - // fmt.Println("---co.LastNewEscapedRealm: ", co.GetLastNewEscapedRealm()) - // fmt.Println("---co.GetRefCount: ", co.GetRefCount()) - // fmt.Println("---co isReal(attached): ", co.GetIsReal()) - // fmt.Println("---co objectID: ", co.GetObjectID()) - //} - - //fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - if rlm == nil { return } @@ -164,7 +150,6 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } if po == nil || !po.GetIsReal() { // XXX, make sure po is attached - fmt.Println("---po(Base) not real, do nothing!!!") return // do nothing. } @@ -179,16 +164,14 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { rlm.MarkDirty(po) if co != nil { - //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() - //fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsEscaped() { // XXX, why packageBlock is automatically escaped? - //println("---already escaped, should check cross realm?") // already escaped } else { + // XXX, just mark rlm.MarkNewEscapedCheckCrossRealm(nil, co, false, 0, 0) } } else if co.GetIsReal() { @@ -201,7 +184,6 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { if xo != nil { xo.DecRefCount() - //fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) if xo.GetRefCount() == 0 { if xo.GetIsReal() { rlm.MarkNewDeleted(xo) @@ -327,6 +309,7 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { //res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + // TODO: replace these logic fmt.Println("---e: ", e, reflect.TypeOf(e.V)) if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough fmt.Println("---escaped: ", e.V.(RefValue).Escaped) @@ -401,7 +384,6 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo } func (rlm *Realm) MarkNewReal(oo Object) { - //fmt.Println("---markNewReal---, oo: ", oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -515,13 +497,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -536,9 +518,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -957,9 +939,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index 880a75396ca..b13bd1a4317 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -303,6 +303,7 @@ func UverseNode() *PackageNode { newElem := arg1Base.List[arg1Offset+i].unrefCopy(m.Alloc, m.Store) list[arg0Offset+arg0Length+i] = newElem + // XXX, DidUpdate2? m.Realm.DidUpdate( arg0Base, oldElem.GetFirstObject(m.Store), diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 5f4c527d800..f64ed670403 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -1732,9 +1732,6 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { // as in OpRef. func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath) PointerValue { //fmt.Println("---GetPointerTo, tv: ", tv) - //fmt.Println("---rt of tv: ", reflect.TypeOf(tv)) - //fmt.Println("---path: ", path) - //fmt.Println("---path.Type: ", path.Type) if debug { if tv.IsUndefined() { panic("GetPointerTo() on undefined value") diff --git a/gnovm/tests/files/zrealm_crossrealm38.gno b/gnovm/tests/files/zrealm_crossrealm38.gno index 29b6c9f6670..3eda0c34e7e 100644 --- a/gnovm/tests/files/zrealm_crossrealm38.gno +++ b/gnovm/tests/files/zrealm_crossrealm38.gno @@ -7,7 +7,8 @@ var f func() string func main() { f = crossrealm.GetFunc() - println(f) + println(f()) } // Output: +// a From 588b9dd28aa13224b47756456d181bce5362a425 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 11:58:20 +0900 Subject: [PATCH 28/88] change api --- gnovm/pkg/gnolang/ownership.go | 65 +++------------ gnovm/pkg/gnolang/realm.go | 146 +++++++++++++++++---------------- gnovm/pkg/gnolang/values.go | 12 ++- 3 files changed, 97 insertions(+), 126 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 67352a7c93e..0f9dbbc1f15 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -382,34 +382,30 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } // XXX, get first accessible object, maybe containing(parent) object, maybe itself. -func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isRef bool, length int, offset int) { +func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) - //fmt.Println("---tv.T, type of tv.T", tv.T, reflect.TypeOf(tv.T)) + // general case if dt, ok := tv.T.(*DeclaredType); ok { //fmt.Println("---dt: ", dt) //fmt.Println("---dt.Name: ", dt.Name) //fmt.Println("---dt.PkgPath: ", dt.PkgPath) //fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) - //fmt.Println("---dt.Base: ", dt.Base) if IsRealmPath(dt.PkgPath) { pkgId = PkgIDFromPkgPath(dt.PkgPath) } } + + // get first object + obj = tv.GetFirstObject(store) + + fmt.Println("---obj: ", obj) switch cv := tv.V.(type) { case PointerValue: - println("---pointer value, get base") + println("---pointer value") if v, ok := cv.TV.V.(Object); ok { fmt.Println("---v: ", v) - //rc := v.GetRefCount() - //fmt.Println("---rc: ", rc) - //fmt.Println("---v Owner: ", v.GetOwnerID()) - //fmt.Println("---v.GetObjectID(): ", v.GetObjectID()) - //fmt.Println("---is Attached?", v.GetIsReal()) - + // TODO: check this if dt, ok := cv.TV.T.(*DeclaredType); ok { - // b0 = &crossrealm.Bar{A: 1} this is valid - // no need to check cross - // XXX, is it right? if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { if IsRealmPath(dt.PkgPath) { pkgId = PkgIDFromPkgPath(dt.PkgPath) @@ -417,59 +413,22 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID, isR } } } - obj, isRef = cv.GetBase(store), true return case *ArrayValue: fmt.Println("---array value, T: ", tv.T) - //fmt.Println("---Elem PkgPath: ", tv.T.Elem().GetPkgPath()) - - obj, pkgId, isRef = cv, PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), false + pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) return case *SliceValue: - //base := cv.GetBase(store) - //fmt.Println("---SliceValue, base: ", base) - //fmt.Printf("---SliceValue len: %d, cap:%d, offsetL:%d \n", cv.Length, cv.Maxcap, cv.Offset) - //fmt.Println("---tv.T...PkgPath: ", tv.T.Elem().GetPkgPath()) - //fmt.Println("---type of base: ", reflect.TypeOf(base)) - - obj, pkgId, isRef, length, offset = cv.GetBase(store), PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()), true, cv.GetLength(), cv.Offset - return - case *StructValue: - println("---struct value") - //fmt.Println("---cv.GetObjectID(): ", cv.GetObjectID()) - obj, isRef = cv, false + pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) return case *FuncValue: fmt.Println("---FuncValue") clo := cv.GetClosure(store) fmt.Println("---clo: ", clo) fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) - obj, pkgId, isRef = cv.GetClosure(store), PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath), false - return - case *MapValue: - obj, isRef = cv, false - return - case *BoundMethodValue: - obj, isRef = cv, false - return - case *NativeValue: - // XXX allow PointerValue.Assign2 to pass nil for oo1/oo2. - // panic("realm logic for native values not supported") - obj, isRef = nil, false - return - case *Block: - obj, isRef = cv, false - return - case RefValue: - oo := store.GetObject(cv.ObjectID) - tv.V = oo - obj, isRef = oo, false + pkgId = PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath) return - case *HeapItemValue: - // should only appear in PointerValue.Base - panic("heap item value should only appear as a pointer's base") default: - obj, isRef = nil, false return } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index be5acee97eb..f746592951f 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -172,7 +172,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { // already escaped } else { // XXX, just mark - rlm.MarkNewEscapedCheckCrossRealm(nil, co, false, 0, 0) + rlm.MarkNewEscaped(co) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -192,8 +192,9 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } } -func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, offset int) { - fmt.Println("---DidUpdate, rlm.ID: ", rlm.ID) +// ref value is the derived value from co, like a slice. +func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { + fmt.Println("---DidUpdate2, rlm.ID: ", rlm.ID) //fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) @@ -239,7 +240,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, println("---already escaped, should check cross realm?") // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(store, co, isRef, length, offset) + rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) } } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -267,7 +268,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, isRef bool, length, // originType may contain infos like len, cap for slice type, etc. // XXX, oo coming here must be referenced type, since they already escaped. // XXX, so oo has been persisted, thus fillValueTV -func checkCrossRealm(store Store, oo Object, offset, length int) { +func checkCrossRealm(store Store, oo Object, refValue Value) { fmt.Println("---checkCrossReal, oo: ", oo) switch v := oo.(type) { case *StructValue: @@ -298,58 +299,63 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { //r := fillValueTV(store, &v.Value) //fmt.Println("---r: ", r) - checkCrossRealm(store, v.Value.V.(Object), 0, 0) + checkCrossRealm(store, v.Value.V.(Object), refValue) case *ArrayValue: - fmt.Println("---ArrayValue: ", v) - fmt.Println("---offset: ", offset) - fmt.Println("---escaped array, check if elements are real") - for i := offset; i < length; i++ { - // XXX, difference between them? - //e := oo.(*ArrayValue).List[i] - //res := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - - // TODO: replace these logic - fmt.Println("---e: ", e, reflect.TypeOf(e.V)) - if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough - fmt.Println("---escaped: ", e.V.(RefValue).Escaped) - fmt.Println("---string: ", e.V.(RefValue).String()) - fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) - fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) - if store != nil { - oo := store.GetObject(e.V.(RefValue).ObjectID) - fmt.Println("---oo: ", oo) - fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) - if !oo.GetIsReal() { - panic("should not happen while reference unreal element from array of external realm") - } - } - } else { - fmt.Println("---e.V: ", e.V) - fmt.Println("---e.V: ", reflect.TypeOf(e.V)) - - if p, ok := e.V.(PointerValue); ok { - fmt.Println("---p.TV: ", p.TV) - fmt.Println("---p.Index: ", p.Index) - fmt.Println("---p.Base: ", p.Base) - - //r1 := fillValueTV(store, &p.Base) - - rr := fillValueTV(store, p.TV) - fmt.Println("---rr: ", rr) - - if sv, ok := p.TV.V.(*StructValue); ok { - fmt.Println("---sv: ", sv) - fmt.Println("---sv.GetIsReal", sv.GetIsReal()) - if !sv.GetIsReal() { - panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) + if sv, ok := refValue.(*SliceValue); !ok { + panic("should be slice value") + } else { + offset := sv.Offset + length := sv.Length + fmt.Println("---ArrayValue: ", v) + fmt.Println("---offset: ", offset) + fmt.Println("---escaped array, check if elements are real") + for i := offset; i < length; i++ { + // XXX, difference between them? + //e := oo.(*ArrayValue).List[i] + e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + + // TODO: replace these logic + fmt.Println("---e: ", e, reflect.TypeOf(e.V)) + if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough + fmt.Println("---escaped: ", e.V.(RefValue).Escaped) + fmt.Println("---string: ", e.V.(RefValue).String()) + fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) + fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) + if store != nil { + oo := store.GetObject(e.V.(RefValue).ObjectID) + fmt.Println("---oo: ", oo) + fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) + if !oo.GetIsReal() { + panic("should not happen while reference unreal element from array of external realm") } - fmt.Println("---sv.ObjectID", sv.GetObjectID()) } } else { - println("---e.V is not pointer") - if !e.V.(Object).GetIsReal() { - panic("should not happen while reference unreal element from external realm") + fmt.Println("---e.V: ", e.V) + fmt.Println("---e.V: ", reflect.TypeOf(e.V)) + + if p, ok := e.V.(PointerValue); ok { + fmt.Println("---p.TV: ", p.TV) + fmt.Println("---p.Index: ", p.Index) + fmt.Println("---p.Base: ", p.Base) + + //r1 := fillValueTV(store, &p.Base) + + rr := fillValueTV(store, p.TV) + fmt.Println("---rr: ", rr) + + if sv, ok := p.TV.V.(*StructValue); ok { + fmt.Println("---sv: ", sv) + fmt.Println("---sv.GetIsReal", sv.GetIsReal()) + if !sv.GetIsReal() { + panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) + } + fmt.Println("---sv.ObjectID", sv.GetObjectID()) + } + } else { + println("---e.V is not pointer") + if !e.V.(Object).GetIsReal() { + panic("should not happen while reference unreal element from external realm") + } } } } @@ -360,9 +366,9 @@ func checkCrossRealm(store Store, oo Object, offset, length int) { } // escaped realm should be reference object -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bool, length, offset int) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { fmt.Println("---MarkNewEscapedCheckCrossRealm") - //fmt.Println("---isRef: ", isRef) + fmt.Println("---refValue: ", refValue) //fmt.Println("---rlm.ID: ", rlm.ID) //fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) //fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) @@ -373,8 +379,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, isRef bo } if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm - if isRef { - checkCrossRealm(store, oo, offset, length) + if refValue != nil { // is reference object from external realm + checkCrossRealm(store, oo, refValue) } else { panic("should not happen while attempting to attach objects by value from external realm") } @@ -497,13 +503,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -518,9 +524,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -939,9 +945,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index f64ed670403..8dfc5a6100c 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -257,7 +257,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -292,14 +292,20 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo1 := pv.TV.GetFirstObject(store) //fmt.Println("---oo1: ", oo1) pv.TV.Assign(alloc, tv2, cu) - oo2, pkgId, isRef, length, offset := pv.TV.GetFirstObject2(store) + oo2, pkgId := pv.TV.GetFirstObject2(store) + + var refValue Value + switch rv := pv.TV.V.(type) { + case *SliceValue, PointerValue: + refValue = rv + } //fmt.Println("---oo2: ", oo2) //fmt.Println("---oo2 pkgId: ", pkgId) if oo2 != nil { oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } // TODO: make check happens in here? - rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, isRef, length, offset) + rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, refValue) } else { pv.TV.Assign(alloc, tv2, cu) } From 928bda27d82d7c43ebcbb0b4f239d77f26d3da6c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 14:02:39 +0900 Subject: [PATCH 29/88] fixup --- gnovm/pkg/gnolang/realm.go | 94 ++++++++++------------ gnovm/pkg/gnolang/values.go | 3 +- gnovm/tests/files/zrealm_crossrealm33.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm36.gno | 2 +- gnovm/tests/files/zrealm_crossrealm40.gno | 1 + 6 files changed, 48 insertions(+), 56 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index f746592951f..093e2b8b7d4 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -275,8 +275,10 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { fmt.Println("---StructValue...") fmt.Println("---sv: ", v) if !v.GetIsReal() { - panic("---sv is not real!!!") + panic(fmt.Sprintf("should not happen, %v is not real\n", v)) } + fmt.Println("---sv is real, check fields") + // check fields for _, fv := range v.Fields { fmt.Println("---fv: ", fv) fmt.Println("---type of fv: ", reflect.TypeOf(fv.V)) @@ -286,18 +288,31 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { //} rfv := fillValueTV(store, &fv) fmt.Println("---rfv: ", rfv) - if oo, ok := rfv.V.(Object); ok { - if !oo.GetIsReal() { - panic(fmt.Sprintf("---should not happen, %v: is not real \n", oo)) + fmt.Println("---type of rfv.V: ", reflect.TypeOf(rfv.V)) + + if fo, ok := rfv.V.(Object); ok { + checkCrossRealm(store, fo, nil) + } else { // reference to object + var reo Object + switch rv := rfv.V.(type) { + case *SliceValue, PointerValue: // if reference object from external realm + refValue = rv + // TODO: consider pkgId here, A -> B - > A?... + // yes, check PkgId per object + reo, _ = rfv.GetFirstObject2(store) + fmt.Println("---reo: ", reo) + // XXX, if elem of array is slice?, GetFirstObject2?... + checkCrossRealm(store, reo, refValue) } } } case *MapValue: println("---mapValue...") + // TODO: check elem? NO. case *HeapItemValue: fmt.Println("---heapItemValue: ", v) - //r := fillValueTV(store, &v.Value) - //fmt.Println("---r: ", r) + r := fillValueTV(store, &v.Value) + fmt.Println("---r: ", r) checkCrossRealm(store, v.Value.V.(Object), refValue) case *ArrayValue: @@ -307,55 +322,30 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { offset := sv.Offset length := sv.Length fmt.Println("---ArrayValue: ", v) - fmt.Println("---offset: ", offset) + fmt.Printf("---offset: %d, length: %d \n", offset, length) fmt.Println("---escaped array, check if elements are real") + for i := offset; i < length; i++ { // XXX, difference between them? - //e := oo.(*ArrayValue).List[i] - e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - - // TODO: replace these logic - fmt.Println("---e: ", e, reflect.TypeOf(e.V)) - if _, ok := e.V.(RefValue); ok { // TODO: XXX, does this already enough - fmt.Println("---escaped: ", e.V.(RefValue).Escaped) - fmt.Println("---string: ", e.V.(RefValue).String()) - fmt.Println("---pkgpath: ", e.V.(RefValue).PkgPath) - fmt.Println("---objectID: ", e.V.(RefValue).ObjectID) - if store != nil { - oo := store.GetObject(e.V.(RefValue).ObjectID) - fmt.Println("---oo: ", oo) - fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) - if !oo.GetIsReal() { - panic("should not happen while reference unreal element from array of external realm") - } - } - } else { - fmt.Println("---e.V: ", e.V) - fmt.Println("---e.V: ", reflect.TypeOf(e.V)) - - if p, ok := e.V.(PointerValue); ok { - fmt.Println("---p.TV: ", p.TV) - fmt.Println("---p.Index: ", p.Index) - fmt.Println("---p.Base: ", p.Base) - - //r1 := fillValueTV(store, &p.Base) - - rr := fillValueTV(store, p.TV) - fmt.Println("---rr: ", rr) - - if sv, ok := p.TV.V.(*StructValue); ok { - fmt.Println("---sv: ", sv) - fmt.Println("---sv.GetIsReal", sv.GetIsReal()) - if !sv.GetIsReal() { - panic(fmt.Sprintf("---should not happen, %v: is not real \n", sv)) - } - fmt.Println("---sv.ObjectID", sv.GetObjectID()) - } - } else { - println("---e.V is not pointer") - if !e.V.(Object).GetIsReal() { - panic("should not happen while reference unreal element from external realm") - } + ee := oo.(*ArrayValue).List[i] + e := fillValueTV(store, &ee) + + //e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + fmt.Printf("---e[%d]: %v\n", i, e) + fmt.Printf("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) + if eo, ok := e.V.(Object); ok { + checkCrossRealm(store, eo, nil) + } else { // reference to object + var reo Object + switch rv := e.V.(type) { + case *SliceValue, PointerValue: // if reference object from external realm + refValue = rv + // TODO: consider pkgId here, A -> B - > A?... + // yes, check PkgId per object + reo, _ = e.GetFirstObject2(store) + fmt.Println("---reo: ", reo) + // XXX, if elem of array is slice?, GetFirstObject2?... + checkCrossRealm(store, reo, refValue) } } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 8dfc5a6100c..5f8fe658de4 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -257,7 +257,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -294,6 +294,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty pv.TV.Assign(alloc, tv2, cu) oo2, pkgId := pv.TV.GetFirstObject2(store) + // TODO: move to GetFirstObject2 var refValue Value switch rv := pv.TV.V.(type) { case *SliceValue, PointerValue: diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index 1d892444305..845caa81f04 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen while reference unreal element from external realm +// should not happen, struct{("0" string)} is not real diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index 00dd06ba292..b15af3bc3b9 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// ---should not happen, struct{("6.1" string)}: is not real +// should not happen, struct{("6.1" string)} is not real diff --git a/gnovm/tests/files/zrealm_crossrealm36.gno b/gnovm/tests/files/zrealm_crossrealm36.gno index a4ce8f9497f..4a45ef0984d 100644 --- a/gnovm/tests/files/zrealm_crossrealm36.gno +++ b/gnovm/tests/files/zrealm_crossrealm36.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// ---should not happen, struct{("d" string)}: is not real +// should not happen, struct{("d" string)} is not real diff --git a/gnovm/tests/files/zrealm_crossrealm40.gno b/gnovm/tests/files/zrealm_crossrealm40.gno index af9d89d59ac..7f5e126dc2b 100644 --- a/gnovm/tests/files/zrealm_crossrealm40.gno +++ b/gnovm/tests/files/zrealm_crossrealm40.gno @@ -10,4 +10,5 @@ func main() { println(f) } +// XXX, fix this. // Error: From 35927e633113c70ebb8034f4587638633243fe01 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 16:07:55 +0900 Subject: [PATCH 30/88] fixup --- gnovm/pkg/gnolang/alloc.go | 4 +- gnovm/pkg/gnolang/gno_test.go | 1 - gnovm/pkg/gnolang/machine.go | 24 --- gnovm/pkg/gnolang/op_assign.go | 6 - gnovm/pkg/gnolang/op_call.go | 3 - gnovm/pkg/gnolang/op_eval.go | 1 + gnovm/pkg/gnolang/op_exec.go | 3 - gnovm/pkg/gnolang/ownership.go | 15 +- gnovm/pkg/gnolang/preprocess.go | 3 - gnovm/pkg/gnolang/realm.go | 33 +--- gnovm/pkg/gnolang/store.go | 3 - gnovm/pkg/gnolang/values.go | 32 ---- gnovm/tests/files/types/eql_0f49.gno | 21 --- .../files/zrealm_crossrealm0_stdlibs.gno | 17 ++ .../files/zrealm_crossrealm10_stdlibs.gno | 14 ++ .../files/zrealm_crossrealm11_stdlibs.gno | 146 ++++++++++++++++++ .../files/zrealm_crossrealm12_stdlibs.gno | 37 +++++ .../files/zrealm_crossrealm13_stdlibs.gno | 48 ++++++ .../files/zrealm_crossrealm13a_stdlibs.gno | 46 ++++++ .../files/zrealm_crossrealm14_stdlibs.gno | 17 ++ .../files/zrealm_crossrealm1_stdlibs.gno | 20 +++ .../files/zrealm_crossrealm4_stdlibs.gno | 22 +++ .../files/zrealm_crossrealm5_stdlibs.gno | 22 +++ .../files/zrealm_crossrealm6_stdlibs.gno | 21 +++ .../files/zrealm_crossrealm7_stdlibs.gno | 14 ++ .../files/zrealm_crossrealm8_stdlibs.gno | 14 ++ .../files/zrealm_crossrealm9_stdlibs.gno | 14 ++ 27 files changed, 464 insertions(+), 137 deletions(-) delete mode 100644 gnovm/tests/files/types/eql_0f49.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno diff --git a/gnovm/pkg/gnolang/alloc.go b/gnovm/pkg/gnolang/alloc.go index 0c88f1383b2..6fef5eda834 100644 --- a/gnovm/pkg/gnolang/alloc.go +++ b/gnovm/pkg/gnolang/alloc.go @@ -1,8 +1,6 @@ package gnolang -import ( - "reflect" -) +import "reflect" // Keeps track of in-memory allocations. // In the future, allocations within realm boundaries will be diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 2c1ed2f003d..8f6ef7ce009 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -179,7 +179,6 @@ func BenchmarkIfStatement(b *testing.B) { func main() { for i:=0; i<10000; i++ { if i > 10 { - } } }` diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 9765d43b0db..3018796985f 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -212,7 +212,6 @@ func (m *Machine) Release() { // Convenience for initial setup of the machine. func (m *Machine) SetActivePackage(pv *PackageValue) { - //fmt.Println("---SetActivePackage, pv: ", pv) if err := m.CheckEmpty(); err != nil { panic(errors.Wrap(err, "set package when machine not empty")) } @@ -286,9 +285,6 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *std.MemPackage, save bool) } func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { - //fmt.Println("---runMemPackage, save: ", save) - //fmt.Println("---runMemPackage, memPkg: ", memPkg) - //defer func() { fmt.Println("---done runMemPackage: ", memPkg) }() // parse files. files := ParseMemPackage(memPkg) if !overrides && checkDuplicates(files) { @@ -310,7 +306,6 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* m.SetActivePackage(pv) // run files. updates := m.RunFileDecls(files.Files...) - //fmt.Println("---updates: ", updates) // save package value and mempackage. // XXX save condition will be removed once gonative is removed. var throwaway *Realm @@ -734,14 +729,12 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // lexical file name order to a compiler." func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { for _, tv := range updates { - //fmt.Println("---runInitFromUpdates, tv: ", tv) if tv.IsDefined() && tv.T.Kind() == FuncKind && tv.V != nil { fv, ok := tv.V.(*FuncValue) if !ok { continue // skip native functions. } if strings.HasPrefix(string(fv.Name), "init.") { - //fmt.Println("---fv.Name: ", fv.Name) fb := pv.GetFileBlock(m.Store, fv.FileName) m.PushBlock(fb) m.RunFunc(fv.Name) @@ -789,7 +782,6 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { - //fmt.Println("---resavePackageValues, realm: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { @@ -980,14 +972,12 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { - //fmt.Println("---run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. // closure and package already set // during PackageNode.NewPackage(). case *ValueDecl: - //fmt.Println("---valueDecl, d.Type, type of d.Type: ", d.Type, reflect.TypeOf(d.Type)) m.PushOp(OpHalt) m.PushStmt(d) m.PushOp(OpExec) @@ -1858,7 +1848,6 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { - //fmt.Printf("---PushFrameCall---, cx: %v, fv: %v, recv: %v\n", cx, fv, recv) fr := &Frame{ Source: cx, NumOps: m.NumOps, @@ -1884,13 +1873,9 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { m.Printf("+F %#v\n", fr) } m.Frames = append(m.Frames, fr) - //fmt.Println("---recv: ", recv) if recv.IsDefined() { // If the receiver is defined, we enter the receiver's realm. obj := recv.GetFirstObject(m.Store) - //fmt.Println("---obj, rt of obj: ", obj, reflect.TypeOf(obj)) - //fmt.Println("---obj.GetObjectID: ", obj.GetObjectID()) - //fmt.Printf("---obj addr: %p\n", obj) if obj == nil { // could be a nil receiver. // set package and realm of function. @@ -1903,16 +1888,7 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { recvOID := obj.GetObjectInfo().ID fmt.Println("---recvOID is: ", recvOID) if recvOID.IsZero() { - //panic("!!!should not happen!!!") fmt.Println("!!! recvOID is ZERO!!!") - // TODO: object reference by external realm must first be attached, - // check here... - // NOTE: the reference has two types: - // 1. if associated with global or child of global, panic; - // 2. if associated with un-attached object directly/indirectly, ok, - // when the un-attached object is attached, check if the target - // object has been attached(become real), if not, panic. - fmt.Println("---recv is ZERO, it's not owned, recv: ", recv) fmt.Println("---recv is ZERO, m.realm: ", m.Realm) diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index d8db20cac5f..eb67ffcc351 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -1,15 +1,11 @@ package gnolang -import "fmt" - func (m *Machine) doOpDefine() { - fmt.Println("---doOpDefine---") s := m.PopStmt().(*AssignStmt) // Define each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. rvs := m.PopValues(len(s.Lhs)) - fmt.Println("---rvs: ", rvs) lb := m.LastBlock() for i := 0; i < len(s.Lhs); i++ { // Get name and value of i'th term. @@ -29,9 +25,7 @@ func (m *Machine) doOpDefine() { } func (m *Machine) doOpAssign() { - fmt.Println("---doOpAssign, m.Realm: ", m.Realm) s := m.PopStmt().(*AssignStmt) - fmt.Println("---s: ", s) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 5bc54ec1f53..15531ec610d 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -22,9 +22,6 @@ func (m *Machine) doOpPrecall() { m.PushFrameCall(cx, fv, TypedValue{}) m.PushOp(OpCall) case *BoundMethodValue: - //fmt.Println("---BoundMethodValue, fv: ", fv) - //fmt.Println("---BoundMethodValue, fv.Func: ", fv.Func) - //fmt.Println("---BoundMethodValue, fv.Receiver: ", fv.Receiver) m.PushFrameCall(cx, fv.Func, fv.Receiver) m.PushOp(OpCall) case TypeValue: diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 1fe26555239..c37af7d31af 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -21,6 +21,7 @@ func (m *Machine) doOpEval() { x := m.PeekExpr(1) if debug { debug.Printf("EVAL: (%T) %v\n", x, x) + fmt.Println(m.String()) } // This case moved out of switch for performance. // TODO: understand this better. diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index 3d50b4d8131..c7e8ffd600c 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -56,7 +56,6 @@ func (m *Machine) doOpExec(op Op) { debug.Printf("PEEK STMT: %v\n", s) debug.Printf("%v\n", m) } - //fmt.Printf("PEEK STMT: %v\n", s) // NOTE this could go in the switch statement, and we could // use the EXEC_SWITCH to jump back, rather than putting this @@ -432,7 +431,6 @@ EXEC_SWITCH: if debug { debug.Printf("EXEC: %v\n", s) } - //fmt.Printf("EXEC: %v\n", s) switch cs := s.(type) { case *AssignStmt: switch cs.Op { @@ -487,7 +485,6 @@ EXEC_SWITCH: // All expressions push 1 value except calls, // which push as many as there are results. if _, ok := cs.X.(*CallExpr); ok { - //fmt.Println("---CallExpr: ", cs.X) m.PushOp(OpPopResults) } else { m.PushOp(OpPopValue) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 0f9dbbc1f15..e9fd6bc3fb8 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -113,7 +113,7 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) - GetLastNewEscapedRealm() PkgID // XXX, does escape imply this? + GetLastNewEscapedRealm() PkgID SetLastNewEscapedRealm(pkgID PkgID) GetIsNewEscaped() bool SetIsNewEscaped(bool) @@ -209,9 +209,6 @@ func (oi *ObjectInfo) MustGetObjectID() ObjectID { func (oi *ObjectInfo) SetObjectID(oid ObjectID) { oi.ID = oid } -func (oi *ObjectInfo) SetLastEscapedRealm(pkgId PkgID) { - oi.lastNewRealEscapedRealm = pkgId -} func (oi *ObjectInfo) GetHash() ValueHash { return oi.Hash @@ -381,15 +378,12 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } } -// XXX, get first accessible object, maybe containing(parent) object, maybe itself. +// also get pkgId of the object, so it's clear where the object is from func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) // general case if dt, ok := tv.T.(*DeclaredType); ok { - //fmt.Println("---dt: ", dt) - //fmt.Println("---dt.Name: ", dt.Name) - //fmt.Println("---dt.PkgPath: ", dt.PkgPath) - //fmt.Println("---PkgID: ", PkgIDFromPkgPath(dt.PkgPath)) + fmt.Printf("---dt: %v\n", dt) if IsRealmPath(dt.PkgPath) { pkgId = PkgIDFromPkgPath(dt.PkgPath) } @@ -397,8 +391,9 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { // get first object obj = tv.GetFirstObject(store) - fmt.Println("---obj: ", obj) + + // get actual pkgId switch cv := tv.V.(type) { case PointerValue: println("---pointer value") diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index d7b52e3eed9..ba60ead28f6 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1207,9 +1207,6 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { "incompatible types in binary expression: %v %v %v", lt.TypeID(), n.Op, rt.TypeID())) } - // convert untyped to typed - checkOrConvertType(store, last, &n.Left, defaultTypeOf(lt), false) - checkOrConvertType(store, last, &n.Right, defaultTypeOf(rt), false) } else { // left untyped, right typed checkOrConvertType(store, last, &n.Left, rt, false) } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 093e2b8b7d4..edad0e05ae9 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -219,6 +219,11 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { return // do nothing. } + fmt.Println("---po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) + if po.GetObjectID().PkgID != rlm.ID { + panic("cannot modify external-realm or non-realm object") + } + // XXX check if this boosts performance // XXX with broad integration benchmarking. // XXX if co == xo { @@ -891,26 +896,18 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - //fmt.Println("---saveUnsavedObjects, new created, new updated---") - //fmt.Println("---len of new created: ", len(rlm.created)) - //fmt.Println("---len of new updated: ", len(rlm.updated)) for _, co := range rlm.created { - //fmt.Println("------saveUnsavedObject, co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { - //println("---not new real") // might have happened already as child // of something else created. continue } else { - //println("---new real") rlm.saveUnsavedObjectRecursively(store, co) } } for _, uo := range rlm.updated { - //fmt.Println("---uo: ", uo) - // uo := rlm.updated[i] if !uo.GetIsDirty() { // might have happened already as child @@ -924,7 +921,6 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { - //fmt.Println("---saveUnsavedObjectRecursively, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -943,14 +939,8 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // first, save unsaved children. unsaved := getUnsavedChildObjects(oo) - //fmt.Println("---unsaved: ", unsaved) for _, uch := range unsaved { - //fmt.Println("---uch: ", uch) - //fmt.Println("---uch.GetOwnerID(): ", uch.GetOwnerID()) - //fmt.Println("---uch.GetRefCount(): ", uch.GetRefCount()) - //fmt.Println("---type of uch: ", reflect.TypeOf(uch)) if uch.GetIsEscaped() || uch.GetIsNewEscaped() { - //fmt.Println("---uch is escaped or new escaped") // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) @@ -958,7 +948,6 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // then, save self. if oo.GetIsNewReal() { - //fmt.Println("---oo is new real: ", oo) // save created object. if debug { if oo.GetIsDirty() { @@ -968,7 +957,6 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { rlm.saveObject(store, oo) oo.SetIsNewReal(false) } else { - //fmt.Println("---oo is not new real, update it: ", oo) // update existing object. if debug { if !oo.GetIsDirty() { @@ -1012,7 +1000,6 @@ func (rlm *Realm) saveObject(store Store, oo Object) { // removeDeletedObjects func (rlm *Realm) removeDeletedObjects(store Store) { - //fmt.Println("---removeDeletedObjects---") for _, do := range rlm.deleted { store.DelObject(do) } @@ -1057,12 +1044,9 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - //fmt.Println("---getSelfOrChildObjects, val: ", val) if _, ok := val.(RefValue); ok { - //println("---ref value") return append(more, val) } else if _, ok := val.(Object); ok { - //println("---not ref value") return append(more, val) } else { return getChildObjects(val, more) @@ -1072,7 +1056,6 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - //fmt.Println("---getChildObjects, val: ", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1099,10 +1082,8 @@ func getChildObjects(val Value, more []Value) []Value { more = getSelfOrChildObjects(cv.Base, more) return more case *StructValue: - //println("---struct value") for _, ctv := range cv.Fields { // TODO: we have type infos here, so check check cross realm logic - //fmt.Println("---ctv: ", ctv) more = getSelfOrChildObjects(ctv.V, more) } return more @@ -1152,17 +1133,13 @@ func getChildObjects(val Value, more []Value) []Value { // like getChildObjects() but loads RefValues into objects. func getChildObjects2(store Store, val Value) []Object { - //fmt.Println("---getChildObjects2, val: ", val) chos := getChildObjects(val, nil) - //fmt.Println("---chos: ", chos) objs := make([]Object, 0, len(chos)) for _, child := range chos { if ref, ok := child.(RefValue); ok { - //println("---ref value") oo := store.GetObject(ref.ObjectID) objs = append(objs, oo) } else if oo, ok := child.(Object); ok { - //println("---not ref value") objs = append(objs, oo) } } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 8db812ae333..096bc2cb6dc 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -363,10 +363,8 @@ func (ds *defaultStore) SetObject(oo Object) { if ds.opslog != nil { var op StoreOpType if oo.GetIsNewReal() { - //fmt.Println("---SetObject, oo is new real, oo: ", oo) op = StoreOpNew } else { - //fmt.Println("---SetObject, oo is mod, oo: ", oo) op = StoreOpMod } ds.opslog = append(ds.opslog, @@ -382,7 +380,6 @@ func (ds *defaultStore) SetObject(oo Object) { } func (ds *defaultStore) DelObject(oo Object) { - //fmt.Println("---DelObject, oo: ", oo) oid := oo.GetObjectID() // delete from cache. delete(ds.cacheObjects, oid) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 5f8fe658de4..b55815d496a 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -193,17 +193,14 @@ const ( ) func (pv *PointerValue) GetBase(store Store) Object { - fmt.Printf("GetBase, pv.Base: %v\n", pv.Base) switch cbase := pv.Base.(type) { case nil: return nil case RefValue: - println("---RefValue") base := store.GetObject(cbase.ObjectID).(Object) pv.Base = base return base case Object: - fmt.Println("---Object, cbase: ", cbase) return cbase default: panic(fmt.Sprintf("unexpected pointer base type %T", cbase)) @@ -214,9 +211,6 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { - //fmt.Println("---Assign2, pv: ", pv) - //fmt.Println("---Assign2, tv2: ", tv2) - //fmt.Println("---Assign2, realm: ", rlm) // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -379,7 +373,6 @@ func (av *ArrayValue) GetLength() int { // et is only required for .List byte-arrays. func (av *ArrayValue) GetPointerAtIndexInt2(store Store, ii int, et Type) PointerValue { - fmt.Println("----av, GetPointerAtIndexInt2: ", av) if av.Data == nil { ev := fillValueTV(store, &av.List[ii]) // by reference return PointerValue{ @@ -431,17 +424,14 @@ type SliceValue struct { } func (sv *SliceValue) GetBase(store Store) *ArrayValue { - fmt.Println("---GetBase") switch cv := sv.Base.(type) { case nil: return nil case RefValue: - fmt.Println("---RefValue, cv.ObjectID: ", cv.ObjectID) array := store.GetObject(cv.ObjectID).(*ArrayValue) sv.Base = array return array case *ArrayValue: - println("---ArrayValue") return cv default: panic("should not happen") @@ -458,7 +448,6 @@ func (sv *SliceValue) GetLength() int { // et is only required for .List byte-slices. func (sv *SliceValue) GetPointerAtIndexInt2(store Store, ii int, et Type) PointerValue { - fmt.Println("---sv, GetPointerAtIndexInt2: ", sv) // Necessary run-time slice bounds check if ii < 0 { panic(fmt.Sprintf( @@ -481,7 +470,6 @@ type StructValue struct { // TODO handle unexported fields in debug, and also ensure in the preprocessor. func (sv *StructValue) GetPointerTo(store Store, path ValuePath) PointerValue { - fmt.Println("---sv GetPointerTo: ", sv) if debug { if path.Depth != 0 { panic(fmt.Sprintf( @@ -493,8 +481,6 @@ func (sv *StructValue) GetPointerTo(store Store, path ValuePath) PointerValue { } func (sv *StructValue) GetPointerToInt(store Store, index int) PointerValue { - fmt.Println("---sv, GetPointerToInt: ", sv) - fmt.Println("---index: ", index) fv := fillValueTV(store, &sv.Fields[index]) return PointerValue{ TV: fv, @@ -1073,7 +1059,6 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: - //println("---default") cp = tv } return @@ -1712,8 +1697,6 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { // cu: convert untyped after assignment. pass false // for const definitions, but true for all else. func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { - //fmt.Println("---Assign, tv: ", tv) - //fmt.Println("---Assign, tv2: ", tv2, reflect.TypeOf(tv2)) if debug { if tv.T == DataByteType { // assignment to data byte types should only @@ -1738,7 +1721,6 @@ func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { // allocated, *Allocator.AllocatePointer() is called separately, // as in OpRef. func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath) PointerValue { - //fmt.Println("---GetPointerTo, tv: ", tv) if debug { if tv.IsUndefined() { panic("GetPointerTo() on undefined value") @@ -1836,7 +1818,6 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath fillValueTV(store, dtv) } - //fmt.Println("---2, path.Type: ", path.Type) switch path.Type { case VPBlock: switch dtv.T.(type) { @@ -1849,12 +1830,8 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath case VPField: switch baseOf(dtv.T).(type) { case *StructType: - //println("---StructType") - //fmt.Println("---dtv: ", dtv) - //fmt.Println("---return pointer of dtv: ", dtv.V.(*StructValue).GetPointerTo(store, path)) return dtv.V.(*StructValue).GetPointerTo(store, path) case *TypeType: - //println("---TypeType") switch t := dtv.V.(TypeValue).Type.(type) { case *PointerType: dt := t.Elt.(*DeclaredType) @@ -1910,13 +1887,7 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath panic("should not happen") } } - //fmt.Println("---dtv: ", dtv) - //fmt.Printf("---dtv addr: %p\n", dtv) dtv2 := dtv.Copy(alloc) - - //fmt.Println("---dtv2: ", dtv2) - //fmt.Printf("---dtv2 addr: %p\n", dtv2) - alloc.AllocateBoundMethod() bmv := &BoundMethodValue{ Func: mv, @@ -2071,7 +2042,6 @@ func (tv *TypedValue) GetPointerAtIndexInt(store Store, ii int) PointerValue { } func (tv *TypedValue) GetPointerAtIndex(alloc *Allocator, store Store, iv *TypedValue) PointerValue { - //fmt.Println("---tv, GetPointerAtIndex: ", tv) switch bt := baseOf(tv.T).(type) { case PrimitiveType: if bt == StringType || bt == UntypedStringType { @@ -2493,9 +2463,7 @@ func (b *Block) GetPointerToInt(store Store, index int) PointerValue { } func (b *Block) GetPointerTo(store Store, path ValuePath) PointerValue { - //fmt.Println("---GetPointerTo, path: ", path) if path.IsBlockBlankPath() { - //println("---isBlockBlankPath") if debug { if path.Name != blankIdentifier { panic(fmt.Sprintf( diff --git a/gnovm/tests/files/types/eql_0f49.gno b/gnovm/tests/files/types/eql_0f49.gno deleted file mode 100644 index b5a4bf4ed05..00000000000 --- a/gnovm/tests/files/types/eql_0f49.gno +++ /dev/null @@ -1,21 +0,0 @@ -package main - -func main() { - a := "1234" - b := "1234" - - cond := a == b - println(cond) - println(cond == (a == b)) - println((a == b) == cond) - println((a == b) == (a == b)) - println(cond && (a == b)) - println(cond || (a > b)) - -} - -// true -// true -// true -// true -// true diff --git a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno new file mode 100644 index 00000000000..ecb8037bd69 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/r/demo/tests" +) + +// NOTE: it is invalid to persist external realm types. +var somevalue tests.TestRealmObject + +func main() { + somevalue.Field = "test" + println(somevalue) +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno new file mode 100644 index 00000000000..73ad3ea74d7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm10_stdlibs.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +func main() { + tests.ModifyTestRealmObject2c() + println("done") +} + +// Error: +// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno new file mode 100644 index 00000000000..e6f33c50654 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno @@ -0,0 +1,146 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + ptests "gno.land/p/demo/tests" + "gno.land/p/demo/ufmt" + rtests "gno.land/r/demo/tests" + "std" +) + +func getPrevRealm() std.Realm { + return std.PrevRealm() +} + +func Exec(fn func()) { + fn() +} + +func main() { + // Create a map of the potential callers, this will give more understandable + // output than the bech32 addresses. + callersByAddr := make(map[std.Address]string) + for _, caller := range []string{ + "user1.gno", "gno.land/r/crossrealm_test", "gno.land/r/demo/tests", + } { + addr := std.DerivePkgAddr(caller) + callersByAddr[addr] = caller + } + + assertRealm := func(r std.Realm) { + pkgPath := callersByAddr[r.Addr()] + if r.IsUser() && pkgPath != "user1.gno" { + panic(ufmt.Sprintf("ERROR: expected: 'user1.gno', got:'%s'", pkgPath)) + } else if !r.IsUser() && pkgPath != r.PkgPath() { + panic(ufmt.Sprintf("ERROR: expected: '%s', got: '%s'", pkgPath, r.PkgPath())) + } + } + + tests := []struct { + callStackAdd string + callerFn func() std.Realm + }{ + { + callStackAdd: "", + callerFn: std.PrevRealm, + }, + { + callStackAdd: " -> r/crossrealm_test.getPrevRealm", + callerFn: getPrevRealm, + }, + { + callStackAdd: " -> p/demo/tests", + callerFn: ptests.GetPrevRealm, + }, + { + callStackAdd: " -> p/demo/tests -> p/demo/tests/subtests", + callerFn: ptests.GetPSubtestsPrevRealm, + }, + { + callStackAdd: " -> r/demo/tests", + callerFn: rtests.GetPrevRealm, + }, + { + callStackAdd: " -> r/demo/tests -> r/demo/tests/subtests", + callerFn: rtests.GetRSubtestsPrevRealm, + }, + { + callStackAdd: " -> p/demo/tests -> r/demo/tests", + callerFn: ptests.GetRTestsGetPrevRealm, + }, + } + + println("---") // needed to have space prefixes + printColumns("STACK", "std.PrevRealm") + printColumns("-----", "------------------") + + baseCallStack := "user1.gno -> r/crossrealm_test.main" + for i, tt := range tests { + printColumns(baseCallStack+tt.callStackAdd, callersByAddr[tt.callerFn().Addr()]) + Exec(func() { + r := tt.callerFn() + assertRealm(r) + printColumns(baseCallStack+" -> r/crossrealm_test.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + }) + rtests.Exec(func() { + r := tt.callerFn() + assertRealm(r) + printColumns(baseCallStack+" -> r/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + }) + ptests.Exec(func() { + r := tt.callerFn() + assertRealm(r) + printColumns(baseCallStack+" -> p/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + }) + } +} + +func printColumns(left, right string) { + const w = 105 + + output := "" + padding := w - len(left) + + // strings.Repeat is not always available when using various imports modes. + for i := 0; i < padding; i++ { + output += " " + } + + output += left + output += " = " + output += right + println(output) +} + +// Output: +// --- +// STACK = std.PrevRealm +// ----- = ------------------ +// user1.gno -> r/crossrealm_test.main = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.getPrevRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/crossrealm_test.getPrevRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> p/demo/tests = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests = user1.gno +// user1.gno -> r/crossrealm_test.main -> p/demo/tests -> p/demo/tests/subtests = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests -> p/demo/tests/subtests = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests -> p/demo/tests/subtests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests -> p/demo/tests/subtests = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test diff --git a/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno new file mode 100644 index 00000000000..f2f229cd5de --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm12_stdlibs.gno @@ -0,0 +1,37 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "fmt" + "std" + + psubtests "gno.land/p/demo/tests/subtests" + rsubtests "gno.land/r/demo/tests/subtests" +) + +func main() { + tests := []struct { + fn func() std.Realm + }{ + {std.CurrentRealm}, + {psubtests.GetCurrentRealm}, + {rsubtests.GetCurrentRealm}, + } + + for _, test := range tests { + r := test.fn() + + if std.DerivePkgAddr(r.PkgPath()) != r.Addr() { + panic(fmt.Sprintf("ERROR: expected: %v, got: %v", + std.DerivePkgAddr(r.PkgPath()), r.Addr(), + )) + } + + println(r.PkgPath(), r.Addr()) + } +} + +// Output: +// gno.land/r/crossrealm_test g1vla5mffzum6060t99u4xhm8mnhgxr0sz4k574p +// gno.land/r/crossrealm_test g1vla5mffzum6060t99u4xhm8mnhgxr0sz4k574p +// gno.land/r/demo/tests/subtests g13g48xnr7lzxsrvny0uf6lhx0cfaxy4n0n5geuf diff --git a/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno new file mode 100644 index 00000000000..4daeb6de366 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm13_stdlibs.gno @@ -0,0 +1,48 @@ +package main + +import ( + "std" +) + +func main() { + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) + std.TestSetRealm(std.NewUserRealm("g1user")) + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) + std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) +} + +func pad(s string) string { + for len(s) < 26 { + s += " " + } + return s +} + +func PrintRealm() { + println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) + println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) +} + +// Because this is the context of a package, using PrintRealm() +// should not change the output of the main function. + +// Output: +// PrintRealm: CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno new file mode 100644 index 00000000000..2fc37804fce --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm13a_stdlibs.gno @@ -0,0 +1,46 @@ +// PKGPATH: gno.land/r/demo/groups +package groups + +import ( + "std" +) + +func main() { + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) + std.TestSetRealm(std.NewUserRealm("g1user")) + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) + std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) + PrintRealm() + println(pad("CurrentRealm:"), std.CurrentRealm()) + println(pad("PrevRealm:"), std.PrevRealm()) +} + +func pad(s string) string { + for len(s) < 26 { + s += " " + } + return s +} + +func PrintRealm() { + println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) + println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) +} + +// Output: +// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g1user" std.Address),("" string)} std.Realm) +// CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) +// PrintRealm: PrevRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) +// CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) +// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno new file mode 100644 index 00000000000..23451e6f5d1 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +func main() { + // even though we are running within a realm, + // we aren't storing the result of crossrealm.Make1(), + // so this should print fine. + crossrealm.Make1().Touch().Print() +} + +// Output: +// A: 2 +// B: LocalStruct{123} diff --git a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno new file mode 100644 index 00000000000..34e1cc339e6 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno @@ -0,0 +1,20 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/r/demo/tests" +) + +// NOTE: it is valid to persist external realm types. +var somevalue tests.TestRealmObject + +func init() { + somevalue.Field = "test" +} + +func main() { + println(somevalue) +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno new file mode 100644 index 00000000000..c3dbc152930 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/r/demo/tests" +) + +// NOTE: it is invalid to persist external realm types. +var somevalue tests.TestRealmObject + +func init() { + somevalue.Field = "test" +} + +func main() { + // NOTE: but it is invalid to modify it using an external realm function. + somevalue.Modify() + println(somevalue) +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno new file mode 100644 index 00000000000..b22fdf330c0 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/r/demo/tests" +) + +// NOTE: it is valid to persist external realm types. +var somevalue tests.TestRealmObject + +func init() { + somevalue.Field = "test" +} + +func main() { + // NOTE: but it is invalid to modify it using an external realm function. + somevalue.Modify() + println(somevalue) +} + +// Error: +// should not happen while attempting to attach new real object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno new file mode 100644 index 00000000000..d2e7a4b096a --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm6_stdlibs.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +var somevalue tests.TestRealmObject2 + +func init() { + somevalue.Field = "test" +} + +func main() { + // this is OK because the method is declared in a non-realm package. + somevalue.Modify() + println(somevalue) +} + +// Output: +// (struct{("modified" string)} gno.land/p/demo/tests.TestRealmObject2) diff --git a/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno new file mode 100644 index 00000000000..5a4dc3002cc --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm7_stdlibs.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +func main() { + tests.ModifyTestRealmObject2a() + println("done") +} + +// Error: +// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno new file mode 100644 index 00000000000..f03085ff4c7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm8_stdlibs.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +func main() { + tests.ModifyTestRealmObject2b() + println("done") +} + +// Error: +// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno new file mode 100644 index 00000000000..96a7a3484d7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm9_stdlibs.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +func main() { + tests.SomeValue2.Field = "modified" + println("done") +} + +// Error: +// cannot modify external-realm or non-realm object From 8b435e63de605c4cab3f885c2b903ea5ea4ee857 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 16:55:19 +0900 Subject: [PATCH 31/88] fixup --- gnovm/pkg/gnolang/machine.go | 13 +++++++++++++ gnovm/pkg/gnolang/ownership.go | 12 ++++++++---- gnovm/pkg/gnolang/realm.go | 5 +++++ gnovm/pkg/gnolang/values.go | 9 +++++---- gnovm/tests/file.go | 9 +++++---- gnovm/tests/files/heap_item_value.gno | 6 +++--- gnovm/tests/files/zrealm_crossrealm24.gno | 11 ----------- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 3018796985f..d73d75bef5e 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -1848,6 +1848,9 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { + //fmt.Println("---PushFrameCall, cx: ", cx) + //fmt.Println("---fv: ", fv) + //fmt.Println("---m.Realm: ", m.Realm) fr := &Frame{ Source: cx, NumOps: m.NumOps, @@ -1903,11 +1906,21 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { } } } else { + //fmt.Println("---receiver not defined") pv := fv.GetPackage(m.Store) if pv == nil { panic(fmt.Sprintf("package value missing in store: %s", fv.PkgPath)) } + //fmt.Println("---pv: ", pv) + //fmt.Println("---pv: ", pv.Realm) + //fmt.Println("---PkgPath: ", pv.PkgPath) + + //fmt.Println("---1, m.Realm : ", m.Realm) + //if IsRealmPath(pv.PkgPath) { + // println("---isRealmPath") + //} m.setCurrentPackage(pv) // maybe new realm + //fmt.Println("---2, m.Realm : ", m.Realm) } } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index e9fd6bc3fb8..8599e3a8766 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -401,11 +401,15 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---v: ", v) // TODO: check this if dt, ok := cv.TV.T.(*DeclaredType); ok { - if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { - if IsRealmPath(dt.PkgPath) { - pkgId = PkgIDFromPkgPath(dt.PkgPath) - } + //fmt.Println("---dt: ", dt) + //fmt.Println("---cv.Base: ", cv.GetBase(store), reflect.TypeOf(cv.GetBase(store))) + //if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { + //println("---base is heap item") + if IsRealmPath(dt.PkgPath) { + //println("---IsRealmPath") + pkgId = PkgIDFromPkgPath(dt.PkgPath) } + //} } } return diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index edad0e05ae9..1c89f5fcf80 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -153,6 +153,9 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { return // do nothing. } + if po.GetObjectID().PkgID != rlm.ID { + panic("cannot modify external-realm or non-realm object") + } // XXX check if this boosts performance // XXX with broad integration benchmarking. // XXX if co == xo { @@ -373,6 +376,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue return } + fmt.Println("---oo.GetLastNewEscapedRealm(): ", oo.GetLastNewEscapedRealm()) + fmt.Println("---rlm.ID: ", rlm.ID) if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm if refValue != nil { // is reference object from external realm checkCrossRealm(store, oo, refValue) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index b55815d496a..ad824da0508 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -211,6 +211,7 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { + fmt.Println("---Assign2, tv2: ", tv2) // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -284,7 +285,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - //fmt.Println("---oo1: ", oo1) + fmt.Println("---oo1: ", oo1) pv.TV.Assign(alloc, tv2, cu) oo2, pkgId := pv.TV.GetFirstObject2(store) @@ -294,9 +295,9 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty case *SliceValue, PointerValue: refValue = rv } - //fmt.Println("---oo2: ", oo2) - //fmt.Println("---oo2 pkgId: ", pkgId) - if oo2 != nil { + fmt.Println("---oo2: ", oo2) + fmt.Println("---oo2 pkgId: ", pkgId) + if oo2 != nil { // cross realm oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info } // TODO: make check happens in here? diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index f6bd789f1bf..4bffcbd123a 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -148,7 +148,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { err := strings.TrimSpace(fmt.Sprintf("%v", pnc)) // print stack if unexpected error. if errWanted == "" || - !strings.Contains(err, errWanted) { + !strings.Contains(err, errWanted) { fmt.Printf("ERROR:\n%s\n", err) // error didn't match: print stack // NOTE: will fail testcase later. @@ -300,8 +300,8 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { } // check tip line, write to file ctl := errstr + - "\n*** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, " + - "DELETE THIS LINE AND RUN TEST AGAIN ***" + "\n*** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, " + + "DELETE THIS LINE AND RUN TEST AGAIN ***" // write error to file replaceWantedInPlace(path, "Error", ctl) panic(fmt.Sprintf("fail on %s: err recorded, check the message and run test again", path)) @@ -360,7 +360,8 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error { if rops != "" { rops2 := strings.TrimSpace(store.SprintStoreOps()) if rops != rops2 { - if f.syncWanted { + //if f.syncWanted { + if true { // write output to file. replaceWantedInPlace(path, "Realm", rops2) } else { diff --git a/gnovm/tests/files/heap_item_value.gno b/gnovm/tests/files/heap_item_value.gno index 40ec05d3ba1..c0624a1ae85 100644 --- a/gnovm/tests/files/heap_item_value.gno +++ b/gnovm/tests/files/heap_item_value.gno @@ -35,8 +35,8 @@ func main() { // c[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ // "ObjectInfo": { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", -// "IsEscaped": true, // "ModTime": "0", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { @@ -112,7 +112,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Escaped": true, +// "Hash": "91737f5daf35e6544b9a594926b35b20b7322de4", // "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" // }, // "Index": "0", @@ -131,7 +131,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Escaped": true, +// "Hash": "91737f5daf35e6544b9a594926b35b20b7322de4", // "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" // }, // "Index": "0", diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 2f370d55b18..448682186d7 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -5,14 +5,6 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -// XXX, this equals to: -// -// type LocalBar *crossrealm.Bar -// var b0 LocalBar -// -// both should be valid -// TODO: expand this - var b0 *crossrealm.Bar func init() { @@ -23,8 +15,5 @@ func main() { print(".") } -// XXX, should work to attach by reference to -// type defined in another realm??? - // Output: // . From 0d2c203ee067649c6575137bca132d3813ccf3a4 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 18:48:22 +0900 Subject: [PATCH 32/88] debug --- gnovm/pkg/gnolang/machine.go | 1 + gnovm/pkg/gnolang/ownership.go | 15 ++++++++++++++- gnovm/pkg/gnolang/realm.go | 20 ++++++++++++++------ gnovm/tests/files/zrealm_crossrealm24.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm24a.gno | 19 +++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm28.gno | 13 ++++++++----- gnovm/tests/files/zrealm_crossrealm28a.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm28c.gno | 6 +++--- 8 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm24a.gno diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index d73d75bef5e..e3d77ca35d4 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -972,6 +972,7 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { + fmt.Println("---run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 8599e3a8766..fdbe9053730 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -115,6 +115,8 @@ type Object interface { SetIsNewReal(bool) GetLastNewEscapedRealm() PkgID SetLastNewEscapedRealm(pkgID PkgID) + GetIsRef() bool + SetIsRef(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -146,7 +148,7 @@ type ObjectInfo struct { isDirty bool isDeleted bool isNewReal bool - isCrossRealm bool + isRef bool isNewEscaped bool isNewDeleted bool lastNewRealEscapedRealm PkgID @@ -323,6 +325,14 @@ func (oi *ObjectInfo) SetLastNewEscapedRealm(pkgId PkgID) { oi.lastNewRealEscapedRealm = pkgId } +func (oi *ObjectInfo) GetIsRef() bool { + return oi.isRef +} + +func (oi *ObjectInfo) SetIsRef(isRef bool) { + oi.isRef = isRef +} + func (oi *ObjectInfo) GetIsNewEscaped() bool { return oi.isNewEscaped } @@ -419,6 +429,9 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { return case *SliceValue: pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) + base := cv.GetBase(store) + fmt.Println("---base: ", base) + fmt.Println("---base.ID: ", base.ID) return case *FuncValue: fmt.Println("---FuncValue") diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 1c89f5fcf80..742b3b27901 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -217,6 +217,11 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { } } + if refValue != nil { + fmt.Printf("---SetIsRef, co: %v\n", co) + co.SetIsRef(true) + } + if po == nil || !po.GetIsReal() { // XXX, make sure po is attached fmt.Println("---po(Base) not real, do nothing!!!") return // do nothing. @@ -566,13 +571,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // All newly created objects become appended to .created, // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { - //fmt.Println("---processNewCreatedMarks---") + fmt.Println("---processNewCreatedMarks---") //fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - //fmt.Printf("---oo[%d] is %v:\n", i, oo) + fmt.Printf("---oo[%d] is %v:\n", i, oo) //if _, ok := oo.(*BoundMethodValue); ok { // panic("should not happen persist bound method") //} @@ -605,7 +610,8 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { //fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) //fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) - //fmt.Println("---incRefCreatedDescendants from oo: ", oo) + fmt.Println("---incRefCreatedDescendants from oo: ", oo) + //fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) //fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { @@ -618,7 +624,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } // XXX, oo must be new real here, it's not escaped - if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID { + // if it's reference, all right + fmt.Println("---oo.GetIsRef: ", oo.GetIsRef()) + if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID && !oo.GetIsRef() { //fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) //fmt.Println("---rlm.ID: ", rlm.ID) panic("should not happen while attempting to attach new real object from external realm") @@ -980,9 +988,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - //fmt.Println("---saveObject: ", oo) + fmt.Println("---saveObject: ", oo) oid := oo.GetObjectID() - //fmt.Println("---saveObject: ", oid) + fmt.Println("---saveObject: ", oid) if oid.IsZero() { panic("unexpected zero object id") } diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 448682186d7..81a2b773137 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -5,10 +5,10 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -var b0 *crossrealm.Bar +var b0 *crossrealm.Bar // this is not attached, po is not real func init() { - b0 = &crossrealm.Bar{A: 1} + b0 = &crossrealm.Bar{A: 22} // heapItem } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm24a.gno b/gnovm/tests/files/zrealm_crossrealm24a.gno new file mode 100644 index 00000000000..afb7b969768 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24a.gno @@ -0,0 +1,19 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +var b0 *crossrealm.Bar = &crossrealm.Bar{A: 11} // not attached here + +func init() { + b0 = &crossrealm.Bar{A: 22} +} + +func main() { + print(".") +} + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno index 7b9a9379ef7..73b468aaa1c 100644 --- a/gnovm/tests/files/zrealm_crossrealm28.gno +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -13,17 +13,20 @@ type foo struct { func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var fs []crossrealm.Fooer // panic +// XXX, consider this +var fs []crossrealm.Fooer func init() { - fs = append(fs, foo{name: "1"}) // attached + fs = append(fs, foo{name: "1"}) fs = append(fs, foo{name: "2"}) } func main() { - println("ok") crossrealm.SetSlice(fs) + println("ok") } -// Error: -// should not happen while attempting to attach new real object from external realm +// Output: +// (struct{("1" string)} gno.land/r/crossrealm_test.foo) +// (struct{("2" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28a.gno b/gnovm/tests/files/zrealm_crossrealm28a.gno index 089b54c4209..f386768ff5f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28a.gno +++ b/gnovm/tests/files/zrealm_crossrealm28a.gno @@ -23,5 +23,5 @@ func main() { println(".") } -// Error: -// should not happen while attempting to attach new real object from external realm +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index 7dad77b41b2..96f6fe746c4 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -14,17 +14,17 @@ type foo struct { func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } func main() { - var arr []crossrealm.Fooer // not attached here + var arr []crossrealm.Fooer // XXX, the array object should be in current realm arr = append(arr, foo{name: "1"}) arr = append(arr, foo{name: "2"}) arr = append(arr, foo{name: "3"}) fs := arr[1:] - println("ok") crossrealm.SetSlice(fs) + println("ok") } // Output: -// ok // (struct{("2" string)} gno.land/r/crossrealm_test.foo) // (struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok From e0a040e853336b2ad914c916070407167364b744 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 28 Nov 2024 12:58:46 +0900 Subject: [PATCH 33/88] add test --- gnovm/pkg/gnolang/op_assign.go | 4 ++++ gnovm/pkg/gnolang/op_decl.go | 2 ++ gnovm/pkg/gnolang/op_eval.go | 2 ++ gnovm/tests/files/zrealm_crossrealm41.gno | 20 ++++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm42.gno | 12 ++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm41.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm42.gno diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index eb67ffcc351..41d210df3ee 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -1,7 +1,10 @@ package gnolang +import "fmt" + func (m *Machine) doOpDefine() { s := m.PopStmt().(*AssignStmt) + fmt.Println("---doOpDefine, s: ", s) // Define each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. @@ -26,6 +29,7 @@ func (m *Machine) doOpDefine() { func (m *Machine) doOpAssign() { s := m.PopStmt().(*AssignStmt) + fmt.Println("---doOpAssign, s: ", s) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. diff --git a/gnovm/pkg/gnolang/op_decl.go b/gnovm/pkg/gnolang/op_decl.go index 2c20c43ae2f..a17b95935b7 100644 --- a/gnovm/pkg/gnolang/op_decl.go +++ b/gnovm/pkg/gnolang/op_decl.go @@ -6,6 +6,7 @@ import ( func (m *Machine) doOpValueDecl() { s := m.PopStmt().(*ValueDecl) + fmt.Println("---doOpValueDecl, s: ", s) lb := m.LastBlock() nt := Type(nil) if s.Type != nil { @@ -18,6 +19,7 @@ func (m *Machine) doOpValueDecl() { for i := 0; i < len(s.NameExprs); i++ { var tv TypedValue if rvs == nil { + println("---rvs is nil, using default value") // NOTE: Go/Gno wart. // implicit interface casting could // requiring the consideration of the typed-nil case. diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index c37af7d31af..8aaffa074c4 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -23,6 +23,7 @@ func (m *Machine) doOpEval() { debug.Printf("EVAL: (%T) %v\n", x, x) fmt.Println(m.String()) } + fmt.Printf("EVAL: (%T) %v\n", x, x) // This case moved out of switch for performance. // TODO: understand this better. if nx, ok := x.(*NameExpr); ok { @@ -37,6 +38,7 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerTo(m.Store, nx.Path) + fmt.Println("---ptr.Deref(): ", ptr.Deref()) m.PushValue(ptr.Deref()) return } diff --git a/gnovm/tests/files/zrealm_crossrealm41.gno b/gnovm/tests/files/zrealm_crossrealm41.gno new file mode 100644 index 00000000000..1d921647607 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm41.gno @@ -0,0 +1,20 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type local struct { + name string +} + +var ll local // this is attached as a zero value + +// XXX, consider more about this. +// var sll []crossrealm.bar +// var pll *crossrealm.bar + +func main() { + l := local{name: "a"} + println(l) +} + +// Output: +// (struct{("a" string)} gno.land/r/crossrealm_test.local) diff --git a/gnovm/tests/files/zrealm_crossrealm42.gno b/gnovm/tests/files/zrealm_crossrealm42.gno new file mode 100644 index 00000000000..c4ea99ff24d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm42.gno @@ -0,0 +1,12 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" + +type LocalBar crossrealm.Bar + +var lb LocalBar + +func main() { + println(lb) +} From 3ec7a2e7ca45ad5971465ebe6f72be51b7577c4b Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 30 Dec 2024 23:51:57 +0800 Subject: [PATCH 34/88] fixup --- .../r/demo/tests/crossrealm/crossrealm3.gno | 18 - .../{crossrealm5.gno => crossrealm_func.gno} | 0 .../{crossrealm9.gno => crossrealm_func2.gno} | 0 .../{crossrealm2.gno => crossrealm_iface.gno} | 0 .../{crossrealm8.gno => crossrealm_map.gno} | 0 .../{crossrealm.gno => crossrealm_p.gno} | 0 .../{crossrealm4.gno => crossrealm_slice.gno} | 0 ...{crossrealm6.gno => crossrealm_slice2.gno} | 4 +- .../tests/crossrealm/crossrealm_struct.gno | 28 + ...crossrealm7.gno => crossrealm_struct2.gno} | 0 gnovm/pkg/gnolang/ownership.go | 35 +- gnovm/pkg/gnolang/realm.go | 57 +- gnovm/pkg/gnolang/store.go | 8 +- gnovm/pkg/gnolang/values.go | 15 +- .../files/zrealm_crossrealm0_stdlibs.gno | 2 +- .../files/zrealm_crossrealm1_stdlibs.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21b.gno | 26 + gnovm/tests/files/zrealm_crossrealm22.gno | 19 - gnovm/tests/files/zrealm_crossrealm23a.gno | 122 +- gnovm/tests/files/zrealm_crossrealm23b.gno | 109 + gnovm/tests/files/zrealm_crossrealm24.gno | 204 +- gnovm/tests/files/zrealm_crossrealm24a.gno | 7 +- gnovm/tests/files/zrealm_crossrealm24b.gno | 22 + gnovm/tests/files/zrealm_crossrealm24c.gno | 23 + gnovm/tests/files/zrealm_crossrealm24d.gno | 214 + gnovm/tests/files/zrealm_crossrealm25.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25b.gno | 39 + gnovm/tests/files/zrealm_crossrealm25c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm27.gno | 211 + gnovm/tests/files/zrealm_crossrealm27a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28.gno | 16 +- gnovm/tests/files/zrealm_crossrealm28a.gno | 27 - gnovm/tests/files/zrealm_crossrealm28b.gno | 10 +- gnovm/tests/files/zrealm_crossrealm29.gno | 2 +- gnovm/tests/files/zrealm_crossrealm29a.gno | 6 +- gnovm/tests/files/zrealm_crossrealm29b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm29c.gno | 19 + gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- gnovm/tests/files/zrealm_crossrealm32.gno | 5438 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm34.gno | 86 + gnovm/tests/files/zrealm_crossrealm34b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm35.gno | 18 - gnovm/tests/files/zrealm_crossrealm37.gno | 2 +- gnovm/tests/files/zrealm_crossrealm38.gno | 4 +- gnovm/tests/files/zrealm_crossrealm39.gno | 2 +- gnovm/tests/files/zrealm_crossrealm40.gno | 2 +- gnovm/tests/files/zrealm_crossrealm42.gno | 6 +- gnovm/tests/files/zrealm_crossrealm43.gno | 16 + .../files/zrealm_crossrealm4_stdlibs.gno | 2 +- .../files/zrealm_crossrealm5_stdlibs.gno | 2 +- 54 files changed, 6674 insertions(+), 169 deletions(-) delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm5.gno => crossrealm_func.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm9.gno => crossrealm_func2.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm2.gno => crossrealm_iface.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm8.gno => crossrealm_map.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm.gno => crossrealm_p.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm4.gno => crossrealm_slice.gno} (100%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm6.gno => crossrealm_slice2.gno} (92%) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm7.gno => crossrealm_struct2.gno} (100%) create mode 100644 gnovm/tests/files/zrealm_crossrealm21b.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm22.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm24b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm24c.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm24d.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm28a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm29c.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm35.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm43.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno deleted file mode 100644 index 1d1c0cf6f35..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm3.gno +++ /dev/null @@ -1,18 +0,0 @@ -package crossrealm - -type Bar struct { - A int -} - -var bar *Bar -var Bar2 *Bar // exported - -func SetBar(b *Bar) *Bar { - bar = b - return bar -} - -func CallBar() { - bar.A += 1 - println(bar.A) -} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm5.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func2.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm9.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_func2.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_iface.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm2.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_iface.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_map.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm8.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_map.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_p.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_p.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm4.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno similarity index 92% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno index ad4cad9ebac..f74a9623d0a 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm6.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno @@ -56,8 +56,8 @@ func GetSlice5() []*XYZ { // TODO, unwrap } func GetSlice6(f func(s []*XYZ)) { - s6[1] = &XYZ{"6.1"} // the initial value is deleted, so this is not real after append - f(s6) + s6[1] = &XYZ{"6.1"} + f(s6) // not real now } func GetSlice7(f func(s [2]XYZ)) { diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno new file mode 100644 index 00000000000..f3eb3f21f00 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno @@ -0,0 +1,28 @@ +package crossrealm + +type Bar struct { + A int +} + +var bar *Bar + +// TODO: deprovision this +var Bar2 *Bar = &Bar{A: 22} // exported + +func (b *Bar) String() { + println("b.A: ", b.A) +} + +func SetBar(b *Bar) *Bar { + bar = b + return bar +} + +func ChangeBar() { + Bar2.A += 1 + //println(Bar2.A) +} + +func (b *Bar) ModifyBar() { + b.A += 1 +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno similarity index 100% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm7.gno rename to examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index fdbe9053730..df532be6f4c 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -113,8 +113,8 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) - GetLastNewEscapedRealm() PkgID - SetLastNewEscapedRealm(pkgID PkgID) + GetOriginRealm() PkgID + SetOriginRealm(pkgID PkgID) GetIsRef() bool SetIsRef(bool) GetIsNewEscaped() bool @@ -256,6 +256,7 @@ func (oi *ObjectInfo) GetModTime() uint64 { } func (oi *ObjectInfo) IncRefCount() int { + fmt.Println("---IncRefCount") oi.RefCount++ return oi.RefCount } @@ -316,11 +317,11 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { oi.isNewReal = x } -func (oi *ObjectInfo) GetLastNewEscapedRealm() PkgID { +func (oi *ObjectInfo) GetOriginRealm() PkgID { return oi.lastNewRealEscapedRealm } -func (oi *ObjectInfo) SetLastNewEscapedRealm(pkgId PkgID) { +func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { fmt.Println("---SetLastNewEscapedRealm") oi.lastNewRealEscapedRealm = pkgId } @@ -394,8 +395,12 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { // general case if dt, ok := tv.T.(*DeclaredType); ok { fmt.Printf("---dt: %v\n", dt) - if IsRealmPath(dt.PkgPath) { - pkgId = PkgIDFromPkgPath(dt.PkgPath) + fmt.Println("---dt.base: ", dt.Base) + if _, ok := dt.Base.(*FuncType); !ok { + fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + } } } @@ -411,7 +416,7 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---v: ", v) // TODO: check this if dt, ok := cv.TV.T.(*DeclaredType); ok { - //fmt.Println("---dt: ", dt) + fmt.Println("---dt: ", dt) //fmt.Println("---cv.Base: ", cv.GetBase(store), reflect.TypeOf(cv.GetBase(store))) //if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { //println("---base is heap item") @@ -421,6 +426,7 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { } //} } + fmt.Println("---pkgId; ", pkgId) } return case *ArrayValue: @@ -440,6 +446,21 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) pkgId = PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath) return + case *BoundMethodValue: + fmt.Println("---BoundMethodValue, recv: ", cv.Receiver) + fmt.Println("---type of T: ", reflect.TypeOf(cv.Receiver.T)) + if pv, ok := cv.Receiver.V.(PointerValue); ok { + println("---pointer value") + // TODO: check this + if dt, ok := pv.TV.T.(*DeclaredType); ok { + fmt.Println("---2, dt: ", dt) + if IsRealmPath(dt.PkgPath) { + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } + } + fmt.Println("---pkgId; ", pkgId) + } + return default: return } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 742b3b27901..a4b62601a13 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -197,10 +197,13 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { // ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { - fmt.Println("---DidUpdate2, rlm.ID: ", rlm.ID) - //fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + fmt.Printf("---DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - fmt.Printf("---po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + if co != nil { + fmt.Println("co.GetOriginRealm: ", co.GetOriginRealm()) + } + fmt.Println("---rlm.ID: ", rlm.ID) if rlm == nil { return @@ -227,6 +230,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { return // do nothing. } + // TODO: check not real external here, if po is real, association is invalid fmt.Println("---po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) if po.GetObjectID().PkgID != rlm.ID { panic("cannot modify external-realm or non-realm object") @@ -252,6 +256,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { // XXX, why packageBlock is automatically escaped? println("---already escaped, should check cross realm?") // already escaped + rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) } else { rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) } @@ -282,7 +287,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { // XXX, oo coming here must be referenced type, since they already escaped. // XXX, so oo has been persisted, thus fillValueTV func checkCrossRealm(store Store, oo Object, refValue Value) { - fmt.Println("---checkCrossReal, oo: ", oo) + fmt.Println("---checkCrossRealm, oo: ", oo) switch v := oo.(type) { case *StructValue: fmt.Println("---StructValue...") @@ -377,21 +382,23 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue //fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) //fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) - if oo.GetLastNewEscapedRealm() == rlm.ID { + if oo.GetOriginRealm() == rlm.ID { return } - fmt.Println("---oo.GetLastNewEscapedRealm(): ", oo.GetLastNewEscapedRealm()) + fmt.Println("---oo.GetLastNewEscapedRealm(): ", oo.GetOriginRealm()) fmt.Println("---rlm.ID: ", rlm.ID) - if oo.GetLastNewEscapedRealm() != rlm.ID { // crossing realm + if oo.GetOriginRealm() != rlm.ID { // crossing realm if refValue != nil { // is reference object from external realm checkCrossRealm(store, oo, refValue) } else { - panic("should not happen while attempting to attach objects by value from external realm") + panic("cannot attach objects by value from external realm") } } - rlm.MarkNewEscaped(oo) + if !oo.GetIsEscaped() { + rlm.MarkNewEscaped(oo) + } } func (rlm *Realm) MarkNewReal(oo Object) { @@ -609,9 +616,9 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { //fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) - //fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm()) fmt.Println("---incRefCreatedDescendants from oo: ", oo) - //fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) + fmt.Println("---oo.GetOriginRealm: ", oo.GetOriginRealm()) + fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) //fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { @@ -626,10 +633,14 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // XXX, oo must be new real here, it's not escaped // if it's reference, all right fmt.Println("---oo.GetIsRef: ", oo.GetIsRef()) - if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID && !oo.GetIsRef() { + if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { //fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) //fmt.Println("---rlm.ID: ", rlm.ID) - panic("should not happen while attempting to attach new real object from external realm") + if oo.GetIsRef() { + panic("cannot attach a reference to an unreal object from an external realm") + } else { + panic("cannot attach a value of a type defined by another realm") + } } // RECURSE GUARD @@ -661,7 +672,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - //fmt.Println("---rc after inc: ", rc) + fmt.Println("---rc after inc: ", rc) if rc == 1 { if child.GetIsReal() { //fmt.Println("---child is real, child: ", child) @@ -990,7 +1001,8 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { func (rlm *Realm) saveObject(store Store, oo Object) { fmt.Println("---saveObject: ", oo) oid := oo.GetObjectID() - fmt.Println("---saveObject: ", oid) + fmt.Println("---oid: ", oid) + fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") } @@ -1207,9 +1219,12 @@ func copyMethods(methods []TypedValue) []TypedValue { } func refOrCopyType(typ Type) Type { + fmt.Println("---refOrCopyType, typ: ", typ) if dt, ok := typ.(*DeclaredType); ok { + fmt.Println("---declared type: ", dt) return RefType{ID: dt.TypeID()} } else { + println("---else") return copyTypeWithRefs(typ) } } @@ -1230,6 +1245,7 @@ func copyFieldsWithRefs(fields []FieldType) []FieldType { // Copies type but with references to dependant types; // the result is suitable for persistence bytes serialization. func copyTypeWithRefs(typ Type) Type { + fmt.Println("---copyTypeWithRefs, typ: ", typ) switch ct := typ.(type) { case nil: panic("cannot copy nil types") @@ -1320,7 +1336,7 @@ func copyTypeWithRefs(typ Type) Type { // Also checks for integrity of immediate children -- they must already be // persistent (real), and not dirty, or else this function panics. func copyValueWithRefs(val Value) Value { - //fmt.Println("---copyValueWithRefs, val: ", val) + fmt.Println("---copyValueWithRefs, val: ", val) switch cv := val.(type) { case nil: return nil @@ -1371,6 +1387,7 @@ func copyValueWithRefs(val Value) Value { Maxcap: cv.Maxcap, } case *StructValue: + println("---struct value") fields := make([]TypedValue, len(cv.Fields)) for i, ftv := range cv.Fields { fields[i] = refOrCopyValue(ftv) @@ -1495,6 +1512,7 @@ func copyValueWithRefs(val Value) Value { // (fully) fills the type. func fillType(store Store, typ Type) Type { + fmt.Println("---fillType, typ: ", typ) switch ct := typ.(type) { case nil: return nil @@ -1570,6 +1588,7 @@ func fillType(store Store, typ Type) Type { } return ct case RefType: + println("---ref type") return store.GetType(ct.TypeID()) default: panic(fmt.Sprintf( @@ -1578,6 +1597,7 @@ func fillType(store Store, typ Type) Type { } func fillTypesTV(store Store, tv *TypedValue) { + fmt.Println("---fillTypesTV, tv: ", tv) tv.T = fillType(store, tv.T) tv.V = fillTypesOfValue(store, tv.V) } @@ -1585,6 +1605,7 @@ func fillTypesTV(store Store, tv *TypedValue) { // Partially fills loaded objects shallowly, similarly to // getUnsavedTypes. Replaces all RefTypes with corresponding types. func fillTypesOfValue(store Store, val Value) Value { + fmt.Println("---fillTypesOfValue, val: ", val) switch cv := val.(type) { case nil: // do nothing return cv @@ -1615,6 +1636,7 @@ func fillTypesOfValue(store Store, val Value) Value { fillTypesOfValue(store, cv.Base) return cv case *StructValue: + println("struct value") for i := 0; i < len(cv.Fields); i++ { ctv := &cv.Fields[i] fillTypesTV(store, ctv) @@ -1780,10 +1802,11 @@ func ensureUniq(oozz ...[]Object) { } func refOrCopyValue(tv TypedValue) TypedValue { - //fmt.Println("---refOrCopyValue:", tv) + fmt.Println("---refOrCopyValue:", tv) if tv.T != nil { tv.T = refOrCopyType(tv.T) } + fmt.Println("---Tv.T: ", tv.T) if obj, ok := tv.V.(Object); ok { tv.V = toRefValue(obj) return tv diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 096bc2cb6dc..e2dea647ae2 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -299,6 +299,7 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { + fmt.Println("---loadObjectSafe, oid: ", oid) key := backendObjectKey(oid) hashbz := ds.baseStore.Get([]byte(key)) if hashbz != nil { @@ -324,11 +325,11 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - //fmt.Println("---SetObject---,oo: ", oo) + fmt.Println("---SetObject: ", oo) oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - //fmt.Println("---SetObject, o2: ", o2) + fmt.Println("---o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) // set hash. @@ -399,7 +400,9 @@ func (ds *defaultStore) DelObject(oo Object) { // NOTE: The implementation matches that of GetObject() in anticipation of what // the persistent type system might work like. func (ds *defaultStore) GetType(tid TypeID) Type { + fmt.Println("---GetType: ", tid) tt := ds.GetTypeSafe(tid) + fmt.Println("---tt: ", tt) if tt == nil { ds.Print() panic(fmt.Sprintf("unexpected type with id %s", tid.String())) @@ -408,6 +411,7 @@ func (ds *defaultStore) GetType(tid TypeID) Type { } func (ds *defaultStore) GetTypeSafe(tid TypeID) Type { + fmt.Println("---GetTypeSafe: ", tid) // check cache. if tt, exists := ds.cacheTypes[tid]; exists { return tt diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index ad824da0508..9951a4fb6a7 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -211,7 +211,8 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { - fmt.Println("---Assign2, tv2: ", tv2) + fmt.Println("---Assign2, pv: ", pv) + fmt.Println("---tv2: ", tv2) // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -298,7 +299,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty fmt.Println("---oo2: ", oo2) fmt.Println("---oo2 pkgId: ", pkgId) if oo2 != nil { // cross realm - oo2.SetLastNewEscapedRealm(pkgId) // attach origin package info + oo2.SetOriginRealm(pkgId) // attach origin package info } // TODO: make check happens in here? rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, refValue) @@ -2645,20 +2646,20 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - //fmt.Println("---fillValueTV, tv: ", tv) + fmt.Println("---fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: - //println("---tv.V RefValue") - //fmt.Println("---cv: ", cv) + println("---tv.V RefValue") + fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) - //fmt.Println("---tv.V: ", tv.V) + fmt.Println("---tv.V: ", tv.V) } case PointerValue: - //fmt.Println("---PointerValue") + fmt.Println("---PointerValue") // As a special case, cv.Base is filled // and cv.TV set appropriately. // Alternatively, could implement diff --git a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno index ecb8037bd69..b425344615e 100644 --- a/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm0_stdlibs.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno index 34e1cc339e6..ee401bd7774 100644 --- a/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm1_stdlibs.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno index f03e3b3af66..4e0fcb57591 100644 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -12,4 +12,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index a50a6614920..6f8c7570e85 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno new file mode 100644 index 00000000000..4e6a497a588 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +// associate to a containing object +type Container struct { + name string + b *crossrealm.Bar +} + +var c Container + +func init() { + b0 := &crossrealm.Bar{A: 1} // this is valid association + c = Container{name: "container", b: b0} // XXX, should panic +} + +func main() { + print(".") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno deleted file mode 100644 index e45db3510e0..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ /dev/null @@ -1,19 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -type Bar struct { - A int -} - -var b0 Bar - -func init() { - b0 = Bar{A: 1} -} - -func main() { - print(".") -} - -// Output: -// . diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index 10a2006a98b..1865874ca38 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -5,15 +5,129 @@ import "gno.land/p/demo/tests/p_crossrealm" var b0 *p_crossrealm.Container -func init() { +func main() { b0 = &p_crossrealm.Container{ A: 1, } -} - -func main() { print(".") } // Output: // . + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ +// "Fields": [ +// { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// {} +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "RefCount": "1" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "01799eb680e2f34495c1050457f9ccd79795a561", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// } +// } +// } +// 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.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "49801c40c9c71898edc425edc24654efb17f7164", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "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": "8", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } diff --git a/gnovm/tests/files/zrealm_crossrealm23b.gno b/gnovm/tests/files/zrealm_crossrealm23b.gno new file mode 100644 index 00000000000..29b94f4cb76 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23b.gno @@ -0,0 +1,109 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import "gno.land/p/demo/tests/p_crossrealm" + +var b0 p_crossrealm.Container + +func main() { + b0 = p_crossrealm.Container{ + A: 1, + } + print(".") +} + +// XXX, this works attach value with type defined in p + +// Output: +// . + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ +// "Fields": [ +// { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// {} +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "IsEscaped": true, +// "ModTime": "4", +// "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.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "9e2d3b66941a43f567a3e83c2d2df8205f433f1c", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// }, +// "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": "8", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 81a2b773137..a1f2ccab778 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -5,15 +5,211 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -var b0 *crossrealm.Bar // this is not attached, po is not real +type Ibar interface { + String() +} + +var ib Ibar + +var b0 *crossrealm.Bar func init() { - b0 = &crossrealm.Bar{A: 22} // heapItem } func main() { - print(".") + b0 = crossrealm.Bar2 + ib = crossrealm.Bar2 + println(ib) + crossrealm.ChangeBar() + println(ib) + println(b0) } // Output: -// . +// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:20]={ +// "Fields": [ +// { +// "N": "FwAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:20", +// "ModTime": "44", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19", +// "RefCount": "1" +// } +// } +// 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.InterfaceType", +// "Generic": "", +// "Methods": [ +// { +// "Embedded": false, +// "Name": "String", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// ], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [], +// "Name": "Ibar", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "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": "init.3", +// "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.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": "19", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } diff --git a/gnovm/tests/files/zrealm_crossrealm24a.gno b/gnovm/tests/files/zrealm_crossrealm24a.gno index afb7b969768..4f69450bde4 100644 --- a/gnovm/tests/files/zrealm_crossrealm24a.gno +++ b/gnovm/tests/files/zrealm_crossrealm24a.gno @@ -5,15 +5,14 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -var b0 *crossrealm.Bar = &crossrealm.Bar{A: 11} // not attached here +var b0 *crossrealm.Bar = &crossrealm.Bar{A: 11} func init() { - b0 = &crossrealm.Bar{A: 22} } func main() { print(".") } -// Output: -// . +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm24b.gno b/gnovm/tests/files/zrealm_crossrealm24b.gno new file mode 100644 index 00000000000..53eda7705c8 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24b.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +// TODO: +// type XX crossrealm.Bar + +var b1 *crossrealm.Bar // this is valid decl, NOT attach + +func init() { +} + +func main() { + b1 = &crossrealm.Bar{A: 22} // this should panic + println(b1) +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm24c.gno b/gnovm/tests/files/zrealm_crossrealm24c.gno new file mode 100644 index 00000000000..1360003dade --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24c.gno @@ -0,0 +1,23 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "fmt" + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type Dt *crossrealm.Bar + +var b Dt + +func init() { +} + +func main() { + b = &crossrealm.Bar{A: 22} // this should panic + //println(b) + fmt.Println(b) +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno new file mode 100644 index 00000000000..5c5df3ee123 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -0,0 +1,214 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type Ibar interface { + String() +} + +var ib Ibar + +var b0 *crossrealm.Bar // no attach + +func init() {} + +func main() { + b0 = crossrealm.Bar2 // attach by reference + ib = crossrealm.Bar2 + println(ib) + b0.ModifyBar() // call bound methond + println(ib) + println(b0) +} + +// Output: +// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:20]={ +// "Fields": [ +// { +// "N": "FwAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:20", +// "ModTime": "44", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19", +// "RefCount": "1" +// } +// } +// 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.InterfaceType", +// "Generic": "", +// "Methods": [ +// { +// "Embedded": false, +// "Name": "String", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// ], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [], +// "Name": "Ibar", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "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": "init.3", +// "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.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": "18", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno index 68da79914b6..11a30a1a17e 100644 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// should not happen while attempting to attach objects by value from external realm +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno index 112b4fe599f..b5744340648 100644 --- a/gnovm/tests/files/zrealm_crossrealm25b.gno +++ b/gnovm/tests/files/zrealm_crossrealm25b.gno @@ -32,3 +32,42 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:8]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// }, +// "Index": "1", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", +// "ModTime": "44", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno index 74599ba2106..b70dd3aa4ea 100644 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -30,4 +30,4 @@ func main() { } // Error: -// should not happen while attempting to attach objects by value from external realm +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno index 9d8af7decc1..fa05f3dfae5 100644 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -31,4 +31,4 @@ func main() { } // Error: -// should not happen while attempting to attach objects by value from external realm +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25e.gno b/gnovm/tests/files/zrealm_crossrealm25e.gno index 439839e8aa9..ce9d137c378 100644 --- a/gnovm/tests/files/zrealm_crossrealm25e.gno +++ b/gnovm/tests/files/zrealm_crossrealm25e.gno @@ -29,4 +29,4 @@ func main() { } // Error: -// should not happen while attempting to attach objects by value from external realm +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index 9889cc194c7..fab4a6cc54b 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -23,3 +23,214 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:8]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "1", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", +// "ModTime": "44", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_fooer" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "IsEscaped": true, +// "ModTime": "4", +// "RefCount": "3" +// }, +// "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": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "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": "14", +// "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.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "01b50926620ac1c9cff16ae679ccc89029394a2d", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// }, +// "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": "18", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm27a.gno index 8eb4d4686a1..cefcf319a88 100644 --- a/gnovm/tests/files/zrealm_crossrealm27a.gno +++ b/gnovm/tests/files/zrealm_crossrealm27a.gno @@ -20,4 +20,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno index 73b468aaa1c..87bc87813a2 100644 --- a/gnovm/tests/files/zrealm_crossrealm28.gno +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -17,16 +17,16 @@ func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var fs []crossrealm.Fooer func init() { - fs = append(fs, foo{name: "1"}) - fs = append(fs, foo{name: "2"}) + //fs = append(fs, foo{name: "1"}) // type of elem is from external realm + //s1 := []crossrealm.Fooer{foo{name: "s1"}} + //r := append(fs, s1) + + r := append(fs, foo{name: "1"}) // type of elem is from external realm, but no panic since no attach + fs = r // panic while attach } func main() { - crossrealm.SetSlice(fs) - println("ok") } -// Output: -// (struct{("1" string)} gno.land/r/crossrealm_test.foo) -// (struct{("2" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28a.gno b/gnovm/tests/files/zrealm_crossrealm28a.gno deleted file mode 100644 index f386768ff5f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm28a.gno +++ /dev/null @@ -1,27 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm" -) - -type foo struct { - name string -} - -func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var arr []crossrealm.Fooer - -func main() { - arr = append(arr, foo{name: "1"}) - arr = append(arr, foo{name: "2"}) - arr = append(arr, foo{name: "3"}) - - println(".") -} - -// Output: -// . diff --git a/gnovm/tests/files/zrealm_crossrealm28b.gno b/gnovm/tests/files/zrealm_crossrealm28b.gno index 1cb7685ec3d..ca89bb8ba3c 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b.gno @@ -13,16 +13,10 @@ type foo struct { func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var arr [2]crossrealm.Fooer // panic +var arr [2]crossrealm.Fooer // panic while attach zero value func main() { - arr[0] = foo{name: "1"} - arr[1] = foo{name: "2"} - - fs := arr[1:] - println("ok") - crossrealm.SetSlice(fs) } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm29.gno b/gnovm/tests/files/zrealm_crossrealm29.gno index cb4cbe050e1..2ca67b09cd1 100644 --- a/gnovm/tests/files/zrealm_crossrealm29.gno +++ b/gnovm/tests/files/zrealm_crossrealm29.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm29a.gno b/gnovm/tests/files/zrealm_crossrealm29a.gno index 6688e9dd933..aaeda22503e 100644 --- a/gnovm/tests/files/zrealm_crossrealm29a.gno +++ b/gnovm/tests/files/zrealm_crossrealm29a.gno @@ -13,9 +13,9 @@ var f = func() bool { } func main() { - crossrealm.SetCallback(f) + crossrealm.SetCallback(f) // func value crossrealm.ExecuteCallback() } -// Output: -// callback +// Error: +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29b.gno b/gnovm/tests/files/zrealm_crossrealm29b.gno index 62e90a9d988..c0e00f79852 100644 --- a/gnovm/tests/files/zrealm_crossrealm29b.gno +++ b/gnovm/tests/files/zrealm_crossrealm29b.gno @@ -16,4 +16,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm29c.gno b/gnovm/tests/files/zrealm_crossrealm29c.gno new file mode 100644 index 00000000000..fdd1cf278af --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29c.gno @@ -0,0 +1,19 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type Foo struct { +} + +var a = Foo{} + +var f = func() bool { + println("callback") + return true +} + +func main() { + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index 366fafb377a..70d62fe320b 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index 5dd6dafbc20..a9f196ed62b 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -16,3 +16,5441 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:46]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "0" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:46", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45", +// "RefCount": "1" +// } +// } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:45]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:32" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "2489b816b7c9cfcc07f7e853718aaa019016fced", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:46" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// } +// } +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "44", +// "RefCount": "10" +// }, +// "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.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "F", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ff", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_func.gno", +// "IsMethod": false, +// "Name": "SetCallback", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func.gno", +// "Line": "7", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ff", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_func.gno", +// "IsMethod": false, +// "Name": "ExecuteCallback", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func.gno", +// "Line": "11", +// "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.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "", +// "IsMethod": false, +// "Name": "", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "10", +// "File": "crossrealm_func2.gno", +// "Line": "3", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetFunc", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "8", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetFunc2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": true, +// "Name": "M", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "20", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "MyStruct", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "66606f1f6d50797bbe89640247170078dcbf0e6a", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:5" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetMethod", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "30", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "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.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "FileName": "crossrealm_iface.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_iface.gno", +// "Line": "8", +// "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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "FileName": "crossrealm_iface.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_iface.gno", +// "Line": "13", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "Container", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "a7562372e10ade1d106ae5ef9e97c170ee4b50f1", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" +// } +// }, +// { +// "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:7" +// }, +// "FileName": "crossrealm_iface.gno", +// "IsMethod": false, +// "Name": "SetContainer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_iface.gno", +// "Line": "23", +// "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": [ +// { +// "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:7" +// }, +// "FileName": "crossrealm_iface.gno", +// "IsMethod": false, +// "Name": "SetContainer2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_iface.gno", +// "Line": "27", +// "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.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "cda4bc373a1cceedd07fe9fd29410bfd5732df7c", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:25" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// }, +// "FileName": "crossrealm_map.gno", +// "IsMethod": false, +// "Name": "init.19", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_map.gno", +// "Line": "5", +// "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.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// }, +// "FileName": "crossrealm_map.gno", +// "IsMethod": false, +// "Name": "GetMap", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_map.gno", +// "Line": "10", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "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_p.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_p.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.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "921bae5520c2c8b9d456b47651ea80481836de4e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:26" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:10" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "init.23", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.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:10" +// }, +// "FileName": "crossrealm_p.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_p.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.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:11" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "SetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "5", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "XYZ", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "b3b42c06d65da2199792616887b55d65b79f075e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:28" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "fa5658dcf95bafce7154d3380ebf7e9211b4ab4d", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "7c8932f1337c257a3236c79d7d8b4211812d8385", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:33" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "dbf56198a94f3a1d98c501d1b8c58b88bfbe8bce", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "8f5471d881fd68800170d03c52907ce7a7607d09", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:12" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "41d4fd3b5431d4cd8494803a01f437bddd45b521", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:13" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "init.34", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "13", +// "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.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "28", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "b439d9527c852f481b3dcc9c4ad27fcf6b2cbc6e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:17" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "c3a08360b77971b3c8a35a4c9c0955f6336760c4", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:18" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "36", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice3", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "44", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice4", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "49", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice5", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "54", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice6", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "58", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice7", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "63", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "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": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_struct.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_struct.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": true, +// "Name": "ModifyBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// } +// ], +// "Name": "Bar", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "eb498518bc671b8c1625ffbe54846ac1df8601a5", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" +// }, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": false, +// "Name": "SetBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "16", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" +// }, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": false, +// "Name": "ChangeBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "21", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "A", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "B", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "D", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": true, +// "Name": "A", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.A" +// } +// }, +// { +// "Embedded": true, +// "Name": "B", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.B" +// } +// }, +// { +// "Embedded": true, +// "Name": "D", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.D" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "C", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.A" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "600bc777de2ebe4f91378028f2331fdfdc891ddc", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:22" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.B" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "78dd21cd9cef4925a96ee4fbbf182d1494f646d5", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:23" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "c443db3ae26b6a807ae6a997f395af8ca986b3b3", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:42" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// }, +// "FileName": "crossrealm_struct2.gno", +// "IsMethod": false, +// "Name": "init.56", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct2.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "cb", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "v", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// }, +// "FileName": "crossrealm_struct2.gno", +// "IsMethod": false, +// "Name": "GetStruct", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct2.gno", +// "Line": "32", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "cb", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "v", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ] +// } +// } +// } +// ] +// } +// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:31] +// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:32] +// 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.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "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": "12", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "3", +// "RefCount": "10" +// }, +// "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.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "F", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ff", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_func.gno", +// "IsMethod": false, +// "Name": "SetCallback", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func.gno", +// "Line": "7", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "ff", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.F" +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_func.gno", +// "IsMethod": false, +// "Name": "ExecuteCallback", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func.gno", +// "Line": "11", +// "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.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "", +// "IsMethod": false, +// "Name": "", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "10", +// "File": "crossrealm_func2.gno", +// "Line": "3", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetFunc", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "8", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetFunc2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": true, +// "Name": "M", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "20", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "MyStruct", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "66606f1f6d50797bbe89640247170078dcbf0e6a", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:5" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// }, +// "FileName": "crossrealm_func2.gno", +// "IsMethod": false, +// "Name": "GetMethod", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_func2.gno", +// "Line": "30", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// ] +// } +// } +// }, +// { +// "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.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "FileName": "crossrealm_iface.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_iface.gno", +// "Line": "8", +// "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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "FileName": "crossrealm_iface.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_iface.gno", +// "Line": "13", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "Container", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "a7562372e10ade1d106ae5ef9e97c170ee4b50f1", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" +// } +// }, +// { +// "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:7" +// }, +// "FileName": "crossrealm_iface.gno", +// "IsMethod": false, +// "Name": "SetContainer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_iface.gno", +// "Line": "23", +// "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": [ +// { +// "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:7" +// }, +// "FileName": "crossrealm_iface.gno", +// "IsMethod": false, +// "Name": "SetContainer2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_iface.gno", +// "Line": "27", +// "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.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "cda4bc373a1cceedd07fe9fd29410bfd5732df7c", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:25" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// }, +// "FileName": "crossrealm_map.gno", +// "IsMethod": false, +// "Name": "init.19", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_map.gno", +// "Line": "5", +// "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.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// }, +// "FileName": "crossrealm_map.gno", +// "IsMethod": false, +// "Name": "GetMap", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_map.gno", +// "Line": "10", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.MapType", +// "Key": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "Value": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "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_p.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_p.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.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "921bae5520c2c8b9d456b47651ea80481836de4e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:26" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:10" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "init.23", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.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:10" +// }, +// "FileName": "crossrealm_p.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_p.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.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:11" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "SetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "5", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "XYZ", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "b3b42c06d65da2199792616887b55d65b79f075e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:28" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "7c8932f1337c257a3236c79d7d8b4211812d8385", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:33" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "dbf56198a94f3a1d98c501d1b8c58b88bfbe8bce", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "8f5471d881fd68800170d03c52907ce7a7607d09", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:12" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "41d4fd3b5431d4cd8494803a01f437bddd45b521", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:13" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "init.34", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "13", +// "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.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "28", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "b439d9527c852f481b3dcc9c4ad27fcf6b2cbc6e", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:17" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "c3a08360b77971b3c8a35a4c9c0955f6336760c4", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:18" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "36", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice3", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "44", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice4", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "49", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice5", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "54", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice6", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "58", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" +// }, +// "FileName": "crossrealm_slice2.gno", +// "IsMethod": false, +// "Name": "GetSlice7", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice2.gno", +// "Line": "63", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "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": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_struct.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_struct.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": true, +// "Name": "ModifyBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// } +// ], +// "Name": "Bar", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "eb498518bc671b8c1625ffbe54846ac1df8601a5", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" +// }, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": false, +// "Name": "SetBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "16", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "b", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// } +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" +// }, +// "FileName": "crossrealm_struct.gno", +// "IsMethod": false, +// "Name": "ChangeBar", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct.gno", +// "Line": "21", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "A", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "B", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "D", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": true, +// "Name": "A", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.A" +// } +// }, +// { +// "Embedded": true, +// "Name": "B", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.B" +// } +// }, +// { +// "Embedded": true, +// "Name": "D", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.D" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// }, +// "Methods": [], +// "Name": "C", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.A" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "600bc777de2ebe4f91378028f2331fdfdc891ddc", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:22" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.B" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "78dd21cd9cef4925a96ee4fbbf182d1494f646d5", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:23" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "c443db3ae26b6a807ae6a997f395af8ca986b3b3", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:42" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// }, +// "FileName": "crossrealm_struct2.gno", +// "IsMethod": false, +// "Name": "init.56", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct2.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "cb", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "v", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// }, +// "FileName": "crossrealm_struct2.gno", +// "IsMethod": false, +// "Name": "GetStruct", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_struct2.gno", +// "Line": "32", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "cb", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "v", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.C" +// } +// } +// } +// ] +// } +// } +// } +// ] +// } diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index 0cd5be053ff..14f51d9de75 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -16,3 +16,89 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// 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.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "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": "12", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno index 673d2538188..ba1c8a8e398 100644 --- a/gnovm/tests/files/zrealm_crossrealm34b.gno +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno deleted file mode 100644 index 3a223dca545..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ /dev/null @@ -1,18 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -type XYZ struct{ name string } - -var S []*XYZ - -func init() { - S = append(S, &XYZ{"1"}) -} - -func main() { - a := S[0].name - println(a) -} - -// Output: -// 1 diff --git a/gnovm/tests/files/zrealm_crossrealm37.gno b/gnovm/tests/files/zrealm_crossrealm37.gno index 65dc493b100..a445dd73074 100644 --- a/gnovm/tests/files/zrealm_crossrealm37.gno +++ b/gnovm/tests/files/zrealm_crossrealm37.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// should not happen while attempting to attach objects by value from external realm +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm38.gno b/gnovm/tests/files/zrealm_crossrealm38.gno index 3eda0c34e7e..59627cdd4bd 100644 --- a/gnovm/tests/files/zrealm_crossrealm38.gno +++ b/gnovm/tests/files/zrealm_crossrealm38.gno @@ -10,5 +10,5 @@ func main() { println(f()) } -// Output: -// a +// Error: +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm39.gno b/gnovm/tests/files/zrealm_crossrealm39.gno index f638eb67f4d..7cd5e0de0af 100644 --- a/gnovm/tests/files/zrealm_crossrealm39.gno +++ b/gnovm/tests/files/zrealm_crossrealm39.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm40.gno b/gnovm/tests/files/zrealm_crossrealm40.gno index 7f5e126dc2b..dde17b0dd20 100644 --- a/gnovm/tests/files/zrealm_crossrealm40.gno +++ b/gnovm/tests/files/zrealm_crossrealm40.gno @@ -10,5 +10,5 @@ func main() { println(f) } -// XXX, fix this. // Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm42.gno b/gnovm/tests/files/zrealm_crossrealm42.gno index c4ea99ff24d..28abca22cb7 100644 --- a/gnovm/tests/files/zrealm_crossrealm42.gno +++ b/gnovm/tests/files/zrealm_crossrealm42.gno @@ -2,11 +2,15 @@ package crossrealm_test import crossrealm "gno.land/r/demo/tests/crossrealm" +import "fmt" type LocalBar crossrealm.Bar var lb LocalBar func main() { - println(lb) + fmt.Println(lb) } + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm43.gno b/gnovm/tests/files/zrealm_crossrealm43.gno new file mode 100644 index 00000000000..2b5e5ee7b05 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm43.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm" +import "fmt" + +type LocalBar *crossrealm.Bar // no attach + +var lb LocalBar + +func main() { + lb = &crossrealm.Bar{A: 1} +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno index c3dbc152930..c1ddc5157a0 100644 --- a/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm4_stdlibs.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno index b22fdf330c0..e0c800aa624 100644 --- a/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm5_stdlibs.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen while attempting to attach new real object from external realm +// cannot attach a value of a type defined by another realm From fd7f8c8e4e784978097e50debcdc98f002761d18 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 31 Dec 2024 18:30:26 +0800 Subject: [PATCH 35/88] refactor test --- .../demo/tests/crossrealm/crossrealm_func.gno | 13 - .../tests/crossrealm/crossrealm_slice.gno | 10 - .../tests/crossrealm/crossrealm_struct.gno | 28 - .../tests/crossrealm/crossrealm_struct2.gno | 36 - .../crossrealm_func.gno} | 14 +- .../{ => iface}/crossrealm_iface.gno | 2 +- .../crossrealm/{ => map}/crossrealm_map.gno | 2 +- .../crossrealm_slice.gno} | 14 +- .../crossrealm/struct/crossrealm_struct.gno | 64 + gnovm/tests/files/zrealm_crossrealm20.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24.gno | 26 +- gnovm/tests/files/zrealm_crossrealm24a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24d.gno | 26 +- gnovm/tests/files/zrealm_crossrealm25.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25b.gno | 12 +- gnovm/tests/files/zrealm_crossrealm25c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm27.gno | 12 +- gnovm/tests/files/zrealm_crossrealm27a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm29.gno | 2 +- gnovm/tests/files/zrealm_crossrealm29a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm29b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm30.gno | 2 +- gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- gnovm/tests/files/zrealm_crossrealm32.gno | 5706 ++++------------- gnovm/tests/files/zrealm_crossrealm33.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34.gno | 8 +- gnovm/tests/files/zrealm_crossrealm34a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm36.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37.gno | 2 +- gnovm/tests/files/zrealm_crossrealm38.gno | 2 +- gnovm/tests/files/zrealm_crossrealm39.gno | 2 +- gnovm/tests/files/zrealm_crossrealm40.gno | 2 +- gnovm/tests/files/zrealm_crossrealm42.gno | 2 +- gnovm/tests/files/zrealm_crossrealm43.gno | 2 +- 46 files changed, 1237 insertions(+), 4798 deletions(-) delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm_func2.gno => func/crossrealm_func.gno} (82%) rename examples/gno.land/r/demo/tests/crossrealm/{ => iface}/crossrealm_iface.gno (96%) rename examples/gno.land/r/demo/tests/crossrealm/{ => map}/crossrealm_map.gno (84%) rename examples/gno.land/r/demo/tests/crossrealm/{crossrealm_slice2.gno => slice/crossrealm_slice.gno} (85%) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno deleted file mode 100644 index a8d20091de5..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func.gno +++ /dev/null @@ -1,13 +0,0 @@ -package crossrealm - -type F func() bool - -var f F - -func SetCallback(ff F) { - f = ff -} - -func ExecuteCallback() { - f() -} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno deleted file mode 100644 index d58aba3553f..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice.gno +++ /dev/null @@ -1,10 +0,0 @@ -package crossrealm - -var S []Fooer - -func SetSlice(fs []Fooer) { - S = fs - for _, f := range fs { - println(f) - } -} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno deleted file mode 100644 index f3eb3f21f00..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct.gno +++ /dev/null @@ -1,28 +0,0 @@ -package crossrealm - -type Bar struct { - A int -} - -var bar *Bar - -// TODO: deprovision this -var Bar2 *Bar = &Bar{A: 22} // exported - -func (b *Bar) String() { - println("b.A: ", b.A) -} - -func SetBar(b *Bar) *Bar { - bar = b - return bar -} - -func ChangeBar() { - Bar2.A += 1 - //println(Bar2.A) -} - -func (b *Bar) ModifyBar() { - b.A += 1 -} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno b/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno deleted file mode 100644 index 2cb43b369ce..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_struct2.gno +++ /dev/null @@ -1,36 +0,0 @@ -package crossrealm - -type A struct { - name string -} - -type B struct { - name string -} - -type D struct { - name string -} - -type C struct { - A - B - D -} - -var a A = A{name: "a"} -var b B = B{name: "b"} - -var c *C - -func init() { - c = &C{} - c.A = a - c.B = b -} - -func GetStruct(cb func(v *C)) *C { - c.D = D{name: "d"} // this is not attached before return - cb(c) - return c -} diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func2.gno b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno similarity index 82% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm_func2.gno rename to examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno index 7961fe4a2ec..9589cac78bd 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_func2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno @@ -1,4 +1,16 @@ -package crossrealm +package crossrealm_func + +type F func() bool + +var f F + +func SetCallback(ff F) { + f = ff +} + +func ExecuteCallback() { + f() +} var ff = func() string { return "a" } // parent object already escaped diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_iface.gno b/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno similarity index 96% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm_iface.gno rename to examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno index 528b8cba023..769a2e3ad59 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_iface.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno @@ -1,4 +1,4 @@ -package crossrealm +package iface // XXX, how about not interface type Fooer interface{ Foo() } diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_map.gno b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno similarity index 84% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm_map.gno rename to examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno index a3241dfe721..eff818c6fdf 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_map.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno @@ -1,4 +1,4 @@ -package crossrealm +package crossrealm_map var m map[string]int diff --git a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno similarity index 85% rename from examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno rename to examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index f74a9623d0a..18f86c9a1b2 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/crossrealm_slice2.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -1,5 +1,17 @@ -package crossrealm +package crossrealm_slice +type Fooer interface{ Foo() } + +var S []Fooer + +func SetSlice(fs []Fooer) { + S = fs + for _, f := range fs { + println(f) + } +} + +// ------------------------------------- type XYZ struct{ name string } var s1 []XYZ diff --git a/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno new file mode 100644 index 00000000000..dc5a90038b6 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno @@ -0,0 +1,64 @@ +package crossrealm_struct + +type Bar struct { + A int +} + +var bar *Bar + +// TODO: deprovision this +var Bar2 *Bar = &Bar{A: 22} // exported + +func (b *Bar) String() { + println("b.A: ", b.A) +} + +func SetBar(b *Bar) *Bar { + bar = b + return bar +} + +func ChangeBar() { + Bar2.A += 1 + //println(Bar2.A) +} + +func (b *Bar) ModifyBar() { + b.A += 1 +} + +// ------------------------------------------------- +type A struct { + name string +} + +type B struct { + name string +} + +type D struct { + name string +} + +type C struct { + A + B + D +} + +var a A = A{name: "a"} +var b B = B{name: "b"} + +var c *C + +func init() { + c = &C{} + c.A = a + c.B = b +} + +func GetStruct(cb func(v *C)) *C { + c.D = D{name: "d"} // this is not attached before return + cb(c) + return c +} diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno index 4e0fcb57591..3bac413912d 100644 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) var b0 crossrealm.Bar // run declarations diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index ae8b58a44f6..dea0cc50103 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index 6f8c7570e85..1ac379df2e0 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) // associate to a containing object diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno index 4e6a497a588..635a92bc0e1 100644 --- a/gnovm/tests/files/zrealm_crossrealm21b.gno +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) // associate to a containing object diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index a1f2ccab778..9b46421f253 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) type Ibar interface { @@ -26,13 +26,13 @@ func main() { } // Output: -// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:20]={ +// switchrealm["gno.land/r/demo/tests/crossrealm/struct"] +// u[5965ae851c02ab677bc8394b408535c1db9b2635:4]={ // "Fields": [ // { // "N": "FwAAAAAAAAA=", @@ -43,9 +43,9 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:20", -// "ModTime": "44", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19", +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", +// "ModTime": "10", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } // } @@ -106,7 +106,7 @@ func main() { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" // } // }, // "V": { @@ -114,7 +114,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" // }, // "Index": "0", // "TV": null @@ -125,7 +125,7 @@ func main() { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" // } // }, // "V": { @@ -133,7 +133,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" // }, // "Index": "0", // "TV": null diff --git a/gnovm/tests/files/zrealm_crossrealm24a.gno b/gnovm/tests/files/zrealm_crossrealm24a.gno index 4f69450bde4..0177783a82f 100644 --- a/gnovm/tests/files/zrealm_crossrealm24a.gno +++ b/gnovm/tests/files/zrealm_crossrealm24a.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) var b0 *crossrealm.Bar = &crossrealm.Bar{A: 11} diff --git a/gnovm/tests/files/zrealm_crossrealm24b.gno b/gnovm/tests/files/zrealm_crossrealm24b.gno index 53eda7705c8..5fe246e439d 100644 --- a/gnovm/tests/files/zrealm_crossrealm24b.gno +++ b/gnovm/tests/files/zrealm_crossrealm24b.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) // TODO: diff --git a/gnovm/tests/files/zrealm_crossrealm24c.gno b/gnovm/tests/files/zrealm_crossrealm24c.gno index 1360003dade..eb6b3dcbf8a 100644 --- a/gnovm/tests/files/zrealm_crossrealm24c.gno +++ b/gnovm/tests/files/zrealm_crossrealm24c.gno @@ -3,7 +3,7 @@ package crossrealm_test import ( "fmt" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) type Dt *crossrealm.Bar diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno index 5c5df3ee123..43d40d5b7a1 100644 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -2,7 +2,7 @@ package crossrealm_test import ( - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) type Ibar interface { @@ -25,13 +25,13 @@ func main() { } // Output: -// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm.Bar) +// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:20]={ +// switchrealm["gno.land/r/demo/tests/crossrealm/struct"] +// u[5965ae851c02ab677bc8394b408535c1db9b2635:4]={ // "Fields": [ // { // "N": "FwAAAAAAAAA=", @@ -42,9 +42,9 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:20", -// "ModTime": "44", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19", +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", +// "ModTime": "10", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } // } @@ -105,7 +105,7 @@ func main() { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" // } // }, // "V": { @@ -113,7 +113,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" // }, // "Index": "0", // "TV": null @@ -124,7 +124,7 @@ func main() { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" +// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" // } // }, // "V": { @@ -132,7 +132,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" // }, // "Index": "0", // "TV": null diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno index 11a30a1a17e..4b856ac244f 100644 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct{ name string } diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno index 6b8a25e6dd3..df9f6d157d2 100644 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ b/gnovm/tests/files/zrealm_crossrealm25a.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno index b5744340648..166c811ee75 100644 --- a/gnovm/tests/files/zrealm_crossrealm25b.gno +++ b/gnovm/tests/files/zrealm_crossrealm25b.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { @@ -34,8 +34,8 @@ func main() { // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:8]={ +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ // "Fields": [ // { // "T": { @@ -64,9 +64,9 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", -// "ModTime": "44", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", // "RefCount": "1" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno index b70dd3aa4ea..3ed3a1871ba 100644 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno index fa05f3dfae5..8c2f1990d13 100644 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { diff --git a/gnovm/tests/files/zrealm_crossrealm25e.gno b/gnovm/tests/files/zrealm_crossrealm25e.gno index ce9d137c378..7e0f8d29a2c 100644 --- a/gnovm/tests/files/zrealm_crossrealm25e.gno +++ b/gnovm/tests/files/zrealm_crossrealm25e.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index fab4a6cc54b..c3c437ab04b 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { @@ -25,8 +25,8 @@ func main() { // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:8]={ +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ // "Fields": [ // { // "T": { @@ -55,9 +55,9 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8", -// "ModTime": "44", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", // "RefCount": "1" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm27a.gno index cefcf319a88..a70d2b1fba4 100644 --- a/gnovm/tests/files/zrealm_crossrealm27a.gno +++ b/gnovm/tests/files/zrealm_crossrealm27a.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type fooer struct { diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno index 87bc87813a2..ad69b0318be 100644 --- a/gnovm/tests/files/zrealm_crossrealm28.gno +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type foo struct { diff --git a/gnovm/tests/files/zrealm_crossrealm28b.gno b/gnovm/tests/files/zrealm_crossrealm28b.gno index ca89bb8ba3c..255d824ba77 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) type foo struct { diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index 96f6fe746c4..7f2970d7a2b 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) type foo struct { diff --git a/gnovm/tests/files/zrealm_crossrealm29.gno b/gnovm/tests/files/zrealm_crossrealm29.gno index 2ca67b09cd1..6c7ed5e073d 100644 --- a/gnovm/tests/files/zrealm_crossrealm29.gno +++ b/gnovm/tests/files/zrealm_crossrealm29.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/func" ) func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm29a.gno b/gnovm/tests/files/zrealm_crossrealm29a.gno index aaeda22503e..3303a5dde9a 100644 --- a/gnovm/tests/files/zrealm_crossrealm29a.gno +++ b/gnovm/tests/files/zrealm_crossrealm29a.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/func" ) var f = func() bool { diff --git a/gnovm/tests/files/zrealm_crossrealm29b.gno b/gnovm/tests/files/zrealm_crossrealm29b.gno index c0e00f79852..9425782cd1b 100644 --- a/gnovm/tests/files/zrealm_crossrealm29b.gno +++ b/gnovm/tests/files/zrealm_crossrealm29b.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/func" ) func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno index cac8dd6cd8e..1c797a882cf 100644 --- a/gnovm/tests/files/zrealm_crossrealm30.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []crossrealm.XYZ diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index 70d62fe320b..dc00b5204fe 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []crossrealm.XYZ diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index a9f196ed62b..e8ec8b0e2a7 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []crossrealm.XYZ @@ -18,8 +18,8 @@ func main() { // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:46]={ +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25]={ // "Fields": [ // { // "T": { @@ -33,52 +33,52 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:46", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", // "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24", // "RefCount": "1" // } // } -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:45]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24]={ // "Data": null, // "List": [ // { // "T": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, // "V": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:32" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" // } // }, // { // "T": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "2489b816b7c9cfcc07f7e853718aaa019016fced", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:46" +// "Hash": "d0a7406378470009aced840189d7ac80419e2b2b", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" // } // } // ], // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24", // "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "1" // } // } -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2]={ // "Blank": {}, // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "IsEscaped": true, -// "ModTime": "44", -// "RefCount": "10" +// "ModTime": "23", +// "RefCount": "2" // }, // "Parent": null, // "Source": { @@ -88,7 +88,7 @@ func main() { // "Column": "0", // "File": "", // "Line": "0", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Values": [ @@ -101,30 +101,36 @@ func main() { // "Type": { // "@type": "/gno.DeclaredType", // "Base": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ +// "@type": "/gno.InterfaceType", +// "Generic": "", +// "Methods": [ // { // "Embedded": false, -// "Name": "", +// "Name": "Foo", // "Tag": "", // "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "4" +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] // } // } -// ] +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // }, // "Methods": [], -// "Name": "F", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "Name": "Fooer", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // } // }, // { // "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false // } // }, // { @@ -133,11 +139,15 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "ff", +// "Name": "fs", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false // } // } // ], @@ -148,22 +158,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_func.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "SetCallback", +// "Name": "SetSlice", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_func.gno", +// "File": "crossrealm_slice.gno", // "Line": "7", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -171,11 +181,15 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "ff", +// "Name": "fs", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false // } // } // ], @@ -185,6 +199,162 @@ func main() { // }, // { // "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// }, +// "Methods": [], +// "Name": "XYZ", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "1b66d81a105bccbb2c1cb48b5826de001451c4f4", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "4e2c5feb184ed4c3756c8662f4849b05e55b510a", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "f6278e80ac84fd1944704d0ab55f4ba1b01e76f1", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "875dcfc247f2beb0db7a9556971202d5f83953a7", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "df881fbce43e93be6a59fa06c45b5b9959c2d597", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "719153550186d4f8347763b1c1ffcbb9b62a967f", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" +// } +// }, +// { +// "T": { // "@type": "/gno.FuncType", // "Params": [], // "Results": [] @@ -194,22 +364,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_func.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "ExecuteCallback", +// "Name": "init.10", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_func.gno", -// "Line": "11", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "25", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -229,8 +399,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -240,22 +414,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "", +// "Name": "GetSlice", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { -// "Column": "10", -// "File": "crossrealm_func2.gno", -// "Line": "3", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -267,8 +441,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -277,6 +455,28 @@ func main() { // }, // { // "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d10003fa5a9ebd5bb30cadd5e11bd5aad76ec9f4", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "8a2889ef5ccf6c7e4ec0c59ed627267fa3a51026", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:9" +// } +// }, +// { +// "T": { // "@type": "/gno.FuncType", // "Params": [], // "Results": [ @@ -285,19 +485,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -307,22 +500,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_func2.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "GetFunc", +// "Name": "GetSlice2", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "8", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -334,19 +527,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -363,19 +549,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -385,22 +564,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_func2.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "GetFunc2", +// "Name": "GetSlice3", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "56", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -412,19 +591,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -433,119 +605,88 @@ func main() { // }, // { // "T": { -// "@type": "/gno.TypeType" +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] // }, // "V": { -// "@type": "/gno.TypeValue", +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice4", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "61", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, // "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [ +// "@type": "/gno.FuncType", +// "Params": [ // { -// "T": { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { // "@type": "/gno.FuncType", // "Params": [ // { // "Embedded": false, -// "Name": "sv", +// "Name": "s", // "Tag": "", // "Type": { -// "@type": "/gno.PointerType", +// "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" -// } +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_func2.gno", -// "IsMethod": true, -// "Name": "M", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "20", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "sv", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } +// "Results": [] // } // } // ], -// "Name": "MyStruct", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" +// "Results": [] // } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "66606f1f6d50797bbe89640247170078dcbf0e6a", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:5" -// }, -// "Index": "0", -// "TV": null // } // }, // { @@ -558,19 +699,15 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // } -// ] +// }, +// "Vrd": false // } // } // ] @@ -580,22 +717,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_func2.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "GetMethod", +// "Name": "GetSlice5", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "30", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "66", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -607,19 +744,15 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // } -// ] +// }, +// "Vrd": false // } // } // ] @@ -628,43 +761,6 @@ func main() { // }, // { // "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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// }, -// { -// "T": { // "@type": "/gno.FuncType", // "Params": [ // { @@ -672,44 +768,52 @@ func main() { // "Name": "f", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] // } // } // ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "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:7" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_iface.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "SetFooer", +// "Name": "GetSlice6", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "8", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "70", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -720,29 +824,63 @@ func main() { // "Name": "f", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] // } // } // ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] +// "Results": [] // } // } // }, // { // "T": { // "@type": "/gno.FuncType", -// "Params": [], +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], // "Results": [] // }, // "V": { @@ -750,94 +888,107 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_iface.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "CallFoo", +// "Name": "GetSlice7", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "13", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "75", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { // "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// }, -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] // } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "Container", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// ], +// "Results": [] // } // } -// }, +// } +// ] +// } +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13] +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14] +// 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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Container" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // }, // "V": { -// "@type": "/gno.RefValue", -// "Hash": "a7562372e10ade1d106ae5ef9e97c170ee4b50f1", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" // } // }, // { // "T": { // "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], +// "Params": [], // "Results": [] // }, // "V": { @@ -845,40 +996,93 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "crossrealm_iface.gno", +// "FileName": "main.gno", // "IsMethod": false, -// "Name": "SetContainer", +// "Name": "main", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/crossrealm_test", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "23", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "main.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/crossrealm_test" // } // }, // "Type": { // "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], +// "Params": [], // "Results": [] // } // } +// } +// ] +// } +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e: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/demo/tests/crossrealm/slice" +// } +// }, +// "Values": [ +// { +// "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/slice" +// }, +// "Methods": [], +// "Name": "Fooer", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false +// } // }, // { // "T": { @@ -886,11 +1090,15 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "f", +// "Name": "fs", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false // } // } // ], @@ -901,22 +1109,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_iface.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "SetContainer2", +// "Name": "SetSlice", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "27", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "7", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -924,11 +1132,15 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "f", +// "Name": "fs", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false // } // } // ], @@ -938,253 +1150,158 @@ func main() { // }, // { // "T": { -// "@type": "/gno.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } +// "@type": "/gno.TypeType" // }, // "V": { -// "@type": "/gno.RefValue", -// "Hash": "cda4bc373a1cceedd07fe9fd29410bfd5732df7c", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:25" +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// }, +// "Methods": [], +// "Name": "XYZ", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } // } // }, // { // "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // }, // "V": { -// "@type": "/gno.FuncValue", -// "Closure": { +// "@type": "/gno.SliceValue", +// "Base": { // "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" -// }, -// "FileName": "crossrealm_map.gno", -// "IsMethod": false, -// "Name": "init.19", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_map.gno", -// "Line": "5", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } +// "Hash": "1b66d81a105bccbb2c1cb48b5826de001451c4f4", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" // }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" // } // }, // { // "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// } -// ] +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // }, // "V": { -// "@type": "/gno.FuncValue", -// "Closure": { +// "@type": "/gno.SliceValue", +// "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" // }, -// "FileName": "crossrealm_map.gno", -// "IsMethod": false, -// "Name": "GetMap", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_map.gno", -// "Line": "10", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// } -// ] -// } +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "f6278e80ac84fd1944704d0ab55f4ba1b01e76f1", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" // } // }, // { // "T": { -// "@type": "/gno.TypeType" +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false // }, // "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_p.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_p.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" -// } +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "875dcfc247f2beb0db7a9556971202d5f83953a7", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" // } // }, // { // "T": { -// "@type": "/gno.PointerType", +// "@type": "/gno.SliceType", // "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" -// } +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false // }, // "V": { -// "@type": "/gno.PointerValue", +// "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "921bae5520c2c8b9d456b47651ea80481836de4e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:26" +// "Hash": "df881fbce43e93be6a59fa06c45b5b9959c2d597", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, -// "Index": "0", -// "TV": null +// "Len": "2", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "719153550186d4f8347763b1c1ffcbb9b62a967f", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" // } // }, // { @@ -1198,22 +1315,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:10" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_p.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "init.23", +// "Name": "init.10", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "19", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "25", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -1233,11 +1350,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PointerType", +// "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" -// } +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -1247,22 +1365,22 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:10" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_p.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "Make1", +// "Name": "GetSlice", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "24", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -1274,11 +1392,12 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PointerType", +// "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" -// } +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false // } // } // ] @@ -1287,313 +1406,133 @@ func main() { // }, // { // "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// }, -// "Vrd": false +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d10003fa5a9ebd5bb30cadd5e11bd5aad76ec9f4", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "8a2889ef5ccf6c7e4ec0c59ed627267fa3a51026", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:9" // } // }, // { // "T": { // "@type": "/gno.FuncType", -// "Params": [ +// "Params": [], +// "Results": [ // { // "Embedded": false, -// "Name": "fs", +// "Name": "", // "Tag": "", // "Type": { // "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, // "Vrd": false // } // } -// ], -// "Results": [] +// ] // }, // "V": { // "@type": "/gno.FuncValue", // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:11" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, // "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "SetSlice", +// "Name": "GetSlice2", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "5", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { // "@type": "/gno.FuncType", -// "Params": [ +// "Params": [], +// "Results": [ // { // "Embedded": false, -// "Name": "fs", +// "Name": "", // "Tag": "", // "Type": { // "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, // "Vrd": false // } // } -// ], -// "Results": [] +// ] // } // } // }, // { // "T": { -// "@type": "/gno.TypeType" +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] // }, // "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "XYZ", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "b3b42c06d65da2199792616887b55d65b79f075e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:28" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "fa5658dcf95bafce7154d3380ebf7e9211b4ab4d", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "7c8932f1337c257a3236c79d7d8b4211812d8385", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:33" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "dbf56198a94f3a1d98c501d1b8c58b88bfbe8bce", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "8f5471d881fd68800170d03c52907ce7a7607d09", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:12" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "41d4fd3b5431d4cd8494803a01f437bddd45b521", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:13" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "init.34", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "13", -// "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.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "28", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice3", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "56", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, // "Type": { // "@type": "/gno.FuncType", // "Params": [], @@ -1606,3710 +1545,203 @@ func main() { // "@type": "/gno.SliceType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "b439d9527c852f481b3dcc9c4ad27fcf6b2cbc6e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:17" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "c3a08360b77971b3c8a35a4c9c0955f6336760c4", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:18" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "36", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "44", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice4", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "49", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice5", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "54", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice6", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "58", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice7", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "63", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "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": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_struct.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_struct.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": true, -// "Name": "ModifyBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "26", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// } -// ], -// "Name": "Bar", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "eb498518bc671b8c1625ffbe54846ac1df8601a5", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" -// }, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": false, -// "Name": "SetBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "16", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" -// }, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": false, -// "Name": "ChangeBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "21", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "A", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "B", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "D", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": true, -// "Name": "A", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.A" -// } -// }, -// { -// "Embedded": true, -// "Name": "B", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.B" -// } -// }, -// { -// "Embedded": true, -// "Name": "D", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.D" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "C", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.A" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "600bc777de2ebe4f91378028f2331fdfdc891ddc", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:22" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.B" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "78dd21cd9cef4925a96ee4fbbf182d1494f646d5", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:23" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "c443db3ae26b6a807ae6a997f395af8ca986b3b3", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:42" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" -// }, -// "FileName": "crossrealm_struct2.gno", -// "IsMethod": false, -// "Name": "init.56", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct2.gno", -// "Line": "26", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "cb", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "v", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" -// }, -// "FileName": "crossrealm_struct2.gno", -// "IsMethod": false, -// "Name": "GetStruct", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct2.gno", -// "Line": "32", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "cb", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "v", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ] -// } -// } -// } -// ] -// } -// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:31] -// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:32] -// 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.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "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": "12", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "IsEscaped": true, -// "ModTime": "3", -// "RefCount": "10" -// }, -// "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.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "4" -// } -// } -// ] -// }, -// "Methods": [], -// "Name": "F", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "ff", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_func.gno", -// "IsMethod": false, -// "Name": "SetCallback", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func.gno", -// "Line": "7", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "ff", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.F" -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_func.gno", -// "IsMethod": false, -// "Name": "ExecuteCallback", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func.gno", -// "Line": "11", -// "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.PrimitiveType", -// "value": "16" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" -// }, -// "FileName": "", -// "IsMethod": false, -// "Name": "", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "10", -// "File": "crossrealm_func2.gno", -// "Line": "3", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" -// }, -// "FileName": "crossrealm_func2.gno", -// "IsMethod": false, -// "Name": "GetFunc", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "8", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" -// }, -// "FileName": "crossrealm_func2.gno", -// "IsMethod": false, -// "Name": "GetFunc2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [ -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "sv", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_func2.gno", -// "IsMethod": true, -// "Name": "M", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "20", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "sv", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// } -// ], -// "Name": "MyStruct", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.MyStruct" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "66606f1f6d50797bbe89640247170078dcbf0e6a", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:5" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:4" -// }, -// "FileName": "crossrealm_func2.gno", -// "IsMethod": false, -// "Name": "GetMethod", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_func2.gno", -// "Line": "30", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// ] -// } -// } -// }, -// { -// "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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" -// }, -// "FileName": "crossrealm_iface.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_iface.gno", -// "Line": "8", -// "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": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" -// }, -// "FileName": "crossrealm_iface.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_iface.gno", -// "Line": "13", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// }, -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "Container", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Container" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "a7562372e10ade1d106ae5ef9e97c170ee4b50f1", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:8" -// } -// }, -// { -// "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:7" -// }, -// "FileName": "crossrealm_iface.gno", -// "IsMethod": false, -// "Name": "SetContainer", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "23", -// "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": [ -// { -// "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:7" -// }, -// "FileName": "crossrealm_iface.gno", -// "IsMethod": false, -// "Name": "SetContainer2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_iface.gno", -// "Line": "27", -// "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.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "cda4bc373a1cceedd07fe9fd29410bfd5732df7c", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:25" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" -// }, -// "FileName": "crossrealm_map.gno", -// "IsMethod": false, -// "Name": "init.19", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_map.gno", -// "Line": "5", -// "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.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:9" -// }, -// "FileName": "crossrealm_map.gno", -// "IsMethod": false, -// "Name": "GetMap", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_map.gno", -// "Line": "10", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.MapType", -// "Key": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "Value": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// } -// ] -// } -// } -// }, -// { -// "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_p.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_p.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.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.LocalStruct" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "921bae5520c2c8b9d456b47651ea80481836de4e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:26" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:10" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "init.23", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.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:10" -// }, -// "FileName": "crossrealm_p.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_p.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.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// }, -// "Vrd": false -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:11" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "SetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "5", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "XYZ", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "b3b42c06d65da2199792616887b55d65b79f075e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:28" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:45" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "7c8932f1337c257a3236c79d7d8b4211812d8385", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:33" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "dbf56198a94f3a1d98c501d1b8c58b88bfbe8bce", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "8f5471d881fd68800170d03c52907ce7a7607d09", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:12" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "41d4fd3b5431d4cd8494803a01f437bddd45b521", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:13" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "init.34", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "13", -// "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.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "28", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "b439d9527c852f481b3dcc9c4ad27fcf6b2cbc6e", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:17" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "c3a08360b77971b3c8a35a4c9c0955f6336760c4", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:18" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "36", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "44", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice4", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "49", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice5", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "54", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice6", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "58", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:16" -// }, -// "FileName": "crossrealm_slice2.gno", -// "IsMethod": false, -// "Name": "GetSlice7", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice2.gno", -// "Line": "63", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "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": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_struct.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_struct.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": true, -// "Name": "ModifyBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "26", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [] -// } -// } -// } -// ], -// "Name": "Bar", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "eb498518bc671b8c1625ffbe54846ac1df8601a5", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:19" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" -// }, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": false, -// "Name": "SetBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "16", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "b", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Bar" -// } -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:21" -// }, -// "FileName": "crossrealm_struct.gno", -// "IsMethod": false, -// "Name": "ChangeBar", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_struct.gno", -// "Line": "21", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "A", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "B", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "D", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": true, -// "Name": "A", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.A" -// } -// }, -// { -// "Embedded": true, -// "Name": "B", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.B" -// } -// }, -// { -// "Embedded": true, -// "Name": "D", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.D" -// } +// "Vrd": false // } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// }, -// "Methods": [], -// "Name": "C", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// ] // } // } // }, // { // "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.A" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "600bc777de2ebe4f91378028f2331fdfdc891ddc", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:22" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.B" +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] // }, // "V": { -// "@type": "/gno.RefValue", -// "Hash": "78dd21cd9cef4925a96ee4fbbf182d1494f646d5", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:23" +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice4", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "61", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } // } // }, // { // "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] // }, // "V": { -// "@type": "/gno.PointerValue", -// "Base": { +// "@type": "/gno.FuncValue", +// "Closure": { // "@type": "/gno.RefValue", -// "Hash": "c443db3ae26b6a807ae6a997f395af8ca986b3b3", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:42" +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice5", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "66", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } // }, -// "Index": "0", -// "TV": null +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// } // } // }, // { // "T": { // "@type": "/gno.FuncType", -// "Params": [], +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], // "Results": [] // }, // "V": { @@ -5317,27 +1749,55 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_struct2.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "init.56", +// "Name": "GetSlice6", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_struct2.gno", -// "Line": "26", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "70", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { // "@type": "/gno.FuncType", -// "Params": [], +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], // "Results": [] // } // } @@ -5348,21 +1808,23 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "cb", +// "Name": "f", // "Tag": "", // "Type": { // "@type": "/gno.FuncType", // "Params": [ // { // "Embedded": false, -// "Name": "v", +// "Name": "s", // "Tag": "", // "Type": { -// "@type": "/gno.PointerType", +// "@type": "/gno.ArrayType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false // } // } // ], @@ -5370,42 +1832,29 @@ func main() { // } // } // ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ] +// "Results": [] // }, // "V": { // "@type": "/gno.FuncValue", // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:24" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" // }, -// "FileName": "crossrealm_struct2.gno", +// "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "GetStruct", +// "Name": "GetSlice7", // "NativeName": "", // "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm_struct2.gno", -// "Line": "32", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// "File": "crossrealm_slice.gno", +// "Line": "75", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, // "Type": { @@ -5413,21 +1862,23 @@ func main() { // "Params": [ // { // "Embedded": false, -// "Name": "cb", +// "Name": "f", // "Tag": "", // "Type": { // "@type": "/gno.FuncType", // "Params": [ // { // "Embedded": false, -// "Name": "v", +// "Name": "s", // "Tag": "", // "Type": { -// "@type": "/gno.PointerType", +// "@type": "/gno.ArrayType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false // } // } // ], @@ -5435,20 +1886,7 @@ func main() { // } // } // ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.C" -// } -// } -// } -// ] +// "Results": [] // } // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index 845caa81f04..87f5da43bdd 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []crossrealm.XYZ diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index 14f51d9de75..bee619ecbcb 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []*crossrealm.XYZ @@ -18,7 +18,7 @@ func main() { // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] // switchrealm["gno.land/r/crossrealm_test"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ // "Blank": {}, @@ -47,7 +47,7 @@ func main() { // "@type": "/gno.PointerType", // "Elt": { // "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.XYZ" +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" // } // }, // "Vrd": false @@ -57,7 +57,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:35" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" // }, // "Length": "1", // "Maxcap": "1", diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index b15af3bc3b9..85a55301ebd 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []*crossrealm.XYZ diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno index ba1c8a8e398..6cc613e1237 100644 --- a/gnovm/tests/files/zrealm_crossrealm34b.gno +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -4,7 +4,7 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm" + crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS [2]crossrealm.XYZ diff --git a/gnovm/tests/files/zrealm_crossrealm36.gno b/gnovm/tests/files/zrealm_crossrealm36.gno index 4a45ef0984d..b707faca7dc 100644 --- a/gnovm/tests/files/zrealm_crossrealm36.gno +++ b/gnovm/tests/files/zrealm_crossrealm36.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/struct" var s *crossrealm.C diff --git a/gnovm/tests/files/zrealm_crossrealm37.gno b/gnovm/tests/files/zrealm_crossrealm37.gno index a445dd73074..5745feb7a2a 100644 --- a/gnovm/tests/files/zrealm_crossrealm37.gno +++ b/gnovm/tests/files/zrealm_crossrealm37.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/map" var m1 map[string]int diff --git a/gnovm/tests/files/zrealm_crossrealm38.gno b/gnovm/tests/files/zrealm_crossrealm38.gno index 59627cdd4bd..1b82f4b617f 100644 --- a/gnovm/tests/files/zrealm_crossrealm38.gno +++ b/gnovm/tests/files/zrealm_crossrealm38.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/func" var f func() string diff --git a/gnovm/tests/files/zrealm_crossrealm39.gno b/gnovm/tests/files/zrealm_crossrealm39.gno index 7cd5e0de0af..e400c486214 100644 --- a/gnovm/tests/files/zrealm_crossrealm39.gno +++ b/gnovm/tests/files/zrealm_crossrealm39.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/func" var f func() string diff --git a/gnovm/tests/files/zrealm_crossrealm40.gno b/gnovm/tests/files/zrealm_crossrealm40.gno index dde17b0dd20..3d105a77b8f 100644 --- a/gnovm/tests/files/zrealm_crossrealm40.gno +++ b/gnovm/tests/files/zrealm_crossrealm40.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/func" var f func() string diff --git a/gnovm/tests/files/zrealm_crossrealm42.gno b/gnovm/tests/files/zrealm_crossrealm42.gno index 28abca22cb7..626bbd7dcb8 100644 --- a/gnovm/tests/files/zrealm_crossrealm42.gno +++ b/gnovm/tests/files/zrealm_crossrealm42.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/struct" import "fmt" type LocalBar crossrealm.Bar diff --git a/gnovm/tests/files/zrealm_crossrealm43.gno b/gnovm/tests/files/zrealm_crossrealm43.gno index 2b5e5ee7b05..01d07ea4a6e 100644 --- a/gnovm/tests/files/zrealm_crossrealm43.gno +++ b/gnovm/tests/files/zrealm_crossrealm43.gno @@ -1,7 +1,7 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import crossrealm "gno.land/r/demo/tests/crossrealm" +import crossrealm "gno.land/r/demo/tests/crossrealm/struct" import "fmt" type LocalBar *crossrealm.Bar // no attach From 453554be851b5fc54d211a9e536303638a64d8dc Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 1 Jan 2025 23:30:59 +0800 Subject: [PATCH 36/88] fixup --- .../crossrealm/slice/crossrealm_slice.gno | 15 + .../crossrealm/struct/crossrealm_struct.gno | 1 + gnovm/pkg/gnolang/debug.go | 12 + gnovm/pkg/gnolang/debug_false.go | 2 + gnovm/pkg/gnolang/machine.go | 6 + gnovm/pkg/gnolang/op_call.go | 6 + gnovm/pkg/gnolang/op_exec.go | 1 + gnovm/pkg/gnolang/ownership.go | 117 +++-- gnovm/pkg/gnolang/realm.go | 84 ++-- gnovm/pkg/gnolang/uverse.go | 1 + gnovm/pkg/gnolang/values.go | 25 +- gnovm/tests/files/zrealm_crossrealm24.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24e.gno | 18 + gnovm/tests/files/zrealm_crossrealm32.gno | 472 ++++++++++++++++-- gnovm/tests/files/zrealm_crossrealm34.gno | 2 +- gnovm/tests/files/zrealm_crossrealm35.gno | 26 + gnovm/tests/files/zrealm_crossrealm35a.gno | 261 ++++++++++ 18 files changed, 884 insertions(+), 169 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm24e.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm35.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm35a.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index 18f86c9a1b2..4185d8c020d 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -1,5 +1,7 @@ package crossrealm_slice +import "gno.land/p/demo/tests/p_crossrealm" + type Fooer interface{ Foo() } var S []Fooer @@ -76,3 +78,16 @@ func GetSlice7(f func(s [2]XYZ)) { //s7[1] = XYZ{"7.1"} f(s7) } + +var s8 [1]p_crossrealm.Stringer + +func GetSlice8(f p_crossrealm.Stringer) [1]p_crossrealm.Stringer { + s8[0] = f + return s8 +} + +func GetSlice9(f p_crossrealm.Stringer) [1]p_crossrealm.Stringer { + var s9 [1]p_crossrealm.Stringer + s9[0] = f + return s9 +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno index dc5a90038b6..6f6e8cb798d 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno @@ -8,6 +8,7 @@ var bar *Bar // TODO: deprovision this var Bar2 *Bar = &Bar{A: 22} // exported +var Bar3 Bar = Bar{A: 22} func (b *Bar) String() { println("b.A: ", b.A) diff --git a/gnovm/pkg/gnolang/debug.go b/gnovm/pkg/gnolang/debug.go index c7f9311ffe4..30db0aa415c 100644 --- a/gnovm/pkg/gnolang/debug.go +++ b/gnovm/pkg/gnolang/debug.go @@ -45,6 +45,18 @@ func init() { var enabled bool = true +func (debugging) Println2(args ...interface{}) { + if debug2 { + fmt.Println(append([]interface{}{"DEBUG:"}, args...)...) + } +} + +func (debugging) Printf2(format string, args ...interface{}) { + if debug2 { + fmt.Printf("DEBUG: "+format, args...) + } +} + func (debugging) Println(args ...interface{}) { if debug { if enabled { diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index ce714452be7..015ef2d088d 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -3,3 +3,5 @@ package gnolang const debug debugging = false + +const debug2 debugging = true diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index e3d77ca35d4..1ee97a52775 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -1974,6 +1974,7 @@ func (m *Machine) PopFrameAndReset() { // TODO: optimize by passing in last frame. func (m *Machine) PopFrameAndReturn() { + debug2.Println2("PopFrameAndReturn") fr := m.PopFrame() fr.Popped = true if debug { @@ -1996,6 +1997,11 @@ func (m *Machine) PopFrameAndReturn() { if res.IsUndefined() && rtypes[i].Type.Kind() != InterfaceKind { res.T = rtypes[i].Type } + debug2.Println2("res: ", res) + debug2.Printf2("addr of res: %p \n", &res) + if oo, ok := res.V.(Object); ok { + debug2.Println2("oo.GetObjectInfo(): ", oo.GetObjectInfo()) + } m.Values[fr.NumValues+i] = res } m.NumValues = fr.NumValues + numRes diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 15531ec610d..d2e5c02df8d 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -46,6 +46,7 @@ func (m *Machine) doOpPrecall() { var gReturnStmt = &ReturnStmt{} func (m *Machine) doOpCall() { + debug2.Println2("doOpCall") // NOTE: Frame won't be popped until the statement is complete, to // discard the correct number of results for func calls in ExprStmts. fr := m.LastFrame() @@ -180,6 +181,8 @@ func (m *Machine) doOpCallDeferNativeBody() { // Assumes that result values are pushed onto the Values stack. func (m *Machine) doOpReturn() { + debug2.Println2("doOpReturn") + debug2.Println2("---done doOpReturn") cfr := m.PopUntilLastCallFrame() // See if we are exiting a realm boundary. // NOTE: there are other ways to implement realm boundary transitions, @@ -199,6 +202,7 @@ func (m *Machine) doOpReturn() { finalize = true } if finalize { + debug2.Println2("finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -211,6 +215,7 @@ func (m *Machine) doOpReturn() { // Like doOpReturn, but with results from the block; // i.e. named result vars declared in func signatures. func (m *Machine) doOpReturnFromBlock() { + debug2.Println2("doOpReturnFromBlock") // Copy results from block. cfr := m.PopUntilLastCallFrame() ft := cfr.Func.GetType(m.Store) @@ -247,6 +252,7 @@ func (m *Machine) doOpReturnFromBlock() { // deferred statements can refer to results with name // expressions. func (m *Machine) doOpReturnToBlock() { + debug2.Println2("doOpReturnToBlock") cfr := m.MustLastCallFrame(1) ft := cfr.Func.GetType(m.Store) numParams := len(ft.Params) diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index c7e8ffd600c..92f623faf5c 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -431,6 +431,7 @@ EXEC_SWITCH: if debug { debug.Printf("EXEC: %v\n", s) } + debug2.Printf2("EXEC: %v\n", s) switch cs := s.(type) { case *AssignStmt: switch cs.Op { diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index df532be6f4c..afed6aa0e8c 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -392,76 +392,71 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // also get pkgId of the object, so it's clear where the object is from func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) - // general case - if dt, ok := tv.T.(*DeclaredType); ok { - fmt.Printf("---dt: %v\n", dt) - fmt.Println("---dt.base: ", dt.Base) - if _, ok := dt.Base.(*FuncType); !ok { - fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) - if IsRealmPath(dt.Base.GetPkgPath()) { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - } - } - } // get first object obj = tv.GetFirstObject(store) fmt.Println("---obj: ", obj) + if obj != nil { + pkgId = obj.GetObjectID().PkgID + } - // get actual pkgId - switch cv := tv.V.(type) { - case PointerValue: - println("---pointer value") - if v, ok := cv.TV.V.(Object); ok { - fmt.Println("---v: ", v) - // TODO: check this - if dt, ok := cv.TV.T.(*DeclaredType); ok { - fmt.Println("---dt: ", dt) - //fmt.Println("---cv.Base: ", cv.GetBase(store), reflect.TypeOf(cv.GetBase(store))) - //if _, ok := cv.GetBase(store).(*HeapItemValue); !ok { - //println("---base is heap item") - if IsRealmPath(dt.PkgPath) { - //println("---IsRealmPath") - pkgId = PkgIDFromPkgPath(dt.PkgPath) + if pkgId.IsZero() { + switch cv := obj.(type) { + case *ArrayValue: + fmt.Println("---array value, T: ", tv.T) + debug2.Println2("objectInfo: ", cv.GetObjectInfo()) + if IsRealmPath(tv.T.Elem().GetPkgPath()) { + // TODO: func type don't have pkgpath, retrieve from clo + pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) + } + return + case *Block: + pkgId = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + return + case *HeapItemValue: + debug2.Println2("heapItemValue: ", cv) + debug2.Println2("heapItemValue.Value.T: ", cv.Value.T) + if dt, ok := cv.Value.T.(*DeclaredType); ok { + fmt.Printf("---dt: %v\n", dt) + fmt.Println("---dt.base: ", dt.Base) + if _, ok := dt.Base.(*FuncType); !ok { + fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + } } - //} } - fmt.Println("---pkgId; ", pkgId) - } - return - case *ArrayValue: - fmt.Println("---array value, T: ", tv.T) - pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) - return - case *SliceValue: - pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) - base := cv.GetBase(store) - fmt.Println("---base: ", base) - fmt.Println("---base.ID: ", base.ID) - return - case *FuncValue: - fmt.Println("---FuncValue") - clo := cv.GetClosure(store) - fmt.Println("---clo: ", clo) - fmt.Println("clo...PkgPath", clo.Source.GetLocation().PkgPath) - pkgId = PkgIDFromPkgPath(clo.Source.GetLocation().PkgPath) - return - case *BoundMethodValue: - fmt.Println("---BoundMethodValue, recv: ", cv.Receiver) - fmt.Println("---type of T: ", reflect.TypeOf(cv.Receiver.T)) - if pv, ok := cv.Receiver.V.(PointerValue); ok { - println("---pointer value") - // TODO: check this - if dt, ok := pv.TV.T.(*DeclaredType); ok { - fmt.Println("---2, dt: ", dt) - if IsRealmPath(dt.PkgPath) { - pkgId = PkgIDFromPkgPath(dt.PkgPath) + return + case *BoundMethodValue: + fmt.Println("---BoundMethodValue, recv: ", cv.Receiver) + fmt.Println("---type of T: ", reflect.TypeOf(cv.Receiver.T)) + if pv, ok := cv.Receiver.V.(PointerValue); ok { + println("---pointer value") + // TODO: check this + if dt, ok := pv.TV.T.(*DeclaredType); ok { + fmt.Println("---2, dt: ", dt) + if IsRealmPath(dt.PkgPath) { + pkgId = PkgIDFromPkgPath(dt.PkgPath) + } } + fmt.Println("---pkgId; ", pkgId) } - fmt.Println("---pkgId; ", pkgId) + return + case *MapValue, *StructValue: + if dt, ok := tv.T.(*DeclaredType); ok { + fmt.Printf("---dt: %v\n", dt) + fmt.Println("---dt.base: ", dt.Base) + if _, ok := dt.Base.(*FuncType); !ok { + fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + } + } + } + return + default: + // do nothing } - return - default: - return } + return } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index a4b62601a13..7605877caac 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -221,7 +221,6 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { } if refValue != nil { - fmt.Printf("---SetIsRef, co: %v\n", co) co.SetIsRef(true) } @@ -252,8 +251,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { co.IncRefCount() fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { - if co.GetIsEscaped() { // XXX, this implies attached? - // XXX, why packageBlock is automatically escaped? + if co.GetIsEscaped() { println("---already escaped, should check cross realm?") // already escaped rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) @@ -282,31 +280,21 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { //---------------------------------------- // mark* -// oo can can be base of the originType, like array for a slice type. -// originType may contain infos like len, cap for slice type, etc. -// XXX, oo coming here must be referenced type, since they already escaped. +// XXX, oo here must be referenced type, since they already escaped. // XXX, so oo has been persisted, thus fillValueTV func checkCrossRealm(store Store, oo Object, refValue Value) { - fmt.Println("---checkCrossRealm, oo: ", oo) + debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) switch v := oo.(type) { case *StructValue: - fmt.Println("---StructValue...") - fmt.Println("---sv: ", v) + // TODO: rm this if !v.GetIsReal() { panic(fmt.Sprintf("should not happen, %v is not real\n", v)) } - fmt.Println("---sv is real, check fields") // check fields for _, fv := range v.Fields { - fmt.Println("---fv: ", fv) - fmt.Println("---type of fv: ", reflect.TypeOf(fv.V)) - // XXX, consider this - //if _, ok := fv.V.(RefValue); !ok { - // panic("---sv is not ref value!!!") - //} + debug2.Println2("fv: ", fv) rfv := fillValueTV(store, &fv) - fmt.Println("---rfv: ", rfv) - fmt.Println("---type of rfv.V: ", reflect.TypeOf(rfv.V)) + debug2.Println2("---rfv: ", rfv) if fo, ok := rfv.V.(Object); ok { checkCrossRealm(store, fo, nil) @@ -317,7 +305,12 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { refValue = rv // TODO: consider pkgId here, A -> B - > A?... // yes, check PkgId per object - reo, _ = rfv.GetFirstObject2(store) + var pkgId PkgID + reo, pkgId = rfv.GetFirstObject2(store) + // TODO: simplify + if !pkgId.IsZero() { + reo.SetOriginRealm(pkgId) + } fmt.Println("---reo: ", reo) // XXX, if elem of array is slice?, GetFirstObject2?... checkCrossRealm(store, reo, refValue) @@ -326,7 +319,7 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { } case *MapValue: println("---mapValue...") - // TODO: check elem? NO. + // TODO: check elem? case *HeapItemValue: fmt.Println("---heapItemValue: ", v) r := fillValueTV(store, &v.Value) @@ -339,18 +332,20 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { } else { offset := sv.Offset length := sv.Length - fmt.Println("---ArrayValue: ", v) - fmt.Printf("---offset: %d, length: %d \n", offset, length) - fmt.Println("---escaped array, check if elements are real") + debug2.Println2("ArrayValue: ", v) + debug2.Printf2("offset: %d, length: %d \n", offset, length) + debug2.Println2("escaped array, check if elements are real") + // check referenced elem for i := offset; i < length; i++ { // XXX, difference between them? ee := oo.(*ArrayValue).List[i] e := fillValueTV(store, &ee) - //e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() + fmt.Printf("---e[%d]: %v\n", i, e) fmt.Printf("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) + if eo, ok := e.V.(Object); ok { checkCrossRealm(store, eo, nil) } else { // reference to object @@ -359,9 +354,12 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { case *SliceValue, PointerValue: // if reference object from external realm refValue = rv // TODO: consider pkgId here, A -> B - > A?... - // yes, check PkgId per object - reo, _ = e.GetFirstObject2(store) - fmt.Println("---reo: ", reo) + var pkgId PkgID + reo, pkgId = e.GetFirstObject2(store) + // TODO: simplify + if !pkgId.IsZero() { + reo.SetOriginRealm(pkgId) + } // XXX, if elem of array is slice?, GetFirstObject2?... checkCrossRealm(store, reo, refValue) } @@ -375,19 +373,20 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { // escaped realm should be reference object func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { - fmt.Println("---MarkNewEscapedCheckCrossRealm") - fmt.Println("---refValue: ", refValue) - //fmt.Println("---rlm.ID: ", rlm.ID) - //fmt.Println("---oo.GetRefCount(): ", oo.GetRefCount()) - //fmt.Println("---oo.lastNewRealEscapedRealm: ", oo.GetLastNewEscapedRealm()) - //fmt.Println("---oo.GetIsReal: ", oo.GetIsReal()) + debug2.Println2("MarkNewEscapedCheckCrossRealm") + debug2.Println2("---refValue: ", refValue) + + // mark escaped + if !oo.GetIsEscaped() { + rlm.MarkNewEscaped(oo) + } if oo.GetOriginRealm() == rlm.ID { return } - fmt.Println("---oo.GetLastNewEscapedRealm(): ", oo.GetOriginRealm()) - fmt.Println("---rlm.ID: ", rlm.ID) + debug2.Println2("---oo.GetLastNewEscapedRealm(): ", oo.GetOriginRealm()) + debug2.Println2("---rlm.ID: ", rlm.ID) if oo.GetOriginRealm() != rlm.ID { // crossing realm if refValue != nil { // is reference object from external realm checkCrossRealm(store, oo, refValue) @@ -395,10 +394,6 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue panic("cannot attach objects by value from external realm") } } - - if !oo.GetIsEscaped() { - rlm.MarkNewEscaped(oo) - } } func (rlm *Realm) MarkNewReal(oo Object) { @@ -615,11 +610,9 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - //fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID) fmt.Println("---incRefCreatedDescendants from oo: ", oo) fmt.Println("---oo.GetOriginRealm: ", oo.GetOriginRealm()) fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) - //fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID()) if debug { if oo.GetIsDirty() { @@ -634,8 +627,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // if it's reference, all right fmt.Println("---oo.GetIsRef: ", oo.GetIsRef()) if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { - //fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm()) - //fmt.Println("---rlm.ID: ", rlm.ID) if oo.GetIsRef() { panic("cannot attach a reference to an unreal object from an external realm") } else { @@ -656,11 +647,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) - //fmt.Println("---incRefCreatedDescendants, more: ", more) - //fmt.Println("---len of more: ", len(more)) for _, child := range more { - //fmt.Printf("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) - //fmt.Printf("---child addr: %p\n", child) + //debug2.Printf2("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -680,7 +668,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { child.SetOwner(oo) rlm.MarkDirty(child) } else { - //fmt.Println("---child NOT real, child: ", child) // a (possibly pre-existing) new object // became real (again). // NOTE: may already be marked for first gen @@ -693,7 +680,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } else if rc > 1 { if child.GetIsEscaped() { - //fmt.Println("---child is escaped, child: ", child) // already escaped, do nothing. } else { // NOTE: do not unset owner here, diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index b13bd1a4317..525374ea4b1 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -303,6 +303,7 @@ func UverseNode() *PackageNode { newElem := arg1Base.List[arg1Offset+i].unrefCopy(m.Alloc, m.Store) list[arg0Offset+arg0Length+i] = newElem + // TODO: xxx // XXX, DidUpdate2? m.Realm.DidUpdate( arg0Base, diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 9951a4fb6a7..b091ecda405 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -211,8 +211,10 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { - fmt.Println("---Assign2, pv: ", pv) - fmt.Println("---tv2: ", tv2) + debug2.Println2("Assign2, pv: ", pv) + debug2.Println2("tv2: ", tv2) + debug2.Printf2("addr of tv2: %p \n", &tv2) + // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -287,21 +289,25 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) fmt.Println("---oo1: ", oo1) + + // get origin pkgId + _, pkgId := tv2.GetFirstObject2(store) + debug2.Println2("pkgId ", pkgId) + pv.TV.Assign(alloc, tv2, cu) - oo2, pkgId := pv.TV.GetFirstObject2(store) + oo2 := pv.TV.GetFirstObject(store) // TODO: move to GetFirstObject2 var refValue Value switch rv := pv.TV.V.(type) { case *SliceValue, PointerValue: refValue = rv } - fmt.Println("---oo2: ", oo2) - fmt.Println("---oo2 pkgId: ", pkgId) - if oo2 != nil { // cross realm + debug2.Println2("oo2: ", oo2) + debug2.Println2("pkgId: ", pkgId) + if oo2 != nil && !pkgId.IsZero() { // cross realm oo2.SetOriginRealm(pkgId) // attach origin package info } - // TODO: make check happens in here? rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, refValue) } else { pv.TV.Assign(alloc, tv2, cu) @@ -400,6 +406,7 @@ func (av *ArrayValue) GetPointerAtIndexInt2(store Store, ii int, et Type) Pointe } func (av *ArrayValue) Copy(alloc *Allocator) *ArrayValue { + debug2.Println2("Array copy, av: ", av) /* TODO: consider second ref count field. if av.GetRefCount() == 0 { return av @@ -1046,7 +1053,8 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { - //fmt.Println("---Copy, type of tv.V: ", reflect.TypeOf(tv.V)) + debug2.Println2("Copy, tv: ", tv) + debug2.Println2("Copy, type of tv.V: ", reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -1699,6 +1707,7 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { // cu: convert untyped after assignment. pass false // for const definitions, but true for all else. func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { + debug2.Println2("Assign, tv2: ", tv2) if debug { if tv.T == DataByteType { // assignment to data byte types should only diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 9b46421f253..00cd3942254 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -44,7 +44,7 @@ func main() { // ], // "ObjectInfo": { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "10", +// "ModTime": "11", // "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno index 43d40d5b7a1..8103f13f80d 100644 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -43,7 +43,7 @@ func main() { // ], // "ObjectInfo": { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "10", +// "ModTime": "11", // "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24e.gno b/gnovm/tests/files/zrealm_crossrealm24e.gno new file mode 100644 index 00000000000..ce98a25eac7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24e.gno @@ -0,0 +1,18 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/struct" +) + +// TODO: should panic at once +// var b0 crossrealm.Bar = crossrealm.Bar3 +var root interface{} + +func main() { + root = crossrealm.Bar3 + println("ok") +} + +// Error: +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index e8ec8b0e2a7..3ebceef83de 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -19,7 +19,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26]={ // "Fields": [ // { // "T": { @@ -33,13 +33,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26", // "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", // "RefCount": "1" // } // } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25]={ // "Data": null, // "List": [ // { @@ -50,7 +50,7 @@ func main() { // "V": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" // } // }, // { @@ -60,13 +60,13 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "d0a7406378470009aced840189d7ac80419e2b2b", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" +// "Hash": "14593ec2b92fe8a53780cf8a6c430a6526f05283", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26" // } // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", // "ModTime": "0", // "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "1" @@ -77,7 +77,7 @@ func main() { // "ObjectInfo": { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "IsEscaped": true, -// "ModTime": "23", +// "ModTime": "24", // "RefCount": "2" // }, // "Parent": null, @@ -172,7 +172,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "7", +// "Line": "9", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -239,8 +239,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "1b66d81a105bccbb2c1cb48b5826de001451c4f4", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// "Hash": "0934dceb3731dd613f35a5e4a4a82396f3dc474e", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" // }, // "Length": "2", // "Maxcap": "2", @@ -260,8 +260,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "4e2c5feb184ed4c3756c8662f4849b05e55b510a", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" +// "Hash": "51b5198111d9cdcf7c980e3816d111cfbe0b7cc4", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" // }, // "Length": "2", // "Maxcap": "2", @@ -281,8 +281,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "f6278e80ac84fd1944704d0ab55f4ba1b01e76f1", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// "Hash": "9073c630fa09e61b0e3b824056c022eebe7bd86b", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:16" // }, // "Length": "1", // "Maxcap": "1", @@ -305,8 +305,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "875dcfc247f2beb0db7a9556971202d5f83953a7", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// "Hash": "088eb6ee7e7fe1c5e10101801be9e64ac6794e29", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" // }, // "Length": "1", // "Maxcap": "1", @@ -329,7 +329,7 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "df881fbce43e93be6a59fa06c45b5b9959c2d597", +// "Hash": "3450ddb4764c2026edd313f230c633e0af6cd8ed", // "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" // }, // "Length": "2", @@ -349,7 +349,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "719153550186d4f8347763b1c1ffcbb9b62a967f", +// "Hash": "e03c7067902bb4b3c2aa477a27d6abfcd51ce3a6", // "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" // } // }, @@ -378,7 +378,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "25", +// "Line": "27", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -428,7 +428,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "40", +// "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -514,7 +514,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "48", +// "Line": "50", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -578,7 +578,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "56", +// "Line": "58", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -653,7 +653,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "61", +// "Line": "63", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -731,7 +731,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "66", +// "Line": "68", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -812,7 +812,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "70", +// "Line": "72", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -902,7 +902,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "75", +// "Line": "77", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -938,11 +938,199 @@ func main() { // "Results": [] // } // } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "ed9761e4c90097cbcf3d55a627ab1b7c65ff8a62", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice8", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "84", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice9", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "89", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } // } // ] // } -// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13] // d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14] +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15] // switchrealm["gno.land/r/crossrealm_test"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ // "Blank": {}, @@ -978,7 +1166,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" // }, // "Length": "2", // "Maxcap": "2", @@ -1123,7 +1311,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "7", +// "Line": "9", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1190,8 +1378,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "1b66d81a105bccbb2c1cb48b5826de001451c4f4", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// "Hash": "0934dceb3731dd613f35a5e4a4a82396f3dc474e", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" // }, // "Length": "2", // "Maxcap": "2", @@ -1212,7 +1400,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:24" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" // }, // "Length": "2", // "Maxcap": "2", @@ -1232,8 +1420,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "f6278e80ac84fd1944704d0ab55f4ba1b01e76f1", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// "Hash": "9073c630fa09e61b0e3b824056c022eebe7bd86b", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:16" // }, // "Length": "1", // "Maxcap": "1", @@ -1256,8 +1444,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "875dcfc247f2beb0db7a9556971202d5f83953a7", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// "Hash": "088eb6ee7e7fe1c5e10101801be9e64ac6794e29", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" // }, // "Length": "1", // "Maxcap": "1", @@ -1280,7 +1468,7 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "df881fbce43e93be6a59fa06c45b5b9959c2d597", +// "Hash": "3450ddb4764c2026edd313f230c633e0af6cd8ed", // "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" // }, // "Length": "2", @@ -1300,7 +1488,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "719153550186d4f8347763b1c1ffcbb9b62a967f", +// "Hash": "e03c7067902bb4b3c2aa477a27d6abfcd51ce3a6", // "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" // } // }, @@ -1329,7 +1517,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "25", +// "Line": "27", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1379,7 +1567,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "40", +// "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1465,7 +1653,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "48", +// "Line": "50", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1529,7 +1717,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "56", +// "Line": "58", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1604,7 +1792,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "61", +// "Line": "63", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1682,7 +1870,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "66", +// "Line": "68", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1763,7 +1951,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "70", +// "Line": "72", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1853,7 +2041,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "75", +// "Line": "77", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1889,6 +2077,194 @@ func main() { // "Results": [] // } // } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "ed9761e4c90097cbcf3d55a627ab1b7c65ff8a62", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice8", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "84", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice9", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "89", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } // } // ] // } diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index bee619ecbcb..0875ef6a92a 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -57,7 +57,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" // }, // "Length": "1", // "Maxcap": "1", diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno new file mode 100644 index 00000000000..d187ea285bc --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (*foo) String() string { return std.CurrentRealm().PkgPath() } + +var f = &foo{"foo"} + +var arr interface{} + +func main() { + arr = crossrealm.GetSlice8(f) + println(".") +} + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno new file mode 100644 index 00000000000..425308042fd --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -0,0 +1,261 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (*foo) String() string { return std.CurrentRealm().PkgPath() } + +var f = &foo{"foo"} + +var arr interface{} + +func main() { + arr = crossrealm.GetSlice9(f) + println(".") +} + +// Output: +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d: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/crossrealm_test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/crossrealm_test" +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "main.gno", +// "IsMethod": true, +// "Name": "String", +// "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": [ +// { +// "Embedded": false, +// "Name": ".recv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "foo", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "2dcefa704545dfed35968f0cca05d38a6a01caf5", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "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": "20", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } From 30883f08a030bb0008b73fc94511442cb4dda0b9 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sat, 4 Jan 2025 23:25:48 +0800 Subject: [PATCH 37/88] debug --- examples/gno.land/p/demo/tests/tests.gno | 74 ---------------- examples/gno.land/p/demo/tests/tests2.gno | 5 ++ .../crossrealm/slice/crossrealm_slice.gno | 10 ++- .../slice/crossrealm_slice.gno.bak2 | 14 +++ .../crossrealm/struct/crossrealm_struct.gno | 8 ++ gnovm/pkg/gnolang/machine.go | 14 ++- gnovm/pkg/gnolang/op_call.go | 3 +- gnovm/pkg/gnolang/ownership.go | 12 ++- gnovm/pkg/gnolang/realm.go | 87 ++++++++++++------- gnovm/pkg/gnolang/uverse.go | 6 ++ gnovm/pkg/gnolang/values.go | 22 ++++- gnovm/tests/files/zrealm_crossrealm24.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24f.gno | 16 ++++ gnovm/tests/files/zrealm_crossrealm24g.gno | 15 ++++ gnovm/tests/files/zrealm_crossrealm25.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25f.gno | 28 ++++++ gnovm/tests/files/zrealm_crossrealm32.gno | 32 +++++-- gnovm/tests/files/zrealm_crossrealm33.gno | 2 +- gnovm/tests/files/zrealm_crossrealm36.gno | 2 +- gnovm/tests/files/zrealm_crossrealm36a.gno | 17 ++++ 25 files changed, 250 insertions(+), 131 deletions(-) delete mode 100644 examples/gno.land/p/demo/tests/tests.gno create mode 100644 examples/gno.land/p/demo/tests/tests2.gno create mode 100644 examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 create mode 100644 gnovm/tests/files/zrealm_crossrealm24f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm24g.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm25f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm36a.gno diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno deleted file mode 100644 index 43732d82dac..00000000000 --- a/examples/gno.land/p/demo/tests/tests.gno +++ /dev/null @@ -1,74 +0,0 @@ -package tests - -import ( - "std" - - psubtests "gno.land/p/demo/tests/subtests" - "gno.land/r/demo/tests" - rtests "gno.land/r/demo/tests" -) - -const World = "world" - -// IncCounter demonstrates that it's possible to call a realm function from -// a package. So a package can potentially write into the store, by calling -// an other realm. -func IncCounter() { - tests.IncCounter() -} - -func CurrentRealmPath() string { - return std.CurrentRealm().PkgPath() -} - -//---------------------------------------- -// cross realm test vars - -type TestRealmObject2 struct { - Field string -} - -func (o2 *TestRealmObject2) Modify() { - o2.Field = "modified" -} - -var ( - somevalue1 TestRealmObject2 - SomeValue2 TestRealmObject2 - SomeValue3 *TestRealmObject2 -) - -func init() { - somevalue1 = TestRealmObject2{Field: "init"} - SomeValue2 = TestRealmObject2{Field: "init"} - SomeValue3 = &TestRealmObject2{Field: "init"} -} - -func ModifyTestRealmObject2a() { - somevalue1.Field = "modified" -} - -func ModifyTestRealmObject2b() { - SomeValue2.Field = "modified" -} - -func ModifyTestRealmObject2c() { - SomeValue3.Field = "modified" -} - -func GetPrevRealm() std.Realm { - return std.PrevRealm() -} - -func GetPSubtestsPrevRealm() std.Realm { - return psubtests.GetPrevRealm() -} - -func GetRTestsGetPrevRealm() std.Realm { - return rtests.GetPrevRealm() -} - -// Warning: unsafe pattern. -func Exec(fn func()) { - fn() -} diff --git a/examples/gno.land/p/demo/tests/tests2.gno b/examples/gno.land/p/demo/tests/tests2.gno new file mode 100644 index 00000000000..eeb3fe0ffa5 --- /dev/null +++ b/examples/gno.land/p/demo/tests/tests2.gno @@ -0,0 +1,5 @@ +package tests + +type Foo struct{ name string } + +var F = Foo{"p"} diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index 4185d8c020d..446ff265ab4 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -18,7 +18,12 @@ type XYZ struct{ name string } var s1 []XYZ var s3 []XYZ -var s4 []XYZ + +// var s4 []XYZ +var s4 = make([]XYZ, 1, 2) + +// NOTE that if new list allocated, XYZ{"4"} will be copied, and it's a new object +// var s4 = make([]XYZ, 1) var s5 []*XYZ var s6 = make([]*XYZ, 2) @@ -29,7 +34,8 @@ func init() { s1 = append(s1, XYZ{"2"}) s3 = append(s3, XYZ{"3"}) - s4 = append(s4, XYZ{"4"}) + //s4 = append(s4, XYZ{"4"}) + s4[0] = XYZ{"4"} s5 = append(s5, &XYZ{"5"}) diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 new file mode 100644 index 00000000000..48ef3dbdbc7 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 @@ -0,0 +1,14 @@ +package crossrealm_slice + +type XYZ struct{ name string } + +var s4 = make([]XYZ, 1) + +func init() { + s4[0] = XYZ{"4"} // TODO; is it owned by array +} + +func GetSlice4(f func(s []XYZ)) { + s4 = append(s4, XYZ{"0"}) // this is real after this function + f(s4) // XYZ{"0"} is floating +} diff --git a/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno index 6f6e8cb798d..4a9fb22289e 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/struct/crossrealm_struct.gno @@ -63,3 +63,11 @@ func GetStruct(cb func(v *C)) *C { cb(c) return c } + +func GetStruct2(cb func(v *C)) *C { + var e = &C{} + e.A = a + e.B = b + cb(e) + return e +} diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 1ee97a52775..5720766ca28 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -325,6 +325,9 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* // store mempackage m.Store.AddMemPackage(memPkg) if throwaway != nil { + debug2.Println2("m.Realm: ", m.Realm) + debug2.Println2("m.Realm created: ", m.Realm.created) + debug2.Println2("m.Realm updated: ", m.Realm.updated) m.Realm = nil } } @@ -750,16 +753,18 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { - //fmt.Println("---saveNewPackageValuesAndTypes") + debug2.Println2("saveNewPackageValuesAndTypes") // save package value and dependencies. pv := m.Package if pv.IsRealm() { + debug2.Println2("pv is realm") rlm := pv.Realm rlm.MarkNewReal(pv) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // save package realm info. m.Store.SetPackageRealm(rlm) } else { // use a throwaway realm. + debug2.Println2("pv not realm") rlm := NewRealm(pv.PkgPath) rlm.MarkNewReal(pv) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -782,11 +787,12 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { + debug2.Println2("resavePackageValues, rlm: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { rlm = pv.Realm - //fmt.Println("---rlm: ", rlm) + debug2.Println2("rlm.ID: ", rlm.ID) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // re-save package realm info. m.Store.SetPackageRealm(rlm) @@ -1849,9 +1855,9 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { - //fmt.Println("---PushFrameCall, cx: ", cx) + debug2.Println2("PushFrameCall, cx: ", cx) //fmt.Println("---fv: ", fv) - //fmt.Println("---m.Realm: ", m.Realm) + debug2.Println2("m.Realm: ", m.Realm) fr := &Frame{ Source: cx, NumOps: m.NumOps, diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index d2e5c02df8d..c7cbe5e176d 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -202,7 +202,7 @@ func (m *Machine) doOpReturn() { finalize = true } if finalize { - debug2.Println2("finalizing") + debug2.Println2("doOpReturn, finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -239,6 +239,7 @@ func (m *Machine) doOpReturnFromBlock() { finalize = true } if finalize { + debug2.Println2("doOpReturnFromBlock, finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index afed6aa0e8c..9c51d6ce76a 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -322,7 +322,7 @@ func (oi *ObjectInfo) GetOriginRealm() PkgID { } func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { - fmt.Println("---SetLastNewEscapedRealm") + debug2.Println2("SetOriginRealm: ", pkgId) oi.lastNewRealEscapedRealm = pkgId } @@ -390,14 +390,22 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } // also get pkgId of the object, so it's clear where the object is from +// TODO, just return isRealm func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) // get first object obj = tv.GetFirstObject(store) fmt.Println("---obj: ", obj) + if obj != nil { - pkgId = obj.GetObjectID().PkgID + + pkgId = obj.GetOriginRealm() + if pkgId.IsZero() { + pkgId = obj.GetObjectID().PkgID + } + debug2.Println2("obj.GetObjectInfo(): ", obj.GetObjectInfo()) + debug2.Println2("obj.GetObjectID.PkgID: ", pkgId) } if pkgId.IsZero() { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 7605877caac..5b8f43fcfc4 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -282,13 +282,26 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { // XXX, oo here must be referenced type, since they already escaped. // XXX, so oo has been persisted, thus fillValueTV -func checkCrossRealm(store Store, oo Object, refValue Value) { +func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("oo.GetObjectInfo: ", oo.GetObjectInfo()) switch v := oo.(type) { case *StructValue: - // TODO: rm this + + //debug2.Println2("oo.GetOriginRealm: ", oo.GetOriginRealm()) + //if refValue == nil { // not ref + // if rlm.ID != oo.GetOriginRealm() { + // panic("cannot attach object from external realm") + // } + //} + + // ref, check real + //if oo.GetObjectID().IsZero() { + //} + //// TODO: rm this if !v.GetIsReal() { - panic(fmt.Sprintf("should not happen, %v is not real\n", v)) + panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", v)) } // check fields for _, fv := range v.Fields { @@ -297,7 +310,7 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { debug2.Println2("---rfv: ", rfv) if fo, ok := rfv.V.(Object); ok { - checkCrossRealm(store, fo, nil) + checkCrossRealm(rlm, store, fo, nil) } else { // reference to object var reo Object switch rv := rfv.V.(type) { @@ -313,7 +326,7 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { } fmt.Println("---reo: ", reo) // XXX, if elem of array is slice?, GetFirstObject2?... - checkCrossRealm(store, reo, refValue) + checkCrossRealm(rlm, store, reo, refValue) } } } @@ -325,7 +338,7 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { r := fillValueTV(store, &v.Value) fmt.Println("---r: ", r) - checkCrossRealm(store, v.Value.V.(Object), refValue) + checkCrossRealm(rlm, store, v.Value.V.(Object), refValue) case *ArrayValue: if sv, ok := refValue.(*SliceValue); !ok { panic("should be slice value") @@ -339,15 +352,17 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { // check referenced elem for i := offset; i < length; i++ { // XXX, difference between them? - ee := oo.(*ArrayValue).List[i] + ee := v.List[i] e := fillValueTV(store, &ee) //e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() fmt.Printf("---e[%d]: %v\n", i, e) fmt.Printf("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) + debug2.Println2("e...GetOriginRealm: ", e.V.(Object).GetOriginRealm()) + debug2.Println2("e....GetObjectInfo: ", e.V.(Object).GetObjectInfo()) if eo, ok := e.V.(Object); ok { - checkCrossRealm(store, eo, nil) + checkCrossRealm(rlm, store, eo, refValue) } else { // reference to object var reo Object switch rv := e.V.(type) { @@ -361,7 +376,7 @@ func checkCrossRealm(store Store, oo Object, refValue Value) { reo.SetOriginRealm(pkgId) } // XXX, if elem of array is slice?, GetFirstObject2?... - checkCrossRealm(store, reo, refValue) + checkCrossRealm(rlm, store, reo, refValue) } } } @@ -376,12 +391,10 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue debug2.Println2("MarkNewEscapedCheckCrossRealm") debug2.Println2("---refValue: ", refValue) - // mark escaped - if !oo.GetIsEscaped() { - rlm.MarkNewEscaped(oo) - } - if oo.GetOriginRealm() == rlm.ID { + //if !oo.GetIsEscaped() { + // rlm.MarkNewEscaped(oo) + //} return } @@ -389,14 +402,19 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue debug2.Println2("---rlm.ID: ", rlm.ID) if oo.GetOriginRealm() != rlm.ID { // crossing realm if refValue != nil { // is reference object from external realm - checkCrossRealm(store, oo, refValue) + checkCrossRealm(rlm, store, oo, refValue) } else { panic("cannot attach objects by value from external realm") } } + // mark escaped + if !oo.GetIsEscaped() { + rlm.MarkNewEscaped(oo) + } } func (rlm *Realm) MarkNewReal(oo Object) { + debug2.Println2("MarkNewReal, oo:", oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -425,9 +443,9 @@ func (rlm *Realm) MarkNewReal(oo Object) { if rlm.newCreated == nil { rlm.newCreated = make([]Object, 0, 256) } - //fmt.Println("---append oo to newCreated object: ", oo) + debug2.Println2("---append oo to newCreated object: ", oo) rlm.newCreated = append(rlm.newCreated, oo) - //fmt.Println("---len of new created: ", len(rlm.newCreated)) + debug2.Println2("---len of new created: ", len(rlm.newCreated)) } // mark dirty == updated @@ -504,7 +522,7 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { // to a realm gets attached here, which should panic. // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { - fmt.Println("-------------FinalizeRealmTransaction---------------") + debug2.Println2("FinalizeRealmTransaction, rlm.ID: ", rlm.ID) defer func() { fmt.Println("================done FinalizeRealmTransaction==================") }() @@ -610,9 +628,10 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - fmt.Println("---incRefCreatedDescendants from oo: ", oo) - fmt.Println("---oo.GetOriginRealm: ", oo.GetOriginRealm()) - fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("---incRefCreatedDescendants from oo: ", oo) + debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) + debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("---oo.GetObjectID: ", oo.GetObjectInfo()) if debug { if oo.GetIsDirty() { @@ -634,11 +653,13 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } + debug2.Println2("oo.GetObjectID(): ", oo.GetObjectID()) // RECURSE GUARD // if id already set, skip. // this happens when a node marked created was already // visited via recursion from a prior marked created. if !oo.GetObjectID().IsZero() { + debug2.Println2("not zero, do nothing, return") return } rlm.assignNewObjectID(oo) @@ -647,8 +668,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) - for _, child := range more { - //debug2.Printf2("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) + for i, child := range more { + debug2.Printf2("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -906,7 +927,9 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { + debug2.Println2("saveUnsavedObjects") for _, co := range rlm.created { + debug2.Println2("co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { @@ -918,6 +941,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { } } for _, uo := range rlm.updated { + debug2.Println2("uo: ", uo) // uo := rlm.updated[i] if !uo.GetIsDirty() { // might have happened already as child @@ -1591,7 +1615,9 @@ func fillTypesTV(store Store, tv *TypedValue) { // Partially fills loaded objects shallowly, similarly to // getUnsavedTypes. Replaces all RefTypes with corresponding types. func fillTypesOfValue(store Store, val Value) Value { - fmt.Println("---fillTypesOfValue, val: ", val) + debug2.Println2("fillTypesOfValue, val: ", val) + debug2.Println2("type of val: ", reflect.TypeOf(val)) + defer println("---done FillTypesOfValue") switch cv := val.(type) { case nil: // do nothing return cv @@ -1622,7 +1648,9 @@ func fillTypesOfValue(store Store, val Value) Value { fillTypesOfValue(store, cv.Base) return cv case *StructValue: - println("struct value") + debug2.Println2("struct value") + debug2.Println2("cv.GetOriginRealm: ", cv.GetOriginRealm()) + debug2.Println2("cv.GetObjectInfo: ", cv.GetObjectInfo()) for i := 0; i < len(cv.Fields); i++ { ctv := &cv.Fields[i] fillTypesTV(store, ctv) @@ -1691,14 +1719,14 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { - //fmt.Printf("---assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) + debug2.Printf2("assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) oid := oo.GetObjectID() - //fmt.Println("---oid: ", oid) + debug2.Println2("oid: ", oid) if !oid.IsZero() { panic("unexpected non-zero object id") } noid := rlm.nextObjectID() - //fmt.Println("---noid: ", noid) + debug2.Println2("noid: ", noid) oo.SetObjectID(noid) return noid } @@ -1714,11 +1742,12 @@ func toRefNode(bn BlockNode) RefNode { } func toRefValue(val Value) RefValue { - //fmt.Println("---toRefValue", val) + debug2.Println2("toRefValue, val: ", val) // TODO use type switch stmt. if ref, ok := val.(RefValue); ok { return ref } else if oo, ok := val.(Object); ok { + debug2.Println2("oo: ", oo) if pv, ok := val.(*PackageValue); ok { if pv.GetIsDirty() { panic("unexpected dirty package " + pv.PkgPath) diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index 525374ea4b1..e7729204ab1 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -143,6 +143,7 @@ func UverseNode() *PackageNode { "res", GenT("X", nil), // res ), func(m *Machine) { + debug2.Println2("append") arg0, arg1 := m.LastBlock().GetParams2() // As a special case, if arg1 is a string type, first convert it into // a data slice type. @@ -269,6 +270,7 @@ func UverseNode() *PackageNode { // ---------------------------------------------------------------- // append(*SliceValue, ???) case *SliceValue: + debug2.Println2("SliceValue, ???") arg0Length := arg0Value.Length arg0Offset := arg0Value.Offset arg0Capacity := arg0Value.Maxcap @@ -286,9 +288,12 @@ func UverseNode() *PackageNode { // ------------------------------------------------------------ // append(*SliceValue, *SliceValue) case *SliceValue: + debug2.Println2("arg1 slice value") arg1Length := arg1Value.Length arg1Offset := arg1Value.Offset arg1Base := arg1Value.GetBase(m.Store) + debug2.Println2("arg1Base: ", arg1Base) + debug2.Println2("arg1Base.List: ", arg1Base.List) if arg0Length+arg1Length <= arg0Capacity { // append(*SliceValue, *SliceValue) w/i capacity ----- if 0 < arg1Length { // implies 0 < xvc @@ -376,6 +381,7 @@ func UverseNode() *PackageNode { return } else { // append(*SliceValue, *SliceValue) new list --------- + debug2.Println2("new list") list := make([]TypedValue, arg0Length+arg1Length) if 0 < arg0Length { if arg0Base.Data == nil { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index b091ecda405..53137a75496 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -214,6 +214,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty debug2.Println2("Assign2, pv: ", pv) debug2.Println2("tv2: ", tv2) debug2.Printf2("addr of tv2: %p \n", &tv2) + debug2.Println2("rlm: ", rlm) // Special cases. if pv.Index == PointerIndexNative { @@ -292,7 +293,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // get origin pkgId _, pkgId := tv2.GetFirstObject2(store) - debug2.Println2("pkgId ", pkgId) + debug2.Println2("pkgId: ", pkgId) pv.TV.Assign(alloc, tv2, cu) @@ -305,6 +306,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty } debug2.Println2("oo2: ", oo2) debug2.Println2("pkgId: ", pkgId) + if oo2 != nil && !pkgId.IsZero() { // cross realm oo2.SetOriginRealm(pkgId) // attach origin package info } @@ -525,7 +527,7 @@ func (sv *StructValue) GetSubrefPointerTo(store Store, st *StructType, path Valu } func (sv *StructValue) Copy(alloc *Allocator) *StructValue { - //fmt.Println("---StructValue copy, sv: ", sv) + debug2.Println2("StructValue copy, sv: ", sv) /* TODO consider second refcount field if sv.GetRefCount() == 0 { return sv @@ -542,8 +544,18 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - fmt.Println("---sv.ObjectInfo", sv.ObjectInfo) - nsv.ObjectInfo = sv.ObjectInfo.Copy() + //debug2.Println2("sv.ObjectInfo", sv.ObjectInfo) + //nsv.ObjectInfo = sv.ObjectInfo.Copy() + debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) + debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) + debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) + debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) + // append, unref copy... + //pkgId := sv.GetOriginRealm() + //if pkgId.IsZero() { + // pkgId = sv.GetObjectID().PkgID + //} + //nsv.SetOriginRealm(pkgId) return nsv //return alloc.NewStruct(fields) } @@ -1069,6 +1081,7 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: + println("---default") cp = tv } return @@ -1077,6 +1090,7 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { // unrefCopy makes a copy of the underlying value in the case of reference values. // It copies other values as expected using the normal Copy method. func (tv TypedValue) unrefCopy(alloc *Allocator, store Store) (cp TypedValue) { + debug2.Println2("UnrefCopy, tv: ", tv) switch tv.V.(type) { case RefValue: cp.T = tv.T diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 00cd3942254..09d0d761abc 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -44,7 +44,7 @@ func main() { // ], // "ObjectInfo": { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "11", +// "ModTime": "13", // "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno index 8103f13f80d..29c8719fa93 100644 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -43,7 +43,7 @@ func main() { // ], // "ObjectInfo": { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "11", +// "ModTime": "13", // "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", // "RefCount": "1" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24e.gno b/gnovm/tests/files/zrealm_crossrealm24e.gno index ce98a25eac7..b5d60e3dcf3 100644 --- a/gnovm/tests/files/zrealm_crossrealm24e.gno +++ b/gnovm/tests/files/zrealm_crossrealm24e.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm24f.gno b/gnovm/tests/files/zrealm_crossrealm24f.gno new file mode 100644 index 00000000000..4be67555c6c --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24f.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +var root interface{} + +func main() { + root = tests.F + println("done") +} + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm24g.gno b/gnovm/tests/files/zrealm_crossrealm24g.gno new file mode 100644 index 00000000000..3c308fc8fe2 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm24g.gno @@ -0,0 +1,15 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "gno.land/p/demo/tests" +) + +var root = tests.Foo{"p"} + +func main() { + println("done") +} + +// Output: +// done diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno index 4b856ac244f..d0b3a3aa273 100644 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ b/gnovm/tests/files/zrealm_crossrealm25.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno index 3ed3a1871ba..e647eaa6e1e 100644 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ b/gnovm/tests/files/zrealm_crossrealm25c.gno @@ -30,4 +30,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno index 8c2f1990d13..eba4ee7de76 100644 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ b/gnovm/tests/files/zrealm_crossrealm25d.gno @@ -31,4 +31,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25e.gno b/gnovm/tests/files/zrealm_crossrealm25e.gno index 7e0f8d29a2c..8e48b45a391 100644 --- a/gnovm/tests/files/zrealm_crossrealm25e.gno +++ b/gnovm/tests/files/zrealm_crossrealm25e.gno @@ -29,4 +29,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25f.gno b/gnovm/tests/files/zrealm_crossrealm25f.gno new file mode 100644 index 00000000000..dc12a9de4e8 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm25f.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct{ name string } + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer +var root interface{} + +func init() { + f = fooer{name: "local fooer"} + g := f + root = g +} + +func main() { + print(".") +} + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index 3ebceef83de..f3f4e1243e9 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -28,7 +28,7 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "0" +// "value": "3" // } // } // ], @@ -39,6 +39,26 @@ func main() { // "RefCount": "1" // } // } +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "0" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", +// "RefCount": "1" +// } +// } // c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25]={ // "Data": null, // "List": [ @@ -49,8 +69,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// "Hash": "47bf5eb54da0545110d6486001609dc4203f61b0", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26" // } // }, // { @@ -60,8 +80,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "14593ec2b92fe8a53780cf8a6c430a6526f05283", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26" +// "Hash": "eaa3017cfcfafd8f8217ee1df0afdac5e4ad12a9", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" // } // } // ], @@ -260,7 +280,7 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "51b5198111d9cdcf7c980e3816d111cfbe0b7cc4", +// "Hash": "fcdb6b41091d087be521ae9be69b8328ac495677", // "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" // }, // "Length": "2", diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index 87f5da43bdd..4fe559f0ae9 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen, struct{("0" string)} is not real +// cannot attach un-real object from external realm: struct{("0" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm36.gno b/gnovm/tests/files/zrealm_crossrealm36.gno index b707faca7dc..028e023d934 100644 --- a/gnovm/tests/files/zrealm_crossrealm36.gno +++ b/gnovm/tests/files/zrealm_crossrealm36.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// should not happen, struct{("d" string)} is not real +// cannot attach un-real object from external realm: struct{("d" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm36a.gno b/gnovm/tests/files/zrealm_crossrealm36a.gno new file mode 100644 index 00000000000..18ef893e307 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm36a.gno @@ -0,0 +1,17 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/struct" + +var s *crossrealm.C + +func cb(c *crossrealm.C) { + s = c +} +func main() { + crossrealm.GetStruct2(cb) + println(s) +} + +// Error: +// cannot attach a reference to an unreal object from an external realm From b0241aa237d47e9d9a13ca3b6f16390a7fdc252b Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 5 Jan 2025 22:50:52 +0800 Subject: [PATCH 38/88] fixup --- examples/gno.land/p/demo/tests/tests.gno | 74 +++++++ gnovm/pkg/gnolang/debug_false.go | 2 +- gnovm/pkg/gnolang/machine.go | 14 +- gnovm/pkg/gnolang/op_assign.go | 6 +- gnovm/pkg/gnolang/op_decl.go | 4 +- gnovm/pkg/gnolang/op_eval.go | 3 +- gnovm/pkg/gnolang/ownership.go | 27 ++- gnovm/pkg/gnolang/realm.go | 124 ++++++------ gnovm/pkg/gnolang/store.go | 12 +- gnovm/pkg/gnolang/values.go | 20 +- gnovm/tests/files/heap_item_value_init.gno | 4 +- gnovm/tests/files/zrealm_crossrealm24f.gno | 2 +- gnovm/tests/files/zrealm_crossrealm32.gno | 146 +++++++------- gnovm/tests/files/zrealm_crossrealm34.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34a.gno | 2 +- gnovm/tests/files/zrealm_natbind0_stdlibs.gno | 180 ------------------ gnovm/tests/files/zrealm_tests0_stdlibs.gno | 3 - 17 files changed, 250 insertions(+), 375 deletions(-) create mode 100644 examples/gno.land/p/demo/tests/tests.gno delete mode 100644 gnovm/tests/files/zrealm_natbind0_stdlibs.gno diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno new file mode 100644 index 00000000000..43732d82dac --- /dev/null +++ b/examples/gno.land/p/demo/tests/tests.gno @@ -0,0 +1,74 @@ +package tests + +import ( + "std" + + psubtests "gno.land/p/demo/tests/subtests" + "gno.land/r/demo/tests" + rtests "gno.land/r/demo/tests" +) + +const World = "world" + +// IncCounter demonstrates that it's possible to call a realm function from +// a package. So a package can potentially write into the store, by calling +// an other realm. +func IncCounter() { + tests.IncCounter() +} + +func CurrentRealmPath() string { + return std.CurrentRealm().PkgPath() +} + +//---------------------------------------- +// cross realm test vars + +type TestRealmObject2 struct { + Field string +} + +func (o2 *TestRealmObject2) Modify() { + o2.Field = "modified" +} + +var ( + somevalue1 TestRealmObject2 + SomeValue2 TestRealmObject2 + SomeValue3 *TestRealmObject2 +) + +func init() { + somevalue1 = TestRealmObject2{Field: "init"} + SomeValue2 = TestRealmObject2{Field: "init"} + SomeValue3 = &TestRealmObject2{Field: "init"} +} + +func ModifyTestRealmObject2a() { + somevalue1.Field = "modified" +} + +func ModifyTestRealmObject2b() { + SomeValue2.Field = "modified" +} + +func ModifyTestRealmObject2c() { + SomeValue3.Field = "modified" +} + +func GetPrevRealm() std.Realm { + return std.PrevRealm() +} + +func GetPSubtestsPrevRealm() std.Realm { + return psubtests.GetPrevRealm() +} + +func GetRTestsGetPrevRealm() std.Realm { + return rtests.GetPrevRealm() +} + +// Warning: unsafe pattern. +func Exec(fn func()) { + fn() +} diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index 015ef2d088d..8252bde3abf 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,4 +4,4 @@ package gnolang const debug debugging = false -const debug2 debugging = true +const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 5720766ca28..6b21798de87 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -315,7 +315,7 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* if throwaway != nil { m.Realm = throwaway } - //fmt.Println("---save, throwaway: ", throwaway) + debug2.Println2("save, throwaway: ", throwaway) } // run init functions m.runInitFromUpdates(pv, updates) @@ -787,7 +787,7 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { - debug2.Println2("resavePackageValues, rlm: ", rlm) + debug2.Println2("resavePackageValues, throwaway: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { @@ -978,7 +978,7 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { - fmt.Println("---run declaration, d: ", d) + debug2.Println2("run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. @@ -1896,11 +1896,11 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { m.setCurrentPackage(pv) // maybe new realm } else { recvOID := obj.GetObjectInfo().ID - fmt.Println("---recvOID is: ", recvOID) + debug2.Println2("---recvOID is: ", recvOID) if recvOID.IsZero() { - fmt.Println("!!! recvOID is ZERO!!!") - fmt.Println("---recv is ZERO, it's not owned, recv: ", recv) - fmt.Println("---recv is ZERO, m.realm: ", m.Realm) + debug2.Println2("!!! recvOID is ZERO!!!") + debug2.Println2("---recv is ZERO, it's not owned, recv: ", recv) + debug2.Println2("---recv is ZERO, m.realm: ", m.Realm) // receiver isn't owned yet. // just continue with current package and realm. diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index 41d210df3ee..234b1debf01 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -1,10 +1,8 @@ package gnolang -import "fmt" - func (m *Machine) doOpDefine() { s := m.PopStmt().(*AssignStmt) - fmt.Println("---doOpDefine, s: ", s) + debug2.Println2("---doOpDefine, s: ", s) // Define each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. @@ -29,7 +27,7 @@ func (m *Machine) doOpDefine() { func (m *Machine) doOpAssign() { s := m.PopStmt().(*AssignStmt) - fmt.Println("---doOpAssign, s: ", s) + debug2.Println2("doOpAssign, s: ", s) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. diff --git a/gnovm/pkg/gnolang/op_decl.go b/gnovm/pkg/gnolang/op_decl.go index a17b95935b7..13ad455fc53 100644 --- a/gnovm/pkg/gnolang/op_decl.go +++ b/gnovm/pkg/gnolang/op_decl.go @@ -6,7 +6,7 @@ import ( func (m *Machine) doOpValueDecl() { s := m.PopStmt().(*ValueDecl) - fmt.Println("---doOpValueDecl, s: ", s) + debug2.Println2("doOpValueDecl, s: ", s) lb := m.LastBlock() nt := Type(nil) if s.Type != nil { @@ -19,7 +19,7 @@ func (m *Machine) doOpValueDecl() { for i := 0; i < len(s.NameExprs); i++ { var tv TypedValue if rvs == nil { - println("---rvs is nil, using default value") + debug2.Println2("rvs is nil, using default value") // NOTE: Go/Gno wart. // implicit interface casting could // requiring the consideration of the typed-nil case. diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 8aaffa074c4..6bf5e54a24f 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -23,7 +23,7 @@ func (m *Machine) doOpEval() { debug.Printf("EVAL: (%T) %v\n", x, x) fmt.Println(m.String()) } - fmt.Printf("EVAL: (%T) %v\n", x, x) + debug2.Printf2("EVAL: (%T) %v\n", x, x) // This case moved out of switch for performance. // TODO: understand this better. if nx, ok := x.(*NameExpr); ok { @@ -38,7 +38,6 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerTo(m.Store, nx.Path) - fmt.Println("---ptr.Deref(): ", ptr.Deref()) m.PushValue(ptr.Deref()) return } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 9c51d6ce76a..f10543cdfa0 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -256,7 +256,6 @@ func (oi *ObjectInfo) GetModTime() uint64 { } func (oi *ObjectInfo) IncRefCount() int { - fmt.Println("---IncRefCount") oi.RefCount++ return oi.RefCount } @@ -392,11 +391,11 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // also get pkgId of the object, so it's clear where the object is from // TODO, just return isRealm func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { - fmt.Println("---GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) + debug2.Println2("GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) // get first object obj = tv.GetFirstObject(store) - fmt.Println("---obj: ", obj) + debug2.Println2("obj: ", obj) if obj != nil { @@ -411,7 +410,7 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { if pkgId.IsZero() { switch cv := obj.(type) { case *ArrayValue: - fmt.Println("---array value, T: ", tv.T) + debug2.Println2("array value, T: ", tv.T) debug2.Println2("objectInfo: ", cv.GetObjectInfo()) if IsRealmPath(tv.T.Elem().GetPkgPath()) { // TODO: func type don't have pkgpath, retrieve from clo @@ -425,10 +424,10 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { debug2.Println2("heapItemValue: ", cv) debug2.Println2("heapItemValue.Value.T: ", cv.Value.T) if dt, ok := cv.Value.T.(*DeclaredType); ok { - fmt.Printf("---dt: %v\n", dt) - fmt.Println("---dt.base: ", dt.Base) + debug2.Printf2("---dt: %v\n", dt) + debug2.Println2("---dt.base: ", dt.Base) if _, ok := dt.Base.(*FuncType); !ok { - fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) if IsRealmPath(dt.Base.GetPkgPath()) { pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) } @@ -436,10 +435,10 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { } return case *BoundMethodValue: - fmt.Println("---BoundMethodValue, recv: ", cv.Receiver) - fmt.Println("---type of T: ", reflect.TypeOf(cv.Receiver.T)) + debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) + debug2.Println2("---type of T: ", reflect.TypeOf(cv.Receiver.T)) if pv, ok := cv.Receiver.V.(PointerValue); ok { - println("---pointer value") + debug2.Println2("---pointer value") // TODO: check this if dt, ok := pv.TV.T.(*DeclaredType); ok { fmt.Println("---2, dt: ", dt) @@ -447,15 +446,15 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { pkgId = PkgIDFromPkgPath(dt.PkgPath) } } - fmt.Println("---pkgId; ", pkgId) + debug2.Println2("---pkgId; ", pkgId) } return case *MapValue, *StructValue: if dt, ok := tv.T.(*DeclaredType); ok { - fmt.Printf("---dt: %v\n", dt) - fmt.Println("---dt.base: ", dt.Base) + debug2.Printf2("---dt: %v\n", dt) + debug2.Println2("---dt.base: ", dt.Base) if _, ok := dt.Base.(*FuncType); !ok { - fmt.Println("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) if IsRealmPath(dt.Base.GetPkgPath()) { pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 5b8f43fcfc4..a7dffcdd8e6 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -197,13 +197,13 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { // ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { - fmt.Printf("---DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - fmt.Printf("---xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) - fmt.Printf("---co: %v, type of co: %v\n", co, reflect.TypeOf(co)) + debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) + debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) if co != nil { - fmt.Println("co.GetOriginRealm: ", co.GetOriginRealm()) + debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) } - fmt.Println("---rlm.ID: ", rlm.ID) + debug2.Println2("---rlm.ID: ", rlm.ID) if rlm == nil { return @@ -220,17 +220,18 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { } } + // if oo.GetRefCount() > 0 if refValue != nil { co.SetIsRef(true) } if po == nil || !po.GetIsReal() { // XXX, make sure po is attached - fmt.Println("---po(Base) not real, do nothing!!!") + debug2.Println2("po not real, do nothing!!!") return // do nothing. } // TODO: check not real external here, if po is real, association is invalid - fmt.Println("---po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) + debug2.Println2("po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) if po.GetObjectID().PkgID != rlm.ID { panic("cannot modify external-realm or non-realm object") } @@ -249,15 +250,17 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() - fmt.Println("---after inc, co.GetRefCount: ", co.GetRefCount()) + debug2.Println2("after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { - if co.GetIsEscaped() { - println("---already escaped, should check cross realm?") - // already escaped - rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) - } else { - rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) - } + //if co.GetIsEscaped() { + // debug2.Println2("already escaped, should check cross realm?") + // // already escaped in current realm, can also be escaped to other realm + // rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) + //} else { + // rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) + //} + // debug2.Println2("already escaped, should check cross realm?") + rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) } else if co.GetIsReal() { rlm.MarkDirty(co) } else { @@ -268,7 +271,6 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { if xo != nil { xo.DecRefCount() - fmt.Printf("---xo: %v refCount after dec: %v\n", xo, xo.GetRefCount()) if xo.GetRefCount() == 0 { if xo.GetIsReal() { rlm.MarkNewDeleted(xo) @@ -324,7 +326,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { if !pkgId.IsZero() { reo.SetOriginRealm(pkgId) } - fmt.Println("---reo: ", reo) + debug2.Println2("reo: ", reo) // XXX, if elem of array is slice?, GetFirstObject2?... checkCrossRealm(rlm, store, reo, refValue) } @@ -334,9 +336,9 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { println("---mapValue...") // TODO: check elem? case *HeapItemValue: - fmt.Println("---heapItemValue: ", v) + debug2.Println2("---heapItemValue: ", v) r := fillValueTV(store, &v.Value) - fmt.Println("---r: ", r) + debug2.Println2("---r: ", r) checkCrossRealm(rlm, store, v.Value.V.(Object), refValue) case *ArrayValue: @@ -356,10 +358,10 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { e := fillValueTV(store, &ee) //e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - fmt.Printf("---e[%d]: %v\n", i, e) - fmt.Printf("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) - debug2.Println2("e...GetOriginRealm: ", e.V.(Object).GetOriginRealm()) - debug2.Println2("e....GetObjectInfo: ", e.V.(Object).GetObjectInfo()) + debug2.Printf2("---e[%d]: %v\n", i, e) + debug2.Printf2("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) + //debug2.Println2("e...GetOriginRealm: ", e.V.(Object).GetOriginRealm()) + //debug2.Println2("e....GetObjectInfo: ", e.V.(Object).GetObjectInfo()) if eo, ok := e.V.(Object); ok { checkCrossRealm(rlm, store, eo, refValue) @@ -388,18 +390,16 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { // escaped realm should be reference object func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { - debug2.Println2("MarkNewEscapedCheckCrossRealm") - debug2.Println2("---refValue: ", refValue) + //fmt.Println("MarkNewEscapedCheckCrossRealm, oo: ", oo) + //fmt.Println("refValue: ", refValue) + //fmt.Println("oo.GetOriginRealm(): ", oo.GetOriginRealm()) + //fmt.Println("rlm.ID: ", rlm.ID) if oo.GetOriginRealm() == rlm.ID { - //if !oo.GetIsEscaped() { - // rlm.MarkNewEscaped(oo) - //} + // do nothing return } - debug2.Println2("---oo.GetLastNewEscapedRealm(): ", oo.GetOriginRealm()) - debug2.Println2("---rlm.ID: ", rlm.ID) if oo.GetOriginRealm() != rlm.ID { // crossing realm if refValue != nil { // is reference object from external realm checkCrossRealm(rlm, store, oo, refValue) @@ -435,7 +435,6 @@ func (rlm *Realm) MarkNewReal(oo Object) { } } if oo.GetIsNewReal() { - println("---isNewReal---, oo: ", oo) return // already marked. } oo.SetIsNewReal(true) @@ -443,9 +442,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { if rlm.newCreated == nil { rlm.newCreated = make([]Object, 0, 256) } - debug2.Println2("---append oo to newCreated object: ", oo) rlm.newCreated = append(rlm.newCreated, oo) - debug2.Println2("---len of new created: ", len(rlm.newCreated)) } // mark dirty == updated @@ -524,17 +521,17 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { debug2.Println2("FinalizeRealmTransaction, rlm.ID: ", rlm.ID) defer func() { - fmt.Println("================done FinalizeRealmTransaction==================") + debug2.Println2("================done FinalizeRealmTransaction==================") }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -549,9 +546,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -591,13 +588,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // All newly created objects become appended to .created, // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { - fmt.Println("---processNewCreatedMarks---") + debug2.Println2("processNewCreatedMarks") //fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - fmt.Printf("---oo[%d] is %v:\n", i, oo) + debug2.Printf2("---oo[%d] is %v:\n", i, oo) //if _, ok := oo.(*BoundMethodValue); ok { // panic("should not happen persist bound method") //} @@ -626,6 +623,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { } } +// XXX, unreal oo check happens in here // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---incRefCreatedDescendants from oo: ", oo) @@ -644,7 +642,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // XXX, oo must be new real here, it's not escaped // if it's reference, all right - fmt.Println("---oo.GetIsRef: ", oo.GetIsRef()) + debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { if oo.GetIsRef() { panic("cannot attach a reference to an unreal object from an external realm") @@ -681,7 +679,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - fmt.Println("---rc after inc: ", rc) + debug2.Println2("---rc after inc: ", rc) if rc == 1 { if child.GetIsReal() { //fmt.Println("---child is real, child: ", child) @@ -965,9 +963,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } @@ -1009,10 +1007,10 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - fmt.Println("---saveObject: ", oo) + debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() - fmt.Println("---oid: ", oid) - fmt.Println("---oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("---oid: ", oid) + debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") } @@ -1229,12 +1227,10 @@ func copyMethods(methods []TypedValue) []TypedValue { } func refOrCopyType(typ Type) Type { - fmt.Println("---refOrCopyType, typ: ", typ) + debug2.Println2("refOrCopyType, typ: ", typ) if dt, ok := typ.(*DeclaredType); ok { - fmt.Println("---declared type: ", dt) return RefType{ID: dt.TypeID()} } else { - println("---else") return copyTypeWithRefs(typ) } } @@ -1255,7 +1251,7 @@ func copyFieldsWithRefs(fields []FieldType) []FieldType { // Copies type but with references to dependant types; // the result is suitable for persistence bytes serialization. func copyTypeWithRefs(typ Type) Type { - fmt.Println("---copyTypeWithRefs, typ: ", typ) + debug2.Println2("copyTypeWithRefs, typ: ", typ) switch ct := typ.(type) { case nil: panic("cannot copy nil types") @@ -1346,7 +1342,7 @@ func copyTypeWithRefs(typ Type) Type { // Also checks for integrity of immediate children -- they must already be // persistent (real), and not dirty, or else this function panics. func copyValueWithRefs(val Value) Value { - fmt.Println("---copyValueWithRefs, val: ", val) + debug2.Println2("-copyValueWithRefs, val: ", val) switch cv := val.(type) { case nil: return nil @@ -1397,7 +1393,6 @@ func copyValueWithRefs(val Value) Value { Maxcap: cv.Maxcap, } case *StructValue: - println("---struct value") fields := make([]TypedValue, len(cv.Fields)) for i, ftv := range cv.Fields { fields[i] = refOrCopyValue(ftv) @@ -1522,7 +1517,7 @@ func copyValueWithRefs(val Value) Value { // (fully) fills the type. func fillType(store Store, typ Type) Type { - fmt.Println("---fillType, typ: ", typ) + debug2.Println2("fillType, typ: ", typ) switch ct := typ.(type) { case nil: return nil @@ -1598,7 +1593,6 @@ func fillType(store Store, typ Type) Type { } return ct case RefType: - println("---ref type") return store.GetType(ct.TypeID()) default: panic(fmt.Sprintf( @@ -1607,7 +1601,7 @@ func fillType(store Store, typ Type) Type { } func fillTypesTV(store Store, tv *TypedValue) { - fmt.Println("---fillTypesTV, tv: ", tv) + debug2.Println2("fillTypesTV, tv: ", tv) tv.T = fillType(store, tv.T) tv.V = fillTypesOfValue(store, tv.V) } @@ -1617,7 +1611,6 @@ func fillTypesTV(store Store, tv *TypedValue) { func fillTypesOfValue(store Store, val Value) Value { debug2.Println2("fillTypesOfValue, val: ", val) debug2.Println2("type of val: ", reflect.TypeOf(val)) - defer println("---done FillTypesOfValue") switch cv := val.(type) { case nil: // do nothing return cv @@ -1817,11 +1810,10 @@ func ensureUniq(oozz ...[]Object) { } func refOrCopyValue(tv TypedValue) TypedValue { - fmt.Println("---refOrCopyValue:", tv) + debug2.Println2("refOrCopyValue:", tv) if tv.T != nil { tv.T = refOrCopyType(tv.T) } - fmt.Println("---Tv.T: ", tv.T) if obj, ok := tv.V.(Object); ok { tv.V = toRefValue(obj) return tv diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index e2dea647ae2..afabd70987b 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -299,7 +299,7 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { - fmt.Println("---loadObjectSafe, oid: ", oid) + debug2.Println2("loadObjectSafe, oid: ", oid) key := backendObjectKey(oid) hashbz := ds.baseStore.Get([]byte(key)) if hashbz != nil { @@ -325,11 +325,11 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - fmt.Println("---SetObject: ", oo) + debug2.Println2("SetObject: ", oo) oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - fmt.Println("---o2: ", o2) + debug2.Println2("---o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) // set hash. @@ -400,9 +400,9 @@ func (ds *defaultStore) DelObject(oo Object) { // NOTE: The implementation matches that of GetObject() in anticipation of what // the persistent type system might work like. func (ds *defaultStore) GetType(tid TypeID) Type { - fmt.Println("---GetType: ", tid) + debug2.Println2("GetType: ", tid) tt := ds.GetTypeSafe(tid) - fmt.Println("---tt: ", tt) + debug2.Println2("tt: ", tt) if tt == nil { ds.Print() panic(fmt.Sprintf("unexpected type with id %s", tid.String())) @@ -411,7 +411,7 @@ func (ds *defaultStore) GetType(tid TypeID) Type { } func (ds *defaultStore) GetTypeSafe(tid TypeID) Type { - fmt.Println("---GetTypeSafe: ", tid) + debug2.Println2("GetTypeSafe: ", tid) // check cache. if tt, exists := ds.cacheTypes[tid]; exists { return tt diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 53137a75496..8c1cef6c5f5 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -289,7 +289,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - fmt.Println("---oo1: ", oo1) + debug2.Println2("---oo1: ", oo1) // get origin pkgId _, pkgId := tv2.GetFirstObject2(store) @@ -551,11 +551,11 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) // append, unref copy... - //pkgId := sv.GetOriginRealm() - //if pkgId.IsZero() { - // pkgId = sv.GetObjectID().PkgID - //} - //nsv.SetOriginRealm(pkgId) + pkgId := sv.GetOriginRealm() + if pkgId.IsZero() { + pkgId = sv.GetObjectID().PkgID + } + nsv.SetOriginRealm(pkgId) return nsv //return alloc.NewStruct(fields) } @@ -1081,7 +1081,7 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: - println("---default") + debug2.Println2("---default") cp = tv } return @@ -2669,20 +2669,16 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - fmt.Println("---fillValueTV, tv: ", tv) + debug2.Println2("fillValueTV, tv: ", tv) switch cv := tv.V.(type) { case RefValue: - println("---tv.V RefValue") - fmt.Println("---cv: ", cv) if cv.PkgPath != "" { // load package tv.V = store.GetPackage(cv.PkgPath, false) } else { // load object // XXX XXX allocate object. tv.V = store.GetObject(cv.ObjectID) - fmt.Println("---tv.V: ", tv.V) } case PointerValue: - fmt.Println("---PointerValue") // As a special case, cv.Base is filled // and cv.TV set appropriately. // Alternatively, could implement diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 72f065326f1..152f5ab2784 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -83,7 +83,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Escaped": true, +// "Hash": "4f679d9dc2ea37d8f31b020193e7afae0236c97c", // "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" // }, // "Index": "0", @@ -102,7 +102,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Escaped": true, +// "Hash": "4f679d9dc2ea37d8f31b020193e7afae0236c97c", // "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" // }, // "Index": "0", diff --git a/gnovm/tests/files/zrealm_crossrealm24f.gno b/gnovm/tests/files/zrealm_crossrealm24f.gno index 4be67555c6c..23049563511 100644 --- a/gnovm/tests/files/zrealm_crossrealm24f.gno +++ b/gnovm/tests/files/zrealm_crossrealm24f.gno @@ -8,7 +8,7 @@ import ( var root interface{} func main() { - root = tests.F + root = tests.F // already attached in p println("done") } diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index f3f4e1243e9..f2909115100 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -19,7 +19,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28]={ // "Fields": [ // { // "T": { @@ -33,13 +33,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", // "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", // "RefCount": "1" // } // } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ // "Fields": [ // { // "T": { @@ -53,13 +53,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", // "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", // "RefCount": "1" // } // } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27]={ // "Data": null, // "List": [ // { @@ -69,8 +69,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "47bf5eb54da0545110d6486001609dc4203f61b0", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:26" +// "Hash": "c6f0c0407c9697a6a91451eb572489913de89e71", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" // } // }, // { @@ -80,13 +80,13 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "eaa3017cfcfafd8f8217ee1df0afdac5e4ad12a9", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// "Hash": "2a99f0d55ccbad80a109cecd6fa9a0dece4df7cc", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29" // } // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", // "ModTime": "0", // "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "1" @@ -97,7 +97,7 @@ func main() { // "ObjectInfo": { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "IsEscaped": true, -// "ModTime": "24", +// "ModTime": "26", // "RefCount": "2" // }, // "Parent": null, @@ -259,8 +259,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "0934dceb3731dd613f35a5e4a4a82396f3dc474e", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" +// "Hash": "63edd934ae4e6e1adfa3e8ccaec695d037023467", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" // }, // "Length": "2", // "Maxcap": "2", @@ -280,8 +280,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "fcdb6b41091d087be521ae9be69b8328ac495677", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" +// "Hash": "c1cb1b78808a97bdeb22bdb8fe51cbc5ebe27c15", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" // }, // "Length": "2", // "Maxcap": "2", @@ -301,11 +301,11 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "9073c630fa09e61b0e3b824056c022eebe7bd86b", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:16" +// "Hash": "5b15d0ddccc7056f8a23f92113551faf3458362a", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" // }, // "Length": "1", -// "Maxcap": "1", +// "Maxcap": "2", // "Offset": "0" // } // }, @@ -325,8 +325,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "088eb6ee7e7fe1c5e10101801be9e64ac6794e29", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" +// "Hash": "c4c833f476004da7b523986bfc338fcd6e2259cc", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" // }, // "Length": "1", // "Maxcap": "1", @@ -349,8 +349,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "3450ddb4764c2026edd313f230c633e0af6cd8ed", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" +// "Hash": "47988816818ccc2d075b63242db659eaceb17c09", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:7" // }, // "Length": "2", // "Maxcap": "2", @@ -369,8 +369,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "e03c7067902bb4b3c2aa477a27d6abfcd51ce3a6", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" +// "Hash": "2120aae986302ac34c4d0215158d9bb3aa8e5234", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" // } // }, // { @@ -398,7 +398,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "27", +// "Line": "32", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -448,7 +448,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "42", +// "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -480,8 +480,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "d10003fa5a9ebd5bb30cadd5e11bd5aad76ec9f4", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" +// "Hash": "ee138dfe6fb2fb9d6702fd4a426d40a2ca55e022", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" // } // }, // { @@ -491,8 +491,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "8a2889ef5ccf6c7e4ec0c59ed627267fa3a51026", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:9" +// "Hash": "af3ef02e37f329c151774dc9a73c38f2bd8b5c15", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:12" // } // }, // { @@ -534,7 +534,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "50", +// "Line": "56", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -598,7 +598,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "58", +// "Line": "64", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -673,7 +673,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "63", +// "Line": "69", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -751,7 +751,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "68", +// "Line": "74", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -832,7 +832,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "72", +// "Line": "78", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -922,7 +922,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "77", +// "Line": "83", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -971,8 +971,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "ed9761e4c90097cbcf3d55a627ab1b7c65ff8a62", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// "Hash": "fc759b6634b8975a76435bc16085d82c322842ae", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13" // } // }, // { @@ -1025,7 +1025,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "84", +// "Line": "90", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1111,7 +1111,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "89", +// "Line": "95", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1149,8 +1149,8 @@ func main() { // } // ] // } -// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14] -// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15] +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17] +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18] // switchrealm["gno.land/r/crossrealm_test"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ // "Blank": {}, @@ -1186,7 +1186,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" // }, // "Length": "2", // "Maxcap": "2", @@ -1398,8 +1398,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "0934dceb3731dd613f35a5e4a4a82396f3dc474e", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" +// "Hash": "63edd934ae4e6e1adfa3e8ccaec695d037023467", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" // }, // "Length": "2", // "Maxcap": "2", @@ -1420,7 +1420,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:25" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" // }, // "Length": "2", // "Maxcap": "2", @@ -1440,11 +1440,11 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "9073c630fa09e61b0e3b824056c022eebe7bd86b", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:16" +// "Hash": "5b15d0ddccc7056f8a23f92113551faf3458362a", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" // }, // "Length": "1", -// "Maxcap": "1", +// "Maxcap": "2", // "Offset": "0" // } // }, @@ -1464,8 +1464,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "088eb6ee7e7fe1c5e10101801be9e64ac6794e29", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" +// "Hash": "c4c833f476004da7b523986bfc338fcd6e2259cc", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" // }, // "Length": "1", // "Maxcap": "1", @@ -1488,8 +1488,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "3450ddb4764c2026edd313f230c633e0af6cd8ed", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" +// "Hash": "47988816818ccc2d075b63242db659eaceb17c09", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:7" // }, // "Length": "2", // "Maxcap": "2", @@ -1508,8 +1508,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "e03c7067902bb4b3c2aa477a27d6abfcd51ce3a6", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" +// "Hash": "2120aae986302ac34c4d0215158d9bb3aa8e5234", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" // } // }, // { @@ -1537,7 +1537,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "27", +// "Line": "32", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1587,7 +1587,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "42", +// "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1619,8 +1619,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "d10003fa5a9ebd5bb30cadd5e11bd5aad76ec9f4", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" +// "Hash": "ee138dfe6fb2fb9d6702fd4a426d40a2ca55e022", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" // } // }, // { @@ -1630,8 +1630,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "8a2889ef5ccf6c7e4ec0c59ed627267fa3a51026", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:9" +// "Hash": "af3ef02e37f329c151774dc9a73c38f2bd8b5c15", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:12" // } // }, // { @@ -1673,7 +1673,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "50", +// "Line": "56", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1737,7 +1737,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "58", +// "Line": "64", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1812,7 +1812,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "63", +// "Line": "69", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1890,7 +1890,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "68", +// "Line": "74", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1971,7 +1971,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "72", +// "Line": "78", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2061,7 +2061,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "77", +// "Line": "83", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2110,8 +2110,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "ed9761e4c90097cbcf3d55a627ab1b7c65ff8a62", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:10" +// "Hash": "fc759b6634b8975a76435bc16085d82c322842ae", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13" // } // }, // { @@ -2164,7 +2164,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "84", +// "Line": "90", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2250,7 +2250,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "89", +// "Line": "95", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index 0875ef6a92a..75abe495d4d 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -57,7 +57,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" // }, // "Length": "1", // "Maxcap": "1", diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index 85a55301ebd..faace075600 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// should not happen, struct{("6.1" string)} is not real +// cannot attach un-real object from external realm: struct{("6.1" string)} diff --git a/gnovm/tests/files/zrealm_natbind0_stdlibs.gno b/gnovm/tests/files/zrealm_natbind0_stdlibs.gno deleted file mode 100644 index c852f4a09f7..00000000000 --- a/gnovm/tests/files/zrealm_natbind0_stdlibs.gno +++ /dev/null @@ -1,180 +0,0 @@ -// PKGPATH: gno.land/r/test -package test - -import ( - "std" -) - -var node interface{} - -func init() { - node = std.GetHeight -} - -func main() { - // NOTE: this test uses GetHeight and GetChainID, which are "pure" - // natively bound functions (ie. not indirections through a wrapper fn, - // to convert the types to builtin go/gno identifiers). - f := node.(func() int64) - println(f()) - node = std.GetChainID - g := node.(func() string) - println(g()) -} - -// Output: -// 123 -// dev - -// Realm: -// switchrealm["gno.land/r/test"] -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30: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/test" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:8" -// }, -// "FileName": "native.gno", -// "IsMethod": false, -// "Name": "GetChainID", -// "NativeName": "GetChainID", -// "NativePkg": "std", -// "PkgPath": "std", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "native.gno", -// "Line": "13", -// "PkgPath": "std" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "init.1", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "10", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "14", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_tests0_stdlibs.gno b/gnovm/tests/files/zrealm_tests0_stdlibs.gno index d11701505e5..b6b15229457 100644 --- a/gnovm/tests/files/zrealm_tests0_stdlibs.gno +++ b/gnovm/tests/files/zrealm_tests0_stdlibs.gno @@ -1760,8 +1760,5 @@ 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"] -// switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests"] // switchrealm["gno.land/r/demo/tests_test"] From 926e6e91d8d05d2ac71e601c70b1e79c4c8412b2 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 6 Jan 2025 16:35:39 +0800 Subject: [PATCH 39/88] fixup --- gnovm/pkg/gnolang/ownership.go | 44 +- gnovm/pkg/gnolang/realm.go | 203 +++------ gnovm/pkg/gnolang/values.go | 19 +- gnovm/tests/files/zrealm6.gno | 324 +------------ gnovm/tests/files/zrealm7.gno | 427 +----------------- gnovm/tests/files/zrealm_natbind0_stdlibs.gno | 26 ++ 6 files changed, 125 insertions(+), 918 deletions(-) create mode 100644 gnovm/tests/files/zrealm_natbind0_stdlibs.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index f10543cdfa0..4aa7fe22f1f 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -388,37 +388,33 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } } -// also get pkgId of the object, so it's clear where the object is from -// TODO, just return isRealm -func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { - debug2.Println2("GetFirstObject2---, tv: ", tv, reflect.TypeOf(tv.V)) - +// GetOriginPkg get origin pkg for real or unreal object +func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { + debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) // get first object - obj = tv.GetFirstObject(store) + obj := tv.GetFirstObject(store) debug2.Println2("obj: ", obj) - if obj != nil { - - pkgId = obj.GetOriginRealm() - if pkgId.IsZero() { - pkgId = obj.GetObjectID().PkgID + originPkg = obj.GetOriginRealm() + if originPkg.IsZero() { + originPkg = obj.GetObjectID().PkgID } debug2.Println2("obj.GetObjectInfo(): ", obj.GetObjectInfo()) - debug2.Println2("obj.GetObjectID.PkgID: ", pkgId) + debug2.Println2("obj.originPkg: ", originPkg) } - if pkgId.IsZero() { + // if still zero + if originPkg.IsZero() { switch cv := obj.(type) { case *ArrayValue: debug2.Println2("array value, T: ", tv.T) debug2.Println2("objectInfo: ", cv.GetObjectInfo()) if IsRealmPath(tv.T.Elem().GetPkgPath()) { - // TODO: func type don't have pkgpath, retrieve from clo - pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) + originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) } return case *Block: - pkgId = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) return case *HeapItemValue: debug2.Println2("heapItemValue: ", cv) @@ -429,24 +425,24 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { if _, ok := dt.Base.(*FuncType); !ok { debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) if IsRealmPath(dt.Base.GetPkgPath()) { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + originPkg = PkgIDFromPkgPath(dt.Base.GetPkgPath()) } } } return case *BoundMethodValue: + debug2.Println2("boundMethodValue: ", cv) debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) - debug2.Println2("---type of T: ", reflect.TypeOf(cv.Receiver.T)) + debug2.Println2("type of T: ", reflect.TypeOf(cv.Receiver.T)) if pv, ok := cv.Receiver.V.(PointerValue); ok { - debug2.Println2("---pointer value") - // TODO: check this + debug2.Println2("pointer value, pv: ", pv) if dt, ok := pv.TV.T.(*DeclaredType); ok { - fmt.Println("---2, dt: ", dt) + debug2.Println2("---2, dt: ", dt) if IsRealmPath(dt.PkgPath) { - pkgId = PkgIDFromPkgPath(dt.PkgPath) + originPkg = PkgIDFromPkgPath(dt.PkgPath) } } - debug2.Println2("---pkgId; ", pkgId) + debug2.Println2("originPkg; ", originPkg) } return case *MapValue, *StructValue: @@ -456,7 +452,7 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) { if _, ok := dt.Base.(*FuncType); !ok { debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) if IsRealmPath(dt.Base.GetPkgPath()) { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + originPkg = PkgIDFromPkgPath(dt.Base.GetPkgPath()) } } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index a7dffcdd8e6..74e991b1d6c 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -138,9 +138,6 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { return } if debug { - if co != nil && co.GetIsDeleted() { - panic("cannot attach a deleted object") - } if po != nil && po.GetIsTransient() { panic("cannot attach to a transient object") } @@ -166,25 +163,6 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { // More appends happen during FinalizeRealmTransactions(). (second+ gen) rlm.MarkDirty(po) - if co != nil { - // XXX, inc ref count everytime assignment happens - co.IncRefCount() - if co.GetRefCount() > 1 { - if co.GetIsEscaped() { - // XXX, why packageBlock is automatically escaped? - // already escaped - } else { - // XXX, just mark - rlm.MarkNewEscaped(co) - } - } else if co.GetIsReal() { - rlm.MarkDirty(co) - } else { - co.SetOwner(po) - rlm.MarkNewReal(co) // co will be attached when finalize - } - } - if xo != nil { xo.DecRefCount() if xo.GetRefCount() == 0 { @@ -200,10 +178,10 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) + debug2.Println2("---rlm.ID: ", rlm.ID) if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) } - debug2.Println2("---rlm.ID: ", rlm.ID) if rlm == nil { return @@ -220,17 +198,13 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { } } - // if oo.GetRefCount() > 0 - if refValue != nil { - co.SetIsRef(true) - } - if po == nil || !po.GetIsReal() { // XXX, make sure po is attached debug2.Println2("po not real, do nothing!!!") return // do nothing. } - // TODO: check not real external here, if po is real, association is invalid + // TODO: check unreal external here, if po is real, association is invalid, panic + // else, defer to finalize??? debug2.Println2("po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) if po.GetObjectID().PkgID != rlm.ID { panic("cannot modify external-realm or non-realm object") @@ -250,16 +224,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() - debug2.Println2("after inc, co.GetRefCount: ", co.GetRefCount()) if co.GetRefCount() > 1 { - //if co.GetIsEscaped() { - // debug2.Println2("already escaped, should check cross realm?") - // // already escaped in current realm, can also be escaped to other realm - // rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) - //} else { - // rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) - //} - // debug2.Println2("already escaped, should check cross realm?") rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) } else if co.GetIsReal() { rlm.MarkDirty(co) @@ -282,113 +247,73 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { //---------------------------------------- // mark* -// XXX, oo here must be referenced type, since they already escaped. -// XXX, so oo has been persisted, thus fillValueTV +func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { + debug2.Printf2("checkCrossRealm2, tv: %v\n", tv) + if fo, ok := tv.V.(Object); ok { + checkCrossRealm(rlm, store, fo, nil) + } else { // reference to object + //var reo Object + switch rv := tv.V.(type) { + case *SliceValue, PointerValue: // if reference object from external realm + // XXX: consider pkgId here, A -> B - > A?... + reo := tv.GetFirstObject(store) + debug2.Println2("reo: ", reo) + checkCrossRealm(rlm, store, reo, rv) + } + } +} + +// checkCrossRealm check cross realm recursively func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { - debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + fmt.Println("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("oo.GetObjectInfo: ", oo.GetObjectInfo()) switch v := oo.(type) { case *StructValue: - - //debug2.Println2("oo.GetOriginRealm: ", oo.GetOriginRealm()) - //if refValue == nil { // not ref - // if rlm.ID != oo.GetOriginRealm() { - // panic("cannot attach object from external realm") - // } - //} - - // ref, check real - //if oo.GetObjectID().IsZero() { - //} - //// TODO: rm this if !v.GetIsReal() { - panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", v)) + if rlm.ID != oo.GetOriginRealm() { // it's ok for un-real object from same realm + panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", v)) + } } // check fields for _, fv := range v.Fields { - debug2.Println2("fv: ", fv) rfv := fillValueTV(store, &fv) - debug2.Println2("---rfv: ", rfv) - - if fo, ok := rfv.V.(Object); ok { - checkCrossRealm(rlm, store, fo, nil) - } else { // reference to object - var reo Object - switch rv := rfv.V.(type) { - case *SliceValue, PointerValue: // if reference object from external realm - refValue = rv - // TODO: consider pkgId here, A -> B - > A?... - // yes, check PkgId per object - var pkgId PkgID - reo, pkgId = rfv.GetFirstObject2(store) - // TODO: simplify - if !pkgId.IsZero() { - reo.SetOriginRealm(pkgId) - } - debug2.Println2("reo: ", reo) - // XXX, if elem of array is slice?, GetFirstObject2?... - checkCrossRealm(rlm, store, reo, refValue) - } - } + checkCrossRealm2(rlm, store, rfv) } case *MapValue: - println("---mapValue...") - // TODO: check elem? + // TODO: check recursively + case *BoundMethodValue: + // TODO: check recursively + case *Block: + // XXX, can this happen? + if !v.GetIsRef() { + panic("should not happen, block is not real") + } case *HeapItemValue: - debug2.Println2("---heapItemValue: ", v) - r := fillValueTV(store, &v.Value) - debug2.Println2("---r: ", r) - - checkCrossRealm(rlm, store, v.Value.V.(Object), refValue) + // TODO: is it necessary? + // if heapItem, the embedded should be all real now??? + fillValueTV(store, &v.Value) + checkCrossRealm2(rlm, store, &v.Value) case *ArrayValue: - if sv, ok := refValue.(*SliceValue); !ok { - panic("should be slice value") - } else { - offset := sv.Offset - length := sv.Length + if sv, ok := refValue.(*SliceValue); ok { debug2.Println2("ArrayValue: ", v) - debug2.Printf2("offset: %d, length: %d \n", offset, length) - debug2.Println2("escaped array, check if elements are real") - - // check referenced elem - for i := offset; i < length; i++ { - // XXX, difference between them? - ee := v.List[i] - e := fillValueTV(store, &ee) - //e := oo.(*ArrayValue).GetPointerAtIndexInt2(store, i, nil).Deref() - - debug2.Printf2("---e[%d]: %v\n", i, e) - debug2.Printf2("---type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) - //debug2.Println2("e...GetOriginRealm: ", e.V.(Object).GetOriginRealm()) - //debug2.Println2("e....GetObjectInfo: ", e.V.(Object).GetObjectInfo()) - - if eo, ok := e.V.(Object); ok { - checkCrossRealm(rlm, store, eo, refValue) - } else { // reference to object - var reo Object - switch rv := e.V.(type) { - case *SliceValue, PointerValue: // if reference object from external realm - refValue = rv - // TODO: consider pkgId here, A -> B - > A?... - var pkgId PkgID - reo, pkgId = e.GetFirstObject2(store) - // TODO: simplify - if !pkgId.IsZero() { - reo.SetOriginRealm(pkgId) - } - // XXX, if elem of array is slice?, GetFirstObject2?... - checkCrossRealm(rlm, store, reo, refValue) - } - } + debug2.Println2("SliceValue: ", sv) + // only check referenced elem + for i := sv.Offset; i < sv.Length; i++ { + e := fillValueTV(store, &v.List[i]) + debug2.Printf2("e[%d]: %v\n", i, e) + debug2.Printf2("type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) + checkCrossRealm2(rlm, store, e) } + } else { + panic("should be slice value") } default: - //fmt.Println("---v :", v) + panic("should not happen, oo is not object") } } -// escaped realm should be reference object +// MarkNewEscapedCheckCrossRealm check for escaped object func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { //fmt.Println("MarkNewEscapedCheckCrossRealm, oo: ", oo) //fmt.Println("refValue: ", refValue) @@ -447,8 +372,8 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - //fmt.Printf("---current rlm: %v: \n", rlm) - //fmt.Printf("---Mark Dirty %v: \n", oo) + //debug2.Printf2("---current rlm: %v: \n", rlm) + //debug2.Printf2("---Mark Dirty %v: \n", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -525,13 +450,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { }() if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -546,9 +471,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -963,9 +888,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 8c1cef6c5f5..3ab0e700ec7 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -292,23 +292,27 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty debug2.Println2("---oo1: ", oo1) // get origin pkgId - _, pkgId := tv2.GetFirstObject2(store) - debug2.Println2("pkgId: ", pkgId) + originPkg := tv2.GetOriginPkg(store) + debug2.Println2("originPkg: ", originPkg) pv.TV.Assign(alloc, tv2, cu) + // get origin pkgId, this should happen before assign, + // because assign will discard original object info + oo2 := pv.TV.GetFirstObject(store) - // TODO: move to GetFirstObject2 + debug2.Println2("oo2: ", oo2) + + // refValue checks for embedded values in the base var refValue Value switch rv := pv.TV.V.(type) { case *SliceValue, PointerValue: refValue = rv + oo2.SetIsRef(true) } - debug2.Println2("oo2: ", oo2) - debug2.Println2("pkgId: ", pkgId) - if oo2 != nil && !pkgId.IsZero() { // cross realm - oo2.SetOriginRealm(pkgId) // attach origin package info + if oo2 != nil && !originPkg.IsZero() { + oo2.SetOriginRealm(originPkg) // attach origin package info } rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, refValue) } else { @@ -2707,7 +2711,6 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { vpv := cb.GetPointerToInt(store, cv.Index) cv.TV = vpv.TV // TODO optimize? case *HeapItemValue: - //fmt.Println("---HeapItemValue: ", cb.Value) cv.TV = &cb.Value default: panic("should not happen") diff --git a/gnovm/tests/files/zrealm6.gno b/gnovm/tests/files/zrealm6.gno index 9fb36c64a14..3fb348cb4cd 100644 --- a/gnovm/tests/files/zrealm6.gno +++ b/gnovm/tests/files/zrealm6.gno @@ -19,325 +19,5 @@ func main() { println(updated, tree.Size()) } -// Output: -// false 3 - -// Realm: -// switchrealm["gno.land/r/test"] -// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:9]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key3" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value3" -// } -// }, -// { -// "N": "AQAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:9", -// "ModTime": "0", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8", -// "RefCount": "1" -// } -// } -// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:8]={ -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8", -// "ModTime": "0", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:7", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "34a46349a2bc1b58591d0222a145b585452683be", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:9" -// } -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:7]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key1" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value1" -// } -// }, -// { -// "N": "AgAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "81074f5da453299a913435a2ddd05248ee012f8c", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:7", -// "ModTime": "7", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6", -// "RefCount": "1" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key0" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value0" -// } -// }, -// { -// "N": "AwAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "7c63a8fd451cd7c470c1851f1ead037246422ded", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", -// "ModTime": "7", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", -// "RefCount": "1" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", -// "IsEscaped": true, -// "ModTime": "7", -// "RefCount": "2" -// }, -// "Parent": null, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "0", -// "File": "", -// "Line": "0", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "ade9fce2a987ef1924040a1d75c0172410c66952", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "init.1", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "11", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "16", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } +// Error: +// cannot attach un-real object from external realm: struct{("key0" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value0" string),(2 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(&(struct{("key1" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value1" string),(1 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode) *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} diff --git a/gnovm/tests/files/zrealm7.gno b/gnovm/tests/files/zrealm7.gno index 7e19851cd13..f7707024bad 100644 --- a/gnovm/tests/files/zrealm7.gno +++ b/gnovm/tests/files/zrealm7.gno @@ -20,428 +20,5 @@ func main() { println(updated, tree.Size()) } -// Output: -// false 4 - -// Realm: -// switchrealm["gno.land/r/test"] -// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:11]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key3" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value3" -// } -// }, -// { -// "N": "AQAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:11", -// "ModTime": "0", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:10", -// "RefCount": "1" -// } -// } -// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:10]={ -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:10", -// "ModTime": "0", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:9", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "42cd813e173ad23c7873e9605901e8bea1176c96", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:11" -// } -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:9]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key2" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value2" -// } -// }, -// { -// "N": "AgAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "4f88fcdc73a4a94905e8e4044aa50c2ec7bf2227", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:10" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:9", -// "ModTime": "9", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8", -// "RefCount": "1" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:8]={ -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8", -// "ModTime": "9", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:7", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "2c172bbe0183ccc73c59d9acb196c45b0331c39e", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:9" -// } -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:7]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key1" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value1" -// } -// }, -// { -// "N": "AwAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "a4fa9bdf45caf8c6b5be7a3752704423817b3ef2", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "43f69f24b7827a331921b4af0f667346d186e0c3", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:7", -// "ModTime": "9", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6", -// "RefCount": "1" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/types.String" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key0" -// } -// }, -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "value0" -// } -// }, -// { -// "N": "AQAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", -// "ModTime": "9", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", -// "RefCount": "1" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:6]={ -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6", -// "ModTime": "9", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "f56fbd9c8db299689cc0cf806fe741b6a6e641e6", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:7" -// } -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", -// "IsEscaped": true, -// "ModTime": "9", -// "RefCount": "2" -// }, -// "Parent": null, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "0", -// "File": "", -// "Line": "0", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "450aef9858564ed4ec1c418f1e8dac828079016b", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "init.1", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "11", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" -// }, -// "FileName": "main.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "main.gno", -// "Line": "17", -// "PkgPath": "gno.land/r/test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } +// Error: +// cannot attach un-real object from external realm: struct{("key0" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value0" string),(2 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(&(struct{("key1" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value1" string),(1 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode) *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} diff --git a/gnovm/tests/files/zrealm_natbind0_stdlibs.gno b/gnovm/tests/files/zrealm_natbind0_stdlibs.gno new file mode 100644 index 00000000000..6ff1737e565 --- /dev/null +++ b/gnovm/tests/files/zrealm_natbind0_stdlibs.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/test +package test + +import ( + "std" +) + +var node interface{} + +func init() { + node = std.GetHeight +} + +func main() { + // NOTE: this test uses GetHeight and GetChainID, which are "pure" + // natively bound functions (ie. not indirections through a wrapper fn, + // to convert the types to builtin go/gno identifiers). + f := node.(func() int64) + println(f()) + node = std.GetChainID + g := node.(func() string) + println(g()) +} + +// Error: +// cannot attach objects by value from external realm From bff5b19be97a4db8372e6550c3e6aae599a6184f Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 8 Jan 2025 17:59:48 +0800 Subject: [PATCH 40/88] fixup --- gnovm/pkg/gnolang/machine.go | 9 ++-- gnovm/pkg/gnolang/op_eval.go | 2 +- gnovm/pkg/gnolang/ownership.go | 91 ++++++++++++++-------------------- gnovm/pkg/gnolang/realm.go | 12 ++--- gnovm/pkg/gnolang/values.go | 15 ++---- 5 files changed, 52 insertions(+), 77 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 6b21798de87..3cbc6f3a864 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -2003,11 +2003,10 @@ func (m *Machine) PopFrameAndReturn() { if res.IsUndefined() && rtypes[i].Type.Kind() != InterfaceKind { res.T = rtypes[i].Type } - debug2.Println2("res: ", res) - debug2.Printf2("addr of res: %p \n", &res) - if oo, ok := res.V.(Object); ok { - debug2.Println2("oo.GetObjectInfo(): ", oo.GetObjectInfo()) - } + //debug2.Println2("res: ", res) + //if oo, ok := res.V.(Object); ok { + // debug2.Println2("oo.GetObjectInfo(): ", oo.GetObjectInfo()) + //} m.Values[fr.NumValues+i] = res } m.NumValues = fr.NumValues + numRes diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 6bf5e54a24f..189a959aa02 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -21,7 +21,7 @@ func (m *Machine) doOpEval() { x := m.PeekExpr(1) if debug { debug.Printf("EVAL: (%T) %v\n", x, x) - fmt.Println(m.String()) + //fmt.Println(m.String()) } debug2.Printf2("EVAL: (%T) %v\n", x, x) // This case moved out of switch for performance. diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 4aa7fe22f1f..18d3d1c2a0e 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -145,13 +145,13 @@ 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 - isRef bool - isNewEscaped bool - isNewDeleted bool - lastNewRealEscapedRealm PkgID + isDirty bool + isDeleted bool + isNewReal bool + isRef bool + isNewEscaped bool + isNewDeleted bool + originRealm PkgID // realm where object is from // XXX huh? owner Object // mem reference to owner. @@ -160,13 +160,13 @@ 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, - lastNewRealEscapedRealm: oi.lastNewRealEscapedRealm, + ID: oi.ID, + Hash: oi.Hash.Copy(), + OwnerID: oi.OwnerID, + ModTime: oi.ModTime, + RefCount: oi.RefCount, + IsEscaped: oi.IsEscaped, + originRealm: oi.originRealm, /* // XXX do the following need copying too? isDirty: oi.isDirty, @@ -174,7 +174,7 @@ func (oi *ObjectInfo) Copy() ObjectInfo { isNewReal: oi.isNewReal, isNewEscaped: oi.isNewEscaped, isNewDeleted: oi.isNewDeleted, - lastNewRealEscapedRealm: oi.lastNewRealEscapedRealm, + originRealm: oi.originRealm, */ } } @@ -317,12 +317,12 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { } func (oi *ObjectInfo) GetOriginRealm() PkgID { - return oi.lastNewRealEscapedRealm + return oi.originRealm } func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { debug2.Println2("SetOriginRealm: ", pkgId) - oi.lastNewRealEscapedRealm = pkgId + oi.originRealm = pkgId } func (oi *ObjectInfo) GetIsRef() bool { @@ -393,22 +393,36 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) // get first object obj := tv.GetFirstObject(store) - debug2.Println2("obj: ", obj) + debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) if obj != nil { originPkg = obj.GetOriginRealm() if originPkg.IsZero() { originPkg = obj.GetObjectID().PkgID } debug2.Println2("obj.GetObjectInfo(): ", obj.GetObjectInfo()) - debug2.Println2("obj.originPkg: ", originPkg) + } + debug2.Println2("obj.originPkg: ", originPkg) + + // get pkgId from type + getPkgId := func(t Type) (pkgId PkgID) { + defer debug2.Println2("getPkgId: ", pkgId) + if dt, ok := t.(*DeclaredType); ok { + debug2.Printf2("dt: %v, dt.Base: \n", dt, dt.Base) + if _, ok := dt.Base.(*FuncType); !ok { + debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) + if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + return + } + } + } + return } // if still zero if originPkg.IsZero() { switch cv := obj.(type) { case *ArrayValue: - debug2.Println2("array value, T: ", tv.T) - debug2.Println2("objectInfo: ", cv.GetObjectInfo()) if IsRealmPath(tv.T.Elem().GetPkgPath()) { originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) } @@ -417,45 +431,16 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) return case *HeapItemValue: - debug2.Println2("heapItemValue: ", cv) - debug2.Println2("heapItemValue.Value.T: ", cv.Value.T) - if dt, ok := cv.Value.T.(*DeclaredType); ok { - debug2.Printf2("---dt: %v\n", dt) - debug2.Println2("---dt.base: ", dt.Base) - if _, ok := dt.Base.(*FuncType); !ok { - debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) - if IsRealmPath(dt.Base.GetPkgPath()) { - originPkg = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - } - } - } + originPkg = getPkgId(cv.Value.T) return case *BoundMethodValue: - debug2.Println2("boundMethodValue: ", cv) debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) - debug2.Println2("type of T: ", reflect.TypeOf(cv.Receiver.T)) if pv, ok := cv.Receiver.V.(PointerValue); ok { - debug2.Println2("pointer value, pv: ", pv) - if dt, ok := pv.TV.T.(*DeclaredType); ok { - debug2.Println2("---2, dt: ", dt) - if IsRealmPath(dt.PkgPath) { - originPkg = PkgIDFromPkgPath(dt.PkgPath) - } - } - debug2.Println2("originPkg; ", originPkg) + originPkg = getPkgId(pv.TV.T) } return case *MapValue, *StructValue: - if dt, ok := tv.T.(*DeclaredType); ok { - debug2.Printf2("---dt: %v\n", dt) - debug2.Println2("---dt.base: ", dt.Base) - if _, ok := dt.Base.(*FuncType); !ok { - debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) - if IsRealmPath(dt.Base.GetPkgPath()) { - originPkg = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - } - } - } + originPkg = getPkgId(tv.T) return default: // do nothing diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 74e991b1d6c..c3949682852 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -265,9 +265,11 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { // checkCrossRealm check cross realm recursively func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { - fmt.Println("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + debug2.Println2("refValue: ", refValue) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("oo.GetObjectInfo: ", oo.GetObjectInfo()) + switch v := oo.(type) { case *StructValue: if !v.GetIsReal() { @@ -283,7 +285,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { case *MapValue: // TODO: check recursively case *BoundMethodValue: - // TODO: check recursively + // TODO: check case *Block: // XXX, can this happen? if !v.GetIsRef() { @@ -315,8 +317,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { // MarkNewEscapedCheckCrossRealm check for escaped object func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { - //fmt.Println("MarkNewEscapedCheckCrossRealm, oo: ", oo) - //fmt.Println("refValue: ", refValue) + debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) //fmt.Println("oo.GetOriginRealm(): ", oo.GetOriginRealm()) //fmt.Println("rlm.ID: ", rlm.ID) @@ -555,6 +556,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("---oo.GetObjectID: ", oo.GetObjectInfo()) + debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) if debug { if oo.GetIsDirty() { @@ -567,7 +569,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // XXX, oo must be new real here, it's not escaped // if it's reference, all right - debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { if oo.GetIsRef() { panic("cannot attach a reference to an unreal object from an external realm") @@ -576,7 +577,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } - debug2.Println2("oo.GetObjectID(): ", oo.GetObjectID()) // RECURSE GUARD // if id already set, skip. // this happens when a node marked created was already diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 3ab0e700ec7..4c9ea8ae85d 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -213,7 +213,6 @@ func (pv *PointerValue) GetBase(store Store) Object { func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { debug2.Println2("Assign2, pv: ", pv) debug2.Println2("tv2: ", tv2) - debug2.Printf2("addr of tv2: %p \n", &tv2) debug2.Println2("rlm: ", rlm) // Special cases. @@ -291,15 +290,13 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo1 := pv.TV.GetFirstObject(store) debug2.Println2("---oo1: ", oo1) - // get origin pkgId + // get origin pkgId, this should happen before assign, + // because assign will discard original object info originPkg := tv2.GetOriginPkg(store) debug2.Println2("originPkg: ", originPkg) pv.TV.Assign(alloc, tv2, cu) - // get origin pkgId, this should happen before assign, - // because assign will discard original object info - oo2 := pv.TV.GetFirstObject(store) debug2.Println2("oo2: ", oo2) @@ -548,8 +545,6 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - //debug2.Println2("sv.ObjectInfo", sv.ObjectInfo) - //nsv.ObjectInfo = sv.ObjectInfo.Copy() debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) @@ -1085,7 +1080,6 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { cp.T = tv.T cp.V = cv.Copy(alloc) default: - debug2.Println2("---default") cp = tv } return @@ -2673,7 +2667,7 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - debug2.Println2("fillValueTV, tv: ", tv) + debug2.Println2("fillValueTV, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case RefValue: if cv.PkgPath != "" { // load package @@ -2690,14 +2684,11 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { // but for execution speed traded off for // loading speed, we do the following for now: if ref, ok := cv.Base.(RefValue); ok { - //fmt.Println("---cv.Base: ", ref) base := store.GetObject(ref.ObjectID).(Value) - //fmt.Println("---base: ", base) cv.Base = base switch cb := base.(type) { case *ArrayValue: et := baseOf(tv.T).(*PointerType).Elt - fmt.Println("---et: ", et) epv := cb.GetPointerAtIndexInt2(store, cv.Index, et) cv.TV = epv.TV // TODO optimize? (epv.* ignored) case *StructValue: From 119e505deabbc598273087b6df3de427ef73c337 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 13 Jan 2025 13:09:16 +0800 Subject: [PATCH 41/88] fixup --- examples/gno.land/p/demo/tests/tests.gno | 4 + examples/gno.land/p/demo/tests/tests2.gno | 5 -- gnovm/pkg/gnolang/machine.go | 55 +++++--------- gnovm/pkg/gnolang/op_call.go | 2 +- gnovm/pkg/gnolang/op_decl.go | 4 +- gnovm/pkg/gnolang/ownership.go | 85 +++++++++++----------- gnovm/pkg/gnolang/realm.go | 2 +- gnovm/tests/files/zrealm_crossrealm28.gno | 12 ++- gnovm/tests/files/zrealm_crossrealm28d.gno | 30 ++++++++ gnovm/tests/files/zrealm_crossrealm28e.gno | 30 ++++++++ 10 files changed, 132 insertions(+), 97 deletions(-) delete mode 100644 examples/gno.land/p/demo/tests/tests2.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28d.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28e.gno diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno index 43732d82dac..341f6a78bb6 100644 --- a/examples/gno.land/p/demo/tests/tests.gno +++ b/examples/gno.land/p/demo/tests/tests.gno @@ -8,6 +8,10 @@ import ( rtests "gno.land/r/demo/tests" ) +type Foo struct{ name string } + +var F = Foo{"p"} + const World = "world" // IncCounter demonstrates that it's possible to call a realm function from diff --git a/examples/gno.land/p/demo/tests/tests2.gno b/examples/gno.land/p/demo/tests/tests2.gno deleted file mode 100644 index eeb3fe0ffa5..00000000000 --- a/examples/gno.land/p/demo/tests/tests2.gno +++ /dev/null @@ -1,5 +0,0 @@ -package tests - -type Foo struct{ name string } - -var F = Foo{"p"} diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 3cbc6f3a864..62374cef045 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -217,7 +217,6 @@ func (m *Machine) SetActivePackage(pv *PackageValue) { } m.Package = pv m.Realm = pv.GetRealm() - //fmt.Println("---SetActivePackage, m.Realm", m.Realm) m.Blocks = []*Block{ pv.GetBlock(m.Store), } @@ -325,9 +324,6 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (* // store mempackage m.Store.AddMemPackage(memPkg) if throwaway != nil { - debug2.Println2("m.Realm: ", m.Realm) - debug2.Println2("m.Realm created: ", m.Realm.created) - debug2.Println2("m.Realm updated: ", m.Realm.updated) m.Realm = nil } } @@ -485,27 +481,25 @@ func (m *Machine) TestFunc(t *testing.T, tv TypedValue) { // Stacktrace returns the stack trace of the machine. // It collects the executions and frames from the machine's frames and statements. func (m *Machine) Stacktrace() (stacktrace Stacktrace) { - if len(m.Frames) == 0 { + if len(m.Frames) == 0 || len(m.Stmts) == 0 { return } calls := make([]StacktraceCall, 0, len(m.Stmts)) var nextStmtIndex int - if len(m.Stmts) > 0 { - nextStmtIndex = len(m.Stmts) - 1 - for i := len(m.Frames) - 1; i >= 0; i-- { - if m.Frames[i].IsCall() { - stm := m.Stmts[nextStmtIndex] - bs := stm.(*bodyStmt) - stm = bs.Body[bs.NextBodyIndex-1] - calls = append(calls, StacktraceCall{ - Stmt: stm, - Frame: m.Frames[i], - }) - } - // if the frame is a call, the next statement is the last statement of the frame. - nextStmtIndex = m.Frames[i].NumStmts - 1 + nextStmtIndex = len(m.Stmts) - 1 + for i := len(m.Frames) - 1; i >= 0; i-- { + if m.Frames[i].IsCall() { + stm := m.Stmts[nextStmtIndex] + bs := stm.(*bodyStmt) + stm = bs.Body[bs.NextBodyIndex-1] + calls = append(calls, StacktraceCall{ + Stmt: stm, + Frame: m.Frames[i], + }) } + // if the frame is a call, the next statement is the last statement of the frame. + nextStmtIndex = m.Frames[i].NumStmts - 1 } // if the stacktrace is too long, we trim it down to maxStacktraceSize @@ -750,21 +744,19 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Save the machine's package using realm finalization deep crawl. // Also saves declared types. // This happens before any init calls. -// Returns a throwaway realm package is not a realm, +// Returns a throwaway realm package if not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { - debug2.Println2("saveNewPackageValuesAndTypes") // save package value and dependencies. pv := m.Package + debug2.Println2("saveNewPackageValuesAndTypes, pv is realm? ", pv.IsRealm()) if pv.IsRealm() { - debug2.Println2("pv is realm") rlm := pv.Realm rlm.MarkNewReal(pv) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // save package realm info. m.Store.SetPackageRealm(rlm) } else { // use a throwaway realm. - debug2.Println2("pv not realm") rlm := NewRealm(pv.PkgPath) rlm.MarkNewReal(pv) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -1855,8 +1847,7 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { - debug2.Println2("PushFrameCall, cx: ", cx) - //fmt.Println("---fv: ", fv) + debug2.Println2("PushFrameCall, CallExpr: ", cx) debug2.Println2("m.Realm: ", m.Realm) fr := &Frame{ Source: cx, @@ -1898,10 +1889,7 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { recvOID := obj.GetObjectInfo().ID debug2.Println2("---recvOID is: ", recvOID) if recvOID.IsZero() { - debug2.Println2("!!! recvOID is ZERO!!!") debug2.Println2("---recv is ZERO, it's not owned, recv: ", recv) - debug2.Println2("---recv is ZERO, m.realm: ", m.Realm) - // receiver isn't owned yet. // just continue with current package and realm. // XXX is this reasonable? @@ -1913,21 +1901,12 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { } } } else { - //fmt.Println("---receiver not defined") + debug2.Println2("receiver not defined") pv := fv.GetPackage(m.Store) if pv == nil { panic(fmt.Sprintf("package value missing in store: %s", fv.PkgPath)) } - //fmt.Println("---pv: ", pv) - //fmt.Println("---pv: ", pv.Realm) - //fmt.Println("---PkgPath: ", pv.PkgPath) - - //fmt.Println("---1, m.Realm : ", m.Realm) - //if IsRealmPath(pv.PkgPath) { - // println("---isRealmPath") - //} m.setCurrentPackage(pv) // maybe new realm - //fmt.Println("---2, m.Realm : ", m.Realm) } } diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index c7cbe5e176d..0473404e6cb 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -239,7 +239,7 @@ func (m *Machine) doOpReturnFromBlock() { finalize = true } if finalize { - debug2.Println2("doOpReturnFromBlock, finalizing") + debug2.Println2("finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) diff --git a/gnovm/pkg/gnolang/op_decl.go b/gnovm/pkg/gnolang/op_decl.go index 13ad455fc53..62682cb43c3 100644 --- a/gnovm/pkg/gnolang/op_decl.go +++ b/gnovm/pkg/gnolang/op_decl.go @@ -19,7 +19,6 @@ func (m *Machine) doOpValueDecl() { for i := 0; i < len(s.NameExprs); i++ { var tv TypedValue if rvs == nil { - debug2.Println2("rvs is nil, using default value") // NOTE: Go/Gno wart. // implicit interface casting could // requiring the consideration of the typed-nil case. @@ -28,6 +27,7 @@ func (m *Machine) doOpValueDecl() { } else { tv = TypedValue{T: nt, V: defaultValue(m.Alloc, nt)} } + debug2.Println2("rvs is nil, using default value,: ", tv) } else { tv = rvs[i] } @@ -44,7 +44,7 @@ func (m *Machine) doOpValueDecl() { } else { if debug { if nt.TypeID() != tv.T.TypeID() && - baseOf(nt).TypeID() != tv.T.TypeID() { + baseOf(nt).TypeID() != tv.T.TypeID() { panic(fmt.Sprintf( "type mismatch: %s vs %s", nt.TypeID(), diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 18d3d1c2a0e..a9dc82a3efb 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -160,13 +160,13 @@ 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, - originRealm: oi.originRealm, + ID: oi.ID, + Hash: oi.Hash.Copy(), + OwnerID: oi.OwnerID, + ModTime: oi.ModTime, + RefCount: oi.RefCount, + IsEscaped: oi.IsEscaped, + //originRealm: oi.originRealm, /* // XXX do the following need copying too? isDirty: oi.isDirty, @@ -396,55 +396,54 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) if obj != nil { originPkg = obj.GetOriginRealm() - if originPkg.IsZero() { - originPkg = obj.GetObjectID().PkgID + if !originPkg.IsZero() { + return + } + originPkg = obj.GetObjectID().PkgID + if !originPkg.IsZero() { + return } - debug2.Println2("obj.GetObjectInfo(): ", obj.GetObjectInfo()) } - debug2.Println2("obj.originPkg: ", originPkg) // get pkgId from type getPkgId := func(t Type) (pkgId PkgID) { - defer debug2.Println2("getPkgId: ", pkgId) if dt, ok := t.(*DeclaredType); ok { - debug2.Printf2("dt: %v, dt.Base: \n", dt, dt.Base) - if _, ok := dt.Base.(*FuncType); !ok { - debug2.Println2("---dt.base.PkgPath: ", dt.Base.GetPkgPath()) - if IsRealmPath(dt.Base.GetPkgPath()) { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - return - } + debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) + if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + return } } return } // if still zero - if originPkg.IsZero() { - switch cv := obj.(type) { - case *ArrayValue: - if IsRealmPath(tv.T.Elem().GetPkgPath()) { - originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) - } - return - case *Block: - originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) - return - case *HeapItemValue: - originPkg = getPkgId(cv.Value.T) - return - case *BoundMethodValue: - debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) - if pv, ok := cv.Receiver.V.(PointerValue); ok { - originPkg = getPkgId(pv.TV.T) - } - return - case *MapValue, *StructValue: - originPkg = getPkgId(tv.T) - return - default: - // do nothing + switch cv := obj.(type) { + case *ArrayValue: + // if array is real, retrieved from objectID, + // otherwise, it's retrieved from elem type. + // it panics while attach this kind of slice/array value: `var fs []crossrealm.Fooer`, + if IsRealmPath(tv.T.Elem().GetPkgPath()) { + originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) } + return + case *Block: + originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + return + case *HeapItemValue: + originPkg = getPkgId(cv.Value.T) + return + case *BoundMethodValue: + debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) + if pv, ok := cv.Receiver.V.(PointerValue); ok { + originPkg = getPkgId(pv.TV.T) + } + return + case *MapValue, *StructValue: + originPkg = getPkgId(tv.T) + return + default: + // do nothing } return } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index c3949682852..5f6e8070194 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -555,7 +555,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---incRefCreatedDescendants from oo: ", oo) debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("---oo.GetObjectID: ", oo.GetObjectInfo()) + debug2.Println2("---oo.GetObjectInfo: ", oo.GetObjectInfo()) debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) if debug { diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28.gno index ad69b0318be..11e7ce1dd35 100644 --- a/gnovm/tests/files/zrealm_crossrealm28.gno +++ b/gnovm/tests/files/zrealm_crossrealm28.gno @@ -13,16 +13,14 @@ type foo struct { func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -// XXX, consider this +// XXX, no attach, default value is nil for slice var fs []crossrealm.Fooer func init() { - //fs = append(fs, foo{name: "1"}) // type of elem is from external realm - //s1 := []crossrealm.Fooer{foo{name: "s1"}} - //r := append(fs, s1) - - r := append(fs, foo{name: "1"}) // type of elem is from external realm, but no panic since no attach - fs = r // panic while attach + r := append(fs, foo{name: "1"}) + // while attaching underlying arrayValue(the object), + // it panics since the array type if from external realm + fs = r } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno new file mode 100644 index 00000000000..a3cdc28b7ee --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -0,0 +1,30 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +func main() { + var Local_S []crossrealm.Fooer // XXX, the array object should be in current realm + Local_S = append(Local_S, &foo{name: "1"}) + Local_S = append(Local_S, &foo{name: "2"}) + Local_S = append(Local_S, &foo{name: "3"}) + + fs := Local_S[1:] + crossrealm.SetSlice(fs) + println("ok") +} + +// Output: +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28e.gno b/gnovm/tests/files/zrealm_crossrealm28e.gno new file mode 100644 index 00000000000..016abdb5a7f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28e.gno @@ -0,0 +1,30 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type foo struct { + name string +} + +func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +// XXX, no attach, default value is nil for slice +var fs []crossrealm.Fooer + +func init() { + r := append(fs, &foo{name: "1"}) + // while attaching underlying arrayValue(the object), + // it panics since the array type if from external realm + fs = r +} + +func main() { +} + +// Error: +// cannot attach a reference to an unreal object from an external realm From 91a38af9aeef14e0e907a98f21ad612c59ae26e8 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 13 Jan 2025 17:10:05 +0800 Subject: [PATCH 42/88] clean --- .../tests/crossrealm/map/crossrealm_map.gno | 16 + .../crossrealm/slice/crossrealm_slice.gno | 16 + gnovm/pkg/gnolang/op_decl.go | 2 +- gnovm/pkg/gnolang/ownership.go | 2 + gnovm/pkg/gnolang/preprocess.go | 1 + gnovm/pkg/gnolang/realm.go | 62 +-- gnovm/pkg/gnolang/store.go | 3 - gnovm/pkg/gnolang/values.go | 24 +- gnovm/tests/files/zrealm_crossrealm28f.gno | 28 ++ gnovm/tests/files/zrealm_crossrealm28g.gno | 26 ++ gnovm/tests/files/zrealm_crossrealm32.gno | 420 ++++++++++++++++-- gnovm/tests/files/zrealm_crossrealm37a.gno | 18 + gnovm/tests/files/zrealm_crossrealm37b.gno | 14 + 13 files changed, 536 insertions(+), 96 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm28f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28g.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm37a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm37b.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno index eff818c6fdf..752b2d7ecd1 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno @@ -10,3 +10,19 @@ func init() { func GetMap() map[string]int { return m } + +func GetMap2(f func(map[string]int)) { + m1 := map[string]int{"a": 1} + f(m1) +} + +// -------------------------------------- +type MyMap map[string]int + +var m2 = MyMap{"a": 1} + +func GetMap3() MyMap { + return m2 +} + +// TODO: add some map with elements of object diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index 446ff265ab4..b1822fb45a4 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -29,6 +29,8 @@ var s6 = make([]*XYZ, 2) var s7 [2]XYZ +var s10 []int + func init() { s1 = append(s1, XYZ{"1"}) s1 = append(s1, XYZ{"2"}) @@ -43,6 +45,7 @@ func init() { s7[0] = XYZ{"7"} s7[1] = XYZ{"7.1"} // should be real after this + s10 = append(s10, 1) } func GetSlice() []XYZ { @@ -97,3 +100,16 @@ func GetSlice9(f p_crossrealm.Stringer) [1]p_crossrealm.Stringer { s9[0] = f return s9 } + +// XXX, s10 under array is real, and owned by this realm. +func GetSlice10() []int { + return s10 +} + +func GetSlice11(f func(s []int)) { + // XXX, this is valid cuz the type of + // array is not defined in current realm(or any other), + // and the underlying array is not owned by this realm. + s11 := []int{1} + f(s11) +} diff --git a/gnovm/pkg/gnolang/op_decl.go b/gnovm/pkg/gnolang/op_decl.go index 62682cb43c3..aa59a2c0324 100644 --- a/gnovm/pkg/gnolang/op_decl.go +++ b/gnovm/pkg/gnolang/op_decl.go @@ -44,7 +44,7 @@ func (m *Machine) doOpValueDecl() { } else { if debug { if nt.TypeID() != tv.T.TypeID() && - baseOf(nt).TypeID() != tv.T.TypeID() { + baseOf(nt).TypeID() != tv.T.TypeID() { panic(fmt.Sprintf( "type mismatch: %s vs %s", nt.TypeID(), diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index a9dc82a3efb..f915450a4be 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -395,6 +395,8 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { obj := tv.GetFirstObject(store) debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) if obj != nil { + // origin realm maybe set while association, even + // it's un-real. originPkg = obj.GetOriginRealm() if !originPkg.IsZero() { return diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index ba60ead28f6..9f596d38381 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1753,6 +1753,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { } pn := pv.GetPackageNode(store) // ensure exposed or package path match. + fmt.Println("---n, n.Sel: ", n, n.Sel) if !isUpper(string(n.Sel)) && lastpn.PkgPath != pv.PkgPath { panic(fmt.Sprintf("cannot access %s.%s from %s", pv.PkgPath, n.Sel, lastpn.PkgPath)) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 5f6e8070194..3d37b9c7a87 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -146,7 +146,7 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } } - if po == nil || !po.GetIsReal() { // XXX, make sure po is attached + if po == nil || !po.GetIsReal() { // XXX, make sure po is real return // do nothing. } @@ -178,7 +178,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - debug2.Println2("---rlm.ID: ", rlm.ID) + debug2.Println2("rlm.ID: ", rlm.ID) if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) } @@ -221,7 +221,6 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { rlm.MarkDirty(po) if co != nil { - //fmt.Println("---co.GetRefCount: ", co.GetRefCount()) // XXX, inc ref count everytime assignment happens co.IncRefCount() if co.GetRefCount() > 1 { @@ -230,7 +229,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { rlm.MarkDirty(co) } else { co.SetOwner(po) - rlm.MarkNewReal(co) // co will be attached when finalize + rlm.MarkNewReal(co) } } @@ -244,26 +243,24 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { } } -//---------------------------------------- -// mark* - func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { - debug2.Printf2("checkCrossRealm2, tv: %v\n", tv) + debug2.Printf2("checkCrossRealm2, tv: %v\n", tv, reflect.TypeOf(tv.V)) if fo, ok := tv.V.(Object); ok { checkCrossRealm(rlm, store, fo, nil) } else { // reference to object - //var reo Object switch rv := tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm // XXX: consider pkgId here, A -> B - > A?... reo := tv.GetFirstObject(store) - debug2.Println2("reo: ", reo) checkCrossRealm(rlm, store, reo, rv) } } + // else nothing to do } -// checkCrossRealm check cross realm recursively +// checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. +// refValue is required to handle cases where the value is a slice. +// The `len` and `offset` are needed to validate proper elements the underlying array. func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("refValue: ", refValue) @@ -272,7 +269,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { switch v := oo.(type) { case *StructValue: - if !v.GetIsReal() { + if !v.GetIsReal() { // it's possible that embedded in another container if rlm.ID != oo.GetOriginRealm() { // it's ok for un-real object from same realm panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", v)) } @@ -283,9 +280,9 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { checkCrossRealm2(rlm, store, rfv) } case *MapValue: - // TODO: check recursively + // TODO: complete this case *BoundMethodValue: - // TODO: check + // TODO: complete this case *Block: // XXX, can this happen? if !v.GetIsRef() { @@ -298,13 +295,9 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { checkCrossRealm2(rlm, store, &v.Value) case *ArrayValue: if sv, ok := refValue.(*SliceValue); ok { - debug2.Println2("ArrayValue: ", v) - debug2.Println2("SliceValue: ", sv) // only check referenced elem for i := sv.Offset; i < sv.Length; i++ { e := fillValueTV(store, &v.List[i]) - debug2.Printf2("e[%d]: %v\n", i, e) - debug2.Printf2("type of e[%d].V: %v\n", i, reflect.TypeOf(e.V)) checkCrossRealm2(rlm, store, e) } } else { @@ -315,11 +308,15 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { } } -// MarkNewEscapedCheckCrossRealm check for escaped object +//---------------------------------------- +// mark* + +// MarkNewEscapedCheckCrossRealm mark new escaped object +// and check cross realm func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) - //fmt.Println("oo.GetOriginRealm(): ", oo.GetOriginRealm()) - //fmt.Println("rlm.ID: ", rlm.ID) + debug2.Println2("oo.GetOriginRealm(): ", oo.GetOriginRealm()) + debug2.Println2("rlm.ID: ", rlm.ID) if oo.GetOriginRealm() == rlm.ID { // do nothing @@ -373,8 +370,6 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - //debug2.Printf2("---current rlm: %v: \n", rlm) - //debug2.Printf2("---Mark Dirty %v: \n", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -415,7 +410,6 @@ func (rlm *Realm) MarkNewDeleted(oo Object) { } func (rlm *Realm) MarkNewEscaped(oo Object) { - //fmt.Println("---MarkNewEscaped---, oo: ", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsReal() { panic("cannot mark unreal object as new escaped") @@ -604,10 +598,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - debug2.Println2("---rc after inc: ", rc) + debug2.Println2("rc after inc: ", rc) if rc == 1 { if child.GetIsReal() { - //fmt.Println("---child is real, child: ", child) // a deleted real became undeleted. child.SetOwner(oo) rlm.MarkDirty(child) @@ -616,8 +609,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // became real (again). // NOTE: may already be marked for first gen // newCreated or updated. - //fmt.Println("---Set owner to be: ", oo) - //println("---set owner") child.SetOwner(oo) rlm.incRefCreatedDescendants(store, child) child.SetIsNewReal(true) @@ -630,7 +621,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // may become unescaped later // in processNewEscapedMarks(). // NOTE: may already be escaped. - //fmt.Println("---in recursive, mark new escaped, child: ", child) rlm.MarkNewEscaped(child) } } else { @@ -648,9 +638,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // to rlm.deleted. // Must run *after* processNewCreatedMarks(). func (rlm *Realm) processNewDeletedMarks(store Store) { - //fmt.Println("---processNewDeletedMarks---") for _, oo := range rlm.newDeleted { - //fmt.Println("---oo: ", oo, oo.GetRefCount()) if debug { if oo.GetObjectID().IsZero() { panic("new deleted mark should have an object ID") @@ -713,7 +701,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) { - //fmt.Println("---processNewEscapedMarks---") escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, @@ -722,10 +709,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // except for new-reals that get demoted // because ref-count isn't >= 2. for _, eo := range rlm.newEscaped { - //fmt.Printf("---processNewEscapedMarks, [%d]eo: %v\n", i, eo) - //fmt.Println("---eo.GetLastEscapedRealm: ", eo.GetLastNewEscapedRealm()) - //fmt.Println("---eo.GetRefCount(): ", eo.GetRefCount()) - //fmt.Println("---rlm.ID: ", rlm.ID) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -781,7 +764,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (ancestors) must be marked as dirty to update the // hash tree. func (rlm *Realm) markDirtyAncestors(store Store) { - //fmt.Println("---markDirtyAncestors---") markAncestorsOne := func(oo Object) { for { if pv, ok := oo.(*PackageValue); ok { @@ -850,9 +832,7 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - debug2.Println2("saveUnsavedObjects") for _, co := range rlm.created { - debug2.Println2("co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { @@ -864,8 +844,6 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { } } for _, uo := range rlm.updated { - debug2.Println2("uo: ", uo) - // uo := rlm.updated[i] if !uo.GetIsDirty() { // might have happened already as child // of something else created/dirty. @@ -935,7 +913,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) { debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() debug2.Println2("---oid: ", oid) - debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index afabd70987b..7cd5bd56a1e 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -400,9 +400,7 @@ func (ds *defaultStore) DelObject(oo Object) { // NOTE: The implementation matches that of GetObject() in anticipation of what // the persistent type system might work like. func (ds *defaultStore) GetType(tid TypeID) Type { - debug2.Println2("GetType: ", tid) tt := ds.GetTypeSafe(tid) - debug2.Println2("tt: ", tt) if tt == nil { ds.Print() panic(fmt.Sprintf("unexpected type with id %s", tid.String())) @@ -411,7 +409,6 @@ func (ds *defaultStore) GetType(tid TypeID) Type { } func (ds *defaultStore) GetTypeSafe(tid TypeID) Type { - debug2.Println2("GetTypeSafe: ", tid) // check cache. if tt, exists := ds.cacheTypes[tid]; exists { return tt diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 4c9ea8ae85d..faa8a38e91b 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -288,7 +288,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - debug2.Println2("---oo1: ", oo1) + debug2.Println2("oo1: ", oo1) // get origin pkgId, this should happen before assign, // because assign will discard original object info @@ -300,7 +300,9 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo2 := pv.TV.GetFirstObject(store) debug2.Println2("oo2: ", oo2) - // refValue checks for embedded values in the base + // refValue is needed for checking + // proper element in the base. + // e.g. refValue is a sliceValue var refValue Value switch rv := pv.TV.V.(type) { case *SliceValue, PointerValue: @@ -545,11 +547,15 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) - debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) - debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) - debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) + //debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) + //debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) + //debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) + //debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) // append, unref copy... + + // this copy is needed, + // copy origin realm is necessary here because, for example, if `sv` is an embedded struct, + // assigning the containing struct will also copy the embedded struct. pkgId := sv.GetOriginRealm() if pkgId.IsZero() { pkgId = sv.GetObjectID().PkgID @@ -1064,8 +1070,7 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { - debug2.Println2("Copy, tv: ", tv) - debug2.Println2("Copy, type of tv.V: ", reflect.TypeOf(tv.V)) + debug2.Println2("Copy, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -1915,7 +1920,6 @@ func (tv *TypedValue) GetPointerTo(alloc *Allocator, store Store, path ValuePath bmv := &BoundMethodValue{ Func: mv, Receiver: dtv2, - //Receiver: *dtv, } return PointerValue{ TV: &TypedValue{ @@ -2475,9 +2479,7 @@ func (b *Block) GetParent(store Store) *Block { } func (b *Block) GetPointerToInt(store Store, index int) PointerValue { - //fmt.Println("---GetPointerToInt") vv := fillValueTV(store, &b.Values[index]) - //fmt.Println("---vv: ", vv) return PointerValue{ TV: vv, Base: b, diff --git a/gnovm/tests/files/zrealm_crossrealm28f.gno b/gnovm/tests/files/zrealm_crossrealm28f.gno new file mode 100644 index 00000000000..26082c589ee --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28f.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +// XXX, no attach, default value is nil for slice +var local_S []int + +func init() { + local_S = crossrealm.GetSlice10() +} + +func main() { + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28g.gno b/gnovm/tests/files/zrealm_crossrealm28g.gno new file mode 100644 index 00000000000..182f06103cb --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28g.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +// XXX, no attach, default value is nil for slice +var local_S []int + +var f = func(s1 []int) { + local_S = s1 +} + +func init() { + crossrealm.GetSlice11(f) +} + +func main() { + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index f2909115100..de1442fa536 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -19,7 +19,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ // "Fields": [ // { // "T": { @@ -33,13 +33,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", // "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", // "RefCount": "1" // } // } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30]={ // "Fields": [ // { // "T": { @@ -53,13 +53,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30", // "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", // "RefCount": "1" // } // } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27]={ +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28]={ // "Data": null, // "List": [ // { @@ -69,8 +69,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "c6f0c0407c9697a6a91451eb572489913de89e71", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" +// "Hash": "af93d4b8543a4ed0e5c7c020bc2ed88f3cbe9d31", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29" // } // }, // { @@ -80,13 +80,13 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "2a99f0d55ccbad80a109cecd6fa9a0dece4df7cc", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29" +// "Hash": "79476ae559f3c897094485a7a1a1cfad0bd14b38", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30" // } // } // ], // "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27", +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", // "ModTime": "0", // "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "1" @@ -97,7 +97,7 @@ func main() { // "ObjectInfo": { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "IsEscaped": true, -// "ModTime": "26", +// "ModTime": "27", // "RefCount": "2" // }, // "Parent": null, @@ -280,8 +280,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "c1cb1b78808a97bdeb22bdb8fe51cbc5ebe27c15", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// "Hash": "3e372219527365f54e2d7651766ad31532018029", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" // }, // "Length": "2", // "Maxcap": "2", @@ -375,6 +375,27 @@ func main() { // }, // { // "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "c67ad4d6692a614a475d6b0665309fc1209dba62", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { // "@type": "/gno.FuncType", // "Params": [], // "Results": [] @@ -388,7 +409,7 @@ func main() { // }, // "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "init.10", +// "Name": "init.11", // "NativeName": "", // "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", @@ -398,7 +419,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "32", +// "Line": "34", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -448,7 +469,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "48", +// "Line": "51", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -534,7 +555,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "56", +// "Line": "59", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -598,7 +619,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "64", +// "Line": "67", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -673,7 +694,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "69", +// "Line": "72", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -751,7 +772,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "74", +// "Line": "77", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -832,7 +853,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "78", +// "Line": "81", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -922,7 +943,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "83", +// "Line": "86", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1025,7 +1046,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "90", +// "Line": "93", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1111,7 +1132,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "95", +// "Line": "98", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1146,6 +1167,156 @@ func main() { // ] // } // } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice10", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "105", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice11", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "109", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } // } // ] // } @@ -1186,7 +1357,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" // }, // "Length": "2", // "Maxcap": "2", @@ -1420,7 +1591,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" // }, // "Length": "2", // "Maxcap": "2", @@ -1514,6 +1685,27 @@ func main() { // }, // { // "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "c67ad4d6692a614a475d6b0665309fc1209dba62", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { // "@type": "/gno.FuncType", // "Params": [], // "Results": [] @@ -1527,7 +1719,7 @@ func main() { // }, // "FileName": "crossrealm_slice.gno", // "IsMethod": false, -// "Name": "init.10", +// "Name": "init.11", // "NativeName": "", // "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", @@ -1537,7 +1729,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "32", +// "Line": "34", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1587,7 +1779,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "48", +// "Line": "51", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1673,7 +1865,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "56", +// "Line": "59", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1737,7 +1929,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "64", +// "Line": "67", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1812,7 +2004,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "69", +// "Line": "72", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1890,7 +2082,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "74", +// "Line": "77", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -1971,7 +2163,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "78", +// "Line": "81", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2061,7 +2253,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "83", +// "Line": "86", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2164,7 +2356,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "90", +// "Line": "93", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2250,7 +2442,7 @@ func main() { // "Location": { // "Column": "1", // "File": "crossrealm_slice.gno", -// "Line": "95", +// "Line": "98", // "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" // } // }, @@ -2285,6 +2477,156 @@ func main() { // ] // } // } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice10", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "105", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice11", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "109", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } // } // ] // } diff --git a/gnovm/tests/files/zrealm_crossrealm37a.gno b/gnovm/tests/files/zrealm_crossrealm37a.gno new file mode 100644 index 00000000000..3b5cd30a175 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm37a.gno @@ -0,0 +1,18 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/map" + +var local_m map[string]int + +var f = func(m map[string]int) { + local_m = m +} + +func main() { + crossrealm.GetMap2(f) + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm37b.gno b/gnovm/tests/files/zrealm_crossrealm37b.gno new file mode 100644 index 00000000000..ee29d007215 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm37b.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/map" + +var m1 crossrealm.MyMap + +func main() { + m1 = crossrealm.GetMap() + println(m1) +} + +// Error: +// cannot attach objects by value from external realm From b09f61a8683a76b5282450e35d0773c572d1fdd0 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 13 Jan 2025 18:19:27 +0800 Subject: [PATCH 43/88] fixup{ --- gnovm/pkg/gnolang/debug_false.go | 2 ++ gnovm/pkg/gnolang/preprocess.go | 1 - gnovm/pkg/gnolang/realm.go | 7 +----- gnovm/pkg/gnolang/store.go | 6 ----- gnovm/pkg/gnolang/uverse.go | 6 ----- ...14_stdlibs.gno => zrealm_crossrealm14.gno} | 0 gnovm/tests/files/zrealm_crossrealm15.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 2 +- gnovm/tests/files/zrealm_crossrealm18.gno | 10 ++++---- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm2.gno | 8 ++----- gnovm/tests/files/zrealm_crossrealm22a.gno | 23 +++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm23a.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm23b.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm24.gno | 8 +++---- gnovm/tests/files/zrealm_crossrealm24d.gno | 8 +++---- gnovm/tests/files/zrealm_crossrealm27.gno | 8 +++---- gnovm/tests/files/zrealm_crossrealm3.gno | 2 +- gnovm/tests/files/zrealm_crossrealm32.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm34.gno | 4 ++-- gnovm/tests/files/zrealm_crossrealm35a.gno | 8 +++---- gnovm/tests/files/zrealm_crossrealm5.gno | 6 ++--- 23 files changed, 64 insertions(+), 63 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm14_stdlibs.gno => zrealm_crossrealm14.gno} (100%) create mode 100644 gnovm/tests/files/zrealm_crossrealm22a.gno diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index 8252bde3abf..bf213870a3a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,4 +4,6 @@ package gnolang const debug debugging = false +//const debug2 debugging = true + const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 1b722cd43f9..79695d8888a 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1900,7 +1900,6 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node { } pn := pv.GetPackageNode(store) // ensure exposed or package path match. - fmt.Println("---n, n.Sel: ", n, n.Sel) if !isUpper(string(n.Sel)) && lastpn.PkgPath != pv.PkgPath { panic(fmt.Sprintf("cannot access %s.%s from %s", pv.PkgPath, n.Sel, lastpn.PkgPath)) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 83341f2db93..6aa56636c33 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -463,17 +463,14 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { // to a realm gets attached here, which should panic. // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { -<<<<<<< HEAD debug2.Println2("FinalizeRealmTransaction, rlm.ID: ", rlm.ID) defer func() { debug2.Println2("================done FinalizeRealmTransaction==================") }() -======= if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() } ->>>>>>> main/master if readonly { if true || len(rlm.newCreated) > 0 || @@ -580,7 +577,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---incRefCreatedDescendants from oo: ", oo) debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("---oo.GetObjectInfo: ", oo.GetObjectInfo()) + debug2.Println2("---rlm.ID: ", rlm.ID) debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) if debug { @@ -773,14 +770,12 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // will be saved regardless. } else { // exists, mark dirty. - //fmt.Println("---exists, mark dirty, po: ", po) rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { panic("new escaped mark has no object ID") } // escaped has no owner. - //println("---escaped has no owner") eo.SetOwner(nil) } } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 8fd2c79a65b..37babf43e1b 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -430,9 +430,7 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { -<<<<<<< HEAD debug2.Println2("loadObjectSafe, oid: ", oid) -======= if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -446,7 +444,6 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { bm.StopStore(size) }() } ->>>>>>> main/master key := backendObjectKey(oid) hashbz := ds.baseStore.Get([]byte(key)) if hashbz != nil { @@ -475,9 +472,7 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { -<<<<<<< HEAD debug2.Println2("SetObject: ", oo) -======= if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -489,7 +484,6 @@ func (ds *defaultStore) SetObject(oo Object) { bm.StopStore(size) }() } ->>>>>>> main/master oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index 008b1e296de..ad5c4c1664b 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -416,15 +416,9 @@ func makeUverseNode() { return } else { // append(*SliceValue, *SliceValue) new list --------- -<<<<<<< HEAD - debug2.Println2("new list") - list := make([]TypedValue, arg0Length+arg1Length) - if 0 < arg0Length { -======= arrayLen := arg0Length + arg1Length arrayValue := m.Alloc.NewListArray(arrayLen) if arg0Length > 0 { ->>>>>>> main/master if arg0Base.Data == nil { for i := 0; i < arg0Length; i++ { arrayValue.List[i] = arg0Base.List[arg0Offset+i].unrefCopy(m.Alloc, m.Store) diff --git a/gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm14.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm14_stdlibs.gno rename to gnovm/tests/files/zrealm_crossrealm14.gno diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index b6f38d81abb..e8965ffdcd2 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -24,4 +24,4 @@ func main() { } // Error: -// new escaped mark has no object ID +// cannot attach un-real object from external realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index e1b4001801c..deaa07a5c82 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// new escaped mark has no object ID +// cannot attach un-real object from external realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 9abb918689a..9314ebadd41 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -24,4 +24,4 @@ func main() { } // Error: -// new escaped mark has no object ID +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno index f7a318ed3a0..b067765930c 100644 --- a/gnovm/tests/files/zrealm_crossrealm18.gno +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -11,9 +11,10 @@ type fooer struct{} func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } -var f crossrealm.Fooer = crossrealm.SetFooer(&fooer{}) +var local_fooer = &fooer{} func init() { + var f crossrealm.Fooer = crossrealm.SetFooer(local_fooer) // until now, local_fooer is real crossrealm.CallFooerFoo() } @@ -23,13 +24,10 @@ 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"] diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index a3b864755fd..291ecd7c7a7 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -29,4 +29,4 @@ func main() { } // Error: -// new escaped mark has no object ID +// cannot attach un-real object from external realm: struct{("A" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm2.gno b/gnovm/tests/files/zrealm_crossrealm2.gno index cfcd4e6898c..69f548c7e70 100644 --- a/gnovm/tests/files/zrealm_crossrealm2.gno +++ b/gnovm/tests/files/zrealm_crossrealm2.gno @@ -5,18 +5,14 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is invalid to persist value of external realm types. var somevalue tests.TestRealmObject func init() { - somevalue.Field = "test" } func main() { - // NOTE: but it is invalid to modify it using an external realm function. - tests.ModifyTestRealmObject(&somevalue) - println(somevalue) } // Error: -// cannot modify external-realm or non-realm object +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a.gno b/gnovm/tests/files/zrealm_crossrealm22a.gno new file mode 100644 index 00000000000..c05fa1668f0 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a.gno @@ -0,0 +1,23 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +func main() { + f := crossrealm_b.Fooer + crossrealm.SetFooerGetter(func() crossrealm.Fooer { return f }) + println("ok") +} + +// TODO: consider this and xxx22.gno, xxx21.gno, xxx20.gno +// how about func()int? and func() crossrealm.Fooer? +// check type for param type? +// see also 37a.gno + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm23a.gno b/gnovm/tests/files/zrealm_crossrealm23a.gno index 1865874ca38..31032925a0e 100644 --- a/gnovm/tests/files/zrealm_crossrealm23a.gno +++ b/gnovm/tests/files/zrealm_crossrealm23a.gno @@ -106,7 +106,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm23a.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -117,7 +117,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm23a.gno", // "Line": "8", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm23b.gno b/gnovm/tests/files/zrealm_crossrealm23b.gno index 29b94f4cb76..b4265ac467a 100644 --- a/gnovm/tests/files/zrealm_crossrealm23b.gno +++ b/gnovm/tests/files/zrealm_crossrealm23b.gno @@ -81,7 +81,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm23b.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -92,7 +92,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm23b.gno", // "Line": "8", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 09d0d761abc..0f8f96a0cfe 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -152,7 +152,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm24.gno", // "IsMethod": false, // "Name": "init.3", // "NativeName": "", @@ -163,7 +163,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm24.gno", // "Line": "16", // "PkgPath": "gno.land/r/crossrealm_test" // } @@ -188,7 +188,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm24.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -199,7 +199,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm24.gno", // "Line": "19", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno index 29c8719fa93..8a7a10411e0 100644 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -151,7 +151,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm24d.gno", // "IsMethod": false, // "Name": "init.3", // "NativeName": "", @@ -162,7 +162,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm24d.gno", // "Line": "16", // "PkgPath": "gno.land/r/crossrealm_test" // } @@ -187,7 +187,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm24d.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -198,7 +198,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm24d.gno", // "Line": "18", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno index c3c437ab04b..0ed782fd49d 100644 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ b/gnovm/tests/files/zrealm_crossrealm27.gno @@ -145,7 +145,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm27.gno", // "IsMethod": true, // "Name": "Foo", // "NativeName": "", @@ -156,7 +156,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm27.gno", // "Line": "14", // "PkgPath": "gno.land/r/crossrealm_test" // } @@ -208,7 +208,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm27.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -219,7 +219,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm27.gno", // "Line": "18", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm3.gno b/gnovm/tests/files/zrealm_crossrealm3.gno index 6aa9c5247d8..e0c800aa624 100644 --- a/gnovm/tests/files/zrealm_crossrealm3.gno +++ b/gnovm/tests/files/zrealm_crossrealm3.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot modify external-realm or non-realm object +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index de1442fa536..67d6cd36063 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -1377,7 +1377,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm32.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -1388,7 +1388,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm32.gno", // "Line": "12", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno index 75abe495d4d..ea977b3a707 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -77,7 +77,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm34.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -88,7 +88,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm34.gno", // "Line": "12", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno index 425308042fd..e11a09378b0 100644 --- a/gnovm/tests/files/zrealm_crossrealm35a.gno +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -134,7 +134,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm35a.gno", // "IsMethod": true, // "Name": "String", // "NativeName": "", @@ -145,7 +145,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm35a.gno", // "Line": "14", // "PkgPath": "gno.land/r/crossrealm_test" // } @@ -234,7 +234,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" // }, -// "FileName": "main.gno", +// "FileName": "files/zrealm_crossrealm35a.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -245,7 +245,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "main.gno", +// "File": "files/zrealm_crossrealm35a.gno", // "Line": "20", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm5.gno b/gnovm/tests/files/zrealm_crossrealm5.gno index d536a7331e5..c7560b21463 100644 --- a/gnovm/tests/files/zrealm_crossrealm5.gno +++ b/gnovm/tests/files/zrealm_crossrealm5.gno @@ -5,8 +5,8 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is invalid to persist external realm types. -var somevalue tests.TestRealmObject +// NOTE: it is valid to persist external realm types. +var somevalue *tests.TestRealmObject func init() { somevalue = &tests.TestRealmObjectValue @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot modify external-realm or non-realm object From aa06af6aeffe3581c06c56934e9d0e15a8795948 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 13 Jan 2025 23:53:39 +0800 Subject: [PATCH 44/88] func value check --- gnovm/pkg/gnolang/debug_false.go | 3 +- gnovm/pkg/gnolang/op_call.go | 1 - gnovm/pkg/gnolang/ownership.go | 21 +++- gnovm/pkg/gnolang/realm.go | 86 ++++++++++----- gnovm/pkg/gnolang/values.go | 9 +- gnovm/tests/files/zrealm_crossrealm21.gno | 37 ++++--- gnovm/tests/files/zrealm_crossrealm22.gno | 108 +++++++++---------- gnovm/tests/files/zrealm_crossrealm22a.gno | 21 ++-- gnovm/tests/files/zrealm_crossrealm_func.gno | 26 +++++ 9 files changed, 199 insertions(+), 113 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm_func.gno diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index bf213870a3a..4a59419a15a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,5 @@ package gnolang const debug debugging = false -//const debug2 debugging = true - +// const debug2 debugging = true const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index dbad05e502c..c3dbd6559da 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -51,7 +51,6 @@ func (m *Machine) doOpPrecall() { var gReturnStmt = &ReturnStmt{} func (m *Machine) doOpCall() { - debug2.Println2("doOpCall") // NOTE: Frame won't be popped until the statement is complete, to // discard the correct number of results for func calls in ExprStmts. fr := m.LastFrame() diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index f915450a4be..e8c82838d44 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -115,6 +115,8 @@ type Object interface { SetIsNewReal(bool) GetOriginRealm() PkgID SetOriginRealm(pkgID PkgID) + GetOriginValue() Value + SetOriginValue(v Value) GetIsRef() bool SetIsRef(bool) GetIsNewEscaped() bool @@ -152,6 +154,7 @@ type ObjectInfo struct { isNewEscaped bool isNewDeleted bool originRealm PkgID // realm where object is from + originValue Value // pointerValue, sliceValue, funcValue // XXX huh? owner Object // mem reference to owner. @@ -325,6 +328,14 @@ func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { oi.originRealm = pkgId } +func (oi *ObjectInfo) GetOriginValue() Value { + return oi.originValue +} + +func (oi *ObjectInfo) SetOriginValue(v Value) { + oi.originValue = v +} + func (oi *ObjectInfo) GetIsRef() bool { return oi.isRef } @@ -365,6 +376,10 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { case *StructValue: return cv case *FuncValue: + //fmt.Println("fv: ", cv) + //fmt.Println("---fv.Closure: ", cv.GetClosure(store)) + //fmt.Println("---fv.Capture: ", cv.Captures) + //fmt.Println("static block.Values: ", cv.Source.(BlockNode).GetStaticBlock().Values) return cv.GetClosure(store) case *MapValue: return cv @@ -430,7 +445,11 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } return case *Block: - originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + if _, ok := tv.V.(*FuncValue); !ok { + //fmt.Println("cv: ", cv) + //fmt.Println("cv.Source: ", cv.Source) + originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + } return case *HeapItemValue: originPkg = getPkgId(cv.Value.T) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 6aa56636c33..ca3de3b015d 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -198,11 +198,13 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { } // ref value is the derived value from co, like a slice. -func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { +func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, originValue Value) { debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + debug2.Println2("po.GetIsReal: ", po.GetIsReal()) debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) debug2.Println2("rlm.ID: ", rlm.ID) + debug2.Println2("originValue: ", originValue) if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) } @@ -248,7 +250,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) { // XXX, inc ref count everytime assignment happens co.IncRefCount() if co.GetRefCount() > 1 { - rlm.MarkNewEscapedCheckCrossRealm(store, co, refValue) + rlm.MarkNewEscapedCheckCrossRealm(store, co, originValue) } else if co.GetIsReal() { rlm.MarkDirty(co) } else { @@ -337,7 +339,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { // MarkNewEscapedCheckCrossRealm mark new escaped object // and check cross realm -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue Value) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originValue Value) { debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) debug2.Println2("oo.GetOriginRealm(): ", oo.GetOriginRealm()) debug2.Println2("rlm.ID: ", rlm.ID) @@ -348,8 +350,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, refValue } if oo.GetOriginRealm() != rlm.ID { // crossing realm - if refValue != nil { // is reference object from external realm - checkCrossRealm(rlm, store, oo, refValue) + if originValue != nil { // is reference object from external realm + checkCrossRealm(rlm, store, oo, originValue) } else { panic("cannot attach objects by value from external realm") } @@ -473,13 +475,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -494,9 +496,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -579,6 +581,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("---rlm.ID: ", rlm.ID) debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) + debug2.Println2("oo.GetOriginValue: ", oo.GetOriginValue()) if debug { if oo.GetIsDirty() { @@ -599,6 +602,36 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } + if b, ok := oo.(*Block); ok { + //fmt.Println("block: ", b) + originValue := b.GetOriginValue() + //fmt.Println("originValue: ", originValue) + + if fv, ok := originValue.(*FuncValue); ok { + //fmt.Println("fv: ", fv) + //fmt.Println("fv...values: ", fv.Source.GetStaticBlock().Values) + for _, tv := range fv.Source.GetStaticBlock().Values { + //fmt.Println("tv: ", tv) + //fmt.Println("tv.V: ", tv.V, reflect.TypeOf(tv.V)) + //fmt.Println("tv.T: ", tv.T, reflect.TypeOf(tv.T)) + + if dt, ok := tv.T.(*DeclaredType); ok { + //debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) + if st, ok := dt.Base.(*StructType); ok { // TODO: some other types? + //fmt.Println("st: ", st) + if IsRealmPath(st.GetPkgPath()) { + originPkg := PkgIDFromPkgPath(dt.Base.GetPkgPath()) + if originPkg != rlm.ID { + panic("cannot attach function contains object from external realm") + } + } + } + } + // TODO: also check captures + } + } + } + // RECURSE GUARD // if id already set, skip. // this happens when a node marked created was already @@ -638,6 +671,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // NOTE: may already be marked for first gen // newCreated or updated. child.SetOwner(oo) + //child.SetIsRef(isRef2) + //child.SetOriginValue(originValue2) rlm.incRefCreatedDescendants(store, child) child.SetIsNewReal(true) } @@ -892,9 +927,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } @@ -1006,6 +1041,7 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { + debug2.Println2("getSelfOrChildObjects: ", val) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1018,6 +1054,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { + debug2.Println2("getChildObjects: ", val) switch cv := val.(type) { case nil: return more @@ -1045,15 +1082,16 @@ func getChildObjects(val Value, more []Value) []Value { return more case *StructValue: for _, ctv := range cv.Fields { - // TODO: we have type infos here, so check check cross realm logic more = getSelfOrChildObjects(ctv.V, more) } return more case *FuncValue: if bv, ok := cv.Closure.(*Block); ok { + debug2.Println2("bv: ", bv) more = getSelfOrChildObjects(bv, more) } for _, c := range cv.Captures { + debug2.Println2("c: ", c) more = getSelfOrChildObjects(c.V, more) } return more @@ -1076,6 +1114,11 @@ func getChildObjects(val Value, more []Value) []Value { } return more case *Block: + //fmt.Println("block, cv: ", cv) + //if _, ok := cv.Parent.(*Block); ok { + // fmt.Println("block, cv.parent: ", cv.Parent) + // fmt.Println("parent.Source: ", cv.Parent.(*Block).Source) + //} for _, ctv := range cv.Values { more = getSelfOrChildObjects(ctv.V, more) } @@ -1183,7 +1226,6 @@ func copyFieldsWithRefs(fields []FieldType) []FieldType { // Copies type but with references to dependant types; // the result is suitable for persistence bytes serialization. func copyTypeWithRefs(typ Type) Type { - debug2.Println2("copyTypeWithRefs, typ: ", typ) switch ct := typ.(type) { case nil: panic("cannot copy nil types") @@ -1274,7 +1316,6 @@ func copyTypeWithRefs(typ Type) Type { // Also checks for integrity of immediate children -- they must already be // persistent (real), and not dirty, or else this function panics. func copyValueWithRefs(val Value) Value { - debug2.Println2("-copyValueWithRefs, val: ", val) switch cv := val.(type) { case nil: return nil @@ -1668,12 +1709,10 @@ func toRefNode(bn BlockNode) RefNode { } func toRefValue(val Value) RefValue { - debug2.Println2("toRefValue, val: ", val) // TODO use type switch stmt. if ref, ok := val.(RefValue); ok { return ref } else if oo, ok := val.(Object); ok { - debug2.Println2("oo: ", oo) if pv, ok := val.(*PackageValue); ok { if pv.GetIsDirty() { panic("unexpected dirty package " + pv.PkgPath) @@ -1743,7 +1782,6 @@ func ensureUniq(oozz ...[]Object) { } func refOrCopyValue(tv TypedValue) TypedValue { - debug2.Println2("refOrCopyValue:", tv) if tv.T != nil { tv.T = refOrCopyType(tv.T) } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 109ac1f3838..4234902baa5 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -303,17 +303,18 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // refValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue - var refValue Value + var originValue Value switch rv := pv.TV.V.(type) { - case *SliceValue, PointerValue: - refValue = rv + case *SliceValue, PointerValue, *FuncValue: + originValue = rv oo2.SetIsRef(true) + oo2.SetOriginValue(rv) } if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info } - rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, refValue) + rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, originValue) } else { pv.TV.Assign(alloc, tv2, cu) } diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 2fe9fb80f97..582177675e7 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -100,7 +100,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": true, // "Name": "String", // "NativeName": "", @@ -111,7 +111,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "12", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -184,7 +184,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "init.2", // "NativeName": "", @@ -195,7 +195,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "19", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -233,7 +233,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "Make1", // "NativeName": "", @@ -244,7 +244,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "24", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -352,7 +352,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooer", // "NativeName": "", @@ -363,7 +363,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "35", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -418,7 +418,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooer", // "NativeName": "", @@ -429,7 +429,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "40", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -464,7 +464,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerFoo", // "NativeName": "", @@ -475,7 +475,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -555,7 +555,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooerGetter", // "NativeName": "", @@ -566,7 +566,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -621,7 +621,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooerGetter", // "NativeName": "", @@ -632,7 +632,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "53", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -667,7 +667,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerGetterFoo", // "NativeName": "", @@ -678,7 +678,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "57", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -721,4 +721,3 @@ func main() { // Error: // ->>>>>>> main/master diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 18985f7719d..251f3dba356 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -159,7 +159,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": true, // "Name": "String", // "NativeName": "", @@ -170,7 +170,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "12", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -243,7 +243,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "init.2", // "NativeName": "", @@ -254,7 +254,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "19", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -292,7 +292,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "Make1", // "NativeName": "", @@ -303,7 +303,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "24", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -398,7 +398,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooer", // "NativeName": "", @@ -409,7 +409,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "35", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -464,7 +464,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooer", // "NativeName": "", @@ -475,7 +475,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "40", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -510,7 +510,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerFoo", // "NativeName": "", @@ -521,7 +521,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -640,7 +640,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooerGetter", // "NativeName": "", @@ -651,7 +651,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -706,7 +706,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooerGetter", // "NativeName": "", @@ -717,7 +717,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "53", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -752,7 +752,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerGetterFoo", // "NativeName": "", @@ -763,7 +763,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "57", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -902,7 +902,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": true, // "Name": "String", // "NativeName": "", @@ -913,7 +913,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "12", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -986,7 +986,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "init.2", // "NativeName": "", @@ -997,7 +997,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "19", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1035,7 +1035,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "Make1", // "NativeName": "", @@ -1046,7 +1046,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "24", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1141,7 +1141,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooer", // "NativeName": "", @@ -1152,7 +1152,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "35", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1207,7 +1207,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooer", // "NativeName": "", @@ -1218,7 +1218,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "40", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1253,7 +1253,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerFoo", // "NativeName": "", @@ -1264,7 +1264,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1383,7 +1383,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooerGetter", // "NativeName": "", @@ -1394,7 +1394,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1449,7 +1449,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooerGetter", // "NativeName": "", @@ -1460,7 +1460,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "53", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1495,7 +1495,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerGetterFoo", // "NativeName": "", @@ -1506,7 +1506,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "57", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1655,7 +1655,7 @@ func main() { // "V": { // "@type": "/gno.FuncValue", // "Closure": null, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": true, // "Name": "String", // "NativeName": "", @@ -1666,7 +1666,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "12", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1739,7 +1739,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "init.2", // "NativeName": "", @@ -1750,7 +1750,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "19", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1788,7 +1788,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "Make1", // "NativeName": "", @@ -1799,7 +1799,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "24", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1894,7 +1894,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooer", // "NativeName": "", @@ -1905,7 +1905,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "35", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -1960,7 +1960,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooer", // "NativeName": "", @@ -1971,7 +1971,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "40", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -2006,7 +2006,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerFoo", // "NativeName": "", @@ -2017,7 +2017,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "42", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -2136,7 +2136,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "SetFooerGetter", // "NativeName": "", @@ -2147,7 +2147,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "48", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -2202,7 +2202,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "GetFooerGetter", // "NativeName": "", @@ -2213,7 +2213,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "53", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } @@ -2248,7 +2248,7 @@ func main() { // "Escaped": true, // "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" // }, -// "FileName": "crossrealm.gno", +// "FileName": "crossrealm_p.gno", // "IsMethod": false, // "Name": "CallFooerGetterFoo", // "NativeName": "", @@ -2259,7 +2259,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "crossrealm.gno", +// "File": "crossrealm_p.gno", // "Line": "57", // "PkgPath": "gno.land/r/demo/tests/crossrealm" // } diff --git a/gnovm/tests/files/zrealm_crossrealm22a.gno b/gnovm/tests/files/zrealm_crossrealm22a.gno index c05fa1668f0..002aed89b06 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a.gno @@ -8,16 +8,21 @@ import ( "gno.land/r/demo/tests/crossrealm_b" ) -func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooerGetter(func() crossrealm.Fooer { return f }) - println("ok") -} - // TODO: consider this and xxx22.gno, xxx21.gno, xxx20.gno // how about func()int? and func() crossrealm.Fooer? // check type for param type? // see also 37a.gno -// Error: -// cannot attach a value of a type defined by another realm +type Foo struct{} + +func main() { + f := crossrealm_b.Fooer + crossrealm.SetFooerGetter(func() crossrealm.Fooer { + //f1 := Foo{} + return f + }) + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm_func.gno b/gnovm/tests/files/zrealm_crossrealm_func.gno new file mode 100644 index 00000000000..0d8531d4e54 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm_func.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + f := func() bool { + c := b + ls := Local_S{} + return true + } + crossrealm.SetCallback(f) +} + +// Error: +// cannot attach function contains object from external realm From ea06afc9ae32eee4580cb24ef222365143cbeb00 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 15 Jan 2025 20:54:56 +0800 Subject: [PATCH 45/88] fixup --- .../r/demo/tests/crossrealm_b/crossrealm.gno | 6 +- gnovm/pkg/gnolang/op_call.go | 1 + gnovm/pkg/gnolang/op_expressions.go | 2 + gnovm/pkg/gnolang/ownership.go | 2 + gnovm/pkg/gnolang/realm.go | 59 +- gnovm/pkg/gnolang/values.go | 23 +- gnovm/tests/files/zrealm_crossrealm22.gno | 1534 +---------------- gnovm/tests/files/zrealm_crossrealm22a.gno | 5 +- ...ealm_func.gno => zrealm_crossrealm29d.gno} | 0 9 files changed, 107 insertions(+), 1525 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm_func.gno => zrealm_crossrealm29d.gno} (100%) diff --git a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno index d412b6ee6b1..c2df8396cad 100644 --- a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno @@ -19,7 +19,9 @@ func (f *fooer) Foo() { } var ( - Fooer = &fooer{s: "A"} - FooerGetter = func() crossrealm.Fooer { return Fooer } + Fooer = &fooer{s: "A"} + // this is already attached, so cannot be attached to external realm + FooerGetter = func() crossrealm.Fooer { return Fooer } + // same FooerGetterBuilder = func() crossrealm.FooerGetter { return func() crossrealm.Fooer { return Fooer } } ) diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index c3dbd6559da..36b407f5cc5 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -62,6 +62,7 @@ func (m *Machine) doOpCall() { // Create new block scope. clo := fr.Func.GetClosure(m.Store) b := m.Alloc.NewBlock(fr.Func.GetSource(m.Store), clo) + debug2.Println2("doOpCall, b: ", b) // Copy *FuncValue.Captures into block // NOTE: addHeapCapture in preprocess ensures order. diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index c0f6225740b..87a9cd345c4 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -758,10 +758,12 @@ func (m *Machine) doOpStructLit() { } func (m *Machine) doOpFuncLit() { + debug2.Println2("doOpFuncLit") x := m.PopExpr().(*FuncLitExpr) ft := m.PopValue().V.(TypeValue).Type.(*FuncType) lb := m.LastBlock() m.Alloc.AllocateFunc() + debug2.Println2("lb: ", lb) // First copy closure captured heap values // to *FuncValue. Later during doOpCall a block diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index e8c82838d44..5cb6e8a5f72 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -366,8 +366,10 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { + debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: + debug2.Println2("pointer value, base: ", cv.Base) return cv.GetBase(store) case *ArrayValue: return cv diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index ca3de3b015d..9e585178db0 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -254,6 +254,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, originValue Value) } else if co.GetIsReal() { rlm.MarkDirty(co) } else { + debug2.Println2("set owner of co: ", co) co.SetOwner(po) rlm.MarkNewReal(co) } @@ -475,13 +476,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -496,9 +497,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -603,23 +604,23 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } if b, ok := oo.(*Block); ok { - //fmt.Println("block: ", b) + debug2.Println2("block: ", b) originValue := b.GetOriginValue() - //fmt.Println("originValue: ", originValue) + debug2.Println2("originValue: ", originValue) if fv, ok := originValue.(*FuncValue); ok { - //fmt.Println("fv: ", fv) - //fmt.Println("fv...values: ", fv.Source.GetStaticBlock().Values) + debug2.Println2("fv: ", fv) + debug2.Println2("fv...values: ", fv.Source.GetStaticBlock().Values) for _, tv := range fv.Source.GetStaticBlock().Values { - //fmt.Println("tv: ", tv) - //fmt.Println("tv.V: ", tv.V, reflect.TypeOf(tv.V)) - //fmt.Println("tv.T: ", tv.T, reflect.TypeOf(tv.T)) + debug2.Println2("tv: ", tv) + debug2.Println2("tv.V: ", tv.V, reflect.TypeOf(tv.V)) + debug2.Println2("tv.T: ", tv.T, reflect.TypeOf(tv.T)) if dt, ok := tv.T.(*DeclaredType); ok { - //debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) - if st, ok := dt.Base.(*StructType); ok { // TODO: some other types? - //fmt.Println("st: ", st) - if IsRealmPath(st.GetPkgPath()) { + debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) + switch tt := dt.Base.(type) { + case *StructType, *InterfaceType: // types with pkgpath + if IsRealmPath(tt.GetPkgPath()) { originPkg := PkgIDFromPkgPath(dt.Base.GetPkgPath()) if originPkg != rlm.ID { panic("cannot attach function contains object from external realm") @@ -825,6 +826,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (ancestors) must be marked as dirty to update the // hash tree. func (rlm *Realm) markDirtyAncestors(store Store) { + debug2.Println2("markDirtyAncestors") markAncestorsOne := func(oo Object) { for { if pv, ok := oo.(*PackageValue); ok { @@ -893,7 +895,9 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { + debug2.Println2("saveUnsavedObjects") for _, co := range rlm.created { + debug2.Println2("co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { @@ -905,6 +909,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { } } for _, uo := range rlm.updated { + debug2.Println2("uo: ", uo) if !uo.GetIsDirty() { // might have happened already as child // of something else created/dirty. @@ -917,6 +922,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { + debug2.Println2("saveUnsavedObjectRecursively", oo) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -927,15 +933,17 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } // first, save unsaved children. unsaved := getUnsavedChildObjects(oo) + debug2.Println2("unsaved: ", unsaved) for _, uch := range unsaved { + debug2.Println2("uch: ", uch) if uch.GetIsEscaped() || uch.GetIsNewEscaped() { // no need to save preemptively. } else { @@ -1054,7 +1062,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - debug2.Println2("getChildObjects: ", val) + debug2.Printf2("getChildObjects, val: %v, type of val: %v \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1125,6 +1133,7 @@ func getChildObjects(val Value, more []Value) []Value { // Generally the parent block must also be persisted. // Otherwise NamePath may not resolve when referencing // a parent block. + debug2.Println2("block value, get parent recursively") more = getSelfOrChildObjects(cv.Parent, more) return more case *HeapItemValue: diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 4234902baa5..11b7aae728e 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -212,7 +212,7 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { debug2.Println2("Assign2, pv: ", pv) - debug2.Println2("tv2: ", tv2) + debug2.Println2("tv2: ", tv2, reflect.TypeOf(tv2.V)) debug2.Println2("rlm: ", rlm) // Special cases. @@ -300,17 +300,35 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo2 := pv.TV.GetFirstObject(store) debug2.Println2("oo2: ", oo2) + // XXX, special case for floating func value + + if originPkg != rlm.ID { + if fv, ok := pv.TV.V.(*FuncValue); ok { + if oo2.GetObjectID().IsZero() { // the funcValue has not attached + debug2.Println2("fv: ", fv) + clo := fv.GetClosure(store) + b := NewBlock(fv.GetSource(store), clo) + debug2.Println2("b for fv: ", b) + oo2 = b + } + } + } + // refValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue var originValue Value switch rv := pv.TV.V.(type) { - case *SliceValue, PointerValue, *FuncValue: + case *SliceValue, PointerValue: originValue = rv oo2.SetIsRef(true) oo2.SetOriginValue(rv) + case *FuncValue: + //originValue = rv + oo2.SetOriginValue(rv) } + debug2.Println2("pv: ", pv) if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info } @@ -2404,6 +2422,7 @@ type Block struct { // NOTE: for allocation, use *Allocator.NewBlock. func NewBlock(source BlockNode, parent *Block) *Block { + //fmt.Println("parent: ", parent) var values []TypedValue if source != nil { values = make([]TypedValue, source.GetNumNames()) diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 251f3dba356..35f82fb0c43 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -16,34 +16,30 @@ func main() { crossrealm.CallFooerGetterFoo() println(".") - f.SetS("C") - crossrealm.SetFooerGetter(crossrealm_b.FooerGetter) - crossrealm.CallFooerGetterFoo() - println(".") - - f.SetS("D") - crossrealm.SetFooerGetter(crossrealm_b.FooerGetterBuilder()) - crossrealm.CallFooerGetterFoo() - println(".") + //f.SetS("C") + //crossrealm.SetFooerGetter(crossrealm_b.FooerGetter) + //crossrealm.CallFooerGetterFoo() + //println(".") + // + //f.SetS("D") + //crossrealm.SetFooerGetter(crossrealm_b.FooerGetterBuilder()) + //crossrealm.CallFooerGetterFoo() + //println(".") } // Output: // hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm // hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm // . -// hello C cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// . -// hello D cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// . // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm"] -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ // "Blank": {}, // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", // "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", // "RefCount": "1" // }, // "Parent": { @@ -83,6 +79,33 @@ func main() { // } // ] // } +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// }, +// "Parent": { +// "@type": "/gno.RefValue", +// "Hash": "47f9df1dd7beb8ae6c59db94bf51bad6beaf4fd7", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "28", +// "File": "files/zrealm_crossrealm22.gno", +// "Line": "13", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Values": [ +// {} +// ] +// } // u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ // "Blank": {}, // "ObjectInfo": { @@ -571,8 +594,8 @@ func main() { // "@type": "/gno.FuncValue", // "Closure": { // "@type": "/gno.RefValue", -// "Hash": "23de97a577d573252d00394ce9b71c24b0646546", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" +// "Hash": "47f9df1dd7beb8ae6c59db94bf51bad6beaf4fd7", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" // }, // "FileName": "", // "IsMethod": false, @@ -804,1479 +827,4 @@ func main() { // switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "C" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "IsEscaped": true, -// "ModTime": "6", -// "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_p.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_p.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.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.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooer", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "40", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "42", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "Methods": [], -// "Name": "FooerGetter", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:5" -// }, -// "FileName": "", -// "IsMethod": false, -// "Name": "", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm_b", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "23", -// "File": "crossrealm.gno", -// "Line": "23", -// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "SetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "48", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "53", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerGetterFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "57", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "D" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", -// "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "RefCount": "1" -// }, -// "Parent": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:5" -// }, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "23", -// "File": "crossrealm.gno", -// "Line": "24", -// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "IsEscaped": true, -// "ModTime": "6", -// "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_p.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_p.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.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.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooer", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "40", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "42", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "Methods": [], -// "Name": "FooerGetter", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Hash": "89352b352826005a86eee78e6c832b43ae0ab6a6", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" -// }, -// "FileName": "", -// "IsMethod": false, -// "Name": "", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm_b", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "62", -// "File": "crossrealm.gno", -// "Line": "24", -// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "SetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "48", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "53", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerGetterFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "57", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] - -// Error: -// diff --git a/gnovm/tests/files/zrealm_crossrealm22a.gno b/gnovm/tests/files/zrealm_crossrealm22a.gno index 002aed89b06..cafa8b44aaa 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a.gno @@ -13,16 +13,15 @@ import ( // check type for param type? // see also 37a.gno -type Foo struct{} - func main() { f := crossrealm_b.Fooer crossrealm.SetFooerGetter(func() crossrealm.Fooer { - //f1 := Foo{} return f }) + crossrealm.CallFooerGetterFoo() println("ok") } // Output: +// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm // ok diff --git a/gnovm/tests/files/zrealm_crossrealm_func.gno b/gnovm/tests/files/zrealm_crossrealm29d.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm_func.gno rename to gnovm/tests/files/zrealm_crossrealm29d.gno From ce22178e56a8db9814dc07e06e1cf831afc6461d Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 15 Jan 2025 20:55:09 +0800 Subject: [PATCH 46/88] fixup --- gnovm/tests/files/zrealm_crossrealm22a1.gno | 24 ++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm22b.gno | 21 ++++++++++++++++ gnovm/tests/files/zrealm_crossrealm22c.gno | 14 +++++++++++ gnovm/tests/files/zrealm_crossrealm22d.gno | 12 +++++++++ gnovm/tests/files/zrealm_crossrealm22e.gno | 21 ++++++++++++++++ gnovm/tests/files/zrealm_crossrealm27b.gno | 22 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm29e.gno | 26 ++++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm29f.gno | 27 +++++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm29g.gno | 27 +++++++++++++++++++++ 9 files changed, 194 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm22a1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22c.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22d.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22e.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm27b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm29e.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm29f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm29g.gno diff --git a/gnovm/tests/files/zrealm_crossrealm22a1.gno b/gnovm/tests/files/zrealm_crossrealm22a1.gno new file mode 100644 index 00000000000..8f7a346c5a9 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a1.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +type Foo struct{} + +func main() { + f := crossrealm_b.Fooer + crossrealm.SetFooerGetter(func() crossrealm.Fooer { + f1 := Foo{} + return f + }) + crossrealm.CallFooerGetterFoo() + println("ok") +} + +// Error: +// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno new file mode 100644 index 00000000000..469120c9b47 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +var f = func() crossrealm.Fooer { + return crossrealm_b.Fooer +} + +func main() { + crossrealm.SetFooerGetter(f) + println("ok") +} + +// Error: +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22c.gno b/gnovm/tests/files/zrealm_crossrealm22c.gno new file mode 100644 index 00000000000..c7ef44e02d3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22c.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +var root interface{} + +func main() { + root = func() { // in this, case, block(main) is attached in the tree + println("func lit") + } + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm22d.gno b/gnovm/tests/files/zrealm_crossrealm22d.gno new file mode 100644 index 00000000000..1cceefa8d6d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22d.gno @@ -0,0 +1,12 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +func main() { + a := func() { // in this case, not attached. + println("func lit") + } + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm22e.gno b/gnovm/tests/files/zrealm_crossrealm22e.gno new file mode 100644 index 00000000000..ccbd61bd45a --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22e.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" +) + +var root interface{} + +func main() { + //f := func() crossrealm.Fooer { + root = func() crossrealm.Fooer { + return crossrealm.Fooer(nil) + } + println("ok") +} + +// Error: +// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm27b.gno b/gnovm/tests/files/zrealm_crossrealm27b.gno new file mode 100644 index 00000000000..29a01c7df32 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm27b.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +func main() { + crossrealm.SetContainer2(&fooer{name: "local_fooer"}) + print(".") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29e.gno b/gnovm/tests/files/zrealm_crossrealm29e.gno new file mode 100644 index 00000000000..920c7b5f118 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29e.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + f := func() bool { + c := b + var ls Local_S + return true + } + crossrealm.SetCallback(f) +} + +// Error: +// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29f.gno b/gnovm/tests/files/zrealm_crossrealm29f.gno new file mode 100644 index 00000000000..0c6ac7719d3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29f.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + f := func() bool { + c := b + var ls *Local_S + return true + } + crossrealm.SetCallback(f) + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm29g.gno b/gnovm/tests/files/zrealm_crossrealm29g.gno new file mode 100644 index 00000000000..63e9068c707 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm29g.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + f := func() bool { + c := b + ls := &Local_S{name: "ls"} + return true + } + crossrealm.SetCallback(f) + println("ok") +} + +// Output: +// ok From 78eca0884b99f27fe68b243d57e52c3a1cd46723 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 15 Jan 2025 22:10:30 +0800 Subject: [PATCH 47/88] fixup --- gnovm/pkg/gnolang/op_assign.go | 22 ++-- gnovm/pkg/gnolang/op_inc_dec.go | 4 +- gnovm/pkg/gnolang/ownership.go | 12 -- gnovm/pkg/gnolang/realm.go | 124 ++++++-------------- gnovm/pkg/gnolang/uverse.go | 9 +- gnovm/pkg/gnolang/values.go | 33 ++---- gnovm/tests/files/zrealm_crossrealm22a2.gno | 35 ++++++ 7 files changed, 104 insertions(+), 135 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm22a2.gno diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index 33bc51b3e44..53cfbe5cad8 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -66,7 +66,7 @@ func (m *Machine) doOpAddAssign() { // add rv to lv. addAssign(m.Alloc, lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -89,7 +89,7 @@ func (m *Machine) doOpSubAssign() { // sub rv from lv. subAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -112,7 +112,7 @@ func (m *Machine) doOpMulAssign() { // lv *= rv mulAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -139,7 +139,7 @@ func (m *Machine) doOpQuoAssign() { } if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -166,7 +166,7 @@ func (m *Machine) doOpRemAssign() { } if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -189,7 +189,7 @@ func (m *Machine) doOpBandAssign() { // lv &= rv bandAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -212,7 +212,7 @@ func (m *Machine) doOpBandnAssign() { // lv &^= rv bandnAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -235,7 +235,7 @@ func (m *Machine) doOpBorAssign() { // lv |= rv borAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -258,7 +258,7 @@ func (m *Machine) doOpXorAssign() { // lv ^= rv xorAssign(lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -278,7 +278,7 @@ func (m *Machine) doOpShlAssign() { // lv <<= rv shlAssign(m, lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } @@ -298,6 +298,6 @@ func (m *Machine) doOpShrAssign() { // lv >>= rv shrAssign(m, lv.TV, rv) if lv.Base != nil { - m.Realm.DidUpdate(lv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, lv.Base.(Object), nil, nil) } } diff --git a/gnovm/pkg/gnolang/op_inc_dec.go b/gnovm/pkg/gnolang/op_inc_dec.go index 1e68e195596..d309094cf76 100644 --- a/gnovm/pkg/gnolang/op_inc_dec.go +++ b/gnovm/pkg/gnolang/op_inc_dec.go @@ -80,7 +80,7 @@ func (m *Machine) doOpInc() { // Mark dirty in realm. if m.Realm != nil && pv.Base != nil { - m.Realm.DidUpdate(pv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, pv.Base.(Object), nil, nil) } } @@ -152,6 +152,6 @@ func (m *Machine) doOpDec() { // Mark dirty in realm. if m.Realm != nil && pv.Base != nil { - m.Realm.DidUpdate(pv.Base.(Object), nil, nil) + m.Realm.DidUpdate(m.Store, pv.Base.(Object), nil, nil) } } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 5cb6e8a5f72..dc9c327d7b8 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -117,8 +117,6 @@ type Object interface { SetOriginRealm(pkgID PkgID) GetOriginValue() Value SetOriginValue(v Value) - GetIsRef() bool - SetIsRef(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -150,7 +148,6 @@ type ObjectInfo struct { isDirty bool isDeleted bool isNewReal bool - isRef bool isNewEscaped bool isNewDeleted bool originRealm PkgID // realm where object is from @@ -169,7 +166,6 @@ func (oi *ObjectInfo) Copy() ObjectInfo { ModTime: oi.ModTime, RefCount: oi.RefCount, IsEscaped: oi.IsEscaped, - //originRealm: oi.originRealm, /* // XXX do the following need copying too? isDirty: oi.isDirty, @@ -336,14 +332,6 @@ func (oi *ObjectInfo) SetOriginValue(v Value) { oi.originValue = v } -func (oi *ObjectInfo) GetIsRef() bool { - return oi.isRef -} - -func (oi *ObjectInfo) SetIsRef(isRef bool) { - oi.isRef = isRef -} - func (oi *ObjectInfo) GetIsNewEscaped() bool { return oi.isNewEscaped } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 9e585178db0..23bc5c06266 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -148,65 +148,16 @@ func (rlm *Realm) String() string { //---------------------------------------- // ownership hooks -// po's old elem value is xo, will become co. -// po, xo, and co may each be nil. -// if rlm or po is nil, do nothing. -// xo or co is nil if the element value is undefined or has no -// associated object. -func (rlm *Realm) DidUpdate(po, xo, co Object) { - if bm.OpsEnabled { - bm.PauseOpCode() - defer bm.ResumeOpCode() - } - if rlm == nil { - return - } - if debug { - if po != nil && po.GetIsTransient() { - panic("cannot attach to a transient object") - } - if po != nil && po.GetIsDeleted() { - panic("cannot attach to a deleted object") - } - } - - if po == nil || !po.GetIsReal() { // XXX, make sure po is real - return // do nothing. - } - - if po.GetObjectID().PkgID != rlm.ID { - panic("cannot modify external-realm or non-realm object") - } - // XXX check if this boosts performance - // XXX with broad integration benchmarking. - // XXX if co == xo { - // XXX } - - // From here on, po is real (not new-real). - // Updates to .newCreated/.newEscaped /.newDeleted made here. (first gen) - // More appends happen during FinalizeRealmTransactions(). (second+ gen) - rlm.MarkDirty(po) - - if xo != nil { - xo.DecRefCount() - if xo.GetRefCount() == 0 { - if xo.GetIsReal() { - rlm.MarkNewDeleted(xo) - } - } - } -} - // ref value is the derived value from co, like a slice. -func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, originValue Value) { +func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) debug2.Println2("po.GetIsReal: ", po.GetIsReal()) debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - debug2.Println2("rlm.ID: ", rlm.ID) - debug2.Println2("originValue: ", originValue) + //debug2.Println2("rlm.ID: ", rlm.ID) if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) + debug2.Println2("originValue: ", co.GetOriginValue()) } if rlm == nil { @@ -250,7 +201,7 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, originValue Value) // XXX, inc ref count everytime assignment happens co.IncRefCount() if co.GetRefCount() > 1 { - rlm.MarkNewEscapedCheckCrossRealm(store, co, originValue) + rlm.MarkNewEscapedCheckCrossRealm(store, co, co.GetOriginValue()) } else if co.GetIsReal() { rlm.MarkDirty(co) } else { @@ -312,7 +263,9 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { // TODO: complete this case *Block: // XXX, can this happen? - if !v.GetIsRef() { + switch v.GetOriginValue().(type) { + case PointerValue, *SliceValue, *FuncValue: + default: panic("should not happen, block is not real") } case *HeapItemValue: @@ -343,6 +296,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originValue Value) { debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) debug2.Println2("oo.GetOriginRealm(): ", oo.GetOriginRealm()) + debug2.Println2("originValue: ", originValue) debug2.Println2("rlm.ID: ", rlm.ID) if oo.GetOriginRealm() == rlm.ID { @@ -350,7 +304,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa return } - if oo.GetOriginRealm() != rlm.ID { // crossing realm + if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm if originValue != nil { // is reference object from external realm checkCrossRealm(rlm, store, oo, originValue) } else { @@ -581,7 +535,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("---rlm.ID: ", rlm.ID) - debug2.Println2("oo.GetIsRef: ", oo.GetIsRef()) debug2.Println2("oo.GetOriginValue: ", oo.GetOriginValue()) if debug { @@ -596,40 +549,41 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // XXX, oo must be new real here, it's not escaped // if it's reference, all right if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { - if oo.GetIsRef() { + switch oo.GetOriginValue().(type) { + case PointerValue, *SliceValue: // ref panic("cannot attach a reference to an unreal object from an external realm") - } else { - panic("cannot attach a value of a type defined by another realm") - } - } - - if b, ok := oo.(*Block); ok { - debug2.Println2("block: ", b) - originValue := b.GetOriginValue() - debug2.Println2("originValue: ", originValue) - - if fv, ok := originValue.(*FuncValue); ok { - debug2.Println2("fv: ", fv) - debug2.Println2("fv...values: ", fv.Source.GetStaticBlock().Values) - for _, tv := range fv.Source.GetStaticBlock().Values { - debug2.Println2("tv: ", tv) - debug2.Println2("tv.V: ", tv.V, reflect.TypeOf(tv.V)) - debug2.Println2("tv.T: ", tv.T, reflect.TypeOf(tv.T)) - - if dt, ok := tv.T.(*DeclaredType); ok { - debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) - switch tt := dt.Base.(type) { - case *StructType, *InterfaceType: // types with pkgpath - if IsRealmPath(tt.GetPkgPath()) { - originPkg := PkgIDFromPkgPath(dt.Base.GetPkgPath()) - if originPkg != rlm.ID { - panic("cannot attach function contains object from external realm") + case *FuncValue: + if b, ok := oo.(*Block); ok { + debug2.Println2("block: ", b) + originValue := b.GetOriginValue() + debug2.Println2("originValue: ", originValue) + + if fv, ok := originValue.(*FuncValue); ok { + debug2.Println2("fv: ", fv) + debug2.Println2("fv...values: ", fv.Source.GetStaticBlock().Values) + for _, tv := range fv.Source.GetStaticBlock().Values { + debug2.Println2("tv: ", tv) + debug2.Println2("tv.V: ", tv.V, reflect.TypeOf(tv.V)) + debug2.Println2("tv.T: ", tv.T, reflect.TypeOf(tv.T)) + + if dt, ok := tv.T.(*DeclaredType); ok { + debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) + switch tt := dt.Base.(type) { + case *StructType, *InterfaceType: // types with pkgpath + if IsRealmPath(tt.GetPkgPath()) { + originPkg := PkgIDFromPkgPath(dt.Base.GetPkgPath()) + if originPkg != rlm.ID { + panic("cannot attach function contains object from external realm") + } + } } } + // TODO: also check captures } } - // TODO: also check captures } + default: + panic("cannot attach a value of a type defined by another realm") } } @@ -672,8 +626,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // NOTE: may already be marked for first gen // newCreated or updated. child.SetOwner(oo) - //child.SetIsRef(isRef2) - //child.SetOriginValue(originValue2) rlm.incRefCreatedDescendants(store, child) child.SetIsNewReal(true) } diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index ad5c4c1664b..c02c6de1144 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -345,6 +345,7 @@ func makeUverseNode() { // TODO: xxx // XXX, DidUpdate2? m.Realm.DidUpdate( + m.Store, arg0Base, oldElem.GetFirstObject(m.Store), newElem.GetFirstObject(m.Store), @@ -355,7 +356,7 @@ func makeUverseNode() { list[arg0Offset+arg0Length:arg0Offset+arg0Length+arg1Length], arg1Base.Data[arg1Offset:arg1Offset+arg1Length], arg0Type.Elem()) - m.Realm.DidUpdate(arg1Base, nil, nil) + m.Realm.DidUpdate(m.Store, arg1Base, nil, nil) } } else { // append(*SliceValue.Data, *SliceValue) --------- @@ -364,7 +365,7 @@ func makeUverseNode() { copyListToData( data[arg0Offset+arg0Length:arg0Offset+arg0Length+arg1Length], arg1Base.List[arg1Offset:arg1Offset+arg1Length]) - m.Realm.DidUpdate(arg0Base, nil, nil) + m.Realm.DidUpdate(m.Store, arg0Base, nil, nil) } else { copy( data[arg0Offset+arg0Length:arg0Offset+arg0Length+arg1Length], @@ -764,11 +765,11 @@ func makeUverseNode() { if m.Realm != nil { // mark key as deleted keyObj := itv.GetFirstObject(m.Store) - m.Realm.DidUpdate(mv, keyObj, nil) + m.Realm.DidUpdate(m.Store, mv, keyObj, nil) // mark value as deleted valObj := val.GetFirstObject(m.Store) - m.Realm.DidUpdate(mv, valObj, nil) + m.Realm.DidUpdate(m.Store, mv, valObj, nil) } return diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 11b7aae728e..e75f818a026 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -255,7 +255,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -301,38 +301,31 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty debug2.Println2("oo2: ", oo2) // XXX, special case for floating func value - if originPkg != rlm.ID { - if fv, ok := pv.TV.V.(*FuncValue); ok { - if oo2.GetObjectID().IsZero() { // the funcValue has not attached - debug2.Println2("fv: ", fv) - clo := fv.GetClosure(store) - b := NewBlock(fv.GetSource(store), clo) - debug2.Println2("b for fv: ", b) - oo2 = b - } + // the funcValue has not attached, + // it has the chance to be attached to + // external realm, if it does not reference + // other values in current realm. + if fv, ok := pv.TV.V.(*FuncValue); ok && oo2.GetObjectID().IsZero() { + //debug2.Println2("fv: ", fv) + b := NewBlock(fv.GetSource(store), fv.GetClosure(store)) + //debug2.Println2("b for fv: ", b) + oo2 = b } } - // refValue is needed for checking + // originValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue - var originValue Value switch rv := pv.TV.V.(type) { - case *SliceValue, PointerValue: - originValue = rv - oo2.SetIsRef(true) - oo2.SetOriginValue(rv) - case *FuncValue: - //originValue = rv + case *SliceValue, PointerValue, *FuncValue: oo2.SetOriginValue(rv) } - debug2.Println2("pv: ", pv) if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info } - rlm.DidUpdate2(store, pv.Base.(Object), oo1, oo2, originValue) + rlm.DidUpdate(store, pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) } diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno new file mode 100644 index 00000000000..0e1290f0594 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a2.gno @@ -0,0 +1,35 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +// TODO: consider this and xxx22.gno, xxx21.gno, xxx20.gno +// how about func()int? and func() crossrealm.Fooer? +// check type for param type? +// see also 37a.gno + +type local_S struct{ name string } + +var root interface{} + +func main() { // the block is attached to current realm + f := crossrealm_b.Fooer + crossrealm.SetFooerGetter(func() crossrealm.Fooer { // this funcLit is attached to external realm + return f + }) + crossrealm.CallFooerGetterFoo() + println("ok") + + root = local_S{name: "root"} + println("ok2") +} + +// Output: +// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// ok +// ok2 From 36738b1b9c703e5c6e166d0dcc36e512b5631f0b Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 15 Jan 2025 23:12:11 +0800 Subject: [PATCH 48/88] save --- gnovm/pkg/gnolang/values.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index e75f818a026..89f53c28cc2 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -308,6 +308,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // other values in current realm. if fv, ok := pv.TV.V.(*FuncValue); ok && oo2.GetObjectID().IsZero() { //debug2.Println2("fv: ", fv) + // TODO: reuse this b := NewBlock(fv.GetSource(store), fv.GetClosure(store)) //debug2.Println2("b for fv: ", b) oo2 = b From 0a2507763509317ba23613e8eba17b4dc1dae6c2 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 3 Feb 2025 23:46:47 +0800 Subject: [PATCH 49/88] add some comments --- gnovm/pkg/gnolang/ownership.go | 2 ++ gnovm/pkg/gnolang/realm.go | 7 +++++++ gnovm/pkg/gnolang/values.go | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index dc9c327d7b8..8b20329457b 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -394,6 +394,8 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } // GetOriginPkg get origin pkg for real or unreal object +// if the object is real, it's retrieved from objectID, +// otherwise, it's inference from its type. func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) // get first object diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 23bc5c06266..784c15e5e3c 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -546,12 +546,19 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } + // TODO: un-real object from external realm, + // can be with declared type, or just a literal, + // regarding the former one, check the origin pkg, + // and panic, for the latter one, check its element + // for map, func, array, slice, etc. + // XXX, oo must be new real here, it's not escaped // if it's reference, all right if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { switch oo.GetOriginValue().(type) { case PointerValue, *SliceValue: // ref panic("cannot attach a reference to an unreal object from an external realm") + // TODO: ignore this now. case *FuncValue: if b, ok := oo.(*Block); ok { debug2.Println2("block: ", b) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 89f53c28cc2..4c38cf01673 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -300,7 +300,9 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo2 := pv.TV.GetFirstObject(store) debug2.Println2("oo2: ", oo2) - // XXX, special case for floating func value + // TODO: defer this... + // XXX, considering this + // special case for un-real func value if originPkg != rlm.ID { // the funcValue has not attached, // it has the chance to be attached to @@ -308,7 +310,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // other values in current realm. if fv, ok := pv.TV.V.(*FuncValue); ok && oo2.GetObjectID().IsZero() { //debug2.Println2("fv: ", fv) - // TODO: reuse this + // XXX, maybe is closure is good, real or unreal b := NewBlock(fv.GetSource(store), fv.GetClosure(store)) //debug2.Println2("b for fv: ", b) oo2 = b From 23644d8bf36e23b5da7d5d638725debe2d2fa89b Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 4 Feb 2025 11:54:56 +0800 Subject: [PATCH 50/88] refactor --- .../tests/crossrealm/map/crossrealm_map.gno | 9 ++ gnovm/pkg/gnolang/debug_false.go | 5 +- gnovm/pkg/gnolang/ownership.go | 3 +- gnovm/pkg/gnolang/realm.go | 107 +++++++----------- gnovm/pkg/gnolang/values.go | 2 +- gnovm/tests/files/zrealm_crossrealm15.gno | 6 +- gnovm/tests/files/zrealm_crossrealm37c.gno | 14 +++ 7 files changed, 75 insertions(+), 71 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm37c.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno index 752b2d7ecd1..0588938a660 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno @@ -1,5 +1,9 @@ package crossrealm_map +type Foo struct{} + +var f = Foo{} + var m map[string]int func init() { @@ -16,6 +20,11 @@ func GetMap2(f func(map[string]int)) { f(m1) } +func GetMap4() map[string]Foo { + var m1 = map[string]Foo{"foo": f} + return m1 +} + // -------------------------------------- type MyMap map[string]int diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index 4a59419a15a..ed949359db7 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,5 +4,6 @@ package gnolang const debug debugging = false -// const debug2 debugging = true -const debug2 debugging = false +const debug2 debugging = true + +//const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 8b20329457b..87cbf89c32e 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -414,7 +414,7 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } } - // get pkgId from type + // infer pkgId from declared type getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) @@ -452,6 +452,7 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = getPkgId(pv.TV.T) } return + // TODO: this is not correct, CompositeLit has no pkgPath case *MapValue, *StructValue: originPkg = getPkgId(tv.T) return diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 784c15e5e3c..be560e4342e 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -180,7 +180,15 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { return // do nothing. } + debug2.Println2("po is real, assert association valid") + // is po is real, the check defers to finalization, incRefCreatedDescendants + if _, ok := co.(*MapValue); ok { + debug2.Println2("association, object is realmless, check elem...") + checkCrossRealm(rlm, store, co, nil) + } + // TODO: check unreal external here, if po is real, association is invalid, panic + // else, defer to finalize??? debug2.Println2("po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) if po.GetObjectID().PkgID != rlm.ID { @@ -222,8 +230,9 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { - debug2.Printf2("checkCrossRealm2, tv: %v\n", tv, reflect.TypeOf(tv.V)) - if fo, ok := tv.V.(Object); ok { + debug2.Println2("checkCrossRealm2, tv: ", tv, reflect.TypeOf(tv.V)) + tv2 := fillValueTV(store, tv) + if fo, ok := tv2.V.(Object); ok { checkCrossRealm(rlm, store, fo, nil) } else { // reference to object switch rv := tv.V.(type) { @@ -238,27 +247,40 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. // refValue is required to handle cases where the value is a slice. -// The `len` and `offset` are needed to validate proper elements the underlying array. +// The `len` and `offset` are needed to validate proper elements of the underlying array. func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("refValue: ", refValue) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("oo.GetObjectInfo: ", oo.GetObjectInfo()) + debug2.Println2("oo.GetObjectID: ", oo.GetObjectID()) + + // if oo.OriginRealm is zero, either from current realm, or a compositeLit from + // external realm, for the former one. both can be unreal. + // if composite value with pkgId inferred from declared type, it should be real. + // So, check if zero, real... + + if rlm.ID != oo.GetOriginRealm() { + if oo.GetOriginRealm().IsZero() { + // A zero value indicates that it is a realmless composite literal. + } else { // with pkgID, it must be real + if !oo.GetIsReal() { // it's possible that embedded in another container, or a pointer + panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", oo)) + } + } + } switch v := oo.(type) { case *StructValue: - if !v.GetIsReal() { // it's possible that embedded in another container - if rlm.ID != oo.GetOriginRealm() { // it's ok for un-real object from same realm - panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", v)) - } - } // check fields for _, fv := range v.Fields { - rfv := fillValueTV(store, &fv) - checkCrossRealm2(rlm, store, rfv) + checkCrossRealm2(rlm, store, &fv) } case *MapValue: - // TODO: complete this + debug2.Println2("MapValue, v: ", v) + for cur := v.List.Head; cur != nil; cur = cur.Next { + checkCrossRealm2(rlm, store, &cur.Key) + checkCrossRealm2(rlm, store, &cur.Value) + } case *BoundMethodValue: // TODO: complete this case *Block: @@ -271,17 +293,15 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { case *HeapItemValue: // TODO: is it necessary? // if heapItem, the embedded should be all real now??? - fillValueTV(store, &v.Value) checkCrossRealm2(rlm, store, &v.Value) case *ArrayValue: if sv, ok := refValue.(*SliceValue); ok { // only check referenced elem for i := sv.Offset; i < sv.Length; i++ { - e := fillValueTV(store, &v.List[i]) - checkCrossRealm2(rlm, store, e) + checkCrossRealm2(rlm, store, &v.List[i]) } } else { - panic("should be slice value") + debug2.Println2("TODO, check elems of ArrayValue, v: ", v) } default: panic("should not happen, oo is not object") @@ -531,7 +551,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // XXX, unreal oo check happens in here // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - debug2.Println2("---incRefCreatedDescendants from oo: ", oo) + debug2.Println2("---incRefCreatedDescendants from oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("---rlm.ID: ", rlm.ID) @@ -546,52 +566,13 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } - // TODO: un-real object from external realm, - // can be with declared type, or just a literal, - // regarding the former one, check the origin pkg, - // and panic, for the latter one, check its element - // for map, func, array, slice, etc. - - // XXX, oo must be new real here, it's not escaped - // if it's reference, all right - if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { - switch oo.GetOriginValue().(type) { - case PointerValue, *SliceValue: // ref - panic("cannot attach a reference to an unreal object from an external realm") - // TODO: ignore this now. - case *FuncValue: - if b, ok := oo.(*Block); ok { - debug2.Println2("block: ", b) - originValue := b.GetOriginValue() - debug2.Println2("originValue: ", originValue) - - if fv, ok := originValue.(*FuncValue); ok { - debug2.Println2("fv: ", fv) - debug2.Println2("fv...values: ", fv.Source.GetStaticBlock().Values) - for _, tv := range fv.Source.GetStaticBlock().Values { - debug2.Println2("tv: ", tv) - debug2.Println2("tv.V: ", tv.V, reflect.TypeOf(tv.V)) - debug2.Println2("tv.T: ", tv.T, reflect.TypeOf(tv.T)) - - if dt, ok := tv.T.(*DeclaredType); ok { - debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, type of base: %v \n", dt, dt.Base, reflect.TypeOf(dt.Base)) - switch tt := dt.Base.(type) { - case *StructType, *InterfaceType: // types with pkgpath - if IsRealmPath(tt.GetPkgPath()) { - originPkg := PkgIDFromPkgPath(dt.Base.GetPkgPath()) - if originPkg != rlm.ID { - panic("cannot attach function contains object from external realm") - } - } - } - } - // TODO: also check captures - } - } - } - default: - panic("cannot attach a value of a type defined by another realm") - } + // while associating, if po is unreal, the check + // defers to here. + // TODO: correct this + _, ok1 := oo.(*PackageValue) + _, ok2 := oo.(*Block) // package block + if !ok1 && !ok2 { + checkCrossRealm(rlm, store, oo, oo.GetOriginValue()) } // RECURSE GUARD diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 4c38cf01673..b1f89b6edc7 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -255,7 +255,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index e8965ffdcd2..726ee2fad40 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -2,14 +2,12 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm" ) type fooer struct{} -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (fooer) Foo() { println("hello") } var f *fooer @@ -24,4 +22,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{} +// cannot attach un-real object from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm37c.gno b/gnovm/tests/files/zrealm_crossrealm37c.gno new file mode 100644 index 00000000000..d470cc59740 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm37c.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/map" + +var root interface{} + +func main() { + root = crossrealm.GetMap4() // XXX, root is real, so check should happen in DidUpdate, namely, association panic + println("ok") +} + +// Error: +// cannot attach object by value from external realm: struct{} From 301935ffb27afff4bd9acac7ae7e8bdfd127c9a5 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 4 Feb 2025 23:16:39 +0800 Subject: [PATCH 51/88] fixup --- gnovm/pkg/gnolang/debug_false.go | 4 +- gnovm/pkg/gnolang/ownership.go | 27 +++--- gnovm/pkg/gnolang/realm.go | 97 ++++++++++++------- gnovm/pkg/gnolang/values.go | 17 ---- gnovm/tests/files/zrealm_crossrealm15.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22.gno | 37 +------ gnovm/tests/files/zrealm_crossrealm24.gno | 2 +- gnovm/tests/files/zrealm_crossrealm24d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm25.gno | 26 ----- gnovm/tests/files/zrealm_crossrealm25a.gno | 26 ----- gnovm/tests/files/zrealm_crossrealm25b.gno | 73 -------------- gnovm/tests/files/zrealm_crossrealm25c.gno | 33 ------- gnovm/tests/files/zrealm_crossrealm25d.gno | 34 ------- gnovm/tests/files/zrealm_crossrealm25e.gno | 32 ------ gnovm/tests/files/zrealm_crossrealm25f.gno | 28 ------ gnovm/tests/files/zrealm_crossrealm28c.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28d.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28d2.gno | 34 +++++++ ...alm29.gno => zrealm_crossrealm29_func.gno} | 0 ...lm30.gno => zrealm_crossrealm30_slice.gno} | 0 gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- ...lm34.gno => zrealm_crossrealm34_slice.gno} | 4 +- ...ealm37.gno => zrealm_crossrealm37_map.gno} | 0 gnovm/tests/files/zrealm_crossrealm37c.gno | 4 +- .../tests/files/zrealm_crossrealm44_array.gno | 16 +++ .../tests/files/zrealm_crossrealm45_array.gno | 16 +++ .../tests/files/zrealm_crossrealm46_array.gno | 16 +++ 29 files changed, 180 insertions(+), 368 deletions(-) delete mode 100644 gnovm/tests/files/zrealm_crossrealm25.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25a.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25b.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25c.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25d.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25e.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm25f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28d2.gno rename gnovm/tests/files/{zrealm_crossrealm29.gno => zrealm_crossrealm29_func.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm30.gno => zrealm_crossrealm30_slice.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm34.gno => zrealm_crossrealm34_slice.gno} (95%) rename gnovm/tests/files/{zrealm_crossrealm37.gno => zrealm_crossrealm37_map.gno} (100%) create mode 100644 gnovm/tests/files/zrealm_crossrealm44_array.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm45_array.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm46_array.gno diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index ed949359db7..bf213870a3a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,6 @@ package gnolang const debug debugging = false -const debug2 debugging = true +//const debug2 debugging = true -//const debug2 debugging = false +const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 87cbf89c32e..2c5035c6599 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -398,7 +398,8 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // otherwise, it's inference from its type. func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) - // get first object + + // attempting to retrieve the original package using the ObjectID obj := tv.GetFirstObject(store) debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) if obj != nil { @@ -414,7 +415,7 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } } - // infer pkgId from declared type + // attempting to infer original package using declared type getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) @@ -426,16 +427,15 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { return } - // if still zero switch cv := obj.(type) { - case *ArrayValue: - // if array is real, retrieved from objectID, - // otherwise, it's retrieved from elem type. - // it panics while attach this kind of slice/array value: `var fs []crossrealm.Fooer`, - if IsRealmPath(tv.T.Elem().GetPkgPath()) { - originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) - } - return + //case *ArrayValue: + // // if array is real, retrieved from objectID, + // // otherwise, it's retrieved from elem type. + // // it panics while attach this kind of slice/array value: `var fs []crossrealm.Fooer`, + // if IsRealmPath(tv.T.Elem().GetPkgPath()) { + // originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) + // } + // return case *Block: if _, ok := tv.V.(*FuncValue); !ok { //fmt.Println("cv: ", cv) @@ -452,9 +452,8 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = getPkgId(pv.TV.T) } return - // TODO: this is not correct, CompositeLit has no pkgPath - case *MapValue, *StructValue: - originPkg = getPkgId(tv.T) + case *MapValue, *StructValue, *ArrayValue: + originPkg = getPkgId(tv.T) // if it's declared type, otherwise zero return default: // do nothing diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index be560e4342e..09f024678ef 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -180,13 +180,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { return // do nothing. } - debug2.Println2("po is real, assert association valid") - // is po is real, the check defers to finalization, incRefCreatedDescendants - if _, ok := co.(*MapValue); ok { - debug2.Println2("association, object is realmless, check elem...") - checkCrossRealm(rlm, store, co, nil) - } - // TODO: check unreal external here, if po is real, association is invalid, panic // else, defer to finalize??? @@ -210,12 +203,17 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { co.IncRefCount() if co.GetRefCount() > 1 { rlm.MarkNewEscapedCheckCrossRealm(store, co, co.GetOriginValue()) - } else if co.GetIsReal() { - rlm.MarkDirty(co) } else { - debug2.Println2("set owner of co: ", co) - co.SetOwner(po) - rlm.MarkNewReal(co) + if co.GetIsReal() { // TODO: how this happen? + rlm.MarkDirty(co) + } else { + debug2.Println2("set owner of co: ", co) + co.SetOwner(po) + rlm.MarkNewReal(co) + } + // check cross realm for non escaped objects + debug2.Println2("=========po is real, check cross realm for non escaped objects========") + checkCrossRealm(rlm, store, co, co.GetOriginValue()) } } @@ -229,16 +227,23 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } +// check cross realm recursively func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { debug2.Println2("checkCrossRealm2, tv: ", tv, reflect.TypeOf(tv.V)) tv2 := fillValueTV(store, tv) - if fo, ok := tv2.V.(Object); ok { - checkCrossRealm(rlm, store, fo, nil) + if oo, ok := tv2.V.(Object); ok { + debug2.Println2("is object") + // set origin realm for embedded value + oo.SetOriginRealm(tv2.GetOriginPkg(store)) + checkCrossRealm(rlm, store, oo, nil) } else { // reference to object switch rv := tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm // XXX: consider pkgId here, A -> B - > A?... reo := tv.GetFirstObject(store) + debug2.Println2("is reference to object, reo: ", reo) + // if base escaped, do nothing + reo.SetOriginRealm(tv2.GetOriginPkg(store)) checkCrossRealm(rlm, store, reo, rv) } } @@ -248,23 +253,44 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. +// NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("refValue: ", refValue) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) debug2.Println2("oo.GetObjectID: ", oo.GetObjectID()) + debug2.Println2("oo.GetOriginRealm: ", oo.GetOriginRealm()) // if oo.OriginRealm is zero, either from current realm, or a compositeLit from // external realm, for the former one. both can be unreal. // if composite value with pkgId inferred from declared type, it should be real. // So, check if zero, real... - if rlm.ID != oo.GetOriginRealm() { - if oo.GetOriginRealm().IsZero() { + if rlm.ID != oo.GetOriginRealm() { // crossing realm + debug2.Println2("crossing realm") + if oo.GetOriginRealm().IsZero() { // mapLit, etc + debug2.Println2("origin realm is zero, check recursively for composite literal") // A zero value indicates that it is a realmless composite literal. - } else { // with pkgID, it must be real - if !oo.GetIsReal() { // it's possible that embedded in another container, or a pointer - panic(fmt.Sprintf("cannot attach un-real object from external realm: %v", oo)) + } else { + debug2.Println2("refValue: ", refValue) + debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("oo.GetIsEscaped: ", oo.GetRefCount()) + // if its real object crossing, must be reference type + if refValue != nil { // reference value + //if oo.GetIsEscaped() { + //if oo.GetRefCount() > 1 { + // debug2.Println2("reference to escaped object, do nothing") + // return + //} + if oo.GetIsReal() { + return + } + if !oo.GetIsReal() { + //panic(fmt.Sprintf("cannot attach unreal object by value from external realm: %v", oo)) + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) + } + } else { + panic(fmt.Sprintf("cannot attach a value of a type defined by another realm")) } } } @@ -302,6 +328,11 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { } } else { debug2.Println2("TODO, check elems of ArrayValue, v: ", v) + if v.Data == nil { + for _, e := range v.List { + checkCrossRealm2(rlm, store, &e) + } + } } default: panic("should not happen, oo is not object") @@ -325,7 +356,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa } if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm - if originValue != nil { // is reference object from external realm + if originValue != nil { // must be reference checkCrossRealm(rlm, store, oo, originValue) } else { panic("cannot attach objects by value from external realm") @@ -450,13 +481,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -471,9 +502,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -873,9 +904,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index b1f89b6edc7..8c47a2c361a 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -300,23 +300,6 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo2 := pv.TV.GetFirstObject(store) debug2.Println2("oo2: ", oo2) - // TODO: defer this... - // XXX, considering this - // special case for un-real func value - if originPkg != rlm.ID { - // the funcValue has not attached, - // it has the chance to be attached to - // external realm, if it does not reference - // other values in current realm. - if fv, ok := pv.TV.V.(*FuncValue); ok && oo2.GetObjectID().IsZero() { - //debug2.Println2("fv: ", fv) - // XXX, maybe is closure is good, real or unreal - b := NewBlock(fv.GetSource(store), fv.GetClosure(store)) - //debug2.Println2("b for fv: ", b) - oo2 = b - } - } - // originValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15.gno index 726ee2fad40..1eed5e49b18 100644 --- a/gnovm/tests/files/zrealm_crossrealm15.gno +++ b/gnovm/tests/files/zrealm_crossrealm15.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index deaa07a5c82..15cae6ab01c 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{} +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index 291ecd7c7a7..ce4b6fea396 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -29,4 +29,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{("A" string)} +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno index 35f82fb0c43..100eccd1709 100644 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ b/gnovm/tests/files/zrealm_crossrealm22.gno @@ -34,12 +34,12 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm"] -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ // "Blank": {}, // "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", // "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", // "RefCount": "1" // }, // "Parent": { @@ -79,33 +79,6 @@ func main() { // } // ] // } -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", -// "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "RefCount": "1" -// }, -// "Parent": { -// "@type": "/gno.RefValue", -// "Hash": "47f9df1dd7beb8ae6c59db94bf51bad6beaf4fd7", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" -// }, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "28", -// "File": "files/zrealm_crossrealm22.gno", -// "Line": "13", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Values": [ -// {} -// ] -// } // u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ // "Blank": {}, // "ObjectInfo": { @@ -594,8 +567,8 @@ func main() { // "@type": "/gno.FuncValue", // "Closure": { // "@type": "/gno.RefValue", -// "Hash": "47f9df1dd7beb8ae6c59db94bf51bad6beaf4fd7", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// "Hash": "23de97a577d573252d00394ce9b71c24b0646546", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" // }, // "FileName": "", // "IsMethod": false, diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24.gno index 0f8f96a0cfe..d14b374a480 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24.gno @@ -26,7 +26,7 @@ func main() { } // Output: -// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(ref(5965ae851c02ab677bc8394b408535c1db9b2635:4) gno.land/r/demo/tests/crossrealm/struct.Bar) // &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) // &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno index 8a7a10411e0..60097623655 100644 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ b/gnovm/tests/files/zrealm_crossrealm24d.gno @@ -25,7 +25,7 @@ func main() { } // Output: -// &(struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) +// &(ref(5965ae851c02ab677bc8394b408535c1db9b2635:4) gno.land/r/demo/tests/crossrealm/struct.Bar) // &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) // &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) diff --git a/gnovm/tests/files/zrealm_crossrealm25.gno b/gnovm/tests/files/zrealm_crossrealm25.gno deleted file mode 100644 index d0b3a3aa273..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25.gno +++ /dev/null @@ -1,26 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -func init() { - f = fooer{name: "local fooer"} -} - -func main() { - crossrealm.SetContainer(f) - print(".") -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25a.gno b/gnovm/tests/files/zrealm_crossrealm25a.gno deleted file mode 100644 index df9f6d157d2..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25a.gno +++ /dev/null @@ -1,26 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct{} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -func init() { - f = fooer{} -} - -func main() { - crossrealm.SetContainer(&f) - print(".") -} - -// Output: -// . diff --git a/gnovm/tests/files/zrealm_crossrealm25b.gno b/gnovm/tests/files/zrealm_crossrealm25b.gno deleted file mode 100644 index 166c811ee75..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25b.gno +++ /dev/null @@ -1,73 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -type localContainer struct { - name string - f fooer -} - -var lc localContainer - -func init() { - // container attached, embedded object attached - lc = localContainer{name: "local_container", f: fooer{name: "local_fooer"}} // attach -} - -func main() { - crossrealm.SetContainer(&lc.f) - print(".") -} - -// Output: -// . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] -// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// }, -// { -// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:6" -// }, -// "Index": "1", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", -// "ModTime": "4", -// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm25c.gno b/gnovm/tests/files/zrealm_crossrealm25c.gno deleted file mode 100644 index e647eaa6e1e..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25c.gno +++ /dev/null @@ -1,33 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -type localContainer struct { - name string - f fooer -} - -var lc localContainer - -func init() { - lc = localContainer{name: "local_container", f: fooer{name: "local_fooer"}} // attach -} - -func main() { - crossrealm.SetContainer(lc.f) - print(".") -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25d.gno b/gnovm/tests/files/zrealm_crossrealm25d.gno deleted file mode 100644 index eba4ee7de76..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25d.gno +++ /dev/null @@ -1,34 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -type localContainer struct { - name string - ff fooer -} - -var lc localContainer - -func init() { - f := fooer{name: "local_fooer_global"} - lc = localContainer{name: "local_container", ff: f} // attach -} - -func main() { - crossrealm.SetContainer(lc.ff) - print(".") -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25e.gno b/gnovm/tests/files/zrealm_crossrealm25e.gno deleted file mode 100644 index 8e48b45a391..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25e.gno +++ /dev/null @@ -1,32 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -type localContainer struct { - name string - f fooer -} - -var lc localContainer -var ff fooer - -func main() { - ff = fooer{name: "local_fooer"} // ref 1, unreal - lc = localContainer{name: "local_container", f: ff} - crossrealm.SetContainer(lc.f) - print(".") -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25f.gno b/gnovm/tests/files/zrealm_crossrealm25f.gno deleted file mode 100644 index dc12a9de4e8..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm25f.gno +++ /dev/null @@ -1,28 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct{ name string } - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer -var root interface{} - -func init() { - f = fooer{name: "local fooer"} - g := f - root = g -} - -func main() { - print(".") -} - -// Output: -// . diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index 7f2970d7a2b..a3f6fd66b56 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -24,7 +24,5 @@ func main() { println("ok") } -// Output: -// (struct{("2" string)} gno.land/r/crossrealm_test.foo) -// (struct{("3" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index a3cdc28b7ee..c93ac2161c1 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -24,7 +24,5 @@ func main() { println("ok") } -// Output: -// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d2.gno b/gnovm/tests/files/zrealm_crossrealm28d2.gno new file mode 100644 index 00000000000..3380001af1a --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28d2.gno @@ -0,0 +1,34 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f1 = &foo{name: "1"} +var f2 = &foo{name: "2"} +var f3 = &foo{name: "3"} + +func main() { + var Local_S []crossrealm.Fooer // XXX, the array object should be in current realm + Local_S = append(Local_S, f1) + Local_S = append(Local_S, f2) + Local_S = append(Local_S, f3) + + fs := Local_S[1:] + crossrealm.SetSlice(fs) + println("ok") +} + +// Output: +// &(ref(f5a516808f8976c33939133293d598ce3bca4e8d:6) gno.land/r/crossrealm_test.foo) +// &(ref(f5a516808f8976c33939133293d598ce3bca4e8d:8) gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm29.gno b/gnovm/tests/files/zrealm_crossrealm29_func.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm29.gno rename to gnovm/tests/files/zrealm_crossrealm29_func.gno diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30_slice.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm30.gno rename to gnovm/tests/files/zrealm_crossrealm30_slice.gno diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index dc00b5204fe..871ad3a2765 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34_slice.gno similarity index 95% rename from gnovm/tests/files/zrealm_crossrealm34.gno rename to gnovm/tests/files/zrealm_crossrealm34_slice.gno index ea977b3a707..ae53ea3d97e 100644 --- a/gnovm/tests/files/zrealm_crossrealm34.gno +++ b/gnovm/tests/files/zrealm_crossrealm34_slice.gno @@ -77,7 +77,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "files/zrealm_crossrealm34.gno", +// "FileName": "files/zrealm_crossrealm34_slice.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -88,7 +88,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "files/zrealm_crossrealm34.gno", +// "File": "files/zrealm_crossrealm34_slice.gno", // "Line": "12", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm37.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm37.gno rename to gnovm/tests/files/zrealm_crossrealm37_map.gno diff --git a/gnovm/tests/files/zrealm_crossrealm37c.gno b/gnovm/tests/files/zrealm_crossrealm37c.gno index d470cc59740..9429ab08d43 100644 --- a/gnovm/tests/files/zrealm_crossrealm37c.gno +++ b/gnovm/tests/files/zrealm_crossrealm37c.gno @@ -6,9 +6,9 @@ import crossrealm "gno.land/r/demo/tests/crossrealm/map" var root interface{} func main() { - root = crossrealm.GetMap4() // XXX, root is real, so check should happen in DidUpdate, namely, association panic + root = crossrealm.GetMap4() println("ok") } // Error: -// cannot attach object by value from external realm: struct{} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm44_array.gno b/gnovm/tests/files/zrealm_crossrealm44_array.gno new file mode 100644 index 00000000000..4fbd5704ae3 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm44_array.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/array" +) + +var root interface{} + +func main() { + root = crossrealm.GetArray() + println(".") +} + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm45_array.gno b/gnovm/tests/files/zrealm_crossrealm45_array.gno new file mode 100644 index 00000000000..4f077307b96 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm45_array.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/array" +) + +var root interface{} + +func main() { + root = crossrealm.GetArray2() + println(".") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm46_array.gno b/gnovm/tests/files/zrealm_crossrealm46_array.gno new file mode 100644 index 00000000000..62f6128ef6b --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm46_array.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/array" +) + +var root interface{} + +func main() { + root = crossrealm.GetArray3() + println(".") +} + +// Output: +// . From 33429915396837024ded9c9f32316bbf84f1a5b6 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 4 Feb 2025 23:58:08 +0800 Subject: [PATCH 52/88] fixup --- .../crossrealm/array/crossrealm_array.gno | 17 + gnovm/pkg/gnolang/ownership.go | 10 - gnovm/pkg/gnolang/realm.go | 45 +- gnovm/tests/files/zrealm_crossrealm20.gno | 40 - ...0a.gno => zrealm_crossrealm20a_struct.gno} | 0 ...srealm21a.gno => zrealm_crossrealm20b.gno} | 0 ...srealm21b.gno => zrealm_crossrealm20c.gno} | 0 gnovm/tests/files/zrealm_crossrealm21c.gno | 17 - gnovm/tests/files/zrealm_crossrealm22.gno | 803 ------ .../tests/files/zrealm_crossrealm22_func.gno | 2279 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm22a.gno | 26 +- gnovm/tests/files/zrealm_crossrealm22a1.gno | 24 - gnovm/tests/files/zrealm_crossrealm22a2.gno | 35 - gnovm/tests/files/zrealm_crossrealm22b.gno | 20 +- gnovm/tests/files/zrealm_crossrealm22c.gno | 17 +- gnovm/tests/files/zrealm_crossrealm22d.gno | 15 +- gnovm/tests/files/zrealm_crossrealm22e.gno | 21 - ...alm23.gno => zrealm_crossrealm23_pure.gno} | 0 ...=> zrealm_crossrealm24_struct_pointer.gno} | 8 +- ...lm28.gno => zrealm_crossrealm28_slice.gno} | 0 .../tests/files/zrealm_crossrealm29_func.gno | 20 - gnovm/tests/files/zrealm_crossrealm29a.gno | 21 - gnovm/tests/files/zrealm_crossrealm29b.gno | 19 - gnovm/tests/files/zrealm_crossrealm29c.gno | 19 - gnovm/tests/files/zrealm_crossrealm29d.gno | 26 - gnovm/tests/files/zrealm_crossrealm29e.gno | 26 - gnovm/tests/files/zrealm_crossrealm29f.gno | 27 - gnovm/tests/files/zrealm_crossrealm29g.gno | 27 - gnovm/tests/files/zrealm_crossrealm38.gno | 14 - gnovm/tests/files/zrealm_crossrealm39.gno | 14 - ...m40.gno => zrealm_crossrealm40_method.gno} | 0 31 files changed, 2375 insertions(+), 1215 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm20.gno rename gnovm/tests/files/{zrealm_crossrealm20a.gno => zrealm_crossrealm20a_struct.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm21a.gno => zrealm_crossrealm20b.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm21b.gno => zrealm_crossrealm20c.gno} (100%) delete mode 100644 gnovm/tests/files/zrealm_crossrealm21c.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm22.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22_func.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm22a1.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm22a2.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm22e.gno rename gnovm/tests/files/{zrealm_crossrealm23.gno => zrealm_crossrealm23_pure.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm24.gno => zrealm_crossrealm24_struct_pointer.gno} (95%) rename gnovm/tests/files/{zrealm_crossrealm28.gno => zrealm_crossrealm28_slice.gno} (100%) delete mode 100644 gnovm/tests/files/zrealm_crossrealm29_func.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29a.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29b.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29c.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29d.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29e.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29f.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm29g.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm38.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm39.gno rename gnovm/tests/files/{zrealm_crossrealm40.gno => zrealm_crossrealm40_method.gno} (100%) diff --git a/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno b/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno new file mode 100644 index 00000000000..e48255875e6 --- /dev/null +++ b/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno @@ -0,0 +1,17 @@ +package crossrealm_array + +type Foo struct{ name string } + +var f = Foo{"foo"} + +func GetArray() [2]Foo { + return [2]Foo{Foo{"a"}, Foo{"b"}} +} + +func GetArray2() [2]*Foo { + return [2]*Foo{&Foo{"a"}, &Foo{"b"}} +} + +func GetArray3() [1]*Foo { + return [1]*Foo{&f} +} diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 2c5035c6599..e8a0b5fead4 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -428,18 +428,8 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } switch cv := obj.(type) { - //case *ArrayValue: - // // if array is real, retrieved from objectID, - // // otherwise, it's retrieved from elem type. - // // it panics while attach this kind of slice/array value: `var fs []crossrealm.Fooer`, - // if IsRealmPath(tv.T.Elem().GetPkgPath()) { - // originPkg = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath()) - // } - // return case *Block: if _, ok := tv.V.(*FuncValue); !ok { - //fmt.Println("cv: ", cv) - //fmt.Println("cv.Source: ", cv.Source) originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) } return diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 09f024678ef..95b7dbf27b8 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -258,7 +258,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) debug2.Println2("refValue: ", refValue) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("oo.GetObjectID: ", oo.GetObjectID()) + //debug2.Println2("oo.GetObjectID: ", oo.GetObjectID()) debug2.Println2("oo.GetOriginRealm: ", oo.GetOriginRealm()) // if oo.OriginRealm is zero, either from current realm, or a compositeLit from @@ -310,12 +310,17 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { case *BoundMethodValue: // TODO: complete this case *Block: - // XXX, can this happen? - switch v.GetOriginValue().(type) { - case PointerValue, *SliceValue, *FuncValue: - default: - panic("should not happen, block is not real") - } + debug2.Println2("BlockValue, v: ", v) + // XXX, also captures? + for _, tv := range v.Values { + checkCrossRealm2(rlm, store, &tv) + } + //// XXX, can this happen? + //switch v.GetOriginValue().(type) { + //case PointerValue, *SliceValue, *FuncValue: + //default: + // panic("should not happen, block is not real") + //} case *HeapItemValue: // TODO: is it necessary? // if heapItem, the embedded should be all real now??? @@ -481,13 +486,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -502,9 +507,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -904,9 +909,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno deleted file mode 100644 index d8e02d8659e..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm20.gno +++ /dev/null @@ -1,40 +0,0 @@ -// 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"} - fg := func() crossrealm.Fooer { return f } - crossrealm.SetFooerGetter(fg) - crossrealm.CallFooerGetterFoo() - f.s = "C" - crossrealm.CallFooerGetterFoo() -} - -func main() { - print(".") -} - -// Output: -// hello B gno.land/r/crossrealm_test -// hello B gno.land/r/crossrealm_test -// . - -// Realm: -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm20a.gno b/gnovm/tests/files/zrealm_crossrealm20a_struct.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm20a.gno rename to gnovm/tests/files/zrealm_crossrealm20a_struct.gno diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm20b.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm21a.gno rename to gnovm/tests/files/zrealm_crossrealm20b.gno diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm21b.gno rename to gnovm/tests/files/zrealm_crossrealm20c.gno diff --git a/gnovm/tests/files/zrealm_crossrealm21c.gno b/gnovm/tests/files/zrealm_crossrealm21c.gno deleted file mode 100644 index dea0cc50103..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm21c.gno +++ /dev/null @@ -1,17 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm/struct" -) - -func init() { - b0 := crossrealm.Bar{A: 1} -} - -func main() { - print(".") -} - -// Output: -// . diff --git a/gnovm/tests/files/zrealm_crossrealm22.gno b/gnovm/tests/files/zrealm_crossrealm22.gno deleted file mode 100644 index 100eccd1709..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm22.gno +++ /dev/null @@ -1,803 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" -) - -func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooerGetter(func() crossrealm.Fooer { return f }) - crossrealm.CallFooerGetterFoo() - f.SetS("B") - crossrealm.CallFooerGetterFoo() - println(".") - - //f.SetS("C") - //crossrealm.SetFooerGetter(crossrealm_b.FooerGetter) - //crossrealm.CallFooerGetterFoo() - //println(".") - // - //f.SetS("D") - //crossrealm.SetFooerGetter(crossrealm_b.FooerGetterBuilder()) - //crossrealm.CallFooerGetterFoo() - //println(".") -} - -// Output: -// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", -// "ModTime": "0", -// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", -// "RefCount": "1" -// }, -// "Parent": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm22.gno", -// "Line": "11", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:3" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ] -// } -// 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_p.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_p.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.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.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooer", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "40", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "42", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "Methods": [], -// "Name": "FooerGetter", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Hash": "23de97a577d573252d00394ce9b71c24b0646546", -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" -// }, -// "FileName": "", -// "IsMethod": false, -// "Name": "", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "28", -// "File": "files/zrealm_crossrealm22.gno", -// "Line": "13", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "SetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "48", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "53", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerGetterFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "57", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// switchrealm["gno.land/r/crossrealm_test"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "B" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/crossrealm_test"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22_func.gno b/gnovm/tests/files/zrealm_crossrealm22_func.gno new file mode 100644 index 00000000000..402efd7774e --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22_func.gno @@ -0,0 +1,2279 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +func main() { + f := crossrealm_b.Fooer + crossrealm.SetFooerGetter(func() crossrealm.Fooer { return f }) + crossrealm.CallFooerGetterFoo() + f.SetS("B") + crossrealm.CallFooerGetterFoo() + println(".") + + f.SetS("C") + crossrealm.SetFooerGetter(crossrealm_b.FooerGetter) + crossrealm.CallFooerGetterFoo() + println(".") + + f.SetS("D") + crossrealm.SetFooerGetter(crossrealm_b.FooerGetterBuilder()) + crossrealm.CallFooerGetterFoo() + println(".") +} + +// Output: +// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// . +// hello C cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// . +// hello D cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// }, +// "Parent": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "files/zrealm_crossrealm22_func.gno", +// "Line": "11", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ] +// } +// 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_p.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_p.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.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.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "42", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "FooerGetter", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Hash": "6910a67014683a4a2c8baad2a512640042e693d1", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:6" +// }, +// "FileName": "", +// "IsMethod": false, +// "Name": "", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "28", +// "File": "files/zrealm_crossrealm22_func.gno", +// "Line": "13", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "SetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "53", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerGetterFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "57", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "B" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "C" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "6", +// "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_p.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_p.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.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.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "42", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "FooerGetter", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:5" +// }, +// "FileName": "", +// "IsMethod": false, +// "Name": "", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm_b", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "16", +// "File": "crossrealm.gno", +// "Line": "24", +// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "SetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "53", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerGetterFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "57", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// d[1712ac7adcfdc8e58a67e5615e20fb312394c4df:6] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "D" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// c[1712ac7adcfdc8e58a67e5615e20fb312394c4df:7]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7", +// "ModTime": "0", +// "OwnerID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "RefCount": "1" +// }, +// "Parent": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:5" +// }, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "23", +// "File": "crossrealm.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// u[1712ac7adcfdc8e58a67e5615e20fb312394c4df:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:2", +// "IsEscaped": true, +// "ModTime": "6", +// "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_p.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_p.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.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.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "42", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "FooerGetter", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Hash": "55afa79ac9e1ceaea5478f76e9fe40623598bdb7", +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:7" +// }, +// "FileName": "", +// "IsMethod": false, +// "Name": "", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm_b", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "62", +// "File": "crossrealm.gno", +// "Line": "26", +// "PkgPath": "gno.land/r/demo/tests/crossrealm_b" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "SetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "53", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerGetterFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "57", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22a.gno b/gnovm/tests/files/zrealm_crossrealm22a.gno index cafa8b44aaa..70d6a63855e 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a.gno @@ -2,26 +2,24 @@ package crossrealm_test import ( - "std" - - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" + crossrealm "gno.land/r/demo/tests/crossrealm/func" ) -// TODO: consider this and xxx22.gno, xxx21.gno, xxx20.gno -// how about func()int? and func() crossrealm.Fooer? -// check type for param type? -// see also 37a.gno +var b = 1 + +type Local_S struct { + name string +} func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooerGetter(func() crossrealm.Fooer { - return f - }) - crossrealm.CallFooerGetterFoo() + f := func() bool { + c := b + var ls Local_S + return true + } + crossrealm.SetCallback(f) println("ok") } // Output: -// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm // ok diff --git a/gnovm/tests/files/zrealm_crossrealm22a1.gno b/gnovm/tests/files/zrealm_crossrealm22a1.gno deleted file mode 100644 index 8f7a346c5a9..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm22a1.gno +++ /dev/null @@ -1,24 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" -) - -type Foo struct{} - -func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooerGetter(func() crossrealm.Fooer { - f1 := Foo{} - return f - }) - crossrealm.CallFooerGetterFoo() - println("ok") -} - -// Error: -// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno deleted file mode 100644 index 0e1290f0594..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm22a2.gno +++ /dev/null @@ -1,35 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" -) - -// TODO: consider this and xxx22.gno, xxx21.gno, xxx20.gno -// how about func()int? and func() crossrealm.Fooer? -// check type for param type? -// see also 37a.gno - -type local_S struct{ name string } - -var root interface{} - -func main() { // the block is attached to current realm - f := crossrealm_b.Fooer - crossrealm.SetFooerGetter(func() crossrealm.Fooer { // this funcLit is attached to external realm - return f - }) - crossrealm.CallFooerGetterFoo() - println("ok") - - root = local_S{name: "root"} - println("ok2") -} - -// Output: -// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// ok -// ok2 diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index 469120c9b47..636a1cdae18 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -2,20 +2,24 @@ package crossrealm_test import ( - "std" - - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" + crossrealm "gno.land/r/demo/tests/crossrealm/func" ) -var f = func() crossrealm.Fooer { - return crossrealm_b.Fooer +var b = 1 + +type Local_S struct { + name string } func main() { - crossrealm.SetFooerGetter(f) + var ls Local_S + f := func() bool { + c := b + return true + } + crossrealm.SetCallback(f) println("ok") } // Error: -// cannot attach objects by value from external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm22c.gno b/gnovm/tests/files/zrealm_crossrealm22c.gno index c7ef44e02d3..550a2279370 100644 --- a/gnovm/tests/files/zrealm_crossrealm22c.gno +++ b/gnovm/tests/files/zrealm_crossrealm22c.gno @@ -1,12 +1,23 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -var root interface{} +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} func main() { - root = func() { // in this, case, block(main) is attached in the tree - println("func lit") + f := func() bool { + c := b + var ls *Local_S + return true } + crossrealm.SetCallback(f) println("ok") } diff --git a/gnovm/tests/files/zrealm_crossrealm22d.gno b/gnovm/tests/files/zrealm_crossrealm22d.gno index 1cceefa8d6d..c781ad81285 100644 --- a/gnovm/tests/files/zrealm_crossrealm22d.gno +++ b/gnovm/tests/files/zrealm_crossrealm22d.gno @@ -1,12 +1,21 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var f = func() bool { + println("callback") + return true +} + func main() { - a := func() { // in this case, not attached. - println("func lit") - } + crossrealm.SetCallback(f) + crossrealm.ExecuteCallback() println("ok") } // Output: +// callback // ok diff --git a/gnovm/tests/files/zrealm_crossrealm22e.gno b/gnovm/tests/files/zrealm_crossrealm22e.gno deleted file mode 100644 index ccbd61bd45a..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm22e.gno +++ /dev/null @@ -1,21 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - "gno.land/r/demo/tests/crossrealm" -) - -var root interface{} - -func main() { - //f := func() crossrealm.Fooer { - root = func() crossrealm.Fooer { - return crossrealm.Fooer(nil) - } - println("ok") -} - -// Error: -// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm23.gno b/gnovm/tests/files/zrealm_crossrealm23_pure.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm23.gno rename to gnovm/tests/files/zrealm_crossrealm23_pure.gno diff --git a/gnovm/tests/files/zrealm_crossrealm24.gno b/gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno similarity index 95% rename from gnovm/tests/files/zrealm_crossrealm24.gno rename to gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno index d14b374a480..60782d3e426 100644 --- a/gnovm/tests/files/zrealm_crossrealm24.gno +++ b/gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno @@ -152,7 +152,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "files/zrealm_crossrealm24.gno", +// "FileName": "files/zrealm_crossrealm24_struct_pointer.gno", // "IsMethod": false, // "Name": "init.3", // "NativeName": "", @@ -163,7 +163,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "files/zrealm_crossrealm24.gno", +// "File": "files/zrealm_crossrealm24_struct_pointer.gno", // "Line": "16", // "PkgPath": "gno.land/r/crossrealm_test" // } @@ -188,7 +188,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" // }, -// "FileName": "files/zrealm_crossrealm24.gno", +// "FileName": "files/zrealm_crossrealm24_struct_pointer.gno", // "IsMethod": false, // "Name": "main", // "NativeName": "", @@ -199,7 +199,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "files/zrealm_crossrealm24.gno", +// "File": "files/zrealm_crossrealm24_struct_pointer.gno", // "Line": "19", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm28.gno b/gnovm/tests/files/zrealm_crossrealm28_slice.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm28.gno rename to gnovm/tests/files/zrealm_crossrealm28_slice.gno diff --git a/gnovm/tests/files/zrealm_crossrealm29_func.gno b/gnovm/tests/files/zrealm_crossrealm29_func.gno deleted file mode 100644 index 6c7ed5e073d..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29_func.gno +++ /dev/null @@ -1,20 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -func main() { - f := func() bool { - println("callback") - return true - } - crossrealm.SetCallback(f) - crossrealm.ExecuteCallback() -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm29a.gno b/gnovm/tests/files/zrealm_crossrealm29a.gno deleted file mode 100644 index 3303a5dde9a..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29a.gno +++ /dev/null @@ -1,21 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -var f = func() bool { - println("callback") - return true -} - -func main() { - crossrealm.SetCallback(f) // func value - crossrealm.ExecuteCallback() -} - -// Error: -// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29b.gno b/gnovm/tests/files/zrealm_crossrealm29b.gno deleted file mode 100644 index 9425782cd1b..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29b.gno +++ /dev/null @@ -1,19 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -func main() { - crossrealm.SetCallback(func() bool { - println("callback") - return true - }) - crossrealm.ExecuteCallback() -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm29c.gno b/gnovm/tests/files/zrealm_crossrealm29c.gno deleted file mode 100644 index fdd1cf278af..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29c.gno +++ /dev/null @@ -1,19 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -type Foo struct { -} - -var a = Foo{} - -var f = func() bool { - println("callback") - return true -} - -func main() { - println("ok") -} - -// Output: -// ok diff --git a/gnovm/tests/files/zrealm_crossrealm29d.gno b/gnovm/tests/files/zrealm_crossrealm29d.gno deleted file mode 100644 index 0d8531d4e54..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29d.gno +++ /dev/null @@ -1,26 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -var b = 1 - -type Local_S struct { - name string -} - -func main() { - f := func() bool { - c := b - ls := Local_S{} - return true - } - crossrealm.SetCallback(f) -} - -// Error: -// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29e.gno b/gnovm/tests/files/zrealm_crossrealm29e.gno deleted file mode 100644 index 920c7b5f118..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29e.gno +++ /dev/null @@ -1,26 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -var b = 1 - -type Local_S struct { - name string -} - -func main() { - f := func() bool { - c := b - var ls Local_S - return true - } - crossrealm.SetCallback(f) -} - -// Error: -// cannot attach function contains object from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm29f.gno b/gnovm/tests/files/zrealm_crossrealm29f.gno deleted file mode 100644 index 0c6ac7719d3..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29f.gno +++ /dev/null @@ -1,27 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -var b = 1 - -type Local_S struct { - name string -} - -func main() { - f := func() bool { - c := b - var ls *Local_S - return true - } - crossrealm.SetCallback(f) - println("ok") -} - -// Output: -// ok diff --git a/gnovm/tests/files/zrealm_crossrealm29g.gno b/gnovm/tests/files/zrealm_crossrealm29g.gno deleted file mode 100644 index 63e9068c707..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm29g.gno +++ /dev/null @@ -1,27 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/func" -) - -var b = 1 - -type Local_S struct { - name string -} - -func main() { - f := func() bool { - c := b - ls := &Local_S{name: "ls"} - return true - } - crossrealm.SetCallback(f) - println("ok") -} - -// Output: -// ok diff --git a/gnovm/tests/files/zrealm_crossrealm38.gno b/gnovm/tests/files/zrealm_crossrealm38.gno deleted file mode 100644 index 1b82f4b617f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm38.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import crossrealm "gno.land/r/demo/tests/crossrealm/func" - -var f func() string - -func main() { - f = crossrealm.GetFunc() - println(f()) -} - -// Error: -// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm39.gno b/gnovm/tests/files/zrealm_crossrealm39.gno deleted file mode 100644 index e400c486214..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm39.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import crossrealm "gno.land/r/demo/tests/crossrealm/func" - -var f func() string - -func main() { - f = crossrealm.GetFunc2() - println(f) -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm40.gno b/gnovm/tests/files/zrealm_crossrealm40_method.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm40.gno rename to gnovm/tests/files/zrealm_crossrealm40_method.gno From 4ed5fe6ebc3135b03859078740f57f85e1e0dc2f Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 5 Feb 2025 23:40:44 +0800 Subject: [PATCH 53/88] save --- .../crossrealm/iface/crossrealm_iface.gno | 5 + .../crossrealm/slice/crossrealm_slice.gno | 4 +- gnovm/pkg/gnolang/debug_false.go | 4 +- gnovm/pkg/gnolang/ownership.go | 24 +- gnovm/pkg/gnolang/realm.go | 134 +++- gnovm/pkg/gnolang/store.go | 5 +- gnovm/pkg/gnolang/values.go | 4 +- gnovm/pkg/test/filetest.go | 8 + ...m15.gno => zrealm_crossrealm15_struct.gno} | 0 gnovm/tests/files/zrealm_crossrealm17.gno | 13 +- gnovm/tests/files/zrealm_crossrealm18.gno | 14 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- ...0a_struct.gno => zrealm_crossrealm20a.gno} | 0 gnovm/tests/files/zrealm_crossrealm20b.gno | 7 +- gnovm/tests/files/zrealm_crossrealm20c.gno | 6 +- ...srealm24a.gno => zrealm_crossrealm20d.gno} | 0 ...srealm24b.gno => zrealm_crossrealm20e.gno} | 8 +- ...srealm24c.gno => zrealm_crossrealm20f.gno} | 3 - ...srealm24e.gno => zrealm_crossrealm20g.gno} | 0 ...srealm24f.gno => zrealm_crossrealm20h.gno} | 6 + ...srealm24g.gno => zrealm_crossrealm20i.gno} | 1 + gnovm/tests/files/zrealm_crossrealm20j.gno | 723 ++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm21.gno | 722 +---------------- ...srealm27a.gno => zrealm_crossrealm21a.gno} | 9 +- ...srealm27b.gno => zrealm_crossrealm21b.gno} | 0 gnovm/tests/files/zrealm_crossrealm23b.gno | 109 --- .../zrealm_crossrealm24_struct_pointer.gno | 215 ------ gnovm/tests/files/zrealm_crossrealm24d.gno | 214 ------ gnovm/tests/files/zrealm_crossrealm27.gno | 236 ------ gnovm/tests/files/zrealm_crossrealm28_0.gno | 22 + .../tests/files/zrealm_crossrealm28_slice.gno | 13 +- gnovm/tests/files/zrealm_crossrealm28b.gno | 7 +- gnovm/tests/files/zrealm_crossrealm28b1.gno | 21 + gnovm/tests/files/zrealm_crossrealm28c.gno | 16 +- gnovm/tests/files/zrealm_crossrealm28c1.gno | 21 + gnovm/tests/files/zrealm_crossrealm28d.gno | 12 +- gnovm/tests/files/zrealm_crossrealm28d2.gno | 10 +- gnovm/tests/files/zrealm_crossrealm28e.gno | 30 - gnovm/tests/files/zrealm_crossrealm28f.gno | 5 +- gnovm/tests/files/zrealm_crossrealm28g.gno | 2 - ...lm30_slice.gno => zrealm_crossrealm30.gno} | 4 +- gnovm/tests/files/zrealm_crossrealm31.gno | 2 - 42 files changed, 1005 insertions(+), 1636 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm15.gno => zrealm_crossrealm15_struct.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm20a_struct.gno => zrealm_crossrealm20a.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm24a.gno => zrealm_crossrealm20d.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm24b.gno => zrealm_crossrealm20e.gno} (72%) rename gnovm/tests/files/{zrealm_crossrealm24c.gno => zrealm_crossrealm20f.gno} (95%) rename gnovm/tests/files/{zrealm_crossrealm24e.gno => zrealm_crossrealm20g.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm24f.gno => zrealm_crossrealm20h.gno} (60%) rename gnovm/tests/files/{zrealm_crossrealm24g.gno => zrealm_crossrealm20i.gno} (90%) create mode 100644 gnovm/tests/files/zrealm_crossrealm20j.gno rename gnovm/tests/files/{zrealm_crossrealm27a.gno => zrealm_crossrealm21a.gno} (52%) rename gnovm/tests/files/{zrealm_crossrealm27b.gno => zrealm_crossrealm21b.gno} (100%) delete mode 100644 gnovm/tests/files/zrealm_crossrealm23b.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm24d.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm27.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28_0.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28b1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c1.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm28e.gno rename gnovm/tests/files/{zrealm_crossrealm30_slice.gno => zrealm_crossrealm30.gno} (68%) diff --git a/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno b/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno index 769a2e3ad59..b97b4b5a8f3 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/iface/crossrealm_iface.gno @@ -1,5 +1,7 @@ package iface +type Foo2 struct{} + // XXX, how about not interface type Fooer interface{ Foo() } @@ -20,6 +22,9 @@ type Container struct { var container Container // attached +func RunF() { + container.f.Foo() +} func SetContainer(f Fooer) { container.f = f // update } diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index b1822fb45a4..efe899ada6d 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -16,7 +16,7 @@ func SetSlice(fs []Fooer) { // ------------------------------------- type XYZ struct{ name string } -var s1 []XYZ +var s1 []XYZ // underlying array is real after decl var s3 []XYZ // var s4 []XYZ @@ -49,7 +49,7 @@ func init() { } func GetSlice() []XYZ { - return s1[1:] + return s1[:] } // ------------------------------------------------------- diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index bf213870a3a..ed949359db7 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,6 @@ package gnolang const debug debugging = false -//const debug2 debugging = true +const debug2 debugging = true -const debug2 debugging = false +//const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index e8a0b5fead4..1fa6e40fde2 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -354,10 +354,10 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { - debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) + //debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: - debug2.Println2("pointer value, base: ", cv.Base) + //debug2.Println2("pointer value, base: ", cv.Base) return cv.GetBase(store) case *ArrayValue: return cv @@ -399,6 +399,11 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) + // special case for func value + if _, ok := tv.V.(*FuncValue); ok { + return + } + // attempting to retrieve the original package using the ObjectID obj := tv.GetFirstObject(store) debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) @@ -407,10 +412,12 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { // it's un-real. originPkg = obj.GetOriginRealm() if !originPkg.IsZero() { + debug2.Println2("got originPkg from object: ", originPkg) return } originPkg = obj.GetObjectID().PkgID if !originPkg.IsZero() { + debug2.Println2("got originPkg from object: ", originPkg) return } } @@ -428,11 +435,9 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } switch cv := obj.(type) { - case *Block: - if _, ok := tv.V.(*FuncValue); !ok { - originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) - } - return + //case *Block: + // originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) + // return case *HeapItemValue: originPkg = getPkgId(cv.Value.T) return @@ -442,9 +447,12 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = getPkgId(pv.TV.T) } return - case *MapValue, *StructValue, *ArrayValue: + case *MapValue, *StructValue: originPkg = getPkgId(tv.T) // if it's declared type, otherwise zero return + case *ArrayValue: + originPkg = getPkgId(tv.T.Elem()) + return default: // do nothing } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 95b7dbf27b8..bb17f8f2bfb 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -150,7 +150,7 @@ func (rlm *Realm) String() string { // ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { - debug2.Printf2("DidUpdate2, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) + debug2.Printf2("DidUpdate, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) debug2.Println2("po.GetIsReal: ", po.GetIsReal()) debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) @@ -250,6 +250,71 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { // else nothing to do } +func assertRealObject2(rlm *Realm, store Store, tv *TypedValue) { + debug2.Println2("assertRealObject2, tv: ", tv, reflect.TypeOf(tv.V)) + tv2 := fillValueTV(store, tv) + if oo, ok := tv2.V.(Object); ok { + debug2.Println2("is object") + assertRealObjectCrossRealm(rlm, store, oo, nil) + } else { // reference to object + switch rv := tv.V.(type) { + case *SliceValue, PointerValue: + reo := tv.GetFirstObject(store) + debug2.Println2("is reference to object, reo: ", reo) + assertRealObjectCrossRealm(rlm, store, reo, rv) + } + } +} + +// assertRealObject checks if object is real recursively +func assertRealObjectCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { + debug2.Println2("assertRealObjectCrossRealm, oo: ", oo) + debug2.Println2("refValue: ", refValue) + if !oo.GetIsReal() { + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) + } + switch v := oo.(type) { + case *StructValue: + // check fields + for _, fv := range v.Fields { + assertRealObject2(rlm, store, &fv) + } + case *MapValue: + debug2.Println2("MapValue, v: ", v) + for cur := v.List.Head; cur != nil; cur = cur.Next { + assertRealObject2(rlm, store, &cur.Key) + assertRealObject2(rlm, store, &cur.Value) + } + case *BoundMethodValue: + // TODO: complete this, check receiver, and? + case *Block: + debug2.Println2("BlockValue, v: ", v) + // XXX, also captures? + for _, tv := range v.Values { + assertRealObject2(rlm, store, &tv) + } + case *HeapItemValue: + assertRealObject2(rlm, store, &v.Value) + case *ArrayValue: + if sv, ok := refValue.(*SliceValue); ok { + debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) + // only check referenced elem + for i := sv.Offset; i < sv.Length; i++ { + assertRealObject2(rlm, store, &v.List[i]) + } + } else { + debug2.Println2("2, check elems of ArrayValue, v: ", v) + if v.Data == nil { + for _, e := range v.List { + assertRealObject2(rlm, store, &e) + } + } + } + default: + panic("should not happen, oo is not object") + } +} + // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. @@ -274,25 +339,36 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { } else { debug2.Println2("refValue: ", refValue) debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("oo.GetIsEscaped: ", oo.GetRefCount()) + debug2.Println2("oo.GetIsEscaped: ", oo.GetIsEscaped()) + debug2.Println2("oo.GetIsReal: ", oo.GetIsReal()) // if its real object crossing, must be reference type if refValue != nil { // reference value - //if oo.GetIsEscaped() { - //if oo.GetRefCount() > 1 { - // debug2.Println2("reference to escaped object, do nothing") - // return + assertRealObjectCrossRealm(rlm, store, oo, refValue) + //if oo.GetIsReal() { + // if oo.GetIsEscaped() { // Note, oo not set escaped until now, would be after this check + // debug2.Println2("oo escaped, do nothing") + // return + // } else { + // debug2.Println2("oo NOT escaped, if HeapItemValue, check recursively, otherwise do nothing") + // if _, ok := oo.(*HeapItemValue); ok { + // // check elem + // debug2.Println2("oo is heapItemValue, it's a real base for pointer value, check recursively for elem") + // } else { + // debug2.Println2("not heapItemValue, do nothing") + // return + // } + // } + //} + //if !oo.GetIsReal() { + // panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) //} - if oo.GetIsReal() { - return - } - if !oo.GetIsReal() { - //panic(fmt.Sprintf("cannot attach unreal object by value from external realm: %v", oo)) - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) - } } else { panic(fmt.Sprintf("cannot attach a value of a type defined by another realm")) } } + } else { + debug2.Println2("Not crossing realm") + return } switch v := oo.(type) { @@ -322,17 +398,19 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { // panic("should not happen, block is not real") //} case *HeapItemValue: - // TODO: is it necessary? - // if heapItem, the embedded should be all real now??? - checkCrossRealm2(rlm, store, &v.Value) + // unwrap to check recursively + if o2, ok := v.Value.V.(Object); ok { + checkCrossRealm(rlm, store, o2, refValue) + } case *ArrayValue: if sv, ok := refValue.(*SliceValue); ok { + debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) // only check referenced elem for i := sv.Offset; i < sv.Length; i++ { checkCrossRealm2(rlm, store, &v.List[i]) } } else { - debug2.Println2("TODO, check elems of ArrayValue, v: ", v) + debug2.Println2("2, check elems of ArrayValue, v: ", v) if v.Data == nil { for _, e := range v.List { checkCrossRealm2(rlm, store, &e) @@ -362,7 +440,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm if originValue != nil { // must be reference - checkCrossRealm(rlm, store, oo, originValue) + //checkCrossRealm(rlm, store, oo, originValue) + assertRealObjectCrossRealm(rlm, store, oo, originValue) } else { panic("cannot attach objects by value from external realm") } @@ -604,10 +683,14 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // while associating, if po is unreal, the check // defers to here. + // TODO: add test, associate to a container, just associate to global, + // package block not real now. // TODO: correct this + // TODO: avoid duplicate check with DidUpdate... _, ok1 := oo.(*PackageValue) _, ok2 := oo.(*Block) // package block if !ok1 && !ok2 { + debug2.Println2("===incRefCreatedDescendants, checkCrossRealm") checkCrossRealm(rlm, store, oo, oo.GetOriginValue()) } @@ -955,9 +1038,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - debug2.Println2("saveObject: ", oo) + //debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() - debug2.Println2("---oid: ", oid) + //debug2.Println2("---oid: ", oid) //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") @@ -1025,7 +1108,6 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - debug2.Println2("getSelfOrChildObjects: ", val) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1038,7 +1120,6 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - debug2.Printf2("getChildObjects, val: %v, type of val: %v \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1071,11 +1152,9 @@ func getChildObjects(val Value, more []Value) []Value { return more case *FuncValue: if bv, ok := cv.Closure.(*Block); ok { - debug2.Println2("bv: ", bv) more = getSelfOrChildObjects(bv, more) } for _, c := range cv.Captures { - debug2.Println2("c: ", c) more = getSelfOrChildObjects(c.V, more) } return more @@ -1187,7 +1266,6 @@ func copyMethods(methods []TypedValue) []TypedValue { } func refOrCopyType(typ Type) Type { - debug2.Println2("refOrCopyType, typ: ", typ) if dt, ok := typ.(*DeclaredType); ok { return RefType{ID: dt.TypeID()} } else { @@ -1476,7 +1554,6 @@ func copyValueWithRefs(val Value) Value { // (fully) fills the type. func fillType(store Store, typ Type) Type { - debug2.Println2("fillType, typ: ", typ) switch ct := typ.(type) { case nil: return nil @@ -1568,8 +1645,6 @@ func fillTypesTV(store Store, tv *TypedValue) { // Partially fills loaded objects shallowly, similarly to // getUnsavedTypes. Replaces all RefTypes with corresponding types. func fillTypesOfValue(store Store, val Value) Value { - debug2.Println2("fillTypesOfValue, val: ", val) - debug2.Println2("type of val: ", reflect.TypeOf(val)) switch cv := val.(type) { case nil: // do nothing return cv @@ -1600,9 +1675,6 @@ func fillTypesOfValue(store Store, val Value) Value { fillTypesOfValue(store, cv.Base) return cv case *StructValue: - debug2.Println2("struct value") - debug2.Println2("cv.GetOriginRealm: ", cv.GetOriginRealm()) - debug2.Println2("cv.GetObjectInfo: ", cv.GetObjectInfo()) for i := 0; i < len(cv.Fields); i++ { ctv := &cv.Fields[i] fillTypesTV(store, ctv) diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 37babf43e1b..9223fd5527a 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -430,7 +430,6 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { - debug2.Println2("loadObjectSafe, oid: ", oid) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -472,7 +471,7 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - debug2.Println2("SetObject: ", oo) + //debug2.Println2("SetObject: ", oo) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -487,7 +486,7 @@ func (ds *defaultStore) SetObject(oo Object) { oid := oo.GetObjectID() // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - debug2.Println2("---o2: ", o2) + //debug2.Println2("---o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) gas := overflow.Mul64p(ds.gasConfig.GasSetObject, store.Gas(len(bz))) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 8c47a2c361a..7e0d9b0eced 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -534,7 +534,7 @@ func (sv *StructValue) GetSubrefPointerTo(store Store, st *StructType, path Valu } func (sv *StructValue) Copy(alloc *Allocator) *StructValue { - debug2.Println2("StructValue copy, sv: ", sv) + //debug2.Println2("StructValue copy, sv: ", sv) /* TODO consider second refcount field if sv.GetRefCount() == 0 { return sv @@ -1075,7 +1075,6 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { - debug2.Println2("Copy, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -2725,7 +2724,6 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - debug2.Println2("fillValueTV, tv: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case RefValue: if cv.PkgPath != "" { // load package diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index 1934f429568..85fecd05714 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -93,8 +93,10 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // First, check if we have an error, whether we're supposed to get it. if result.Error != "" { + //fmt.Println("result.Error NOT empty:", result.Error) // Ensure this error was supposed to happen. errDirective := dirs.First(DirectiveError) + //fmt.Println("errDirective:", errDirective) if errDirective == nil { return "", fmt.Errorf("unexpected panic: %s\noutput:\n%s\nstack:\n%v", result.Error, result.Output, string(result.GoPanicStack)) @@ -104,6 +106,12 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // which is not in the output - so add it there. match(errDirective, result.Error+"\n") } else { + //fmt.Println("result.Error is empty:", result.Error) + outputDirective := dirs.First(DirectiveOutput) + //fmt.Println("outputDirective:", outputDirective) + if outputDirective == nil { + return "", fmt.Errorf("unexpected output: \n%s", result.Output) + } err = m.CheckEmpty() if err != nil { return "", fmt.Errorf("machine not empty after main: %w", err) diff --git a/gnovm/tests/files/zrealm_crossrealm15.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm15.gno rename to gnovm/tests/files/zrealm_crossrealm15_struct.gno diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 9314ebadd41..e42c0172612 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -7,17 +7,22 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type container struct{ *fooer } +type container struct{ f *fooer } func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } -type fooer struct{} +type fooer struct{ name string } var f *fooer +var c = &container{} func main() { - f = &fooer{} - c := &container{f} + // the object attaching is heapItemValue, not escaped + // while attempting to attach it to external realm, + // check recursively. + // also see xxx_crossrealm21.gno + f = &fooer{name: "local_foo"} + c.f = f crossrealm.SetFooer(c) crossrealm.CallFooerFoo() print(".") diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno index b067765930c..27ef95bf733 100644 --- a/gnovm/tests/files/zrealm_crossrealm18.gno +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -7,25 +7,25 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type fooer struct{} +type fooer struct{ name string } -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (fooer) Foo() { println("hello from local realm fooer: " + std.CurrentRealm().PkgPath()) } -var local_fooer = &fooer{} +var local_fooer = &fooer{name: "local_fooer"} func init() { - var f crossrealm.Fooer = crossrealm.SetFooer(local_fooer) // until now, local_fooer is real + crossrealm.SetFooer(local_fooer) crossrealm.CallFooerFoo() } func main() { crossrealm.CallFooerFoo() - print(".") + println(".") } // Output: -// hello gno.land/r/demo/tests/crossrealm -// hello gno.land/r/demo/tests/crossrealm +// hello from local realm fooer: gno.land/r/demo/tests/crossrealm +// hello from local realm fooer: gno.land/r/demo/tests/crossrealm // . // Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index ce4b6fea396..70795aa2c4d 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -19,7 +19,7 @@ func (f *fooer) Foo() { var f *fooer func init() { - f = &fooer{s: "A"} + f = &fooer{s: "A"} // this is unreal crossrealm.SetFooer(f) crossrealm.CallFooerFoo() } diff --git a/gnovm/tests/files/zrealm_crossrealm20a_struct.gno b/gnovm/tests/files/zrealm_crossrealm20a.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm20a_struct.gno rename to gnovm/tests/files/zrealm_crossrealm20a.gno diff --git a/gnovm/tests/files/zrealm_crossrealm20b.gno b/gnovm/tests/files/zrealm_crossrealm20b.gno index 1ac379df2e0..5bf3a838a76 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b.gno @@ -8,19 +8,16 @@ import ( // associate to a containing object type Container struct { name string - b crossrealm.Bar + b crossrealm.Bar // panic while attaching(finalizing) } var c Container func init() { - b0 := crossrealm.Bar{A: 1} // this is valid association - c = Container{name: "container", b: b0} // XXX, should panic + print(".") } func main() { - print(".") } // Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno index 635a92bc0e1..61a323cfcbc 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c.gno @@ -11,11 +11,11 @@ type Container struct { b *crossrealm.Bar } -var c Container +var c = Container{name: "local_container"} func init() { - b0 := &crossrealm.Bar{A: 1} // this is valid association - c = Container{name: "container", b: b0} // XXX, should panic + b0 := &crossrealm.Bar{A: 1} // this is valid association + c.b = b0 // c is real, so panic while association, for b0 is unreal } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm24a.gno b/gnovm/tests/files/zrealm_crossrealm20d.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm24a.gno rename to gnovm/tests/files/zrealm_crossrealm20d.gno diff --git a/gnovm/tests/files/zrealm_crossrealm24b.gno b/gnovm/tests/files/zrealm_crossrealm20e.gno similarity index 72% rename from gnovm/tests/files/zrealm_crossrealm24b.gno rename to gnovm/tests/files/zrealm_crossrealm20e.gno index 5fe246e439d..db78e37ccff 100644 --- a/gnovm/tests/files/zrealm_crossrealm24b.gno +++ b/gnovm/tests/files/zrealm_crossrealm20e.gno @@ -5,13 +5,7 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) -// TODO: -// type XX crossrealm.Bar - -var b1 *crossrealm.Bar // this is valid decl, NOT attach - -func init() { -} +var b1 *crossrealm.Bar func main() { b1 = &crossrealm.Bar{A: 22} // this should panic diff --git a/gnovm/tests/files/zrealm_crossrealm24c.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno similarity index 95% rename from gnovm/tests/files/zrealm_crossrealm24c.gno rename to gnovm/tests/files/zrealm_crossrealm20f.gno index eb6b3dcbf8a..981ce43b9ce 100644 --- a/gnovm/tests/files/zrealm_crossrealm24c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -10,9 +10,6 @@ type Dt *crossrealm.Bar var b Dt -func init() { -} - func main() { b = &crossrealm.Bar{A: 22} // this should panic //println(b) diff --git a/gnovm/tests/files/zrealm_crossrealm24e.gno b/gnovm/tests/files/zrealm_crossrealm20g.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm24e.gno rename to gnovm/tests/files/zrealm_crossrealm20g.gno diff --git a/gnovm/tests/files/zrealm_crossrealm24f.gno b/gnovm/tests/files/zrealm_crossrealm20h.gno similarity index 60% rename from gnovm/tests/files/zrealm_crossrealm24f.gno rename to gnovm/tests/files/zrealm_crossrealm20h.gno index 23049563511..9919cc02654 100644 --- a/gnovm/tests/files/zrealm_crossrealm24f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20h.gno @@ -7,6 +7,12 @@ import ( var root interface{} +// TODO: consider this +// should it be valid to attach +// an object by value with type +// from p? maybe yes, but it should +// be invalid if the type is from +// an another realm. func main() { root = tests.F // already attached in p println("done") diff --git a/gnovm/tests/files/zrealm_crossrealm24g.gno b/gnovm/tests/files/zrealm_crossrealm20i.gno similarity index 90% rename from gnovm/tests/files/zrealm_crossrealm24g.gno rename to gnovm/tests/files/zrealm_crossrealm20i.gno index 3c308fc8fe2..23b1527fc20 100644 --- a/gnovm/tests/files/zrealm_crossrealm24g.gno +++ b/gnovm/tests/files/zrealm_crossrealm20i.gno @@ -7,6 +7,7 @@ import ( var root = tests.Foo{"p"} +// TODO: also this. func main() { println("done") } diff --git a/gnovm/tests/files/zrealm_crossrealm20j.gno b/gnovm/tests/files/zrealm_crossrealm20j.gno new file mode 100644 index 00000000000..582177675e7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20j.gno @@ -0,0 +1,723 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "std" + + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" +) + +func main() { + f := crossrealm_b.Fooer + crossrealm.SetFooer(f) + crossrealm.CallFooerFoo() + f.SetS("B") + crossrealm.CallFooerFoo() + print(".") +} + +// Output: +// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// 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_p.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_p.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.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.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:3" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.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_p.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": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooer", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "40", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "42", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" +// } +// } +// ] +// }, +// "Methods": [], +// "Name": "FooerGetter", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "SetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "48", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fg", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "GetFooerGetter", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "53", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" +// }, +// "FileName": "crossrealm_p.gno", +// "IsMethod": false, +// "Name": "CallFooerGetterFoo", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_p.gno", +// "Line": "57", +// "PkgPath": "gno.land/r/demo/tests/crossrealm" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "B" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] + +// Error: +// diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 582177675e7..99851287ba9 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -4,720 +4,24 @@ package crossrealm_test import ( "std" - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooer(f) - crossrealm.CallFooerFoo() - f.SetS("B") - crossrealm.CallFooerFoo() + f = fooer{name: "local_fooer"} + crossrealm.SetContainer2(&f) // the object attached is package block, escaped, so this works. + crossrealm.RunF() print(".") } // Output: -// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// hello gno.land/r/demo/tests/crossrealm/iface // . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// 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_p.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_p.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.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.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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_p.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_p.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.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.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.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_p.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": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooer", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "40", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "42", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.Fooer" -// } -// } -// ] -// }, -// "Methods": [], -// "Name": "FooerGetter", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "SetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "48", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fg", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "GetFooerGetter", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "53", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm.FooerGetter" -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "1712ac7adcfdc8e58a67e5615e20fb312394c4df:3" -// }, -// "FileName": "crossrealm_p.gno", -// "IsMethod": false, -// "Name": "CallFooerGetterFoo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_p.gno", -// "Line": "57", -// "PkgPath": "gno.land/r/demo/tests/crossrealm" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "B" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] - -// Error: -// diff --git a/gnovm/tests/files/zrealm_crossrealm27a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno similarity index 52% rename from gnovm/tests/files/zrealm_crossrealm27a.gno rename to gnovm/tests/files/zrealm_crossrealm21a.gno index a70d2b1fba4..ace6c73fb8b 100644 --- a/gnovm/tests/files/zrealm_crossrealm27a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -14,10 +14,13 @@ type fooer struct { func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } func main() { - f := fooer{name: "local_fooer"} // f is "new real" cuz it's parent object is new real - crossrealm.SetContainer2(&f) // attach new real from external realm, panic + // object attaching to external is main block, + // f is a value defined w/i this block, + // and invalid to attach to external, panic. + f := fooer{name: "local_fooer"} + crossrealm.SetContainer2(&f) print(".") } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm27b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm27b.gno rename to gnovm/tests/files/zrealm_crossrealm21b.gno diff --git a/gnovm/tests/files/zrealm_crossrealm23b.gno b/gnovm/tests/files/zrealm_crossrealm23b.gno deleted file mode 100644 index b4265ac467a..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm23b.gno +++ /dev/null @@ -1,109 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import "gno.land/p/demo/tests/p_crossrealm" - -var b0 p_crossrealm.Container - -func main() { - b0 = p_crossrealm.Container{ - A: 1, - } - print(".") -} - -// XXX, this works attach value with type defined in p - -// Output: -// . - -// Realm: -// switchrealm["gno.land/r/crossrealm_test"] -// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ -// "Fields": [ -// { -// "N": "AQAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// {} -// ], -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "RefCount": "1" -// } -// } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "IsEscaped": true, -// "ModTime": "4", -// "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.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Container" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "9e2d3b66941a43f567a3e83c2d2df8205f433f1c", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" -// }, -// "FileName": "files/zrealm_crossrealm23b.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm23b.gno", -// "Line": "8", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] diff --git a/gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno b/gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno deleted file mode 100644 index 60782d3e426..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm24_struct_pointer.gno +++ /dev/null @@ -1,215 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm/struct" -) - -type Ibar interface { - String() -} - -var ib Ibar - -var b0 *crossrealm.Bar - -func init() { -} - -func main() { - b0 = crossrealm.Bar2 - ib = crossrealm.Bar2 - println(ib) - crossrealm.ChangeBar() - println(ib) - println(b0) -} - -// Output: -// &(ref(5965ae851c02ab677bc8394b408535c1db9b2635:4) gno.land/r/demo/tests/crossrealm/struct.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/struct"] -// u[5965ae851c02ab677bc8394b408535c1db9b2635:4]={ -// "Fields": [ -// { -// "N": "FwAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "13", -// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", -// "RefCount": "1" -// } -// } -// 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.InterfaceType", -// "Generic": "", -// "Methods": [ -// { -// "Embedded": false, -// "Name": "String", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// ], -// "PkgPath": "gno.land/r/crossrealm_test" -// }, -// "Methods": [], -// "Name": "Ibar", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm24_struct_pointer.gno", -// "IsMethod": false, -// "Name": "init.3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm24_struct_pointer.gno", -// "Line": "16", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm24_struct_pointer.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm24_struct_pointer.gno", -// "Line": "19", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_crossrealm24d.gno b/gnovm/tests/files/zrealm_crossrealm24d.gno deleted file mode 100644 index 60097623655..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm24d.gno +++ /dev/null @@ -1,214 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - crossrealm "gno.land/r/demo/tests/crossrealm/struct" -) - -type Ibar interface { - String() -} - -var ib Ibar - -var b0 *crossrealm.Bar // no attach - -func init() {} - -func main() { - b0 = crossrealm.Bar2 // attach by reference - ib = crossrealm.Bar2 - println(ib) - b0.ModifyBar() // call bound methond - println(ib) - println(b0) -} - -// Output: -// &(ref(5965ae851c02ab677bc8394b408535c1db9b2635:4) gno.land/r/demo/tests/crossrealm/struct.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) -// &(struct{(23 int)} gno.land/r/demo/tests/crossrealm/struct.Bar) - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/struct"] -// u[5965ae851c02ab677bc8394b408535c1db9b2635:4]={ -// "Fields": [ -// { -// "N": "FwAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:4", -// "ModTime": "13", -// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:3", -// "RefCount": "1" -// } -// } -// 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.InterfaceType", -// "Generic": "", -// "Methods": [ -// { -// "Embedded": false, -// "Name": "String", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// ], -// "PkgPath": "gno.land/r/crossrealm_test" -// }, -// "Methods": [], -// "Name": "Ibar", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/struct.Bar" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm24d.gno", -// "IsMethod": false, -// "Name": "init.3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm24d.gno", -// "Line": "16", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm24d.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm24d.gno", -// "Line": "18", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_crossrealm27.gno b/gnovm/tests/files/zrealm_crossrealm27.gno deleted file mode 100644 index 0ed782fd49d..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm27.gno +++ /dev/null @@ -1,236 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - -func main() { - f = fooer{name: "local_fooer"} - crossrealm.SetContainer2(&f) - print(".") -} - -// Output: -// . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] -// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// }, -// { -// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" -// }, -// "Index": "1", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", -// "ModTime": "4", -// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/crossrealm_test"] -// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "local_fooer" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "RefCount": "1" -// } -// } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "IsEscaped": true, -// "ModTime": "4", -// "RefCount": "3" -// }, -// "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": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "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": "files/zrealm_crossrealm27.gno", -// "IsMethod": true, -// "Name": "Foo", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm27.gno", -// "Line": "14", -// "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.RefType", -// "ID": "gno.land/r/crossrealm_test.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "01b50926620ac1c9cff16ae679ccc89029394a2d", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" -// }, -// "FileName": "files/zrealm_crossrealm27.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm27.gno", -// "Line": "18", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] diff --git a/gnovm/tests/files/zrealm_crossrealm28_0.gno b/gnovm/tests/files/zrealm_crossrealm28_0.gno new file mode 100644 index 00000000000..4cc74b0361d --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28_0.gno @@ -0,0 +1,22 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type foo struct { + name string +} + +var root interface{} + +func main() { + var arr []foo // unreal array with type from local realm + arr = append(arr, foo{name: "1"}) + arr = append(arr, foo{name: "2"}) + arr = append(arr, foo{name: "3"}) + + fs := arr[1:] + root = fs + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28_slice.gno b/gnovm/tests/files/zrealm_crossrealm28_slice.gno index 11e7ce1dd35..8299b00fdc6 100644 --- a/gnovm/tests/files/zrealm_crossrealm28_slice.gno +++ b/gnovm/tests/files/zrealm_crossrealm28_slice.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) @@ -11,19 +9,20 @@ type foo struct { name string } -func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } -// XXX, no attach, default value is nil for slice var fs []crossrealm.Fooer +// the attachment works cuz +// the object being attached +// is foo{name: "1"} func init() { r := append(fs, foo{name: "1"}) - // while attaching underlying arrayValue(the object), - // it panics since the array type if from external realm - fs = r + fs = r // the array is from external realm and unreal } func main() { + println("ok") } // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm28b.gno b/gnovm/tests/files/zrealm_crossrealm28b.gno index 255d824ba77..9847b999312 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) @@ -11,11 +9,12 @@ type foo struct { name string } -func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } -var arr [2]crossrealm.Fooer // panic while attach zero value +var arr [2]crossrealm.Fooer // the element attaching is nil, so it's ok func main() { + println("ok") } // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm28b1.gno b/gnovm/tests/files/zrealm_crossrealm28b1.gno new file mode 100644 index 00000000000..afce1ecbe20 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28b1.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var arr [2]crossrealm.Foo2 // object attaching is zero value of struct, panic + +func main() { + println("ok") +} + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index a3f6fd66b56..f38085084a3 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,18 +9,22 @@ type foo struct { name string } -func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } func main() { - var arr []crossrealm.Fooer // XXX, the array object should be in current realm + var arr []crossrealm.Fooer // unreal array with type from external realm arr = append(arr, foo{name: "1"}) arr = append(arr, foo{name: "2"}) arr = append(arr, foo{name: "3"}) fs := arr[1:] - crossrealm.SetSlice(fs) + // this works cuz it's not crossing realm, + // even underlying array is unreal + crossrealm.SetSlice(fs) // valid println("ok") } -// Error: -// cannot attach a value of a type defined by another realm +// Output: +// (struct{("2" string)} gno.land/r/crossrealm_test.foo) +// (struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28c1.gno b/gnovm/tests/files/zrealm_crossrealm28c1.gno new file mode 100644 index 00000000000..2456bffe541 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c1.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +// should panic, underlying array with external type is unreal +var arr = []crossrealm.Fooer{foo{name: "1"}, foo{name: "2"}, foo{name: "3"}} + +func main() { +} + +// Error: +// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index c93ac2161c1..1159c4d1b14 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,10 +9,10 @@ type foo struct { name string } -func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } func main() { - var Local_S []crossrealm.Fooer // XXX, the array object should be in current realm + var Local_S []crossrealm.Fooer Local_S = append(Local_S, &foo{name: "1"}) Local_S = append(Local_S, &foo{name: "2"}) Local_S = append(Local_S, &foo{name: "3"}) @@ -24,5 +22,7 @@ func main() { println("ok") } -// Error: -// cannot attach a reference to an unreal object from an external realm +// Output: +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28d2.gno b/gnovm/tests/files/zrealm_crossrealm28d2.gno index 3380001af1a..574b2cc101d 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d2.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d2.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,20 +9,20 @@ type foo struct { name string } -func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } var f1 = &foo{name: "1"} var f2 = &foo{name: "2"} var f3 = &foo{name: "3"} func main() { - var Local_S []crossrealm.Fooer // XXX, the array object should be in current realm + var Local_S []crossrealm.Fooer Local_S = append(Local_S, f1) - Local_S = append(Local_S, f2) + Local_S = append(Local_S, f2) // reference real object, good Local_S = append(Local_S, f3) fs := Local_S[1:] - crossrealm.SetSlice(fs) + crossrealm.SetSlice(fs) // not crossing realm println("ok") } diff --git a/gnovm/tests/files/zrealm_crossrealm28e.gno b/gnovm/tests/files/zrealm_crossrealm28e.gno deleted file mode 100644 index 016abdb5a7f..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm28e.gno +++ /dev/null @@ -1,30 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/iface" -) - -type foo struct { - name string -} - -func (*foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -// XXX, no attach, default value is nil for slice -var fs []crossrealm.Fooer - -func init() { - r := append(fs, &foo{name: "1"}) - // while attaching underlying arrayValue(the object), - // it panics since the array type if from external realm - fs = r -} - -func main() { -} - -// Error: -// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28f.gno b/gnovm/tests/files/zrealm_crossrealm28f.gno index 26082c589ee..47aa3d3ed4f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28f.gno +++ b/gnovm/tests/files/zrealm_crossrealm28f.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,9 +9,8 @@ type foo struct { name string } -func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (foo) Foo() { println("hello from crossrealm_test") } -// XXX, no attach, default value is nil for slice var local_S []int func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm28g.gno b/gnovm/tests/files/zrealm_crossrealm28g.gno index 182f06103cb..b34b1a89cb9 100644 --- a/gnovm/tests/files/zrealm_crossrealm28g.gno +++ b/gnovm/tests/files/zrealm_crossrealm28g.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) diff --git a/gnovm/tests/files/zrealm_crossrealm30_slice.gno b/gnovm/tests/files/zrealm_crossrealm30.gno similarity index 68% rename from gnovm/tests/files/zrealm_crossrealm30_slice.gno rename to gnovm/tests/files/zrealm_crossrealm30.gno index 1c797a882cf..c11a450c09f 100644 --- a/gnovm/tests/files/zrealm_crossrealm30_slice.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -2,15 +2,13 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) var SS []crossrealm.XYZ func main() { - SS = crossrealm.GetSlice() // this is valid if elem are all attached in origin realm + SS = crossrealm.GetSlice() // attaching xxx.XYZ zero value, panic println(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index 871ad3a2765..22b02fefdc8 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) From 6b13f348ae24c01dca5124975f6bde2260b49c25 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 6 Feb 2025 22:17:03 +0800 Subject: [PATCH 54/88] fixup --- .../slice/crossrealm_slice.gno.bak2 | 14 - gnovm/pkg/gnolang/debug_false.go | 4 +- gnovm/pkg/gnolang/machine.go | 1 + gnovm/pkg/gnolang/op_eval.go | 1 + gnovm/pkg/gnolang/ownership.go | 8 +- gnovm/pkg/gnolang/realm.go | 281 +- gnovm/pkg/gnolang/store.go | 2 +- gnovm/pkg/gnolang/values.go | 1 + gnovm/tests/files/zrealm_crossrealm0.gno | 2 +- gnovm/tests/files/zrealm_crossrealm1.gno | 2 +- .../files/zrealm_crossrealm15_struct.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 11 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm2.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20b.gno | 1 + gnovm/tests/files/zrealm_crossrealm20c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20f.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20g.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20h.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21.gno | 9 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21c.gno | 24 + gnovm/tests/files/zrealm_crossrealm21d.gno | 26 + gnovm/tests/files/zrealm_crossrealm21e.gno | 27 + ...ssrealm36.gno => zrealm_crossrealm21f.gno} | 2 +- ...srealm36a.gno => zrealm_crossrealm21g.gno} | 2 +- gnovm/tests/files/zrealm_crossrealm22b.gno | 2 +- .../tests/files/zrealm_crossrealm28_slice.gno | 7 +- gnovm/tests/files/zrealm_crossrealm28b.gno | 4 +- gnovm/tests/files/zrealm_crossrealm28b1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28c1.gno | 10 +- gnovm/tests/files/zrealm_crossrealm28d.gno | 6 +- gnovm/tests/files/zrealm_crossrealm3.gno | 2 +- gnovm/tests/files/zrealm_crossrealm30.gno | 2 +- gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- gnovm/tests/files/zrealm_crossrealm32.gno | 2616 ----------------- gnovm/tests/files/zrealm_crossrealm33.gno | 4 +- gnovm/tests/files/zrealm_crossrealm34.gno | 16 + .../tests/files/zrealm_crossrealm34_slice.gno | 104 - gnovm/tests/files/zrealm_crossrealm34a.gno | 4 +- gnovm/tests/files/zrealm_crossrealm34b.gno | 4 +- gnovm/tests/files/zrealm_crossrealm35.gno | 8 +- gnovm/tests/files/zrealm_crossrealm35a.gno | 241 +- gnovm/tests/files/zrealm_crossrealm37c.gno | 2 +- .../files/zrealm_crossrealm40_method.gno | 2 +- gnovm/tests/files/zrealm_crossrealm41.gno | 20 - gnovm/tests/files/zrealm_crossrealm42.gno | 16 - gnovm/tests/files/zrealm_crossrealm43.gno | 16 - .../tests/files/zrealm_crossrealm44_array.gno | 2 +- .../tests/files/zrealm_crossrealm45_array.gno | 2 +- 56 files changed, 304 insertions(+), 3240 deletions(-) delete mode 100644 examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 create mode 100644 gnovm/tests/files/zrealm_crossrealm21c.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm21d.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm21e.gno rename gnovm/tests/files/{zrealm_crossrealm36.gno => zrealm_crossrealm21f.gno} (76%) rename gnovm/tests/files/{zrealm_crossrealm36a.gno => zrealm_crossrealm21g.gno} (54%) create mode 100644 gnovm/tests/files/zrealm_crossrealm34.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm34_slice.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm41.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm42.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm43.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 deleted file mode 100644 index 48ef3dbdbc7..00000000000 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno.bak2 +++ /dev/null @@ -1,14 +0,0 @@ -package crossrealm_slice - -type XYZ struct{ name string } - -var s4 = make([]XYZ, 1) - -func init() { - s4[0] = XYZ{"4"} // TODO; is it owned by array -} - -func GetSlice4(f func(s []XYZ)) { - s4 = append(s4, XYZ{"0"}) // this is real after this function - f(s4) // XYZ{"0"} is floating -} diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index ed949359db7..bf213870a3a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,6 @@ package gnolang const debug debugging = false -const debug2 debugging = true +//const debug2 debugging = true -//const debug2 debugging = false +const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 2fbcfc776c2..9caa536b38c 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -534,6 +534,7 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // recursive function for var declarations. var runDeclarationFor func(fn *FileNode, decl Decl) runDeclarationFor = func(fn *FileNode, decl Decl) { + debug2.Println2("runDeclarationFor, d: ", decl) // get fileblock of fn. // fb := pv.GetFileBlock(nil, fn.Name) // get dependencies of decl. diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index f58099aed2c..5ee6483772c 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -38,6 +38,7 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerToMaybeHeapUse(m.Store, nx) + //debug2.Println2("ptr.Deref(): ", ptr.Deref()) m.PushValue(ptr.Deref()) return } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 1fa6e40fde2..73ff04e82de 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -447,12 +447,12 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = getPkgId(pv.TV.T) } return - case *MapValue, *StructValue: + case *MapValue, *StructValue, *ArrayValue: originPkg = getPkgId(tv.T) // if it's declared type, otherwise zero return - case *ArrayValue: - originPkg = getPkgId(tv.T.Elem()) - return + //case *ArrayValue: + // originPkg = getPkgId(tv.T.Elem()) + // return default: // do nothing } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index bb17f8f2bfb..6fa86d2ff38 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -213,7 +213,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm for non escaped objects debug2.Println2("=========po is real, check cross realm for non escaped objects========") - checkCrossRealm(rlm, store, co, co.GetOriginValue()) + checkCrossRealm(rlm, store, co, co.GetOriginValue(), false) } } @@ -227,15 +227,80 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } +//// checkReferenceCrossRealm checks if object is real recursively +//func checkReferenceCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { +// debug2.Println2("checkReferenceCrossRealm, oo: ", oo, reflect.TypeOf(oo)) +// debug2.Println2("refValue: ", refValue, reflect.TypeOf(refValue)) +// +// if refValue == nil { +// panic("should be a reference value") +// } +// // reference to unreal array, map, closure, +// // check elems... +// if oo.GetOriginRealm().IsZero() { +// debug2.Println2("originRealm is zero, unreal, check elems...") +// } else { +// if rlm.ID != oo.GetOriginRealm() { // crossing realm +// // must be real +// if !oo.GetIsReal() { +// panic("cannot attach a reference to an unreal object from an external realm") +// } else { +// debug2.Println2("oo is real, also check elems...") +// } +// } +// } +// +// switch v := oo.(type) { +// case *StructValue: +// // check fields +// for _, fv := range v.Fields { +// checkCrossRealm2(rlm, store, &fv) +// } +// case *MapValue: +// debug2.Println2("MapValue, v: ", v) +// for cur := v.List.Head; cur != nil; cur = cur.Next { +// checkCrossRealm2(rlm, store, &cur.Key) +// checkCrossRealm2(rlm, store, &cur.Value) +// } +// case *BoundMethodValue: +// // TODO: complete this, check receiver, and? +// case *Block: +// debug2.Println2("BlockValue, v: ", v) +// // XXX, also captures? +// for _, tv := range v.Values { +// checkCrossRealm2(rlm, store, &tv) +// } +// case *HeapItemValue: +// checkCrossRealm2(rlm, store, &v.Value) +// case *ArrayValue: +// if sv, ok := refValue.(*SliceValue); ok { +// debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) +// // only check referenced elem +// for i := sv.Offset; i < sv.Length; i++ { +// checkCrossRealm2(rlm, store, &v.List[i]) +// } +// } else { +// debug2.Println2("2, check elems of ArrayValue, v: ", v) +// if v.Data == nil { +// for _, e := range v.List { +// checkCrossRealm2(rlm, store, &e) +// } +// } +// } +// default: +// panic("should not happen, oo is not object") +// } +//} + // check cross realm recursively -func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { +func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { debug2.Println2("checkCrossRealm2, tv: ", tv, reflect.TypeOf(tv.V)) tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { debug2.Println2("is object") // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, oo, nil) + checkCrossRealm(rlm, store, oo, nil, isLastRef) } else { // reference to object switch rv := tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm @@ -244,176 +309,112 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue) { debug2.Println2("is reference to object, reo: ", reo) // if base escaped, do nothing reo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, reo, rv) + checkCrossRealm(rlm, store, reo, rv, true) } } // else nothing to do } -func assertRealObject2(rlm *Realm, store Store, tv *TypedValue) { - debug2.Println2("assertRealObject2, tv: ", tv, reflect.TypeOf(tv.V)) - tv2 := fillValueTV(store, tv) - if oo, ok := tv2.V.(Object); ok { - debug2.Println2("is object") - assertRealObjectCrossRealm(rlm, store, oo, nil) - } else { // reference to object - switch rv := tv.V.(type) { - case *SliceValue, PointerValue: - reo := tv.GetFirstObject(store) - debug2.Println2("is reference to object, reo: ", reo) - assertRealObjectCrossRealm(rlm, store, reo, rv) - } - } -} - -// assertRealObject checks if object is real recursively -func assertRealObjectCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { - debug2.Println2("assertRealObjectCrossRealm, oo: ", oo) - debug2.Println2("refValue: ", refValue) - if !oo.GetIsReal() { - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) - } - switch v := oo.(type) { - case *StructValue: - // check fields - for _, fv := range v.Fields { - assertRealObject2(rlm, store, &fv) - } - case *MapValue: - debug2.Println2("MapValue, v: ", v) - for cur := v.List.Head; cur != nil; cur = cur.Next { - assertRealObject2(rlm, store, &cur.Key) - assertRealObject2(rlm, store, &cur.Value) - } - case *BoundMethodValue: - // TODO: complete this, check receiver, and? - case *Block: - debug2.Println2("BlockValue, v: ", v) - // XXX, also captures? - for _, tv := range v.Values { - assertRealObject2(rlm, store, &tv) - } - case *HeapItemValue: - assertRealObject2(rlm, store, &v.Value) - case *ArrayValue: - if sv, ok := refValue.(*SliceValue); ok { - debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) - // only check referenced elem - for i := sv.Offset; i < sv.Length; i++ { - assertRealObject2(rlm, store, &v.List[i]) - } - } else { - debug2.Println2("2, check elems of ArrayValue, v: ", v) - if v.Data == nil { - for _, e := range v.List { - assertRealObject2(rlm, store, &e) - } - } - } - default: - panic("should not happen, oo is not object") - } -} - // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. -func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { +func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) - debug2.Println2("refValue: ", refValue) - debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) - //debug2.Println2("oo.GetObjectID: ", oo.GetObjectID()) - debug2.Println2("oo.GetOriginRealm: ", oo.GetOriginRealm()) - - // if oo.OriginRealm is zero, either from current realm, or a compositeLit from - // external realm, for the former one. both can be unreal. - // if composite value with pkgId inferred from declared type, it should be real. - // So, check if zero, real... - - if rlm.ID != oo.GetOriginRealm() { // crossing realm - debug2.Println2("crossing realm") - if oo.GetOriginRealm().IsZero() { // mapLit, etc - debug2.Println2("origin realm is zero, check recursively for composite literal") - // A zero value indicates that it is a realmless composite literal. - } else { - debug2.Println2("refValue: ", refValue) - debug2.Println2("oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("oo.GetIsEscaped: ", oo.GetIsEscaped()) - debug2.Println2("oo.GetIsReal: ", oo.GetIsReal()) - // if its real object crossing, must be reference type - if refValue != nil { // reference value - assertRealObjectCrossRealm(rlm, store, oo, refValue) - //if oo.GetIsReal() { - // if oo.GetIsEscaped() { // Note, oo not set escaped until now, would be after this check - // debug2.Println2("oo escaped, do nothing") - // return - // } else { - // debug2.Println2("oo NOT escaped, if HeapItemValue, check recursively, otherwise do nothing") - // if _, ok := oo.(*HeapItemValue); ok { - // // check elem - // debug2.Println2("oo is heapItemValue, it's a real base for pointer value, check recursively for elem") - // } else { - // debug2.Println2("not heapItemValue, do nothing") - // return - // } - // } - //} - //if !oo.GetIsReal() { - // panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm")) - //} - } else { - panic(fmt.Sprintf("cannot attach a value of a type defined by another realm")) + if refValue != nil { + isLastRef = true + } + + if oo.GetOriginRealm().IsZero() { + debug2.Println2("Origin Realm is zero, unreal, check elems...") + } else { + debug2.Println2("Origin Realm NOT zero...") + if rlm.ID != oo.GetOriginRealm() { // crossing realm + debug2.Println2("crossing realm, check oo, then elems") + // reference value + if isLastRef { + debug2.Println2("Reference to object: ", refValue, reflect.TypeOf(refValue)) + if !oo.GetIsReal() { + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) + } else { + debug2.Println2("oo is real, check elems...") + } + } else { // not reference to object + debug2.Println2("Non reference object crossing realm, panic...") + panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } + } else { + debug2.Println2("oo Not crossing realm, check elems...") } - } else { - debug2.Println2("Not crossing realm") - return } switch v := oo.(type) { case *StructValue: // check fields for _, fv := range v.Fields { - checkCrossRealm2(rlm, store, &fv) + checkCrossRealm2(rlm, store, &fv, false) // ref to struct is heapItemValue or block } case *MapValue: debug2.Println2("MapValue, v: ", v) for cur := v.List.Head; cur != nil; cur = cur.Next { - checkCrossRealm2(rlm, store, &cur.Key) - checkCrossRealm2(rlm, store, &cur.Value) + checkCrossRealm2(rlm, store, &cur.Key, false) + checkCrossRealm2(rlm, store, &cur.Value, false) } case *BoundMethodValue: // TODO: complete this case *Block: debug2.Println2("BlockValue, v: ", v) - // XXX, also captures? - for _, tv := range v.Values { - checkCrossRealm2(rlm, store, &tv) - } - //// XXX, can this happen? - //switch v.GetOriginValue().(type) { - //case PointerValue, *SliceValue, *FuncValue: - //default: - // panic("should not happen, block is not real") - //} + // NOTE, it's not escaped until now, + // will set after check + if oo.GetRefCount() > 1 { + // only check when it's dirty + debug2.Println2("oo escaped, and dirty") + for _, tv := range v.Values { + debug2.Println2("tv: ", tv) + if oo, ok := tv.V.(Object); ok { + if oo.GetIsReal() && !oo.GetIsDirty() { + // ok + } else { + if refValue != nil { + panic("cannot attach a reference to dirty object from an external realm") + } else { + panic("cannot attach dirty object from an external realm") + } + } + } + } + } else { // this will attach the block + // XXX, also captures? + for _, tv := range v.Values { + checkCrossRealm2(rlm, store, &tv, true) // always true + } + } case *HeapItemValue: - // unwrap to check recursively - if o2, ok := v.Value.V.(Object); ok { - checkCrossRealm(rlm, store, o2, refValue) + //checkCrossRealm2(rlm, store, &v.Value) + if oo2, ok := v.Value.V.(Object); ok { + debug2.Println2("oo2.GetIsDirty(): ", oo2.GetIsDirty()) + debug2.Println2("oo2: ", oo2) + if oo2.GetIsDirty() { + panic("cannot attach a reference to dirty object from an external realm") + } } case *ArrayValue: + if !oo.GetOriginRealm().IsZero() { // refer a real object + isLastRef = true + } else { // unreal object, see 28c, 30 + isLastRef = false + } if sv, ok := refValue.(*SliceValue); ok { debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) // only check referenced elem for i := sv.Offset; i < sv.Length; i++ { - checkCrossRealm2(rlm, store, &v.List[i]) + checkCrossRealm2(rlm, store, &v.List[i], isLastRef) } } else { debug2.Println2("2, check elems of ArrayValue, v: ", v) if v.Data == nil { for _, e := range v.List { - checkCrossRealm2(rlm, store, &e) + checkCrossRealm2(rlm, store, &e, isLastRef) } } } @@ -439,9 +440,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa } if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm - if originValue != nil { // must be reference - //checkCrossRealm(rlm, store, oo, originValue) - assertRealObjectCrossRealm(rlm, store, oo, originValue) + if originValue != nil { + checkCrossRealm(rlm, store, oo, originValue, true) } else { panic("cannot attach objects by value from external realm") } @@ -486,6 +486,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { + debug2.Println2("MarkDirty, oo: ", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -691,7 +692,8 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { _, ok2 := oo.(*Block) // package block if !ok1 && !ok2 { debug2.Println2("===incRefCreatedDescendants, checkCrossRealm") - checkCrossRealm(rlm, store, oo, oo.GetOriginValue()) + isLastRef := oo.GetOriginValue() != nil + checkCrossRealm(rlm, store, oo, oo.GetOriginValue(), isLastRef) } // RECURSE GUARD @@ -1038,7 +1040,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - //debug2.Println2("saveObject: ", oo) + debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() //debug2.Println2("---oid: ", oid) //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) @@ -1224,6 +1226,7 @@ func getChildObjects2(store Store, val Value) []Object { // Gets all unsaved child objects. // Shallow; doesn't recurse into objects. func getUnsavedChildObjects(val Value) []Object { + debug2.Println2("getUnsavedChildObjects, val: ", val) vals := getChildObjects(val, nil) unsaved := make([]Object, 0, len(vals)) for _, val := range vals { diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 9223fd5527a..ac476fb14ac 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -471,7 +471,7 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - //debug2.Println2("SetObject: ", oo) + debug2.Println2("SetObject: ", oo) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 7e0d9b0eced..95f246b068a 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2479,6 +2479,7 @@ func (b *Block) GetPointerToInt(store Store, index int) PointerValue { } func (b *Block) GetPointerTo(store Store, path ValuePath) PointerValue { + //debug2.Println2("GetPoinerTo, b: ", b) if path.IsBlockBlankPath() { if debug { if path.Name != blankIdentifier { diff --git a/gnovm/tests/files/zrealm_crossrealm0.gno b/gnovm/tests/files/zrealm_crossrealm0.gno index b425344615e..35c19a6efe6 100644 --- a/gnovm/tests/files/zrealm_crossrealm0.gno +++ b/gnovm/tests/files/zrealm_crossrealm0.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm1.gno b/gnovm/tests/files/zrealm_crossrealm1.gno index ee401bd7774..6d66232f675 100644 --- a/gnovm/tests/files/zrealm_crossrealm1.gno +++ b/gnovm/tests/files/zrealm_crossrealm1.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm15_struct.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno index 1eed5e49b18..3eb54861c1b 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_struct.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_struct.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index 15cae6ab01c..4704f21222e 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index e42c0172612..435a40a2443 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -2,18 +2,15 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm" ) type container struct{ f *fooer } -func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } +func (container) Foo() { println("hello") } type fooer struct{ name string } -var f *fooer var c = &container{} func main() { @@ -21,12 +18,12 @@ func main() { // while attempting to attach it to external realm, // check recursively. // also see xxx_crossrealm21.gno - f = &fooer{name: "local_foo"} - c.f = f + ff := &fooer{name: "local_foo"} + c.f = ff crossrealm.SetFooer(c) crossrealm.CallFooerFoo() print(".") } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index 70795aa2c4d..ff303b0863c 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -29,4 +29,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("A" string)} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm2.gno b/gnovm/tests/files/zrealm_crossrealm2.gno index 69f548c7e70..5414711340e 100644 --- a/gnovm/tests/files/zrealm_crossrealm2.gno +++ b/gnovm/tests/files/zrealm_crossrealm2.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm20a.gno b/gnovm/tests/files/zrealm_crossrealm20a.gno index 3bac413912d..6ad7ee005a3 100644 --- a/gnovm/tests/files/zrealm_crossrealm20a.gno +++ b/gnovm/tests/files/zrealm_crossrealm20a.gno @@ -12,4 +12,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{(0 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm20b.gno b/gnovm/tests/files/zrealm_crossrealm20b.gno index 5bf3a838a76..31a1a6e4bbf 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b.gno @@ -21,3 +21,4 @@ func main() { } // Error: +// cannot attach a value of a type defined by another realm: struct{(0 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm20c.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno index 61a323cfcbc..8837492cecf 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20d.gno b/gnovm/tests/files/zrealm_crossrealm20d.gno index 0177783a82f..c4c49313b45 100644 --- a/gnovm/tests/files/zrealm_crossrealm20d.gno +++ b/gnovm/tests/files/zrealm_crossrealm20d.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(11 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20e.gno b/gnovm/tests/files/zrealm_crossrealm20e.gno index db78e37ccff..38b33242542 100644 --- a/gnovm/tests/files/zrealm_crossrealm20e.gno +++ b/gnovm/tests/files/zrealm_crossrealm20e.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20f.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno index 981ce43b9ce..319d6880f48 100644 --- a/gnovm/tests/files/zrealm_crossrealm20f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20g.gno b/gnovm/tests/files/zrealm_crossrealm20g.gno index b5d60e3dcf3..d52a6a1117d 100644 --- a/gnovm/tests/files/zrealm_crossrealm20g.gno +++ b/gnovm/tests/files/zrealm_crossrealm20g.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{(22 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm20h.gno b/gnovm/tests/files/zrealm_crossrealm20h.gno index 9919cc02654..9c9b84d1a42 100644 --- a/gnovm/tests/files/zrealm_crossrealm20h.gno +++ b/gnovm/tests/files/zrealm_crossrealm20h.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{("p" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 99851287ba9..97c184fcb35 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -16,12 +16,11 @@ func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } var f fooer func main() { - f = fooer{name: "local_fooer"} - crossrealm.SetContainer2(&f) // the object attached is package block, escaped, so this works. + f = fooer{name: "local_fooer"} // f is dirty + crossrealm.SetContainer2(&f) crossrealm.RunF() print(".") } -// Output: -// hello gno.land/r/demo/tests/crossrealm/iface -// . +// Error: +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index ace6c73fb8b..ef81d0cc0dc 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unreal object from an external realm: struct{("local_fooer" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno index 29a01c7df32..df6111c9a92 100644 --- a/gnovm/tests/files/zrealm_crossrealm21b.gno +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("local_fooer" string)} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm21c.gno b/gnovm/tests/files/zrealm_crossrealm21c.gno new file mode 100644 index 00000000000..1fe0344e783 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21c.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello") } + +var f = fooer{name: "local_fooer"} + +func main() { + crossrealm.SetContainer2(&f) // the object attached is package block, escaped, so this works. + crossrealm.RunF() + print(".") +} + +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21d.gno b/gnovm/tests/files/zrealm_crossrealm21d.gno new file mode 100644 index 00000000000..34081346d7f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21d.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string + bar +} +type bar struct{ name string } + +func (fooer) Foo() { println("hello") } + +var f = fooer{name: "local_fooer"} + +func main() { + f.bar = bar{name: "local_bar"} // this makes f dirty, it's real + crossrealm.SetContainer2(&f) + crossrealm.RunF() + print(".") +} + +// Error: +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21e.gno b/gnovm/tests/files/zrealm_crossrealm21e.gno new file mode 100644 index 00000000000..7680fad9dfa --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21e.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string + bar +} +type bar struct{ name string } + +func (fooer) Foo() { println("hello") } + +var f = fooer{name: "local_fooer"} +var b = bar{name: "local_bar"} + +func main() { + f.bar = b // this makes f dirty, no attached after updated, panic + crossrealm.SetContainer2(&f) + crossrealm.RunF() + print(".") +} + +// Error: +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm36.gno b/gnovm/tests/files/zrealm_crossrealm21f.gno similarity index 76% rename from gnovm/tests/files/zrealm_crossrealm36.gno rename to gnovm/tests/files/zrealm_crossrealm21f.gno index 028e023d934..d3c6acfa2a7 100644 --- a/gnovm/tests/files/zrealm_crossrealm36.gno +++ b/gnovm/tests/files/zrealm_crossrealm21f.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{("d" string)} +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm36a.gno b/gnovm/tests/files/zrealm_crossrealm21g.gno similarity index 54% rename from gnovm/tests/files/zrealm_crossrealm36a.gno rename to gnovm/tests/files/zrealm_crossrealm21g.gno index 18ef893e307..ff2dfc4158b 100644 --- a/gnovm/tests/files/zrealm_crossrealm36a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21g.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(struct{("a" string)} gno.land/r/demo/tests/crossrealm/struct.A),(struct{("b" string)} gno.land/r/demo/tests/crossrealm/struct.B),(struct{( string)} gno.land/r/demo/tests/crossrealm/struct.D)} gno.land/r/demo/tests/crossrealm/struct.C)) diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index 636a1cdae18..4d6ce749272 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unreal object from an external realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm28_slice.gno b/gnovm/tests/files/zrealm_crossrealm28_slice.gno index 8299b00fdc6..0a4b339a7d8 100644 --- a/gnovm/tests/files/zrealm_crossrealm28_slice.gno +++ b/gnovm/tests/files/zrealm_crossrealm28_slice.gno @@ -17,13 +17,12 @@ var fs []crossrealm.Fooer // the object being attached // is foo{name: "1"} func init() { - r := append(fs, foo{name: "1"}) - fs = r // the array is from external realm and unreal + fs := append(fs, foo{name: "1"}) } func main() { println("ok") } -// Error: -// cannot attach a reference to an unreal object from an external realm +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28b.gno b/gnovm/tests/files/zrealm_crossrealm28b.gno index 9847b999312..8c2f94b8697 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b.gno @@ -17,5 +17,5 @@ func main() { println("ok") } -// Error: -// cannot attach a value of a type defined by another realm +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28b1.gno b/gnovm/tests/files/zrealm_crossrealm28b1.gno index afce1ecbe20..b467001ba8a 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b1.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b1.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index f38085084a3..3a80b0ce0e5 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -24,7 +24,5 @@ func main() { println("ok") } -// Output: -// (struct{("2" string)} gno.land/r/crossrealm_test.foo) -// (struct{("3" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a value of a type defined by another realm: struct{("2" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm28c1.gno b/gnovm/tests/files/zrealm_crossrealm28c1.gno index 2456bffe541..b9c2fe45c8c 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c1.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c1.gno @@ -11,11 +11,15 @@ type foo struct { func (foo) Foo() { println("hello from crossrealm_test") } -// should panic, underlying array with external type is unreal +// TODO: think about these two +// array[(struct{("1" string)} gno.land/r/crossrealm_test.foo),(struct{("2" string)} gno.land/r/crossrealm_test.foo),(struct{("3" string)} gno.land/r/crossrealm_test.foo)] var arr = []crossrealm.Fooer{foo{name: "1"}, foo{name: "2"}, foo{name: "3"}} +//var arr2 = []foo{foo{name: "1"}, foo{name: "2"}, foo{name: "3"}} + func main() { + println("ok") } -// Error: -// cannot attach a reference to an unreal object from an external realm +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index 1159c4d1b14..7bb560fa422 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -22,7 +22,5 @@ func main() { println("ok") } -// Output: -// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("2" string)} gno.land/r/crossrealm_test.foo)) diff --git a/gnovm/tests/files/zrealm_crossrealm3.gno b/gnovm/tests/files/zrealm_crossrealm3.gno index e0c800aa624..027a059a65f 100644 --- a/gnovm/tests/files/zrealm_crossrealm3.gno +++ b/gnovm/tests/files/zrealm_crossrealm3.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno index c11a450c09f..d889c6245f8 100644 --- a/gnovm/tests/files/zrealm_crossrealm30.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -8,7 +8,7 @@ import ( var SS []crossrealm.XYZ func main() { - SS = crossrealm.GetSlice() // attaching xxx.XYZ zero value, panic + SS = crossrealm.GetSlice() println(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index 22b02fefdc8..877e1de46aa 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{("1" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index 67d6cd36063..26a81fbe50c 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -16,2617 +14,3 @@ func main() { // Output: // . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "3" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", -// "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", -// "RefCount": "1" -// } -// } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "0" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30", -// "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", -// "RefCount": "1" -// } -// } -// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28]={ -// "Data": null, -// "List": [ -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "af93d4b8543a4ed0e5c7c020bc2ed88f3cbe9d31", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "79476ae559f3c897094485a7a1a1cfad0bd14b38", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28", -// "ModTime": "0", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", -// "RefCount": "1" -// } -// } -// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", -// "IsEscaped": true, -// "ModTime": "27", -// "RefCount": "2" -// }, -// "Parent": null, -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "0", -// "File": "", -// "Line": "0", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Values": [ -// { -// "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/slice" -// }, -// "Methods": [], -// "Name": "Fooer", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "SetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "9", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// }, -// "Methods": [], -// "Name": "XYZ", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "63edd934ae4e6e1adfa3e8ccaec695d037023467", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "3e372219527365f54e2d7651766ad31532018029", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "5b15d0ddccc7056f8a23f92113551faf3458362a", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" -// }, -// "Length": "1", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "c4c833f476004da7b523986bfc338fcd6e2259cc", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "47988816818ccc2d075b63242db659eaceb17c09", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:7" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "2120aae986302ac34c4d0215158d9bb3aa8e5234", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "c67ad4d6692a614a475d6b0665309fc1209dba62", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "init.11", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "34", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "51", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "ee138dfe6fb2fb9d6702fd4a426d40a2ca55e022", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "af3ef02e37f329c151774dc9a73c38f2bd8b5c15", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:12" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "59", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "67", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice4", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "72", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice5", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "77", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice6", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "81", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice7", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "86", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "fc759b6634b8975a76435bc16085d82c322842ae", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice8", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "93", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice9", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "98", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice10", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "105", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice11", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "109", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// } -// ] -// } -// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17] -// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18] -// 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.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm32.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm32.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } -// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e: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/demo/tests/crossrealm/slice" -// } -// }, -// "Values": [ -// { -// "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/slice" -// }, -// "Methods": [], -// "Name": "Fooer", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "SetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "9", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "fs", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// }, -// "Methods": [], -// "Name": "XYZ", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "63edd934ae4e6e1adfa3e8ccaec695d037023467", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "5b15d0ddccc7056f8a23f92113551faf3458362a", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" -// }, -// "Length": "1", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "c4c833f476004da7b523986bfc338fcd6e2259cc", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "47988816818ccc2d075b63242db659eaceb17c09", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:7" -// }, -// "Length": "2", -// "Maxcap": "2", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "2120aae986302ac34c4d0215158d9bb3aa8e5234", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" -// } -// }, -// { -// "T": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "c67ad4d6692a614a475d6b0665309fc1209dba62", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:27" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "init.11", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "34", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "51", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "ee138dfe6fb2fb9d6702fd4a426d40a2ca55e022", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:11" -// } -// }, -// { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "af3ef02e37f329c151774dc9a73c38f2bd8b5c15", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:12" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice2", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "59", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice3", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "67", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice4", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "72", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice5", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "77", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice6", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "81", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice7", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "86", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// }, -// "Len": "2", -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "fc759b6634b8975a76435bc16085d82c322842ae", -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice8", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "93", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice9", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "98", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice10", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "105", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ] -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" -// }, -// "FileName": "crossrealm_slice.gno", -// "IsMethod": false, -// "Name": "GetSlice11", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "crossrealm_slice.gno", -// "Line": "109", -// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "f", -// "Tag": "", -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": "s", -// "Tag": "", -// "Type": { -// "@type": "/gno.SliceType", -// "Elt": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// }, -// "Vrd": false -// } -// } -// ], -// "Results": [] -// } -// } -// ], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index 4fe559f0ae9..58b958333f5 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -19,4 +17,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{("0" string)} +// cannot attach a reference to an unreal object from an external realm: struct{("0" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm34.gno b/gnovm/tests/files/zrealm_crossrealm34.gno new file mode 100644 index 00000000000..dd90dba9886 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm34.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +var SS []*crossrealm.XYZ + +func main() { + SS = crossrealm.GetSlice5() + println(".") +} + +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm34_slice.gno b/gnovm/tests/files/zrealm_crossrealm34_slice.gno deleted file mode 100644 index ae53ea3d97e..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm34_slice.gno +++ /dev/null @@ -1,104 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import ( - "std" - - crossrealm "gno.land/r/demo/tests/crossrealm/slice" -) - -var SS []*crossrealm.XYZ - -func main() { - SS = crossrealm.GetSlice5() - println(".") -} - -// Output: -// . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// 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.SliceType", -// "Elt": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" -// } -// }, -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.SliceValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" -// }, -// "Length": "1", -// "Maxcap": "1", -// "Offset": "0" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "FileName": "files/zrealm_crossrealm34_slice.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm34_slice.gno", -// "Line": "12", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index faace075600..530bd0bdcc1 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -19,4 +17,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{("6.1" string)} +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("6.1" string)} gno.land/r/demo/tests/crossrealm/slice.XYZ)) diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno index 6cc613e1237..f772048687f 100644 --- a/gnovm/tests/files/zrealm_crossrealm34b.gno +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -19,4 +17,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{( string)} diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno index d187ea285bc..1154e80d91a 100644 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,16 +9,16 @@ type foo struct { name string } -func (*foo) String() string { return std.CurrentRealm().PkgPath() } +func (*foo) String() string { return "hey" } var f = &foo{"foo"} var arr interface{} func main() { - arr = crossrealm.GetSlice8(f) + arr = crossrealm.GetSlice8(f) // real array value from external realm println(".") } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: array[(&(ref(f5a516808f8976c33939133293d598ce3bca4e8d:4) gno.land/r/crossrealm_test.foo) *gno.land/r/crossrealm_test.foo)] diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno index e11a09378b0..c7cbd6f1988 100644 --- a/gnovm/tests/files/zrealm_crossrealm35a.gno +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/slice" ) @@ -11,251 +9,16 @@ type foo struct { name string } -func (*foo) String() string { return std.CurrentRealm().PkgPath() } +func (*foo) String() string { return "hey" } var f = &foo{"foo"} var arr interface{} func main() { - arr = crossrealm.GetSlice9(f) + arr = crossrealm.GetSlice9(f) // return value is unreal, elem is from local realm println(".") } // Output: // . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] -// switchrealm["gno.land/r/crossrealm_test"] -// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ -// "Data": null, -// "List": [ -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.foo" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "RefCount": "1" -// } -// } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ -// "Blank": {}, -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d: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/crossrealm_test" -// } -// }, -// "Values": [ -// { -// "T": { -// "@type": "/gno.TypeType" -// }, -// "V": { -// "@type": "/gno.TypeValue", -// "Type": { -// "@type": "/gno.DeclaredType", -// "Base": { -// "@type": "/gno.StructType", -// "Fields": [ -// { -// "Embedded": false, -// "Name": "name", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ], -// "PkgPath": "gno.land/r/crossrealm_test" -// }, -// "Methods": [ -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": ".recv", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.foo" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": null, -// "FileName": "files/zrealm_crossrealm35a.gno", -// "IsMethod": true, -// "Name": "String", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm35a.gno", -// "Line": "14", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [ -// { -// "Embedded": false, -// "Name": ".recv", -// "Tag": "", -// "Type": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.foo" -// } -// } -// } -// ], -// "Results": [ -// { -// "Embedded": false, -// "Name": "", -// "Tag": "", -// "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } -// } -// ] -// } -// } -// } -// ], -// "Name": "foo", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.foo" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.ArrayType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" -// }, -// "Len": "1", -// "Vrd": false -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "2dcefa704545dfed35968f0cca05d38a6a01caf5", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" -// } -// }, -// { -// "T": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// }, -// "V": { -// "@type": "/gno.FuncValue", -// "Closure": { -// "@type": "/gno.RefValue", -// "Escaped": true, -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" -// }, -// "FileName": "files/zrealm_crossrealm35a.gno", -// "IsMethod": false, -// "Name": "main", -// "NativeName": "", -// "NativePkg": "", -// "PkgPath": "gno.land/r/crossrealm_test", -// "Source": { -// "@type": "/gno.RefNode", -// "BlockNode": null, -// "Location": { -// "Column": "1", -// "File": "files/zrealm_crossrealm35a.gno", -// "Line": "20", -// "PkgPath": "gno.land/r/crossrealm_test" -// } -// }, -// "Type": { -// "@type": "/gno.FuncType", -// "Params": [], -// "Results": [] -// } -// } -// } -// ] -// } diff --git a/gnovm/tests/files/zrealm_crossrealm37c.gno b/gnovm/tests/files/zrealm_crossrealm37c.gno index 9429ab08d43..bbc3884d5c5 100644 --- a/gnovm/tests/files/zrealm_crossrealm37c.gno +++ b/gnovm/tests/files/zrealm_crossrealm37c.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm40_method.gno b/gnovm/tests/files/zrealm_crossrealm40_method.gno index 3d105a77b8f..b6620ef7f6b 100644 --- a/gnovm/tests/files/zrealm_crossrealm40_method.gno +++ b/gnovm/tests/files/zrealm_crossrealm40_method.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: <*gno.land/r/demo/tests/crossrealm/func.MyStruct>.M(sv *gno.land/r/demo/tests/crossrealm/func.MyStruct)( string) diff --git a/gnovm/tests/files/zrealm_crossrealm41.gno b/gnovm/tests/files/zrealm_crossrealm41.gno deleted file mode 100644 index 1d921647607..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm41.gno +++ /dev/null @@ -1,20 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -type local struct { - name string -} - -var ll local // this is attached as a zero value - -// XXX, consider more about this. -// var sll []crossrealm.bar -// var pll *crossrealm.bar - -func main() { - l := local{name: "a"} - println(l) -} - -// Output: -// (struct{("a" string)} gno.land/r/crossrealm_test.local) diff --git a/gnovm/tests/files/zrealm_crossrealm42.gno b/gnovm/tests/files/zrealm_crossrealm42.gno deleted file mode 100644 index 626bbd7dcb8..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm42.gno +++ /dev/null @@ -1,16 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import crossrealm "gno.land/r/demo/tests/crossrealm/struct" -import "fmt" - -type LocalBar crossrealm.Bar - -var lb LocalBar - -func main() { - fmt.Println(lb) -} - -// Error: -// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm43.gno b/gnovm/tests/files/zrealm_crossrealm43.gno deleted file mode 100644 index 01d07ea4a6e..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm43.gno +++ /dev/null @@ -1,16 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import crossrealm "gno.land/r/demo/tests/crossrealm/struct" -import "fmt" - -type LocalBar *crossrealm.Bar // no attach - -var lb LocalBar - -func main() { - lb = &crossrealm.Bar{A: 1} -} - -// Error: -// cannot attach a reference to an unreal object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm44_array.gno b/gnovm/tests/files/zrealm_crossrealm44_array.gno index 4fbd5704ae3..0d2c2ef4839 100644 --- a/gnovm/tests/files/zrealm_crossrealm44_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm44_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a value of a type defined by another realm: struct{("a" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm45_array.gno b/gnovm/tests/files/zrealm_crossrealm45_array.gno index 4f077307b96..5bb8fe7e38b 100644 --- a/gnovm/tests/files/zrealm_crossrealm45_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm45_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("a" string)} gno.land/r/demo/tests/crossrealm/array.Foo)) From 943a82e11a54ac0b497eeda7b047f0987086a682 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 6 Feb 2025 22:20:54 +0800 Subject: [PATCH 55/88] fixup --- gnovm/pkg/gnolang/realm.go | 87 +++++--------------------------------- 1 file changed, 11 insertions(+), 76 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 6fa86d2ff38..b54244ccd66 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -213,7 +213,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm for non escaped objects debug2.Println2("=========po is real, check cross realm for non escaped objects========") - checkCrossRealm(rlm, store, co, co.GetOriginValue(), false) + checkCrossRealm(rlm, store, co, false) } } @@ -227,71 +227,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } -//// checkReferenceCrossRealm checks if object is real recursively -//func checkReferenceCrossRealm(rlm *Realm, store Store, oo Object, refValue Value) { -// debug2.Println2("checkReferenceCrossRealm, oo: ", oo, reflect.TypeOf(oo)) -// debug2.Println2("refValue: ", refValue, reflect.TypeOf(refValue)) -// -// if refValue == nil { -// panic("should be a reference value") -// } -// // reference to unreal array, map, closure, -// // check elems... -// if oo.GetOriginRealm().IsZero() { -// debug2.Println2("originRealm is zero, unreal, check elems...") -// } else { -// if rlm.ID != oo.GetOriginRealm() { // crossing realm -// // must be real -// if !oo.GetIsReal() { -// panic("cannot attach a reference to an unreal object from an external realm") -// } else { -// debug2.Println2("oo is real, also check elems...") -// } -// } -// } -// -// switch v := oo.(type) { -// case *StructValue: -// // check fields -// for _, fv := range v.Fields { -// checkCrossRealm2(rlm, store, &fv) -// } -// case *MapValue: -// debug2.Println2("MapValue, v: ", v) -// for cur := v.List.Head; cur != nil; cur = cur.Next { -// checkCrossRealm2(rlm, store, &cur.Key) -// checkCrossRealm2(rlm, store, &cur.Value) -// } -// case *BoundMethodValue: -// // TODO: complete this, check receiver, and? -// case *Block: -// debug2.Println2("BlockValue, v: ", v) -// // XXX, also captures? -// for _, tv := range v.Values { -// checkCrossRealm2(rlm, store, &tv) -// } -// case *HeapItemValue: -// checkCrossRealm2(rlm, store, &v.Value) -// case *ArrayValue: -// if sv, ok := refValue.(*SliceValue); ok { -// debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) -// // only check referenced elem -// for i := sv.Offset; i < sv.Length; i++ { -// checkCrossRealm2(rlm, store, &v.List[i]) -// } -// } else { -// debug2.Println2("2, check elems of ArrayValue, v: ", v) -// if v.Data == nil { -// for _, e := range v.List { -// checkCrossRealm2(rlm, store, &e) -// } -// } -// } -// default: -// panic("should not happen, oo is not object") -// } -//} - // check cross realm recursively func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { debug2.Println2("checkCrossRealm2, tv: ", tv, reflect.TypeOf(tv.V)) @@ -300,7 +235,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { debug2.Println2("is object") // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, oo, nil, isLastRef) + checkCrossRealm(rlm, store, oo, isLastRef) } else { // reference to object switch rv := tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm @@ -309,7 +244,8 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { debug2.Println2("is reference to object, reo: ", reo) // if base escaped, do nothing reo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, reo, rv, true) + reo.SetOriginValue(rv) + checkCrossRealm(rlm, store, reo, true) } } // else nothing to do @@ -319,9 +255,9 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. -func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value, isLastRef bool) { +func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) - if refValue != nil { + if oo.GetOriginValue() != nil { isLastRef = true } @@ -333,7 +269,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value, isLastR debug2.Println2("crossing realm, check oo, then elems") // reference value if isLastRef { - debug2.Println2("Reference to object: ", refValue, reflect.TypeOf(refValue)) + debug2.Println2("Reference to object: ", oo.GetOriginValue(), reflect.TypeOf(oo.GetOriginValue())) if !oo.GetIsReal() { panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } else { @@ -375,7 +311,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value, isLastR if oo.GetIsReal() && !oo.GetIsDirty() { // ok } else { - if refValue != nil { + if isLastRef { panic("cannot attach a reference to dirty object from an external realm") } else { panic("cannot attach dirty object from an external realm") @@ -404,7 +340,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, refValue Value, isLastR } else { // unreal object, see 28c, 30 isLastRef = false } - if sv, ok := refValue.(*SliceValue); ok { + if sv, ok := oo.GetOriginValue().(*SliceValue); ok { debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) // only check referenced elem for i := sv.Offset; i < sv.Length; i++ { @@ -441,7 +377,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm if originValue != nil { - checkCrossRealm(rlm, store, oo, originValue, true) + checkCrossRealm(rlm, store, oo, true) } else { panic("cannot attach objects by value from external realm") } @@ -692,8 +628,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { _, ok2 := oo.(*Block) // package block if !ok1 && !ok2 { debug2.Println2("===incRefCreatedDescendants, checkCrossRealm") - isLastRef := oo.GetOriginValue() != nil - checkCrossRealm(rlm, store, oo, oo.GetOriginValue(), isLastRef) + checkCrossRealm(rlm, store, oo, false) } // RECURSE GUARD From a57e1bfed60d14a13ca2e6a8ac97f584d04d62e8 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 6 Feb 2025 22:23:08 +0800 Subject: [PATCH 56/88] fixup --- gnovm/pkg/gnolang/realm.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index b54244ccd66..2aa9186f78b 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -624,6 +624,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // package block not real now. // TODO: correct this // TODO: avoid duplicate check with DidUpdate... + // maybe a flag: CrossRealm, and guard _, ok1 := oo.(*PackageValue) _, ok2 := oo.(*Block) // package block if !ok1 && !ok2 { From 5be6f681d4e7761f84ed3571f5552b4e4ef94990 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 9 Feb 2025 22:30:37 +0800 Subject: [PATCH 57/88] fixup --- gnovm/pkg/test/filetest.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index 85fecd05714..8986b846a87 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -105,13 +105,12 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // The Error directive (and many others) will have one trailing newline, // which is not in the output - so add it there. match(errDirective, result.Error+"\n") - } else { - //fmt.Println("result.Error is empty:", result.Error) + } else if result.Output != "" { outputDirective := dirs.First(DirectiveOutput) - //fmt.Println("outputDirective:", outputDirective) if outputDirective == nil { return "", fmt.Errorf("unexpected output: \n%s", result.Output) } + } else { err = m.CheckEmpty() if err != nil { return "", fmt.Errorf("machine not empty after main: %w", err) From 79e0903c5ad170a28beb212e1d7be6940f21f4f3 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 10 Feb 2025 13:11:40 +0800 Subject: [PATCH 58/88] fixup --- gnovm/pkg/gnolang/realm.go | 93 +++++++++++----------- gnovm/pkg/gnolang/values.go | 4 +- gnovm/tests/files/zrealm_crossrealm22b.gno | 2 +- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 2aa9186f78b..aa3d2b42fa5 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -248,7 +248,6 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { checkCrossRealm(rlm, store, reo, true) } } - // else nothing to do } // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. @@ -257,8 +256,12 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) - if oo.GetOriginValue() != nil { - isLastRef = true + if !isLastRef { + // is last not ref, current + // object can be reference + if oo.GetOriginValue() != nil { + isLastRef = true + } } if oo.GetOriginRealm().IsZero() { @@ -288,13 +291,13 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { case *StructValue: // check fields for _, fv := range v.Fields { - checkCrossRealm2(rlm, store, &fv, false) // ref to struct is heapItemValue or block + checkCrossRealm2(rlm, store, &fv, isLastRef) // ref to struct is heapItemValue or block } case *MapValue: debug2.Println2("MapValue, v: ", v) for cur := v.List.Head; cur != nil; cur = cur.Next { - checkCrossRealm2(rlm, store, &cur.Key, false) - checkCrossRealm2(rlm, store, &cur.Value, false) + checkCrossRealm2(rlm, store, &cur.Key, isLastRef) + checkCrossRealm2(rlm, store, &cur.Value, isLastRef) } case *BoundMethodValue: // TODO: complete this @@ -302,10 +305,10 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("BlockValue, v: ", v) // NOTE, it's not escaped until now, // will set after check - if oo.GetRefCount() > 1 { + if oo.GetRefCount() > 1 { // escaped, as a base of pointer value // only check when it's dirty - debug2.Println2("oo escaped, and dirty") for _, tv := range v.Values { + //if tv == oo.GetOriginValue(){} debug2.Println2("tv: ", tv) if oo, ok := tv.V.(Object); ok { if oo.GetIsReal() && !oo.GetIsDirty() { @@ -319,10 +322,16 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } } } - } else { // this will attach the block - // XXX, also captures? + } else { // this block will be attached, from current or external realm + // TODO:, also check captures? for _, tv := range v.Values { - checkCrossRealm2(rlm, store, &tv, true) // always true + debug2.Println2("origin value of block is: ", oo.GetOriginValue()) + switch oo.GetOriginValue().(type) { + case *SliceValue, PointerValue: // if reference object from external realm + checkCrossRealm2(rlm, store, &tv, isLastRef) + default: + checkCrossRealm2(rlm, store, &tv, isLastRef) + } } } case *HeapItemValue: @@ -335,9 +344,11 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } } case *ArrayValue: - if !oo.GetOriginRealm().IsZero() { // refer a real object - isLastRef = true - } else { // unreal object, see 28c, 30 + // if the array value is unreal, + // it's going to be attached with + // all the elems, so it's attaching + // by value + if oo.GetOriginRealm().IsZero() { isLastRef = false } if sv, ok := oo.GetOriginValue().(*SliceValue); ok { @@ -502,13 +513,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -523,9 +534,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -591,6 +602,10 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // skip if became deleted. continue } else { + // check cross realm while attaching + if pv, ok := oo.(*PackageValue); ok { + checkCrossRealm(rlm, store, pv.Block.(Object), false) + } rlm.incRefCreatedDescendants(store, oo) } } @@ -603,11 +618,11 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // XXX, unreal oo check happens in here // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - debug2.Println2("---incRefCreatedDescendants from oo: ", oo, reflect.TypeOf(oo)) - debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) - debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("---rlm.ID: ", rlm.ID) - debug2.Println2("oo.GetOriginValue: ", oo.GetOriginValue()) + //debug2.Println2("---incRefCreatedDescendants from oo: ", oo, reflect.TypeOf(oo)) + //debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) + //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + //debug2.Println2("---rlm.ID: ", rlm.ID) + //debug2.Println2("oo.GetOriginValue: ", oo.GetOriginValue()) if debug { if oo.GetIsDirty() { @@ -618,20 +633,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } } - // while associating, if po is unreal, the check - // defers to here. - // TODO: add test, associate to a container, just associate to global, - // package block not real now. - // TODO: correct this - // TODO: avoid duplicate check with DidUpdate... - // maybe a flag: CrossRealm, and guard - _, ok1 := oo.(*PackageValue) - _, ok2 := oo.(*Block) // package block - if !ok1 && !ok2 { - debug2.Println2("===incRefCreatedDescendants, checkCrossRealm") - checkCrossRealm(rlm, store, oo, false) - } - // RECURSE GUARD // if id already set, skip. // this happens when a node marked created was already @@ -930,9 +931,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 95f246b068a..c78cf360640 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -255,7 +255,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -304,7 +304,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // proper element in the base. // e.g. refValue is a sliceValue switch rv := pv.TV.V.(type) { - case *SliceValue, PointerValue, *FuncValue: + case *SliceValue, PointerValue: oo2.SetOriginValue(rv) } diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index 4d6ce749272..ae6ffb04679 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: struct{( string)} +// cannot attach a value of a type defined by another realm: struct{( string)} From 5a84415fc3839fca6ef55b44725ad97031bf7fb4 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 10 Feb 2025 22:12:21 +0800 Subject: [PATCH 59/88] fixup --- examples/gno.land/r/demo/tests_foo/foo.gno | 13 +++- gnovm/pkg/gnolang/realm.go | 69 +++++++++++++--------- gnovm/pkg/gnolang/values.go | 2 +- gnovm/tests/files/type_alias.gno | 5 +- gnovm/tests/files/types/eql_0f49.gno | 2 + gnovm/tests/files/zrealm6.gno | 4 +- gnovm/tests/files/zrealm7.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21h.gno | 26 ++++++++ gnovm/tests/files/zrealm_natbind0.gno | 5 +- gnovm/tests/files/zrealm_tests0.gno | 66 +++++---------------- 11 files changed, 106 insertions(+), 90 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm21h.gno diff --git a/examples/gno.land/r/demo/tests_foo/foo.gno b/examples/gno.land/r/demo/tests_foo/foo.gno index 560d85552ab..ac2721f023e 100644 --- a/examples/gno.land/r/demo/tests_foo/foo.gno +++ b/examples/gno.land/r/demo/tests_foo/foo.gno @@ -14,6 +14,17 @@ func (fs *FooStringer) String() string { return "&FooStringer{" + fs.FieldA + "}" } +var f1 = &FooStringer{"one"} // this make it real +var f2 = &FooStringer{"two"} // this make it real +var f3 = &FooStringer{"three"} // this make it real + func AddFooStringer(fa string) { - tests.AddStringer(&FooStringer{fa}) + switch fa { + case "one": + tests.AddStringer(f1) + case "two": + tests.AddStringer(f2) + case "three": + tests.AddStringer(f3) + } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index aa3d2b42fa5..d0e154d96b3 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -158,6 +158,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) debug2.Println2("originValue: ", co.GetOriginValue()) + debug2.Println2("co.GetRefCount: ", co.GetRefCount()) } if rlm == nil { @@ -245,7 +246,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // if base escaped, do nothing reo.SetOriginRealm(tv2.GetOriginPkg(store)) reo.SetOriginValue(rv) - checkCrossRealm(rlm, store, reo, true) + checkCrossRealm(rlm, store, reo, isLastRef) } } } @@ -303,15 +304,16 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // TODO: complete this case *Block: debug2.Println2("BlockValue, v: ", v) + debug2.Printf2("oo: %v, \n oo.GetRefCount: %v \n", oo, oo.GetRefCount()) // NOTE, it's not escaped until now, // will set after check if oo.GetRefCount() > 1 { // escaped, as a base of pointer value - // only check when it's dirty - for _, tv := range v.Values { - //if tv == oo.GetOriginValue(){} - debug2.Println2("tv: ", tv) - if oo, ok := tv.V.(Object); ok { - if oo.GetIsReal() && !oo.GetIsDirty() { + debug2.Println2("block escaped, it's real") + // TODO: no need to check whole block + // only check the ptr.TV itself + if pv, ok := oo.GetOriginValue().(PointerValue); ok { + if oo2, ok := pv.TV.V.(Object); ok { + if oo2.GetIsReal() && !oo2.GetIsDirty() { // ok } else { if isLastRef { @@ -323,14 +325,14 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } } } else { // this block will be attached, from current or external realm + debug2.Println2("block is NOT real, v...PkgID: ", v.GetObjectID().PkgID) // TODO:, also check captures? - for _, tv := range v.Values { - debug2.Println2("origin value of block is: ", oo.GetOriginValue()) - switch oo.GetOriginValue().(type) { - case *SliceValue, PointerValue: // if reference object from external realm - checkCrossRealm2(rlm, store, &tv, isLastRef) - default: - checkCrossRealm2(rlm, store, &tv, isLastRef) + if v.GetObjectID().PkgID != rlm.ID { // not recursively checking for same realm + for i, tv := range v.Values { + debug2.Printf2("tv[%d] is tv: %v \n", i, tv) + if tv.GetFirstObject(store) != v { // recursive guard + checkCrossRealm2(rlm, store, &tv, isLastRef) + } } } } @@ -344,6 +346,13 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } } case *ArrayValue: + debug2.Println2("ArrayValue, v: ", v) + for i, e := range v.List { + debug2.Printf2("List, ArrayValue[%d] is %v: \n", i, e) + } + for i, e := range v.Data { + debug2.Printf2("Data, ArrayValue[%d] is %v: \n", i, e) + } // if the array value is unreal, // it's going to be attached with // all the elems, so it's attaching @@ -354,8 +363,10 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { if sv, ok := oo.GetOriginValue().(*SliceValue); ok { debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) // only check referenced elem - for i := sv.Offset; i < sv.Length; i++ { - checkCrossRealm2(rlm, store, &v.List[i], isLastRef) + if v.Data == nil { + for i := sv.Offset; i < sv.Length; i++ { + checkCrossRealm2(rlm, store, &v.List[i], isLastRef) + } } } else { debug2.Println2("2, check elems of ArrayValue, v: ", v) @@ -513,13 +524,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -534,9 +545,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -931,9 +942,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index c78cf360640..9686c56f758 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -255,7 +255,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } diff --git a/gnovm/tests/files/type_alias.gno b/gnovm/tests/files/type_alias.gno index e95c54126ec..09918f6d591 100644 --- a/gnovm/tests/files/type_alias.gno +++ b/gnovm/tests/files/type_alias.gno @@ -6,7 +6,8 @@ import "gno.land/p/demo/uassert" type TestingT = uassert.TestingT func main() { - println(TestingT) + println("ok") } -// No need for output; not panicking is passing. +// Output: +// ok diff --git a/gnovm/tests/files/types/eql_0f49.gno b/gnovm/tests/files/types/eql_0f49.gno index b5a4bf4ed05..b4d6f7e3972 100644 --- a/gnovm/tests/files/types/eql_0f49.gno +++ b/gnovm/tests/files/types/eql_0f49.gno @@ -14,6 +14,8 @@ func main() { } +// Output: +// true // true // true // true diff --git a/gnovm/tests/files/zrealm6.gno b/gnovm/tests/files/zrealm6.gno index 3fb348cb4cd..b9ab7ff91de 100644 --- a/gnovm/tests/files/zrealm6.gno +++ b/gnovm/tests/files/zrealm6.gno @@ -19,5 +19,5 @@ func main() { println(updated, tree.Size()) } -// Error: -// cannot attach un-real object from external realm: struct{("key0" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value0" string),(2 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(&(struct{("key1" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value1" string),(1 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode) *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} +// Output: +// false 3 diff --git a/gnovm/tests/files/zrealm7.gno b/gnovm/tests/files/zrealm7.gno index f7707024bad..f3a4578d5ac 100644 --- a/gnovm/tests/files/zrealm7.gno +++ b/gnovm/tests/files/zrealm7.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach un-real object from external realm: struct{("key0" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value0" string),(2 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(&(struct{("key1" github.com/gnolang/gno/_test/timtadh/data_structures/types.String),("value1" string),(1 int),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode),(nil *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode) *github.com/gnolang/gno/_test/timtadh/data_structures/tree/avl.AvlNode)} +// cannot attach a reference to dirty object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21d.gno b/gnovm/tests/files/zrealm_crossrealm21d.gno index 34081346d7f..008729215f3 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d.gno @@ -17,7 +17,7 @@ var f = fooer{name: "local_fooer"} func main() { f.bar = bar{name: "local_bar"} // this makes f dirty, it's real - crossrealm.SetContainer2(&f) + crossrealm.SetContainer2(&f) // object DidUpdate is package block crossrealm.RunF() print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm21h.gno b/gnovm/tests/files/zrealm_crossrealm21h.gno new file mode 100644 index 00000000000..37164687421 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21h.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello") } + +var f = fooer{name: "local_fooer"} + +var f1 = &f + +func main() { + crossrealm.SetContainer2(&f) + crossrealm.RunF() + print(".") +} + +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 6ff1737e565..76ca89dc742 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -22,5 +22,6 @@ func main() { println(g()) } -// Error: -// cannot attach objects by value from external realm +// Output: +// 123 +// dev diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index bdd5a0bf73c..33c065d314a 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -26,46 +26,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests"] -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "three" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19", -// "ModTime": "0", -// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18", -// "RefCount": "1" -// } -// } -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18]={ -// "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18", -// "ModTime": "0", -// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests_foo.FooStringer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "6b9b731f6118c2419f23ba57e1481679f17f4a8f", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:19" -// } -// } -// } -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13]={ // "Data": null, // "List": [ // { @@ -80,8 +41,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "148d314678615253ee2032d7ecff6b144b474baf", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:12" +// "Hash": "ba465d7c93b78df4ef63299b2d8f09c9b30fecf4", +// "ObjectID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:3" // }, // "Index": "0", // "TV": null @@ -99,8 +60,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "fa414e1770821b8deb8e6d46d97828c47f7d5fa5", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:15" +// "Hash": "729e21266d34f42f83a286f76a8b5bc45f59290f", +// "ObjectID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:5" // }, // "Index": "0", // "TV": null @@ -118,8 +79,8 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "aaa64d049cf8660d689780acac9f546f270eaa4e", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:18" +// "Escaped": true, +// "ObjectID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:7" // }, // "Index": "0", // "TV": null @@ -127,7 +88,7 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13", // "ModTime": "0", // "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "RefCount": "1" @@ -138,7 +99,7 @@ func main() { // "ObjectInfo": { // "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "IsEscaped": true, -// "ModTime": "16", +// "ModTime": "12", // "RefCount": "5" // }, // "Parent": null, @@ -207,8 +168,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "3c58838c5667649add1ff8ee48a1cdc187fcd2ef", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:17" +// "Hash": "b05c9b53cf7a8585ea042470c2df36df476ddc75", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13" // }, // "Length": "3", // "Maxcap": "3", @@ -1772,7 +1733,10 @@ func main() { // } // ] // } -// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14] +// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:12] +// switchrealm["gno.land/r/demo/tests_foo"] +// switchrealm["gno.land/r/demo/tests_foo"] +// switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests"] // switchrealm["gno.land/r/demo/tests_test"] From dd7bfa46e786b73b907d4ebf0f87d2cda4bf0015 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 11 Feb 2025 10:46:46 +0800 Subject: [PATCH 60/88] fixup --- gnovm/pkg/gnolang/realm.go | 63 +++++++-------------- gnovm/tests/files/zrealm7.gno | 4 +- gnovm/tests/files/zrealm_crossrealm17.gno | 5 +- gnovm/tests/files/zrealm_crossrealm21.gno | 5 +- gnovm/tests/files/zrealm_crossrealm21d.gno | 5 +- gnovm/tests/files/zrealm_crossrealm21d1.gno | 28 +++++++++ gnovm/tests/files/zrealm_crossrealm21d2.gno | 27 +++++++++ gnovm/tests/files/zrealm_crossrealm21e.gno | 7 ++- gnovm/tests/files/zrealm_crossrealm21f.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28c2.gno | 29 ++++++++++ gnovm/tests/files/zrealm_crossrealm33.gno | 9 ++- gnovm/tests/files/zrealm_crossrealm34a.gno | 4 +- 12 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm21d1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm21d2.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c2.gno diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index d0e154d96b3..572bbf29b8e 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -257,17 +257,13 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) - if !isLastRef { - // is last not ref, current - // object can be reference - if oo.GetOriginValue() != nil { - isLastRef = true - } + // is last not ref, current + // object can be reference + if !isLastRef && oo.GetOriginValue() != nil { + isLastRef = true } - if oo.GetOriginRealm().IsZero() { - debug2.Println2("Origin Realm is zero, unreal, check elems...") - } else { + if !oo.GetOriginRealm().IsZero() { // e.g. unreal array, struct... debug2.Println2("Origin Realm NOT zero...") if rlm.ID != oo.GetOriginRealm() { // crossing realm debug2.Println2("crossing realm, check oo, then elems") @@ -277,7 +273,8 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { if !oo.GetIsReal() { panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } else { - debug2.Println2("oo is real, check elems...") + debug2.Println2("oo is real, just return") + return } } else { // not reference to object debug2.Println2("Non reference object crossing realm, panic...") @@ -286,6 +283,8 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } else { debug2.Println2("oo Not crossing realm, check elems...") } + } else { + debug2.Println2("Origin Realm is zero, unreal, check elems...") } switch v := oo.(type) { @@ -307,43 +306,19 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Printf2("oo: %v, \n oo.GetRefCount: %v \n", oo, oo.GetRefCount()) // NOTE, it's not escaped until now, // will set after check - if oo.GetRefCount() > 1 { // escaped, as a base of pointer value - debug2.Println2("block escaped, it's real") - // TODO: no need to check whole block - // only check the ptr.TV itself - if pv, ok := oo.GetOriginValue().(PointerValue); ok { - if oo2, ok := pv.TV.V.(Object); ok { - if oo2.GetIsReal() && !oo2.GetIsDirty() { - // ok - } else { - if isLastRef { - panic("cannot attach a reference to dirty object from an external realm") - } else { - panic("cannot attach dirty object from an external realm") - } - } - } - } - } else { // this block will be attached, from current or external realm - debug2.Println2("block is NOT real, v...PkgID: ", v.GetObjectID().PkgID) - // TODO:, also check captures? - if v.GetObjectID().PkgID != rlm.ID { // not recursively checking for same realm - for i, tv := range v.Values { - debug2.Printf2("tv[%d] is tv: %v \n", i, tv) - if tv.GetFirstObject(store) != v { // recursive guard - checkCrossRealm2(rlm, store, &tv, isLastRef) - } - } + debug2.Println2("block is NOT real, v...PkgID: ", v.GetObjectID().PkgID) + // TODO:, also check captures? + for i, tv := range v.Values { + debug2.Printf2("tv[%d] is tv: %v \n", i, tv) + if tv.GetFirstObject(store) != v { // recursive guard + checkCrossRealm2(rlm, store, &tv, isLastRef) } } case *HeapItemValue: - //checkCrossRealm2(rlm, store, &v.Value) - if oo2, ok := v.Value.V.(Object); ok { - debug2.Println2("oo2.GetIsDirty(): ", oo2.GetIsDirty()) - debug2.Println2("oo2: ", oo2) - if oo2.GetIsDirty() { - panic("cannot attach a reference to dirty object from an external realm") - } + if oo.GetRefCount() > 1 { + debug2.Println2("hiv escaped, do nothing") + } else { + checkCrossRealm2(rlm, store, &v.Value, isLastRef) } case *ArrayValue: debug2.Println2("ArrayValue, v: ", v) diff --git a/gnovm/tests/files/zrealm7.gno b/gnovm/tests/files/zrealm7.gno index f3a4578d5ac..d1f8981ec50 100644 --- a/gnovm/tests/files/zrealm7.gno +++ b/gnovm/tests/files/zrealm7.gno @@ -20,5 +20,5 @@ func main() { println(updated, tree.Size()) } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// false 4 diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 435a40a2443..cd8d4ace1d6 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -25,5 +25,6 @@ func main() { print(".") } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 97c184fcb35..19aac608e34 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -22,5 +22,6 @@ func main() { print(".") } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// hello gno.land/r/demo/tests/crossrealm/iface +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21d.gno b/gnovm/tests/files/zrealm_crossrealm21d.gno index 008729215f3..48807117673 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d.gno @@ -22,5 +22,6 @@ func main() { print(".") } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21d1.gno b/gnovm/tests/files/zrealm_crossrealm21d1.gno new file mode 100644 index 00000000000..fef0063ef22 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21d1.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string + b *bar +} +type bar struct{ name string } + +func (fooer) Foo() { println("hello") } + +var f = fooer{name: "local_fooer"} // already real +var b = &bar{name: "local_bar"} + +func main() { + f.b = b // this makes f dirty, it's real + crossrealm.SetContainer2(&f) // object DidUpdate is package block + crossrealm.RunF() + print(".") +} + +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21d2.gno b/gnovm/tests/files/zrealm_crossrealm21d2.gno new file mode 100644 index 00000000000..5cf35101466 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm21d2.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/iface" +) + +type fooer struct { + name string + bar +} +type bar struct{ name string } + +func (fooer) Foo() { println("hello") } + +var b = bar{name: "bar"} +var f = fooer{name: "local_fooer", bar: b} + +func main() { + crossrealm.SetContainer2(&f) // object DidUpdate is package block + crossrealm.RunF() + print(".") +} + +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21e.gno b/gnovm/tests/files/zrealm_crossrealm21e.gno index 7680fad9dfa..d0a97e3ba69 100644 --- a/gnovm/tests/files/zrealm_crossrealm21e.gno +++ b/gnovm/tests/files/zrealm_crossrealm21e.gno @@ -17,11 +17,12 @@ var f = fooer{name: "local_fooer"} var b = bar{name: "local_bar"} func main() { - f.bar = b // this makes f dirty, no attached after updated, panic + f.bar = b // this makes f dirty crossrealm.SetContainer2(&f) crossrealm.RunF() print(".") } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// hello +// . diff --git a/gnovm/tests/files/zrealm_crossrealm21f.gno b/gnovm/tests/files/zrealm_crossrealm21f.gno index d3c6acfa2a7..34c48369d55 100644 --- a/gnovm/tests/files/zrealm_crossrealm21f.gno +++ b/gnovm/tests/files/zrealm_crossrealm21f.gno @@ -10,8 +10,8 @@ func cb(c *crossrealm.C) { } func main() { crossrealm.GetStruct(cb) - println(s) + println("ok") } -// Error: -// cannot attach a reference to dirty object from an external realm +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28c2.gno b/gnovm/tests/files/zrealm_crossrealm28c2.gno new file mode 100644 index 00000000000..a7adf08725f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c2.gno @@ -0,0 +1,29 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var f1 = foo{name: "1"} +var f2 = foo{name: "2"} +var f3 = foo{name: "3"} + +func main() { + var arr []crossrealm.Fooer // unreal array + arr = append(arr, f1) + arr = append(arr, f2) + arr = append(arr, f3) + + crossrealm.SetSlice(arr) + println("ok") +} + +// Error: +// cannot attach a value of a type defined by another realm: struct{("1" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index 58b958333f5..ffc8dabc2e1 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -12,9 +12,14 @@ var f = func(s []crossrealm.XYZ) { } func main() { + // XXX, even elem of the array is not real, + // but the array is already attached to + // external realm, so the elem has no + // chance to attach to this realm. + // so it isd valid. crossrealm.GetSlice4(f) println(".") } -// Error: -// cannot attach a reference to an unreal object from an external realm: struct{("0" string)} +// Output: +// . diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index 530bd0bdcc1..4572cf2f70e 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -16,5 +16,5 @@ func main() { println(".") } -// Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("6.1" string)} gno.land/r/demo/tests/crossrealm/slice.XYZ)) +// Output: +// . From 3e949ff5ea87878d3c5740b7c02f36a70c99e659 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 11 Feb 2025 20:47:06 +0800 Subject: [PATCH 61/88] recursive guard --- .../crossrealm/slice/crossrealm_slice.gno | 11 +- gnovm/pkg/gnolang/realm.go | 33 +- gnovm/tests/files/zrealm_crossrealm20b1.gno | 24 + gnovm/tests/files/zrealm_crossrealm20c1.gno | 21 + gnovm/tests/files/zrealm_crossrealm28c3.gno | 1360 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm28c4.gno | 32 + gnovm/tests/files/zrealm_crossrealm28c5.gno | 33 + gnovm/tests/files/zrealm_crossrealm34a.gno | 2 +- 8 files changed, 1509 insertions(+), 7 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm20b1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm20c1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c3.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c4.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c5.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index efe899ada6d..240ae30bd57 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -13,6 +13,15 @@ func SetSlice(fs []Fooer) { } } +var Arr [3]Fooer + +func SetArray(arr [3]Fooer) { + Arr = arr + for _, f := range Arr { + println(f) + } +} + // ------------------------------------- type XYZ struct{ name string } @@ -80,7 +89,7 @@ func GetSlice5() []*XYZ { // TODO, unwrap func GetSlice6(f func(s []*XYZ)) { s6[1] = &XYZ{"6.1"} - f(s6) // not real now + f(s6) } func GetSlice7(f func(s [2]XYZ)) { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 572bbf29b8e..18a7962b231 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "reflect" + "slices" "strings" "sync" @@ -159,6 +160,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) debug2.Println2("originValue: ", co.GetOriginValue()) debug2.Println2("co.GetRefCount: ", co.GetRefCount()) + debug2.Println2("co.GetIsReal: ", co.GetIsReal()) } if rlm == nil { @@ -243,10 +245,32 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // XXX: consider pkgId here, A -> B - > A?... reo := tv.GetFirstObject(store) debug2.Println2("is reference to object, reo: ", reo) - // if base escaped, do nothing + debug2.Println2("is reference to object, tv2.V, type of : ", tv2.V, reflect.TypeOf(tv2.V)) + + // if a pointer has a base in + // current realm, implies the + // current realm is finalizing, + // just skip as a recursive guard. + if pv, ok := tv2.V.(PointerValue); ok { + debug2.Println2("pv: ", pv) + debug2.Println2("pv.TV: ", *pv.TV) + // check recursive + if b, ok := reo.(*Block); ok { + if slices.Contains(b.Values, *pv.TV) { // this implies *pv.TV is real + //if o2, ok := (*pv.TV).V.(Object); ok { + // if !o2.GetIsReal() { + // not return + // } + //} + debug2.Println2("return on block recursive") + return + } + } + } + reo.SetOriginRealm(tv2.GetOriginPkg(store)) reo.SetOriginValue(rv) - checkCrossRealm(rlm, store, reo, isLastRef) + checkCrossRealm(rlm, store, reo, true) } } } @@ -257,6 +281,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + debug2.Printf2("isLastRef: %t, is current ref: %t \n", isLastRef, oo.GetOriginValue() != nil) // is last not ref, current // object can be reference if !isLastRef && oo.GetOriginValue() != nil { @@ -310,9 +335,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // TODO:, also check captures? for i, tv := range v.Values { debug2.Printf2("tv[%d] is tv: %v \n", i, tv) - if tv.GetFirstObject(store) != v { // recursive guard - checkCrossRealm2(rlm, store, &tv, isLastRef) - } + checkCrossRealm2(rlm, store, &tv, isLastRef) } case *HeapItemValue: if oo.GetRefCount() > 1 { diff --git a/gnovm/tests/files/zrealm_crossrealm20b1.gno b/gnovm/tests/files/zrealm_crossrealm20b1.gno new file mode 100644 index 00000000000..61712343594 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20b1.gno @@ -0,0 +1,24 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/struct" +) + +// associate to a containing object +type Container struct { + name string + b crossrealm.Bar // panic while attaching(finalizing) +} + +var c *Container + +func init() { + print("ok") +} + +func main() { +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm20c1.gno b/gnovm/tests/files/zrealm_crossrealm20c1.gno new file mode 100644 index 00000000000..713947c1b98 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20c1.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/struct" +) + +// associate to a containing object +type Container struct { + name string + b *crossrealm.Bar +} + +var c = &Container{name: "local_container", b: &crossrealm.Bar{A: 1}} + +func main() { + print(".") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm28c3.gno b/gnovm/tests/files/zrealm_crossrealm28c3.gno new file mode 100644 index 00000000000..5340dd468af --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c3.gno @@ -0,0 +1,1360 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (*foo) Foo() { println("hello from crossrealm_test") } + +var f1 = foo{name: "1"} +var f2 = foo{name: "2"} +var f3 = foo{name: "3"} + +var arr []crossrealm.Fooer // unreal array + +func init() { + arr = append(arr, &f1) + arr = append(arr, &f2) + arr = append(arr, &f3) +} + +func main() { + crossrealm.SetSlice(arr) + println("ok") +} + +// Output: +// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "IsEscaped": true, +// "ModTime": "28", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "0", +// "File": "", +// "Line": "0", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Values": [ +// { +// "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/slice" +// }, +// "Methods": [], +// "Name": "Fooer", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" +// }, +// "Length": "3", +// "Maxcap": "3", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "SetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "9", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "fs", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Len": "3", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d62efae4bccfb771ca26b5401811c88b7a4d4600", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "arr", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Len": "3", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "SetArray", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "18", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "arr", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.Fooer" +// }, +// "Len": "3", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "name", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// }, +// "Methods": [], +// "Name": "XYZ", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "c6af76356d551443236418387570bc8842e2f13d", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "0c857aadf76e22e70e4663947d19179e9b084305", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "48a643765d27caf33f1a84e6cd2626c09de575ec", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5" +// }, +// "Length": "1", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "4a9542d3dbc515401ea899e520e20985a29793eb", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:21" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "efa17cc1bdfcc78d6ce7fd3d37d8eb1463d2f3f8", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:8" +// }, +// "Length": "2", +// "Maxcap": "2", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "9128ce5efd0b78fe0b2508620d33297efc8ca400", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:9" +// } +// }, +// { +// "T": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "3d8f45f94de2ae064cb1b22cb23131014b5e2b3e", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:28" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "init.13", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "43", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "60", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "4e519b2e696d045f540a772835d23f935a34a418", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:12" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "767f878ff4789535ef68989918de26fe5a792ee0", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:13" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice2", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "68", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice3", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "76", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice4", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "81", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice5", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "86", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice6", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "90", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// } +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice7", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "95", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "Len": "2", +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "dc790554954efbbee8c7251652faacd0ffe4f588", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14" +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice8", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "102", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice9", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "107", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.ArrayType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/tests/p_crossrealm.Stringer" +// }, +// "Len": "1", +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice10", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "114", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:3" +// }, +// "FileName": "crossrealm_slice.gno", +// "IsMethod": false, +// "Name": "GetSlice11", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "crossrealm_slice.gno", +// "Line": "118", +// "PkgPath": "gno.land/r/demo/tests/crossrealm/slice" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "f", +// "Tag": "", +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "s", +// "Tag": "", +// "Type": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// }, +// "Vrd": false +// } +// } +// ], +// "Results": [] +// } +// } +// ], +// "Results": [] +// } +// } +// } +// ] +// } +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm28c4.gno b/gnovm/tests/files/zrealm_crossrealm28c4.gno new file mode 100644 index 00000000000..382ad63e94f --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c4.gno @@ -0,0 +1,32 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var f1 = foo{name: "1"} +var f2 = foo{name: "2"} +var f3 = foo{name: "3"} + +func main() { + var arr [3]crossrealm.Fooer // unreal array + arr[0] = &f1 + arr[1] = &f2 + arr[2] = &f3 + + crossrealm.SetArray(arr) + println("ok") +} + +// Output: +// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28c5.gno b/gnovm/tests/files/zrealm_crossrealm28c5.gno new file mode 100644 index 00000000000..febeaba57bc --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c5.gno @@ -0,0 +1,33 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +func main() { + var f1 = foo{name: "1"} + var f2 = foo{name: "2"} + var f3 = foo{name: "3"} + + var arr [3]crossrealm.Fooer // unreal array + + arr[0] = &f1 + arr[1] = &f2 + arr[2] = &f3 + + crossrealm.SetArray(arr) + println("ok") +} + +// Output: +// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index 4572cf2f70e..fa895bb10d9 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -8,7 +8,7 @@ import ( var SS []*crossrealm.XYZ var f = func(s []*crossrealm.XYZ) { - SS = s + SS = s // Note, s is dirty, but it's real, so it's ok } func main() { From 77f4a227e5b82d4984961ccfc2cb8a7033514840 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 11 Feb 2025 21:32:33 +0800 Subject: [PATCH 62/88] fixup --- gnovm/pkg/gnolang/ownership.go | 14 +++--- gnovm/pkg/gnolang/realm.go | 54 ++++++++++----------- gnovm/pkg/gnolang/values.go | 4 +- gnovm/tests/files/zrealm_crossrealm28c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c6.gno | 28 +++++++++++ gnovm/tests/files/zrealm_crossrealm28c7.gno | 27 +++++++++++ gnovm/tests/files/zrealm_crossrealm28d.gno | 2 +- gnovm/tests/files/zrealm_tests0.gno | 6 +-- 8 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm28c6.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c7.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 73ff04e82de..8188da8eade 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -115,8 +115,8 @@ type Object interface { SetIsNewReal(bool) GetOriginRealm() PkgID SetOriginRealm(pkgID PkgID) - GetOriginValue() Value - SetOriginValue(v Value) + GetIsRef() bool + SetIsRef(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -151,7 +151,7 @@ type ObjectInfo struct { isNewEscaped bool isNewDeleted bool originRealm PkgID // realm where object is from - originValue Value // pointerValue, sliceValue, funcValue + isRefValue bool // XXX huh? owner Object // mem reference to owner. @@ -324,12 +324,12 @@ func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { oi.originRealm = pkgId } -func (oi *ObjectInfo) GetOriginValue() Value { - return oi.originValue +func (oi *ObjectInfo) GetIsRef() bool { + return oi.isRefValue } -func (oi *ObjectInfo) SetOriginValue(v Value) { - oi.originValue = v +func (oi *ObjectInfo) SetIsRef(ref bool) { + oi.isRefValue = ref } func (oi *ObjectInfo) GetIsNewEscaped() bool { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 18a7962b231..57e7789105b 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -158,7 +158,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { //debug2.Println2("rlm.ID: ", rlm.ID) if co != nil { debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) - debug2.Println2("originValue: ", co.GetOriginValue()) + debug2.Println2("co.GetIsRef: ", co.GetIsRef()) debug2.Println2("co.GetRefCount: ", co.GetRefCount()) debug2.Println2("co.GetIsReal: ", co.GetIsReal()) } @@ -205,7 +205,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { // XXX, inc ref count everytime assignment happens co.IncRefCount() if co.GetRefCount() > 1 { - rlm.MarkNewEscapedCheckCrossRealm(store, co, co.GetOriginValue()) + rlm.MarkNewEscapedCheckCrossRealm(store, co) } else { if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) @@ -240,7 +240,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { oo.SetOriginRealm(tv2.GetOriginPkg(store)) checkCrossRealm(rlm, store, oo, isLastRef) } else { // reference to object - switch rv := tv.V.(type) { + switch tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm // XXX: consider pkgId here, A -> B - > A?... reo := tv.GetFirstObject(store) @@ -269,7 +269,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { } reo.SetOriginRealm(tv2.GetOriginPkg(store)) - reo.SetOriginValue(rv) + reo.SetIsRef(true) checkCrossRealm(rlm, store, reo, true) } } @@ -281,11 +281,11 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) - debug2.Printf2("isLastRef: %t, is current ref: %t \n", isLastRef, oo.GetOriginValue() != nil) + debug2.Printf2("isLastRef: %t, is current ref: %t \n", isLastRef, oo.GetIsRef()) // is last not ref, current // object can be reference - if !isLastRef && oo.GetOriginValue() != nil { - isLastRef = true + if !isLastRef { + isLastRef = oo.GetIsRef() } if !oo.GetOriginRealm().IsZero() { // e.g. unreal array, struct... @@ -294,7 +294,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Println2("crossing realm, check oo, then elems") // reference value if isLastRef { - debug2.Println2("Reference to object: ", oo.GetOriginValue(), reflect.TypeOf(oo.GetOriginValue())) + debug2.Println2("Reference to object: ") if !oo.GetIsReal() { panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } else { @@ -351,27 +351,25 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { for i, e := range v.Data { debug2.Printf2("Data, ArrayValue[%d] is %v: \n", i, e) } + //// TODO: return if it's real? + //if oo.GetIsReal() { + // debug2.Println2("array IsReal, do nothing") + // return + //} else { + // debug2.Println2("array is unreal") + //} + // if the array value is unreal, // it's going to be attached with // all the elems, so it's attaching - // by value - if oo.GetOriginRealm().IsZero() { + // the array by value. + if !oo.GetIsReal() { isLastRef = false } - if sv, ok := oo.GetOriginValue().(*SliceValue); ok { - debug2.Println2("1, slice, check elems of ArrayValue, sv: ", sv, sv.Offset, sv.Length) - // only check referenced elem - if v.Data == nil { - for i := sv.Offset; i < sv.Length; i++ { - checkCrossRealm2(rlm, store, &v.List[i], isLastRef) - } - } - } else { - debug2.Println2("2, check elems of ArrayValue, v: ", v) - if v.Data == nil { - for _, e := range v.List { - checkCrossRealm2(rlm, store, &e, isLastRef) - } + debug2.Println2("2, check elems of ArrayValue, v: ", v) + if v.Data == nil { + for _, e := range v.List { + checkCrossRealm2(rlm, store, &e, isLastRef) } } default: @@ -384,10 +382,10 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // MarkNewEscapedCheckCrossRealm mark new escaped object // and check cross realm -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originValue Value) { +func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) debug2.Println2("oo.GetOriginRealm(): ", oo.GetOriginRealm()) - debug2.Println2("originValue: ", originValue) + debug2.Println2("isRef: ", oo.GetIsRef()) debug2.Println2("rlm.ID: ", rlm.ID) if oo.GetOriginRealm() == rlm.ID { @@ -396,8 +394,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object, originVa } if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm - if originValue != nil { - checkCrossRealm(rlm, store, oo, true) + if oo.GetIsRef() { + checkCrossRealm(rlm, store, oo, oo.GetIsRef()) } else { panic("cannot attach objects by value from external realm") } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 9686c56f758..73a6958bc33 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -303,9 +303,9 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // originValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue - switch rv := pv.TV.V.(type) { + switch pv.TV.V.(type) { case *SliceValue, PointerValue: - oo2.SetOriginValue(rv) + oo2.SetIsRef(true) } if oo2 != nil && !originPkg.IsZero() { diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index 3a80b0ce0e5..cb309ef0a82 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -25,4 +25,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("2" string)} +// cannot attach a value of a type defined by another realm: struct{("1" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm28c6.gno b/gnovm/tests/files/zrealm_crossrealm28c6.gno new file mode 100644 index 00000000000..80705d7f8fb --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c6.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var arr [3]*foo // arr and all elems are all real +var s []*foo + +func init() { + var f1 = foo{name: "1"} + var f2 = foo{name: "2"} + var f3 = foo{name: "3"} + arr[0] = &f1 + arr[1] = &f2 + arr[2] = &f3 +} + +func main() { + s = arr[:] + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28c7.gno b/gnovm/tests/files/zrealm_crossrealm28c7.gno new file mode 100644 index 00000000000..9c2715161dd --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c7.gno @@ -0,0 +1,27 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var s []*foo + +func main() { + var arr [3]*foo + + var f1 = foo{name: "1"} + var f2 = foo{name: "2"} + var f3 = foo{name: "3"} + arr[0] = &f1 + arr[1] = &f2 + arr[2] = &f3 + + s = arr[1:] // will attach the whole array + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index 7bb560fa422..b8334756377 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("2" string)} gno.land/r/crossrealm_test.foo)) +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("1" string)} gno.land/r/crossrealm_test.foo)) diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 33c065d314a..bc134af64be 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -41,7 +41,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "ba465d7c93b78df4ef63299b2d8f09c9b30fecf4", +// "Escaped": true, // "ObjectID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:3" // }, // "Index": "0", @@ -60,7 +60,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "729e21266d34f42f83a286f76a8b5bc45f59290f", +// "Escaped": true, // "ObjectID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:5" // }, // "Index": "0", @@ -168,7 +168,7 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "b05c9b53cf7a8585ea042470c2df36df476ddc75", +// "Hash": "68be9ee1ced18f6b04bfcac812afe3f5cd7835d8", // "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13" // }, // "Length": "3", From f174e981166a7cbdcc42f111d3698d21e389244c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 11 Feb 2025 22:34:55 +0800 Subject: [PATCH 63/88] test --- gnovm/pkg/gnolang/ownership.go | 15 ++++----------- gnovm/tests/files/zrealm_crossrealm37d.gno | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm37d.gno diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 8188da8eade..6b27a232f45 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -366,10 +366,6 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { case *StructValue: return cv case *FuncValue: - //fmt.Println("fv: ", cv) - //fmt.Println("---fv.Closure: ", cv.GetClosure(store)) - //fmt.Println("---fv.Capture: ", cv.Captures) - //fmt.Println("static block.Values: ", cv.Source.(BlockNode).GetStaticBlock().Values) return cv.GetClosure(store) case *MapValue: return cv @@ -435,9 +431,6 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } switch cv := obj.(type) { - //case *Block: - // originPkg = PkgIDFromPkgPath(cv.Source.GetLocation().PkgPath) - // return case *HeapItemValue: originPkg = getPkgId(cv.Value.T) return @@ -448,11 +441,11 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { } return case *MapValue, *StructValue, *ArrayValue: - originPkg = getPkgId(tv.T) // if it's declared type, otherwise zero + // if it's declared type, + // origin package is deduced + // from type, otherwise zero. + originPkg = getPkgId(tv.T) return - //case *ArrayValue: - // originPkg = getPkgId(tv.T.Elem()) - // return default: // do nothing } diff --git a/gnovm/tests/files/zrealm_crossrealm37d.gno b/gnovm/tests/files/zrealm_crossrealm37d.gno new file mode 100644 index 00000000000..4c81eb193d2 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm37d.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/map" + +var root interface{} + +func main() { + root = crossrealm.GetMap3() + println("ok") +} + +// Error: +// cannot attach objects by value from external realm From d0ead8c080f41bec7b2487192ee088ac1f65fc97 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 11 Feb 2025 23:12:10 +0800 Subject: [PATCH 64/88] fixup --- gnovm/pkg/gnolang/realm.go | 97 +++++++++++++++----------------------- 1 file changed, 39 insertions(+), 58 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 57e7789105b..f24ebf87ea1 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -151,16 +151,25 @@ func (rlm *Realm) String() string { // ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { - debug2.Printf2("DidUpdate, po: %v, type of po: %v\n", po, reflect.TypeOf(po)) - debug2.Println2("po.GetIsReal: ", po.GetIsReal()) - debug2.Printf2("xo: %v, type of xo: %v\n", xo, reflect.TypeOf(xo)) - debug2.Printf2("co: %v, type of co: %v\n", co, reflect.TypeOf(co)) - //debug2.Println2("rlm.ID: ", rlm.ID) + debug2.Printf2( + "DidUpdate - po: %v (type: %v) | xo: %v (type: %v)\n", + po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), + ) + + if rlm != nil { + debug2.Println2("rlm.ID: %s \n", rlm.ID) + } + + if po != nil { + debug2.Println2("po.GetIsReal: %t \n", po.GetIsReal()) + } + + // Combine debug logs for co (if not nil) if co != nil { - debug2.Println2("co.GetOriginRealm: ", co.GetOriginRealm()) - debug2.Println2("co.GetIsRef: ", co.GetIsRef()) - debug2.Println2("co.GetRefCount: ", co.GetRefCount()) - debug2.Println2("co.GetIsReal: ", co.GetIsReal()) + debug2.Printf2( + "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", + co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsRef(), co.GetRefCount(), co.GetIsReal(), + ) } if rlm == nil { @@ -210,12 +219,11 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) } else { - debug2.Println2("set owner of co: ", co) co.SetOwner(po) rlm.MarkNewReal(co) } // check cross realm for non escaped objects - debug2.Println2("=========po is real, check cross realm for non escaped objects========") + debug2.Println2("=========po is real, check cross realm========") checkCrossRealm(rlm, store, co, false) } } @@ -319,7 +327,6 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { checkCrossRealm2(rlm, store, &fv, isLastRef) // ref to struct is heapItemValue or block } case *MapValue: - debug2.Println2("MapValue, v: ", v) for cur := v.List.Head; cur != nil; cur = cur.Next { checkCrossRealm2(rlm, store, &cur.Key, isLastRef) checkCrossRealm2(rlm, store, &cur.Value, isLastRef) @@ -327,11 +334,8 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { case *BoundMethodValue: // TODO: complete this case *Block: - debug2.Println2("BlockValue, v: ", v) - debug2.Printf2("oo: %v, \n oo.GetRefCount: %v \n", oo, oo.GetRefCount()) // NOTE, it's not escaped until now, // will set after check - debug2.Println2("block is NOT real, v...PkgID: ", v.GetObjectID().PkgID) // TODO:, also check captures? for i, tv := range v.Values { debug2.Printf2("tv[%d] is tv: %v \n", i, tv) @@ -345,20 +349,6 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } case *ArrayValue: debug2.Println2("ArrayValue, v: ", v) - for i, e := range v.List { - debug2.Printf2("List, ArrayValue[%d] is %v: \n", i, e) - } - for i, e := range v.Data { - debug2.Printf2("Data, ArrayValue[%d] is %v: \n", i, e) - } - //// TODO: return if it's real? - //if oo.GetIsReal() { - // debug2.Println2("array IsReal, do nothing") - // return - //} else { - // debug2.Println2("array is unreal") - //} - // if the array value is unreal, // it's going to be attached with // all the elems, so it's attaching @@ -366,7 +356,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { if !oo.GetIsReal() { isLastRef = false } - debug2.Println2("2, check elems of ArrayValue, v: ", v) + debug2.Println2("check elems of ArrayValue, v: ", v) if v.Data == nil { for _, e := range v.List { checkCrossRealm2(rlm, store, &e, isLastRef) @@ -383,16 +373,17 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // MarkNewEscapedCheckCrossRealm mark new escaped object // and check cross realm func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { - debug2.Println2("MarkNewEscapedCheckCrossRealm, oo: ", oo) - debug2.Println2("oo.GetOriginRealm(): ", oo.GetOriginRealm()) - debug2.Println2("isRef: ", oo.GetIsRef()) - debug2.Println2("rlm.ID: ", rlm.ID) + debug2.Printf2( + "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", + oo, oo.GetOriginRealm(), oo.GetIsRef(), rlm.ID, + ) if oo.GetOriginRealm() == rlm.ID { // do nothing return } + // origin realm should not be zero for escaped object if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm if oo.GetIsRef() { checkCrossRealm(rlm, store, oo, oo.GetIsRef()) @@ -407,7 +398,6 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { } func (rlm *Realm) MarkNewReal(oo Object) { - debug2.Println2("MarkNewReal, oo:", oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -440,7 +430,6 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - debug2.Println2("MarkDirty, oo: ", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -520,13 +509,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -541,9 +530,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -609,7 +598,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // skip if became deleted. continue } else { - // check cross realm while attaching + // check cross realm before attaching if pv, ok := oo.(*PackageValue); ok { checkCrossRealm(rlm, store, pv.Block.(Object), false) } @@ -622,15 +611,8 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { } } -// XXX, unreal oo check happens in here // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - //debug2.Println2("---incRefCreatedDescendants from oo: ", oo, reflect.TypeOf(oo)) - //debug2.Println2("---oo.GetOriginRealm: ", oo.GetOriginRealm()) - //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) - //debug2.Println2("---rlm.ID: ", rlm.ID) - //debug2.Println2("oo.GetOriginValue: ", oo.GetOriginValue()) - if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -667,7 +649,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { } child.IncRefCount() rc := child.GetRefCount() - debug2.Println2("rc after inc: ", rc) if rc == 1 { if child.GetIsReal() { // a deleted real became undeleted. @@ -938,9 +919,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } From f527e18ea40d05d49581fc68609c86c486fe881a Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 12 Feb 2025 12:26:38 +0800 Subject: [PATCH 65/88] fixup --- gnovm/pkg/gnolang/realm.go | 30 ++++++----------- gnovm/pkg/gnolang/values.go | 6 ++-- .../files/zrealm_crossrealm15_struct.gno | 4 +-- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm19.gno | 10 +++--- gnovm/tests/files/zrealm_crossrealm20c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c2.gno | 21 ++++++++++++ gnovm/tests/files/zrealm_crossrealm20e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20f.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 8 ++--- gnovm/tests/files/zrealm_crossrealm21b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21g.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c8.gno | 29 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm28c9.gno | 32 +++++++++++++++++++ 14 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm20c2.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c8.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28c9.gno diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index f24ebf87ea1..06a16b243df 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -157,11 +157,11 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { ) if rlm != nil { - debug2.Println2("rlm.ID: %s \n", rlm.ID) + debug2.Println2("rlm.ID: ", rlm.ID) } if po != nil { - debug2.Println2("po.GetIsReal: %t \n", po.GetIsReal()) + debug2.Println2("po.GetIsReal: ", po.GetIsReal()) } // Combine debug logs for co (if not nil) @@ -195,7 +195,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { // TODO: check unreal external here, if po is real, association is invalid, panic // else, defer to finalize??? - debug2.Println2("po.GetObjectID().PkgID: ", po.GetObjectID().PkgID) if po.GetObjectID().PkgID != rlm.ID { panic("cannot modify external-realm or non-realm object") } @@ -224,7 +223,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm for non escaped objects debug2.Println2("=========po is real, check cross realm========") - checkCrossRealm(rlm, store, co, false) + checkCrossRealm(rlm, store, co, co.GetIsRef()) } } @@ -240,10 +239,10 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { // check cross realm recursively func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { - debug2.Println2("checkCrossRealm2, tv: ", tv, reflect.TypeOf(tv.V)) + debug2.Printf2("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { - debug2.Println2("is object") + debug2.Println2("is object, GetIsReal: ", oo.GetIsReal()) // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) checkCrossRealm(rlm, store, oo, isLastRef) @@ -270,7 +269,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // not return // } //} - debug2.Println2("return on block recursive") + debug2.Println2("return on block recursive, it MUST be real") return } } @@ -288,21 +287,20 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { - debug2.Println2("checkCrossRealm, oo: ", oo, reflect.TypeOf(oo)) + debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v \n", oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm()) debug2.Printf2("isLastRef: %t, is current ref: %t \n", isLastRef, oo.GetIsRef()) // is last not ref, current // object can be reference + // refer 20c, 20c2 if !isLastRef { isLastRef = oo.GetIsRef() } if !oo.GetOriginRealm().IsZero() { // e.g. unreal array, struct... - debug2.Println2("Origin Realm NOT zero...") if rlm.ID != oo.GetOriginRealm() { // crossing realm debug2.Println2("crossing realm, check oo, then elems") // reference value if isLastRef { - debug2.Println2("Reference to object: ") if !oo.GetIsReal() { panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } else { @@ -349,14 +347,6 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } case *ArrayValue: debug2.Println2("ArrayValue, v: ", v) - // if the array value is unreal, - // it's going to be attached with - // all the elems, so it's attaching - // the array by value. - if !oo.GetIsReal() { - isLastRef = false - } - debug2.Println2("check elems of ArrayValue, v: ", v) if v.Data == nil { for _, e := range v.List { checkCrossRealm2(rlm, store, &e, isLastRef) @@ -374,8 +364,8 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // and check cross realm func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { debug2.Printf2( - "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", - oo, oo.GetOriginRealm(), oo.GetIsRef(), rlm.ID, + "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetRefCount: %d | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", + oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsRef(), rlm.ID, ) if oo.GetOriginRealm() == rlm.ID { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 73a6958bc33..4501a4de739 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -255,7 +255,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -305,7 +305,9 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // e.g. refValue is a sliceValue switch pv.TV.V.(type) { case *SliceValue, PointerValue: - oo2.SetIsRef(true) + if oo2.GetIsReal() { + oo2.SetIsRef(true) + } } if oo2 != nil && !originPkg.IsZero() { diff --git a/gnovm/tests/files/zrealm_crossrealm15_struct.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno index 3eb54861c1b..681cdcb90bc 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_struct.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_struct.gno @@ -12,7 +12,7 @@ func (fooer) Foo() { println("hello") } var f *fooer func init() { - f = &fooer{} + f = &fooer{} // unreal crossrealm.SetFooer(f) crossrealm.CallFooerFoo() } @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index 4704f21222e..25a1e89eee8 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index ff303b0863c..e1d44295b24 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm" ) @@ -13,14 +11,14 @@ type fooer struct { func (f *fooer) Foo() { f.s = "B" - println("hello " + f.s + " " + std.CurrentRealm().PkgPath()) + println("hello") } var f *fooer func init() { - f = &fooer{s: "A"} // this is unreal - crossrealm.SetFooer(f) + f = &fooer{s: "A"} // unreal, refCount 1, owner f + crossrealm.SetFooer(f) // refCount2, escaped crossrealm.CallFooerFoo() } @@ -29,4 +27,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("A" string)} gno.land/r/crossrealm_test.fooer)) +// cannot attach objects by value from external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno index 8837492cecf..5425c6d435b 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20c2.gno b/gnovm/tests/files/zrealm_crossrealm20c2.gno new file mode 100644 index 00000000000..52e52730eef --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20c2.gno @@ -0,0 +1,21 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/struct" +) + +// associate to a containing object +type Container struct { + name string + b crossrealm.Bar +} + +var c = &Container{name: "local_container", b: crossrealm.Bar{A: 1}} + +func main() { + print(".") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm: struct{(1 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm20e.gno b/gnovm/tests/files/zrealm_crossrealm20e.gno index 38b33242542..d867edff307 100644 --- a/gnovm/tests/files/zrealm_crossrealm20e.gno +++ b/gnovm/tests/files/zrealm_crossrealm20e.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm20f.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno index 319d6880f48..3699372c9fa 100644 --- a/gnovm/tests/files/zrealm_crossrealm20f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index ef81d0cc0dc..d5fde82ec7f 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -2,8 +2,6 @@ package crossrealm_test import ( - "std" - crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) @@ -11,16 +9,16 @@ type fooer struct { name string } -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } +func (fooer) Foo() { println("hello") } func main() { // object attaching to external is main block, // f is a value defined w/i this block, // and invalid to attach to external, panic. f := fooer{name: "local_fooer"} - crossrealm.SetContainer2(&f) + crossrealm.SetContainer2(&f) // refCount 1, f not owner print(".") } // Error: -// cannot attach a reference to an unreal object from an external realm: struct{("local_fooer" string)} +// cannot attach a value of a type defined by another realm: struct{("local_fooer" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno index df6111c9a92..79ca820bf62 100644 --- a/gnovm/tests/files/zrealm_crossrealm21b.gno +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("local_fooer" string)} gno.land/r/crossrealm_test.fooer)) +// cannot attach a value of a type defined by another realm: heapitem((struct{("local_fooer" string)} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm21g.gno b/gnovm/tests/files/zrealm_crossrealm21g.gno index ff2dfc4158b..c0bcded157e 100644 --- a/gnovm/tests/files/zrealm_crossrealm21g.gno +++ b/gnovm/tests/files/zrealm_crossrealm21g.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(struct{("a" string)} gno.land/r/demo/tests/crossrealm/struct.A),(struct{("b" string)} gno.land/r/demo/tests/crossrealm/struct.B),(struct{( string)} gno.land/r/demo/tests/crossrealm/struct.D)} gno.land/r/demo/tests/crossrealm/struct.C)) +// cannot attach a value of a type defined by another realm: heapitem((struct{(struct{("a" string)} gno.land/r/demo/tests/crossrealm/struct.A),(struct{("b" string)} gno.land/r/demo/tests/crossrealm/struct.B),(struct{( string)} gno.land/r/demo/tests/crossrealm/struct.D)} gno.land/r/demo/tests/crossrealm/struct.C)) diff --git a/gnovm/tests/files/zrealm_crossrealm28c8.gno b/gnovm/tests/files/zrealm_crossrealm28c8.gno new file mode 100644 index 00000000000..8b80a075299 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c8.gno @@ -0,0 +1,29 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var f1 = foo{name: "1"} +var f2 = foo{name: "2"} +var f3 = foo{name: "3"} + +func main() { + var S []crossrealm.Fooer + S = append(S, f1) // NOTE, f1 here is value copy, so it's not real + S = append(S, f2) + S = append(S, f3) + + crossrealm.SetSlice(S) + println("ok") +} + +// Error: +// cannot attach a value of a type defined by another realm: struct{("1" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm28c9.gno b/gnovm/tests/files/zrealm_crossrealm28c9.gno new file mode 100644 index 00000000000..3a0fd198bec --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28c9.gno @@ -0,0 +1,32 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/slice" +) + +type foo struct { + name string +} + +func (foo) Foo() { println("hello from crossrealm_test") } + +var f1 = foo{name: "1"} +var f2 = foo{name: "2"} +var f3 = foo{name: "3"} + +func main() { + var arr []crossrealm.Fooer // unreal array + arr = append(arr, &f1) + arr = append(arr, &f2) + arr = append(arr, &f3) + + crossrealm.SetSlice(arr) + println("ok") +} + +// Output: +// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) +// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// ok From 0f7448da0181180c362576d45c7fff04b035df34 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 12 Feb 2025 20:38:41 +0800 Subject: [PATCH 66/88] fixup --- .../tests/crossrealm/func/crossrealm_func.gno | 9 + gnovm/pkg/gnolang/ownership.go | 40 ++- gnovm/pkg/gnolang/realm.go | 71 +++-- gnovm/pkg/gnolang/values.go | 9 +- gnovm/tests/files/zrealm_crossrealm22b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22e.gno | 26 ++ gnovm/tests/files/zrealm_crossrealm40_a.gno | 14 + gnovm/tests/files/zrealm_crossrealm40_b.gno | 14 + .../files/zrealm_crossrealm40_method.gno | 4 +- .../files/zrealm_crossrealm41_method.gno | 292 ++++++++++++++++++ 10 files changed, 423 insertions(+), 58 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm22e.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm40_a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm40_b.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm41_method.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno index 9589cac78bd..af0a6ecabff 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno @@ -28,11 +28,16 @@ func GetFunc2() func() string { } type MyStruct struct{} +type MyStruct2 struct{} func (sv *MyStruct) M() string { return "a" } var mysv *MyStruct = &MyStruct{} +func (sv2 MyStruct2) M2() string { return "a2" } + +var mysv2 = MyStruct2{} + //var f_local func() string // //func init() { @@ -42,3 +47,7 @@ var mysv *MyStruct = &MyStruct{} func GetMethod() func() string { return mysv.M } + +func GetMethod2() func() string { + return mysv2.M2 +} diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 6b27a232f45..d1552eca78f 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -115,8 +115,8 @@ type Object interface { SetIsNewReal(bool) GetOriginRealm() PkgID SetOriginRealm(pkgID PkgID) - GetIsRef() bool - SetIsRef(bool) + GetIsAttachingRef() bool + SetIsAttachingRef(bool) GetIsNewEscaped() bool SetIsNewEscaped(bool) GetIsNewDeleted() bool @@ -145,13 +145,13 @@ 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 - originRealm PkgID // realm where object is from - isRefValue bool + isDirty bool + isDeleted bool + isNewReal bool + isNewEscaped bool + isNewDeleted bool + originRealm PkgID // realm where object is from + isAttachingRef bool // XXX huh? owner Object // mem reference to owner. @@ -324,12 +324,12 @@ func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { oi.originRealm = pkgId } -func (oi *ObjectInfo) GetIsRef() bool { - return oi.isRefValue +func (oi *ObjectInfo) GetIsAttachingRef() bool { + return oi.isAttachingRef } -func (oi *ObjectInfo) SetIsRef(ref bool) { - oi.isRefValue = ref +func (oi *ObjectInfo) SetIsAttachingRef(ref bool) { + oi.isAttachingRef = ref } func (oi *ObjectInfo) GetIsNewEscaped() bool { @@ -395,15 +395,11 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) - // special case for func value - if _, ok := tv.V.(*FuncValue); ok { - return - } - // attempting to retrieve the original package using the ObjectID obj := tv.GetFirstObject(store) - debug2.Println2("obj: ", obj, reflect.TypeOf(obj)) + debug2.Printf2("obj: %v (type: %v) \n", obj, reflect.TypeOf(obj)) if obj != nil { + debug2.Println2("GetIsReal: ", obj.GetIsReal()) // origin realm maybe set while association, even // it's un-real. originPkg = obj.GetOriginRealm() @@ -436,9 +432,9 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { return case *BoundMethodValue: debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) - if pv, ok := cv.Receiver.V.(PointerValue); ok { - originPkg = getPkgId(pv.TV.T) - } + //if pv, ok := cv.Receiver.V.(PointerValue); ok { + // originPkg = getPkgId(pv.TV.T) + //} return case *MapValue, *StructValue, *ArrayValue: // if it's declared type, diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 06a16b243df..874cea3afe0 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -168,8 +168,12 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { debug2.Printf2( "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", - co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsRef(), co.GetRefCount(), co.GetIsReal(), + co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), ) + + if b, ok := co.(*Block); ok { + debug2.Printf2("b.source: %v (type: %v) \n", b.Source, reflect.TypeOf(b.Source)) + } } if rlm == nil { @@ -223,7 +227,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm for non escaped objects debug2.Println2("=========po is real, check cross realm========") - checkCrossRealm(rlm, store, co, co.GetIsRef()) + checkCrossRealm(rlm, store, co, false) // XXX, always false? } } @@ -276,7 +280,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { } reo.SetOriginRealm(tv2.GetOriginPkg(store)) - reo.SetIsRef(true) + reo.SetIsAttachingRef(true) checkCrossRealm(rlm, store, reo, true) } } @@ -288,33 +292,42 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v \n", oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm()) - debug2.Printf2("isLastRef: %t, is current ref: %t \n", isLastRef, oo.GetIsRef()) - // is last not ref, current - // object can be reference + debug2.Printf2( + "isLastRef: %t | isCurrentRef: %t\n", + isLastRef, oo.GetIsAttachingRef(), + ) // refer 20c, 20c2 + + // update isLastRef based on the current object's reference status + // If the last object was not a reference, but the current one is, + // then the current object and its children are referenced. if !isLastRef { - isLastRef = oo.GetIsRef() + isLastRef = oo.GetIsAttachingRef() } if !oo.GetOriginRealm().IsZero() { // e.g. unreal array, struct... if rlm.ID != oo.GetOriginRealm() { // crossing realm - debug2.Println2("crossing realm, check oo, then elems") + debug2.Println2("crossing realm, check oo, return or check elems...") // reference value if isLastRef { - if !oo.GetIsReal() { - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) - } else { - debug2.Println2("oo is real, just return") + if oo.GetIsReal() { + debug2.Println2("base is REAL, return") return + } else { + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } } else { // not reference to object debug2.Println2("Non reference object crossing realm, panic...") panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } } else { + // for local realm checking + // maybe a container not cross + // but embedded field does. debug2.Println2("oo Not crossing realm, check elems...") } } else { + // e.g. array, map debug2.Println2("Origin Realm is zero, unreal, check elems...") } @@ -330,21 +343,22 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { checkCrossRealm2(rlm, store, &cur.Value, isLastRef) } case *BoundMethodValue: - // TODO: complete this + checkCrossRealm2(rlm, store, &v.Receiver, isLastRef) + o2 := v.Func.Closure.(Object) + // the closure must be a real fileBlock + if !o2.GetIsReal() { + panic("bound method closure should be real") + } case *Block: + debug2.Printf2("block values: %v | b.source: %v \n ", v.Values, v.Source) // NOTE, it's not escaped until now, // will set after check - // TODO:, also check captures? for i, tv := range v.Values { - debug2.Printf2("tv[%d] is tv: %v \n", i, tv) + debug2.Printf2("block tv[%d] is tv: %v \n", i, tv) checkCrossRealm2(rlm, store, &tv, isLastRef) } case *HeapItemValue: - if oo.GetRefCount() > 1 { - debug2.Println2("hiv escaped, do nothing") - } else { - checkCrossRealm2(rlm, store, &v.Value, isLastRef) - } + checkCrossRealm2(rlm, store, &v.Value, isLastRef) case *ArrayValue: debug2.Println2("ArrayValue, v: ", v) if v.Data == nil { @@ -365,7 +379,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { debug2.Printf2( "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetRefCount: %d | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", - oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsRef(), rlm.ID, + oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsAttachingRef(), rlm.ID, ) if oo.GetOriginRealm() == rlm.ID { @@ -373,11 +387,10 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { return } - // origin realm should not be zero for escaped object + // originRealm can be zero, e.g. an array value + // in current realm, and it's referenced twice. if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm - if oo.GetIsRef() { - checkCrossRealm(rlm, store, oo, oo.GetIsRef()) - } else { + if !oo.GetIsAttachingRef() { panic("cannot attach objects by value from external realm") } } @@ -568,7 +581,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { //for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - debug2.Printf2("---oo[%d] is %v:\n", i, oo) + debug2.Printf2("---oo[%d] is: %v (type: %v) \n", i, oo, reflect.TypeOf(oo)) //if _, ok := oo.(*BoundMethodValue); ok { // panic("should not happen persist bound method") //} @@ -589,6 +602,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { continue } else { // check cross realm before attaching + // from package block, recursively if pv, ok := oo.(*PackageValue); ok { checkCrossRealm(rlm, store, pv.Block.(Object), false) } @@ -603,6 +617,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { + debug2.Printf2("incRefCreatedDescendants, oo: %v (type: %v) \n", oo, reflect.TypeOf(oo)) if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -627,7 +642,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) for i, child := range more { - debug2.Printf2("---[%d]child: %v, type of child: %v \n", i, child, reflect.TypeOf(child)) + debug2.Printf2("---[%d]child: %v, (type: %v) \n", i, child, reflect.TypeOf(child)) if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -1025,6 +1040,7 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { + debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1037,6 +1053,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { + debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 4501a4de739..be83bad3028 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -288,31 +288,28 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - debug2.Println2("oo1: ", oo1) - // get origin pkgId, this should happen before assign, // because assign will discard original object info originPkg := tv2.GetOriginPkg(store) - debug2.Println2("originPkg: ", originPkg) pv.TV.Assign(alloc, tv2, cu) oo2 := pv.TV.GetFirstObject(store) - debug2.Println2("oo2: ", oo2) // originValue is needed for checking // proper element in the base. // e.g. refValue is a sliceValue switch pv.TV.V.(type) { - case *SliceValue, PointerValue: + case *SliceValue, PointerValue, *FuncValue: if oo2.GetIsReal() { - oo2.SetIsRef(true) + oo2.SetIsAttachingRef(true) } } if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info } + rlm.DidUpdate(store, pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index ae6ffb04679..bc6cac1d9cb 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -12,7 +12,7 @@ type Local_S struct { } func main() { - var ls Local_S + var ls Local_S // panic f := func() bool { c := b return true diff --git a/gnovm/tests/files/zrealm_crossrealm22e.gno b/gnovm/tests/files/zrealm_crossrealm22e.gno new file mode 100644 index 00000000000..9c86862f4a8 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22e.gno @@ -0,0 +1,26 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +var f = func() bool { + c := b + var ls Local_S + return true +} + +func main() { + crossrealm.SetCallback(f) + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm40_a.gno b/gnovm/tests/files/zrealm_crossrealm40_a.gno new file mode 100644 index 00000000000..c3cf5abf1e8 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm40_a.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/func" + +var f func() string + +func main() { + f = crossrealm.GetMethod2() + println(f) +} + +// Error: +// cannot attach a value of a type defined by another realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm40_b.gno b/gnovm/tests/files/zrealm_crossrealm40_b.gno new file mode 100644 index 00000000000..c3cf5abf1e8 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm40_b.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import crossrealm "gno.land/r/demo/tests/crossrealm/func" + +var f func() string + +func main() { + f = crossrealm.GetMethod2() + println(f) +} + +// Error: +// cannot attach a value of a type defined by another realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm40_method.gno b/gnovm/tests/files/zrealm_crossrealm40_method.gno index b6620ef7f6b..cfda4c92b89 100644 --- a/gnovm/tests/files/zrealm_crossrealm40_method.gno +++ b/gnovm/tests/files/zrealm_crossrealm40_method.gno @@ -10,5 +10,5 @@ func main() { println(f) } -// Error: -// cannot attach a value of a type defined by another realm: <*gno.land/r/demo/tests/crossrealm/func.MyStruct>.M(sv *gno.land/r/demo/tests/crossrealm/func.MyStruct)( string) +// Output: +// <*gno.land/r/demo/tests/crossrealm/func.MyStruct>.M(sv *gno.land/r/demo/tests/crossrealm/func.MyStruct)( string) diff --git a/gnovm/tests/files/zrealm_crossrealm41_method.gno b/gnovm/tests/files/zrealm_crossrealm41_method.gno new file mode 100644 index 00000000000..a3a75dd14c1 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm41_method.gno @@ -0,0 +1,292 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +var f func() string + +type MyStruct struct{} + +func (sv *MyStruct) M() string { return "a" } + +var mysv *MyStruct = &MyStruct{} + +func main() { + f = mysv.M +} + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Func": { +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "FileName": "files/zrealm_crossrealm41_method.gno", +// "IsMethod": true, +// "Name": "M", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "files/zrealm_crossrealm41_method.gno", +// "Line": "8", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// }, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// }, +// "Receiver": { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.MyStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d: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/crossrealm_test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "192f305dae814cfaa2d2804e0c29ca20b07aaf5b", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// } +// }, +// { +// "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": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "files/zrealm_crossrealm41_method.gno", +// "IsMethod": true, +// "Name": "M", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "files/zrealm_crossrealm41_method.gno", +// "Line": "8", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "sv", +// "Tag": "", +// "Type": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.MyStruct" +// } +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "MyStruct", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.MyStruct" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "FileName": "files/zrealm_crossrealm41_method.gno", +// "IsMethod": false, +// "Name": "main", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/crossrealm_test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "Column": "1", +// "File": "files/zrealm_crossrealm41_method.gno", +// "Line": "12", +// "PkgPath": "gno.land/r/crossrealm_test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// } +// ] +// } From c740c4575b59458cf9bc87c2692791498c3b46cf Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 12 Feb 2025 20:50:52 +0800 Subject: [PATCH 67/88] refactor --- gnovm/pkg/gnolang/realm.go | 59 ++++++++++--------- .../files/zrealm_crossrealm15_struct.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37_map.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37d.gno | 2 +- 7 files changed, 37 insertions(+), 34 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 874cea3afe0..69e644bc8fa 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -291,7 +291,9 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { - debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v \n", oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm()) + debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v | rlm.ID: %v \n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), rlm.ID) + debug2.Printf2( "isLastRef: %t | isCurrentRef: %t\n", isLastRef, oo.GetIsAttachingRef(), @@ -305,32 +307,36 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { isLastRef = oo.GetIsAttachingRef() } - if !oo.GetOriginRealm().IsZero() { // e.g. unreal array, struct... - if rlm.ID != oo.GetOriginRealm() { // crossing realm - debug2.Println2("crossing realm, check oo, return or check elems...") - // reference value - if isLastRef { - if oo.GetIsReal() { - debug2.Println2("base is REAL, return") - return - } else { - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) - } - } else { // not reference to object - debug2.Println2("Non reference object crossing realm, panic...") - panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) + if oo.GetOriginRealm().IsZero() { + debug2.Println2("origin realm is zero, it's unreal, check elems...") + checkCrossRealmChildren(rlm, store, oo, isLastRef) + return + } + + if rlm.ID == oo.GetOriginRealm() { + debug2.Println2("oo Not crossing realm, recursively check for local realm") + // for local realm checking + // maybe a container not cross + // but embedded field does. + checkCrossRealmChildren(rlm, store, oo, isLastRef) + return + } + + if rlm.ID != oo.GetOriginRealm() { // crossing realm + if isLastRef { + if oo.GetIsReal() { + debug2.Println2("reference base is REAL, return") + return + } else { + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } - } else { - // for local realm checking - // maybe a container not cross - // but embedded field does. - debug2.Println2("oo Not crossing realm, check elems...") + } else { // not reference to object + panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } - } else { - // e.g. array, map - debug2.Println2("Origin Realm is zero, unreal, check elems...") } +} +func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool) { switch v := oo.(type) { case *StructValue: // check fields @@ -350,17 +356,14 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { panic("bound method closure should be real") } case *Block: - debug2.Printf2("block values: %v | b.source: %v \n ", v.Values, v.Source) // NOTE, it's not escaped until now, // will set after check - for i, tv := range v.Values { - debug2.Printf2("block tv[%d] is tv: %v \n", i, tv) + for _, tv := range v.Values { checkCrossRealm2(rlm, store, &tv, isLastRef) } case *HeapItemValue: checkCrossRealm2(rlm, store, &v.Value, isLastRef) case *ArrayValue: - debug2.Println2("ArrayValue, v: ", v) if v.Data == nil { for _, e := range v.List { checkCrossRealm2(rlm, store, &e, isLastRef) @@ -391,7 +394,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { // in current realm, and it's referenced twice. if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm if !oo.GetIsAttachingRef() { - panic("cannot attach objects by value from external realm") + panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", oo)) } } // mark escaped diff --git a/gnovm/tests/files/zrealm_crossrealm15_struct.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno index 681cdcb90bc..9c8f3517d3d 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_struct.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_struct.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index 25a1e89eee8..77562f0049d 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index e1d44295b24..f4c763d5738 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: heapitem((struct{("A" string)} gno.land/r/crossrealm_test.fooer)) diff --git a/gnovm/tests/files/zrealm_crossrealm37_map.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno index 5745feb7a2a..a1db21247e8 100644 --- a/gnovm/tests/files/zrealm_crossrealm37_map.gno +++ b/gnovm/tests/files/zrealm_crossrealm37_map.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: map{("a" string):(1 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm37b.gno b/gnovm/tests/files/zrealm_crossrealm37b.gno index ee29d007215..e455b0d8dcf 100644 --- a/gnovm/tests/files/zrealm_crossrealm37b.gno +++ b/gnovm/tests/files/zrealm_crossrealm37b.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: map{("a" string):(1 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm37d.gno b/gnovm/tests/files/zrealm_crossrealm37d.gno index 4c81eb193d2..cc7f0890709 100644 --- a/gnovm/tests/files/zrealm_crossrealm37d.gno +++ b/gnovm/tests/files/zrealm_crossrealm37d.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm +// cannot attach objects by value from external realm: map{("a" string):(1 int)} From e2274bcd55f636c81bc8dbdeabc57e5ef0ee4d07 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 12 Feb 2025 21:58:05 +0800 Subject: [PATCH 68/88] recursive guard --- gnovm/pkg/gnolang/realm.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index e7a2c407e20..cfc7cce5450 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -284,6 +284,12 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { return } } + if hiv, ok := reo.(*HeapItemValue); ok { + debug2.Println2("hiv: ", hiv) + if hiv.Value == *pv.TV { + return + } + } } reo.SetOriginRealm(tv2.GetOriginPkg(store)) From 3cf2dab4b646eed23c4d8ccd266fa3c97482aedb Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 12 Feb 2025 23:42:16 +0800 Subject: [PATCH 69/88] revert machine change --- gnovm/pkg/gnolang/gno_test.go | 4 -- gnovm/pkg/gnolang/machine.go | 75 ++++++------------- gnovm/pkg/gnolang/realm.go | 80 +++++++++------------ gnovm/tests/files/zrealm_crossrealm18.gno | 5 +- gnovm/tests/files/zrealm_crossrealm20c3.gno | 23 ++++++ gnovm/tests/files/zrealm_crossrealm21.gno | 5 +- gnovm/tests/files/zrealm_crossrealm28c5.gno | 7 +- 7 files changed, 87 insertions(+), 112 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm20c3.gno diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 2a8e9edb743..cc208d64c41 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -311,10 +311,6 @@ func BenchmarkIfStatement(b *testing.B) { func main() { for i:=0; i<10000; i++ { if i > 10 { -<<<<<<< HEAD -======= - ->>>>>>> main/master } } }` diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index a0d05d37908..7b89e98eb6d 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -23,8 +23,8 @@ import ( type Machine struct { // State - Ops []Op // operations stack - NumOps int // number of operations + Ops []Op // main operations + NumOps int Values []TypedValue // buffer of values to be operated on NumValues int // number of values Exprs []Expr // pending expressions @@ -34,9 +34,9 @@ type Machine struct { Package *PackageValue // active package Realm *Realm // active realm Alloc *Allocator // memory allocations - Exceptions []Exception // exceptions stack - NumResults int // number of results returned - Cycles int64 // number of "cpu" cycles performed + Exceptions []Exception + NumResults int // number of results returned + Cycles int64 // number of "cpu" cycles Debugger Debugger @@ -186,7 +186,6 @@ 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")) @@ -198,14 +197,6 @@ 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. @@ -298,7 +289,6 @@ func (m *Machine) runMemPackage(memPkg *gnovm.MemPackage, save, overrides bool) if throwaway != nil { m.Realm = throwaway } - debug2.Println2("save, throwaway: ", throwaway) } // run init functions m.runInitFromUpdates(pv, updates) @@ -398,8 +388,7 @@ func (m *Machine) Stacktrace() (stacktrace Stacktrace) { } calls := make([]StacktraceCall, 0, len(m.Stmts)) - var nextStmtIndex int - nextStmtIndex = len(m.Stmts) - 1 + nextStmtIndex := len(m.Stmts) - 1 for i := len(m.Frames) - 1; i >= 0; i-- { if m.Frames[i].IsCall() { stm := m.Stmts[nextStmtIndex] @@ -555,7 +544,6 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // recursive function for var declarations. var runDeclarationFor func(fn *FileNode, decl Decl) runDeclarationFor = func(fn *FileNode, decl Decl) { - debug2.Println2("runDeclarationFor, d: ", decl) // get fileblock of fn. // fb := pv.GetFileBlock(nil, fn.Name) // get dependencies of decl. @@ -646,12 +634,11 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Save the machine's package using realm finalization deep crawl. // Also saves declared types. // This happens before any init calls. -// Returns a throwaway realm package if not a realm, +// Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // save package value and dependencies. pv := m.Package - debug2.Println2("saveNewPackageValuesAndTypes, pv is realm? ", pv.IsRealm()) if pv.IsRealm() { rlm := pv.Realm rlm.MarkNewReal(pv) @@ -681,12 +668,10 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { // Pass in the realm from m.saveNewPackageValuesAndTypes() // in case a throwaway was created. func (m *Machine) resavePackageValues(rlm *Realm) { - debug2.Println2("resavePackageValues, throwaway: ", rlm) // save package value and dependencies. pv := m.Package if pv.IsRealm() { rlm = pv.Realm - debug2.Println2("rlm.ID: ", rlm.ID) rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // re-save package realm info. m.Store.SetPackageRealm(rlm) @@ -881,7 +866,6 @@ func (m *Machine) RunDeclaration(d Decl) { // package level, for which evaluations happen during // preprocessing). func (m *Machine) runDeclaration(d Decl) { - debug2.Println2("run declaration, d: ", d) switch d := d.(type) { case *FuncDecl: // nothing to do. @@ -1799,8 +1783,6 @@ func (m *Machine) PushFrameBasic(s Stmt) { // ensure the counts are consistent, otherwise we mask // bugs with frame pops. func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { - debug2.Println2("PushFrameCall, CallExpr: ", cx) - debug2.Println2("m.Realm: ", m.Realm) fr := &Frame{ Source: cx, NumOps: m.NumOps, @@ -1826,39 +1808,29 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) { m.Printf("+F %#v\n", fr) } m.Frames = append(m.Frames, fr) - if recv.IsDefined() { - // If the receiver is defined, we enter the receiver's realm. + 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() { obj := recv.GetFirstObject(m.Store) if obj == nil { // could be a nil receiver. - // 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 + // just ignore. } else { recvOID := obj.GetObjectInfo().ID - debug2.Println2("---recvOID is: ", recvOID) - if recvOID.IsZero() { - debug2.Println2("---recv is ZERO, it's not owned, recv: ", recv) - // receiver isn't owned yet. - // just continue with current package and realm. - // XXX is this reasonable? - } else { + if !recvOID.IsZero() { // override the pv and rlm with receiver's. recvPkgOID := ObjectIDFromPkgID(recvOID.PkgID) - pv := m.Store.GetObject(recvPkgOID).(*PackageValue) - m.setCurrentPackage(pv) // maybe new realm + pv = m.Store.GetObject(recvPkgOID).(*PackageValue) + rlm = pv.GetRealm() // done } } - } else { - debug2.Println2("receiver not defined") - 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 + } + m.Package = pv + if rlm != nil && m.Realm != rlm { + m.Realm = rlm // enter new realm } } @@ -1911,7 +1883,6 @@ func (m *Machine) PopFrameAndReset() { // TODO: optimize by passing in last frame. func (m *Machine) PopFrameAndReturn() { - debug2.Println2("PopFrameAndReturn") fr := m.PopFrame() fr.Popped = true if debug { @@ -1934,10 +1905,6 @@ func (m *Machine) PopFrameAndReturn() { if res.IsUndefined() && rtypes[i].Type.Kind() != InterfaceKind { res.T = rtypes[i].Type } - //debug2.Println2("res: ", res) - //if oo, ok := res.V.(Object); ok { - // debug2.Println2("oo.GetObjectInfo(): ", oo.GetObjectInfo()) - //} m.Values[fr.NumValues+i] = res } m.NumValues = fr.NumValues + numRes diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index cfc7cce5450..334fef7c557 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -232,7 +232,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm for non escaped objects debug2.Println2("=========po is real, check cross realm========") - checkCrossRealm(rlm, store, co, false) // XXX, always false? + checkCrossRealm(rlm, store, co, false, nil) // XXX, always false? } } @@ -249,14 +249,14 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm recursively -func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { +func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, stack []Object) { debug2.Printf2("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { debug2.Println2("is object, GetIsReal: ", oo.GetIsReal()) // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, oo, isLastRef) + checkCrossRealm(rlm, store, oo, isLastRef, stack) } else { // reference to object switch tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm @@ -273,28 +273,18 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { debug2.Println2("pv: ", pv) debug2.Println2("pv.TV: ", *pv.TV) // check recursive - if b, ok := reo.(*Block); ok { - if slices.Contains(b.Values, *pv.TV) { // this implies *pv.TV is real - //if o2, ok := (*pv.TV).V.(Object); ok { - // if !o2.GetIsReal() { - // not return - // } - //} - debug2.Println2("return on block recursive, it MUST be real") - return - } - } - if hiv, ok := reo.(*HeapItemValue); ok { - debug2.Println2("hiv: ", hiv) - if hiv.Value == *pv.TV { - return - } + + if slices.Contains(stack, reo) { + debug2.Printf2("stack contains reo, return: ", reo) + stack = nil + return } + stack = append(stack, reo) } reo.SetOriginRealm(tv2.GetOriginPkg(store)) reo.SetIsAttachingRef(true) - checkCrossRealm(rlm, store, reo, true) + checkCrossRealm(rlm, store, reo, isLastRef, stack) } } } @@ -303,7 +293,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool) { // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. -func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { +func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, stack []Object) { debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v | rlm.ID: %v \n", oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), rlm.ID) @@ -322,7 +312,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { if oo.GetOriginRealm().IsZero() { debug2.Println2("origin realm is zero, it's unreal, check elems...") - checkCrossRealmChildren(rlm, store, oo, isLastRef) + checkCrossRealmChildren(rlm, store, oo, isLastRef, stack) return } @@ -331,7 +321,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { // for local realm checking // maybe a container not cross // but embedded field does. - checkCrossRealmChildren(rlm, store, oo, isLastRef) + checkCrossRealmChildren(rlm, store, oo, isLastRef, stack) return } @@ -349,20 +339,20 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool) { } } -func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool) { +func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, stack []Object) { switch v := oo.(type) { case *StructValue: // check fields for _, fv := range v.Fields { - checkCrossRealm2(rlm, store, &fv, isLastRef) // ref to struct is heapItemValue or block + checkCrossRealm2(rlm, store, &fv, isLastRef, stack) // ref to struct is heapItemValue or block } case *MapValue: for cur := v.List.Head; cur != nil; cur = cur.Next { - checkCrossRealm2(rlm, store, &cur.Key, isLastRef) - checkCrossRealm2(rlm, store, &cur.Value, isLastRef) + checkCrossRealm2(rlm, store, &cur.Key, isLastRef, stack) + checkCrossRealm2(rlm, store, &cur.Value, isLastRef, stack) } case *BoundMethodValue: - checkCrossRealm2(rlm, store, &v.Receiver, isLastRef) + checkCrossRealm2(rlm, store, &v.Receiver, isLastRef, stack) o2 := v.Func.Closure.(Object) // the closure must be a real fileBlock if !o2.GetIsReal() { @@ -372,14 +362,14 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool) // NOTE, it's not escaped until now, // will set after check for _, tv := range v.Values { - checkCrossRealm2(rlm, store, &tv, isLastRef) + checkCrossRealm2(rlm, store, &tv, isLastRef, stack) } case *HeapItemValue: - checkCrossRealm2(rlm, store, &v.Value, isLastRef) + checkCrossRealm2(rlm, store, &v.Value, isLastRef, stack) case *ArrayValue: if v.Data == nil { for _, e := range v.List { - checkCrossRealm2(rlm, store, &e, isLastRef) + checkCrossRealm2(rlm, store, &e, isLastRef, stack) } } default: @@ -528,13 +518,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -549,9 +539,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -620,7 +610,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // check cross realm before attaching // from package block, recursively if pv, ok := oo.(*PackageValue); ok { - checkCrossRealm(rlm, store, pv.Block.(Object), false) + checkCrossRealm(rlm, store, pv.Block.(Object), false, nil) } rlm.incRefCreatedDescendants(store, oo) } @@ -941,9 +931,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } diff --git a/gnovm/tests/files/zrealm_crossrealm18.gno b/gnovm/tests/files/zrealm_crossrealm18.gno index 27ef95bf733..cd69183133d 100644 --- a/gnovm/tests/files/zrealm_crossrealm18.gno +++ b/gnovm/tests/files/zrealm_crossrealm18.gno @@ -24,10 +24,11 @@ func main() { } // Output: -// hello from local realm fooer: gno.land/r/demo/tests/crossrealm -// hello from local realm fooer: gno.land/r/demo/tests/crossrealm +// hello from local realm fooer: gno.land/r/crossrealm_test +// hello from local realm fooer: gno.land/r/crossrealm_test // . // Realm: +// switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm20c3.gno b/gnovm/tests/files/zrealm_crossrealm20c3.gno new file mode 100644 index 00000000000..4c7bcaded41 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20c3.gno @@ -0,0 +1,23 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/struct" +) + +type Node struct { + *Node +} + +var root interface{} + +func main() { + node := &Node{} + node.Node = node + + root = node + println("ok") +} + +// Output: +// ok diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 4eb49312479..e47dcda0911 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -23,7 +23,7 @@ func main() { } // Output: -// hello gno.land/r/demo/tests/crossrealm/iface +// hello gno.land/r/crossrealm_test // . // Realm: @@ -63,7 +63,6 @@ func main() { // "RefCount": "1" // } // } -// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] // switchrealm["gno.land/r/crossrealm_test"] // c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ // "Fields": [ @@ -86,3 +85,5 @@ func main() { // } // } // d[f5a516808f8976c33939133293d598ce3bca4e8d:3] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm28c5.gno b/gnovm/tests/files/zrealm_crossrealm28c5.gno index febeaba57bc..29f9a948753 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c5.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c5.gno @@ -26,8 +26,5 @@ func main() { println("ok") } -// Output: -// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) -// ok +// Error: +// cannot attach a reference to an unreal object from an external realm: struct{("1" string)} From 8a30b994f7ba2f96fa2b407c77f5dda469b8b32e Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 13 Feb 2025 19:57:43 +0800 Subject: [PATCH 70/88] fixup --- .../gno.land/r/demo/boards/z_4_filetest.gno | 12 +-- .../upgrade_e/v1impl/v1impl.gno | 3 +- gno.land/Makefile | 1 + gnovm/pkg/gnolang/machine.go | 7 ++ gnovm/pkg/gnolang/ownership.go | 35 ++++++--- gnovm/pkg/gnolang/realm.go | 77 +++++++++++-------- gnovm/pkg/gnolang/store.go | 11 ++- gnovm/pkg/gnolang/values.go | 5 +- ...srealm20h.gno => zrealm_crossrealm23b.gno} | 6 +- 9 files changed, 103 insertions(+), 54 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm20h.gno => zrealm_crossrealm23b.gno} (76%) diff --git a/examples/gno.land/r/demo/boards/z_4_filetest.gno b/examples/gno.land/r/demo/boards/z_4_filetest.gno index e519e6babfb..793db574158 100644 --- a/examples/gno.land/r/demo/boards/z_4_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_4_filetest.gno @@ -341,7 +341,7 @@ func main() { // "Base": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "336074805fc853987abe6f7fe3ad97a6a6f3077a:2" +// "ObjectID": "purePkg:336074805fc853987abe6f7fe3ad97a6a6f3077a:2" // }, // "Index": "182", // "TV": null @@ -504,7 +504,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "0fd3352422af0a56a77ef2c9e88f479054e3d51f", +// "Hash": "4f0883532c1f35946dd4ca240781157e91447a92", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:131" // } // }, @@ -541,7 +541,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "c45bbd47a46681a63af973db0ec2180922e4a8ae", +// "Hash": "92761e5476881f637dd3b1c511e7f2beedec200f", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:127" // } // } @@ -792,7 +792,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "a416a751c3a45a1e5cba11e737c51340b081e372", +// "Hash": "92919a731f2816f8ac28938c1ee66fb12d95810c", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:86" // } // }, @@ -810,7 +810,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "36299fccbc13f2a84c4629fad4cb940f0bd4b1c6", +// "Hash": "f00c735099ba634c00dc3076978e16fd9899e9d0", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:87" // } // }, @@ -905,7 +905,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "a88a9b837af217656ee27084309f7cd02cd94cb3", +// "Hash": "bbf8cb63d9a27d3cb74e676801c92239fe00a159", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:85" // } // } diff --git a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno index 7ca2b1d7900..697b3be369b 100644 --- a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno +++ b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno @@ -6,10 +6,11 @@ import ( home "gno.land/r/x/manfred_upgrade_patterns/upgrade_e" ) +var impl = &Impl{} + // init is for self-registration, but in practice, anything can register like a `maketx run` call by an admin. func init() { // self register on init - impl := &Impl{} home.SetImpl(impl) } diff --git a/gno.land/Makefile b/gno.land/Makefile index 90ba7451c35..84159f6e06d 100644 --- a/gno.land/Makefile +++ b/gno.land/Makefile @@ -86,4 +86,5 @@ _test.gnoland:; go test $(GOTEST_FLAGS) ./cmd/gnoland _test.gnoweb:; go test $(GOTEST_FLAGS) ./cmd/gnoweb _test.gnokey:; go test $(GOTEST_FLAGS) ./cmd/gnokey _test.pkgs:; go test $(GOTEST_FLAGS) ./pkg/... +_test.pkgs.integ:; go test $(GOTEST_FLAGS) ./pkg/integration _test.pkgs.sync:; UPDATE_SCRIPTS=true go test $(GOTEST_FLAGS) ./pkg/... diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 7b89e98eb6d..59e7643a0b6 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -257,6 +257,7 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *gnovm.MemPackage, save bool } func (m *Machine) runMemPackage(memPkg *gnovm.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { + debug2.Println2("runMemPackage, save: ", save) // parse files. files := ParseMemPackage(memPkg) if !overrides { @@ -637,6 +638,7 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { + debug2.Println2("saveNewPackageValuesAndTypes...") // save package value and dependencies. pv := m.Package if pv.IsRealm() { @@ -648,14 +650,19 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { } else { // use a throwaway realm. rlm := NewRealm(pv.PkgPath) rlm.MarkNewReal(pv) + debug2.Println2("NOT realm, finalizing throwaway") rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) throwaway = rlm } + debug2.Println2("saving types...") // save declared types. if bv, ok := pv.Block.(*Block); ok { for _, tv := range bv.Values { + debug2.Println2("tv: ", tv) if tvv, ok := tv.V.(TypeValue); ok { + debug2.Println2("tvv: ", tvv) if dt, ok := tvv.Type.(*DeclaredType); ok { + debug2.Println2("---saving types, dt: ", dt) m.Store.SetType(dt) } } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index d1552eca78f..698e04ddcd5 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -6,8 +6,6 @@ import ( "reflect" "strconv" "strings" - - "github.com/gnolang/gno/tm2/pkg/errors" ) /* @@ -47,19 +45,35 @@ type ObjectID struct { func (oid ObjectID) MarshalAmino() (string, error) { pid := hex.EncodeToString(oid.PkgID.Hashlet[:]) - return fmt.Sprintf("%s:%d", pid, oid.NewTime), nil + if oid.PkgID.purePkg { + debug2.Println2("Marshal objectID, is pure") + return fmt.Sprintf("%s:%s:%d", "purePkg", pid, oid.NewTime), nil + } else { + return fmt.Sprintf("%s:%d", pid, oid.NewTime), nil + } } func (oid *ObjectID) UnmarshalAmino(oids string) error { parts := strings.Split(oids, ":") - if len(parts) != 2 { - return errors.New("invalid ObjectID %s", oids) + + if len(parts) < 2 || len(parts) > 3 { + return fmt.Errorf("invalid ObjectID %s", oids) } - _, err := hex.Decode(oid.PkgID.Hashlet[:], []byte(parts[0])) + + index1, index2 := 0, 1 + if len(parts) == 3 { + index1, index2 = 1, 2 + } + + if parts[0] == "purePkg" { + oid.PkgID.purePkg = true + } + + _, err := hex.Decode(oid.PkgID.Hashlet[:], []byte(parts[index1])) if err != nil { return err } - newTime, err := strconv.Atoi(parts[1]) + newTime, err := strconv.Atoi(parts[index2]) if err != nil { return err } @@ -320,7 +334,7 @@ func (oi *ObjectInfo) GetOriginRealm() PkgID { } func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { - debug2.Println2("SetOriginRealm: ", pkgId) + debug2.Println2("SetOriginRealm: ", pkgId, pkgId.purePkg) oi.originRealm = pkgId } @@ -404,12 +418,12 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { // it's un-real. originPkg = obj.GetOriginRealm() if !originPkg.IsZero() { - debug2.Println2("got originPkg from object: ", originPkg) + debug2.Println2("1, got originPkg from object: ", originPkg, originPkg.purePkg) return } originPkg = obj.GetObjectID().PkgID if !originPkg.IsZero() { - debug2.Println2("got originPkg from object: ", originPkg) + debug2.Println2("2, got originPkg from object: ", originPkg, originPkg.purePkg) return } } @@ -420,6 +434,7 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) if IsRealmPath(dt.Base.GetPkgPath()) { pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + debug2.Println2("pkgId.purePkg: ", pkgId.purePkg) return } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 334fef7c557..018c638e6dd 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -53,6 +53,7 @@ a realm to keep it alive. // PkgID & Realm type PkgID struct { + purePkg bool Hashlet } @@ -69,6 +70,10 @@ func (pid PkgID) String() string { return fmt.Sprintf("RID%X", pid.Hashlet[:]) } +func (pid PkgID) IsPurePkg() bool { + return pid.purePkg +} + func (pid PkgID) Bytes() []byte { return pid.Hashlet[:] } @@ -82,13 +87,14 @@ var ( ) func PkgIDFromPkgPath(path string) PkgID { + debug2.Printf2("PkgIDFromPkgPath: %s | purePkg: %t \n", path, !IsRealmPath(path)) pkgIDFromPkgPathCacheMu.Lock() defer pkgIDFromPkgPathCacheMu.Unlock() pkgID, ok := pkgIDFromPkgPathCache[path] if !ok { pkgID = new(PkgID) - *pkgID = PkgID{HashBytes([]byte(path))} + *pkgID = PkgID{purePkg: !IsRealmPath(path), Hashlet: HashBytes([]byte(path))} pkgIDFromPkgPathCache[path] = pkgID } return *pkgID @@ -96,7 +102,9 @@ func PkgIDFromPkgPath(path string) PkgID { // Returns the ObjectID of the PackageValue associated with path. func ObjectIDFromPkgPath(path string) ObjectID { + debug2.Println2("ObjectIDFromPkgPath: ", path) pkgID := PkgIDFromPkgPath(path) + pkgID.purePkg = !IsRealmPath(path) return ObjectIDFromPkgID(pkgID) } @@ -129,6 +137,7 @@ type Realm struct { // Creates a blank new realm with counter 0. func NewRealm(path string) *Realm { id := PkgIDFromPkgPath(path) + debug2.Printf2("NewRealm: %s | purePkg: %t \n", path, id.purePkg) return &Realm{ ID: id, Path: path, @@ -249,14 +258,14 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // check cross realm recursively -func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, stack []Object) { +func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, seenObjs []Object) { debug2.Printf2("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { debug2.Println2("is object, GetIsReal: ", oo.GetIsReal()) // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) - checkCrossRealm(rlm, store, oo, isLastRef, stack) + checkCrossRealm(rlm, store, oo, isLastRef, seenObjs) } else { // reference to object switch tv.V.(type) { case *SliceValue, PointerValue: // if reference object from external realm @@ -269,22 +278,19 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s // current realm, implies the // current realm is finalizing, // just skip as a recursive guard. - if pv, ok := tv2.V.(PointerValue); ok { - debug2.Println2("pv: ", pv) - debug2.Println2("pv.TV: ", *pv.TV) + if _, ok := tv2.V.(PointerValue); ok { // check recursive - - if slices.Contains(stack, reo) { + if slices.Contains(seenObjs, reo) { debug2.Printf2("stack contains reo, return: ", reo) - stack = nil + seenObjs = nil return } - stack = append(stack, reo) + seenObjs = append(seenObjs, reo) } reo.SetOriginRealm(tv2.GetOriginPkg(store)) reo.SetIsAttachingRef(true) - checkCrossRealm(rlm, store, reo, isLastRef, stack) + checkCrossRealm(rlm, store, reo, isLastRef, seenObjs) } } } @@ -293,26 +299,30 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s // refValue is required to handle cases where the value is a slice. // The `len` and `offset` are needed to validate proper elements of the underlying array. // NOTE, oo can be real or unreal. -func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, stack []Object) { - debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v | rlm.ID: %v \n", - oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), rlm.ID) +func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, seenObjs []Object) { + debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v \n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID) debug2.Printf2( "isLastRef: %t | isCurrentRef: %t\n", isLastRef, oo.GetIsAttachingRef(), ) - // refer 20c, 20c2 + + if oo.GetOriginRealm().IsPurePkg() { + return + } // update isLastRef based on the current object's reference status // If the last object was not a reference, but the current one is, // then the current object and its children are referenced. + // refer 20c, 20c2 if !isLastRef { isLastRef = oo.GetIsAttachingRef() } if oo.GetOriginRealm().IsZero() { debug2.Println2("origin realm is zero, it's unreal, check elems...") - checkCrossRealmChildren(rlm, store, oo, isLastRef, stack) + checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) return } @@ -321,7 +331,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, stack [ // for local realm checking // maybe a container not cross // but embedded field does. - checkCrossRealmChildren(rlm, store, oo, isLastRef, stack) + checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) return } @@ -339,20 +349,20 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, stack [ } } -func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, stack []Object) { +func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, seenObjs []Object) { switch v := oo.(type) { case *StructValue: // check fields for _, fv := range v.Fields { - checkCrossRealm2(rlm, store, &fv, isLastRef, stack) // ref to struct is heapItemValue or block + checkCrossRealm2(rlm, store, &fv, isLastRef, seenObjs) // ref to struct is heapItemValue or block } case *MapValue: for cur := v.List.Head; cur != nil; cur = cur.Next { - checkCrossRealm2(rlm, store, &cur.Key, isLastRef, stack) - checkCrossRealm2(rlm, store, &cur.Value, isLastRef, stack) + checkCrossRealm2(rlm, store, &cur.Key, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &cur.Value, isLastRef, seenObjs) } case *BoundMethodValue: - checkCrossRealm2(rlm, store, &v.Receiver, isLastRef, stack) + checkCrossRealm2(rlm, store, &v.Receiver, isLastRef, seenObjs) o2 := v.Func.Closure.(Object) // the closure must be a real fileBlock if !o2.GetIsReal() { @@ -362,14 +372,14 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, // NOTE, it's not escaped until now, // will set after check for _, tv := range v.Values { - checkCrossRealm2(rlm, store, &tv, isLastRef, stack) + checkCrossRealm2(rlm, store, &tv, isLastRef, seenObjs) } case *HeapItemValue: - checkCrossRealm2(rlm, store, &v.Value, isLastRef, stack) + checkCrossRealm2(rlm, store, &v.Value, isLastRef, seenObjs) case *ArrayValue: if v.Data == nil { for _, e := range v.List { - checkCrossRealm2(rlm, store, &e, isLastRef, stack) + checkCrossRealm2(rlm, store, &e, isLastRef, seenObjs) } } default: @@ -395,7 +405,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { // originRealm can be zero, e.g. an array value // in current realm, and it's referenced twice. - if !oo.GetOriginRealm().IsZero() && oo.GetOriginRealm() != rlm.ID { // crossing realm + originRealm := oo.GetOriginRealm() + if !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlm.ID { // crossing realm if !oo.GetIsAttachingRef() { panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", oo)) } @@ -610,7 +621,9 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // check cross realm before attaching // from package block, recursively if pv, ok := oo.(*PackageValue); ok { - checkCrossRealm(rlm, store, pv.Block.(Object), false, nil) + if IsRealmPath(pv.PkgPath) { + checkCrossRealm(rlm, store, pv.Block.(Object), false, nil) + } } rlm.incRefCreatedDescendants(store, oo) } @@ -1047,7 +1060,7 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) + //debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1060,7 +1073,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) + //debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1587,6 +1600,7 @@ func fillTypesTV(store Store, tv *TypedValue) { // Partially fills loaded objects shallowly, similarly to // getUnsavedTypes. Replaces all RefTypes with corresponding types. func fillTypesOfValue(store Store, val Value) Value { + debug2.Printf2("fillTypesOfValue, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: // do nothing return cv @@ -1685,14 +1699,15 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { - debug2.Printf2("assignNewObjectID, rlm: %v, oo: %v, oo: %p\n", rlm, oo, oo) + debug2.Printf2("assignNewObjectID, rlm: %v | rlm.Path: %s | oo: %v \n", rlm, rlm.Path, oo) + debug2.Printf2("%s is Realm path: %t \n", rlm.Path, IsRealmPath(rlm.Path)) oid := oo.GetObjectID() debug2.Println2("oid: ", oid) if !oid.IsZero() { panic("unexpected non-zero object id") } noid := rlm.nextObjectID() - debug2.Println2("noid: ", noid) + debug2.Printf2("noid: %s | purePkg: %t \n", noid, noid.PkgID.purePkg) oo.SetObjectID(noid) return noid } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 2dce4222bfc..8a998a17c45 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -266,6 +266,7 @@ func (ds *defaultStore) SetPackageGetter(pg PackageGetter) { // Gets package from cache, or loads it from baseStore, or gets it from package getter. func (ds *defaultStore) GetPackage(pkgPath string, isImport bool) *PackageValue { + debug2.Printf2("GetPackage: %s \n", pkgPath) // helper to detect circular imports if isImport { if slices.Contains(ds.current, pkgPath) { @@ -397,6 +398,7 @@ func (ds *defaultStore) SetPackageRealm(rlm *Realm) { // all []TypedValue types and TypeValue{} types to be // loaded (non-ref) types. func (ds *defaultStore) GetObject(oid ObjectID) Object { + debug2.Printf2("GetObject %s, pure: %t \n", oid, oid.PkgID.purePkg) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -430,6 +432,7 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { + debug2.Println2("loadObjectSafe: ", oid, oid.PkgID.purePkg) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -460,6 +463,7 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { oid, oo.GetObjectID())) } } + debug2.Println2("oo loaded, objectID: ", oo.GetObjectID(), oo.GetObjectID().PkgID.purePkg) oo.SetHash(ValueHash{NewHashlet(hash)}) ds.cacheObjects[oid] = oo _ = fillTypesOfValue(ds, oo) @@ -484,9 +488,12 @@ func (ds *defaultStore) SetObject(oo Object) { }() } oid := oo.GetObjectID() + debug2.Println2("oid: ", oid, oid.PkgID.purePkg) // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - //debug2.Println2("---o2: ", o2) + debug2.Println2("---o2: ", o2) + oid2 := o2.(Object).GetObjectID() + debug2.Println2("oid2: ", oid2, oid2.PkgID.purePkg) // marshal to binary. bz := amino.MustMarshalAny(o2) gas := overflow.Mul64p(ds.gasConfig.GasSetObject, store.Gas(len(bz))) @@ -506,6 +513,8 @@ func (ds *defaultStore) SetObject(oo Object) { ds.baseStore.Set([]byte(key), hashbz) size = len(hashbz) } + //ooo := ds.loadObjectSafe(oid) + //debug2.Printf2("check ooo: %v, ooo.GetObjectID: %v, pure: %t \n", ooo, ooo.GetObjectID(), ooo.GetObjectID().PkgID.purePkg) // save object to cache. if debug { if oid.IsZero() { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 90e3775316e..06546526a10 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -254,7 +254,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty panic("should not happen") } if nv, ok := tv2.V.(*NativeValue); !ok || - nv.Value.Kind() != reflect.Func { + nv.Value.Kind() != reflect.Func { panic("should not happen") } } @@ -290,6 +290,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // get origin pkgId, this should happen before assign, // because assign will discard original object info originPkg := tv2.GetOriginPkg(store) + debug2.Println2("originPkg: ", originPkg, originPkg.purePkg) pv.TV.Assign(alloc, tv2, cu) @@ -2478,7 +2479,6 @@ func (b *Block) GetPointerToInt(store Store, index int) PointerValue { } func (b *Block) GetPointerTo(store Store, path ValuePath) PointerValue { - //debug2.Println2("GetPoinerTo, b: ", b) if path.IsBlockBlankPath() { if debug { if path.Name != blankIdentifier { @@ -2724,6 +2724,7 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { + debug2.Printf2("fillValueTV: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case RefValue: if cv.PkgPath != "" { // load package diff --git a/gnovm/tests/files/zrealm_crossrealm20h.gno b/gnovm/tests/files/zrealm_crossrealm23b.gno similarity index 76% rename from gnovm/tests/files/zrealm_crossrealm20h.gno rename to gnovm/tests/files/zrealm_crossrealm23b.gno index 9c9b84d1a42..825f48bc5a7 100644 --- a/gnovm/tests/files/zrealm_crossrealm20h.gno +++ b/gnovm/tests/files/zrealm_crossrealm23b.gno @@ -15,8 +15,8 @@ var root interface{} // an another realm. func main() { root = tests.F // already attached in p - println("done") + println("done:", root) } -// Error: -// cannot attach a value of a type defined by another realm: struct{("p" string)} +// Output: +// done: (struct{("p" string)} gno.land/p/demo/tests.Foo) From a64a95139b1cd35f25783292b2c6a7762ebf3e9c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 13 Feb 2025 20:30:08 +0800 Subject: [PATCH 71/88] test pass --- .../integration/testdata/addpkg_namespace.txtar | 4 ++-- gno.land/pkg/integration/testdata/ghverify.txtar | 4 ++-- gnovm/pkg/gnolang/debug_false.go | 3 +-- gnovm/pkg/gnolang/op_eval.go | 3 +-- gnovm/pkg/gnolang/ownership.go | 5 ++--- gnovm/pkg/gnolang/realm.go | 14 +++++++------- gnovm/pkg/gnolang/store.go | 4 ++-- gnovm/pkg/gnolang/values.go | 12 ++++++------ gnovm/pkg/test/filetest.go | 2 -- 9 files changed, 23 insertions(+), 28 deletions(-) diff --git a/gno.land/pkg/integration/testdata/addpkg_namespace.txtar b/gno.land/pkg/integration/testdata/addpkg_namespace.txtar index 2cfd00acda4..575281f0089 100644 --- a/gno.land/pkg/integration/testdata/addpkg_namespace.txtar +++ b/gno.land/pkg/integration/testdata/addpkg_namespace.txtar @@ -63,12 +63,12 @@ stderr 'unauthorized user' # Test admin invites gui # admin call -> demo/users.Invite -gnokey maketx call -pkgpath gno.land/r/demo/users -func Invite -gas-fee 1000000ugnot -gas-wanted 2500000 -broadcast -chainid=tendermint_test -args $gui_user_addr admin +gnokey maketx call -pkgpath gno.land/r/demo/users -func Invite -gas-fee 1000000ugnot -gas-wanted 3000000 -broadcast -chainid=tendermint_test -args $gui_user_addr admin stdout 'OK!' # test gui register namespace # gui call -> demo/users.Register -gnokey maketx call -pkgpath gno.land/r/demo/users -func Register -gas-fee 1000000ugnot -gas-wanted 2500000 -broadcast -chainid=tendermint_test -args $admin_user_addr -args 'guiland' -args 'im gui' gui +gnokey maketx call -pkgpath gno.land/r/demo/users -func Register -gas-fee 1000000ugnot -gas-wanted 3000000 -broadcast -chainid=tendermint_test -args $admin_user_addr -args 'guiland' -args 'im gui' gui stdout 'OK!' # Test gui publishing on guiland/one diff --git a/gno.land/pkg/integration/testdata/ghverify.txtar b/gno.land/pkg/integration/testdata/ghverify.txtar index 0f2d21f6bd5..1df57e22dfa 100644 --- a/gno.land/pkg/integration/testdata/ghverify.txtar +++ b/gno.land/pkg/integration/testdata/ghverify.txtar @@ -8,7 +8,7 @@ gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func RequestVerificatio stdout OK! # request tasks to complete (this is done by the agent) -gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func GnorkleEntrypoint -args 'request' -gas-fee 1000000ugnot -gas-wanted 6000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func GnorkleEntrypoint -args 'request' -gas-fee 1000000ugnot -gas-wanted 6500000 -broadcast -chainid=tendermint_test test1 stdout '\("\[\{\\"id\\":\\"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5\\",\\"type\\":\\"0\\",\\"value_type\\":\\"string\\",\\"tasks\\":\[\{\\"gno_address\\":\\"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5\\",\\"github_handle\\":\\"deelawn\\"\}\]\}\]" string\)' # a verification request was made but there should be no verified address @@ -25,7 +25,7 @@ stdout "" stderr 'invalid ingest id: a' # the agent publishes their response to the task and the verification is complete -gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func GnorkleEntrypoint -args 'ingest,g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5,OK' -gas-fee 1000000ugnot -gas-wanted 6000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func GnorkleEntrypoint -args 'ingest,g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5,OK' -gas-fee 1000000ugnot -gas-wanted 6500000 -broadcast -chainid=tendermint_test test1 stdout OK! # get verified github handle by gno address diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index bf213870a3a..4a59419a15a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,5 @@ package gnolang const debug debugging = false -//const debug2 debugging = true - +// const debug2 debugging = true const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 5ee6483772c..aed467c471a 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -21,7 +21,7 @@ func (m *Machine) doOpEval() { x := m.PeekExpr(1) if debug { debug.Printf("EVAL: (%T) %v\n", x, x) - //fmt.Println(m.String()) + // fmt.Println(m.String()) } debug2.Printf2("EVAL: (%T) %v\n", x, x) // This case moved out of switch for performance. @@ -38,7 +38,6 @@ func (m *Machine) doOpEval() { lb := m.LastBlock() // Push value, done. ptr := lb.GetPointerToMaybeHeapUse(m.Store, nx) - //debug2.Println2("ptr.Deref(): ", ptr.Deref()) m.PushValue(ptr.Deref()) return } diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 698e04ddcd5..4363d90fa0b 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -46,7 +46,6 @@ type ObjectID struct { func (oid ObjectID) MarshalAmino() (string, error) { pid := hex.EncodeToString(oid.PkgID.Hashlet[:]) if oid.PkgID.purePkg { - debug2.Println2("Marshal objectID, is pure") return fmt.Sprintf("%s:%s:%d", "purePkg", pid, oid.NewTime), nil } else { return fmt.Sprintf("%s:%d", pid, oid.NewTime), nil @@ -368,10 +367,10 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { - //debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) + // debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: - //debug2.Println2("pointer value, base: ", cv.Base) + // debug2.Println2("pointer value, base: ", cv.Base) return cv.GetBase(store) case *ArrayValue: return cv diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 018c638e6dd..18f718a88e4 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -231,7 +231,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } else { rlm.MarkNewEscapedCheckCrossRealm(store, co) } - //rlm.MarkNewEscapedCheckCrossRealm(store, co) + // rlm.MarkNewEscapedCheckCrossRealm(store, co) } else { if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) @@ -593,9 +593,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { debug2.Println2("processNewCreatedMarks") - //fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) + // fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. - //for _, oo := range rlm.newCreated { + // for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] debug2.Printf2("---oo[%d] is: %v (type: %v) \n", i, oo, reflect.TypeOf(oo)) @@ -992,8 +992,8 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { func (rlm *Realm) saveObject(store Store, oo Object) { debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() - //debug2.Println2("---oid: ", oid) - //debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + // debug2.Println2("---oid: ", oid) + // debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") } @@ -1060,7 +1060,7 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - //debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) + // debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1073,7 +1073,7 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - //debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) + // debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 8a998a17c45..8eeb0515917 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -513,8 +513,8 @@ func (ds *defaultStore) SetObject(oo Object) { ds.baseStore.Set([]byte(key), hashbz) size = len(hashbz) } - //ooo := ds.loadObjectSafe(oid) - //debug2.Printf2("check ooo: %v, ooo.GetObjectID: %v, pure: %t \n", ooo, ooo.GetObjectID(), ooo.GetObjectID().PkgID.purePkg) + // ooo := ds.loadObjectSafe(oid) + // debug2.Printf2("check ooo: %v, ooo.GetObjectID: %v, pure: %t \n", ooo, ooo.GetObjectID(), ooo.GetObjectID().PkgID.purePkg) // save object to cache. if debug { if oid.IsZero() { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 06546526a10..cb7d015f2b7 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -550,10 +550,10 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv := alloc.NewStruct(fields) - //debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) - //debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) - //debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) - //debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) + // debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) + // debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) + // debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) + // debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) // append, unref copy... // this copy is needed, @@ -565,7 +565,7 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { } nsv.SetOriginRealm(pkgId) return nsv - //return alloc.NewStruct(fields) + // return alloc.NewStruct(fields) } // ---------------------------------------- @@ -2400,7 +2400,7 @@ type Block struct { // NOTE: for allocation, use *Allocator.NewBlock. func NewBlock(source BlockNode, parent *Block) *Block { - //fmt.Println("parent: ", parent) + // fmt.Println("parent: ", parent) var values []TypedValue if source != nil { values = make([]TypedValue, source.GetNumNames()) diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index b83396e745c..c24c014a9ba 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -93,10 +93,8 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // First, check if we have an error, whether we're supposed to get it. if result.Error != "" { - //fmt.Println("result.Error NOT empty:", result.Error) // Ensure this error was supposed to happen. errDirective := dirs.First(DirectiveError) - //fmt.Println("errDirective:", errDirective) if errDirective == nil { return "", fmt.Errorf("unexpected panic: %s\noutput:\n%s\nstack:\n%v", result.Error, result.Output, string(result.GoPanicStack)) From b29397b4501c36b05e5db10893efa2475cc6187b Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 13 Feb 2025 23:03:22 +0800 Subject: [PATCH 72/88] fixup --- gnovm/pkg/gnolang/debug_false.go | 3 +- gnovm/pkg/gnolang/machine.go | 6 +-- gnovm/pkg/gnolang/realm.go | 47 +++++++++++----------- gnovm/pkg/gnolang/store.go | 18 ++++----- gnovm/pkg/test/filetest.go | 8 ++++ gnovm/tests/files/heap_item_value.gno | 2 +- gnovm/tests/files/heap_item_value_init.gno | 2 +- gnovm/tests/files/zrealm16.gno | 2 +- 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index 4a59419a15a..bf213870a3a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,5 +4,6 @@ package gnolang const debug debugging = false -// const debug2 debugging = true +//const debug2 debugging = true + const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 59e7643a0b6..0fc36c42f27 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -545,6 +545,7 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // recursive function for var declarations. var runDeclarationFor func(fn *FileNode, decl Decl) runDeclarationFor = func(fn *FileNode, decl Decl) { + debug2.Println2("runDeclarationFor, decl: ", decl) // get fileblock of fn. // fb := pv.GetFileBlock(nil, fn.Name) // get dependencies of decl. @@ -644,6 +645,7 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { if pv.IsRealm() { rlm := pv.Realm rlm.MarkNewReal(pv) + debug2.Println2("===realm, finalizing throwaway") rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // save package realm info. m.Store.SetPackageRealm(rlm) @@ -654,15 +656,11 @@ func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) throwaway = rlm } - debug2.Println2("saving types...") // save declared types. if bv, ok := pv.Block.(*Block); ok { for _, tv := range bv.Values { - debug2.Println2("tv: ", tv) if tvv, ok := tv.V.(TypeValue); ok { - debug2.Println2("tvv: ", tvv) if dt, ok := tvv.Type.(*DeclaredType); ok { - debug2.Println2("---saving types, dt: ", dt) m.Store.SetType(dt) } } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 18f718a88e4..38b2ffe13e1 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -87,7 +87,6 @@ var ( ) func PkgIDFromPkgPath(path string) PkgID { - debug2.Printf2("PkgIDFromPkgPath: %s | purePkg: %t \n", path, !IsRealmPath(path)) pkgIDFromPkgPathCacheMu.Lock() defer pkgIDFromPkgPathCacheMu.Unlock() @@ -102,7 +101,6 @@ func PkgIDFromPkgPath(path string) PkgID { // Returns the ObjectID of the PackageValue associated with path. func ObjectIDFromPkgPath(path string) ObjectID { - debug2.Println2("ObjectIDFromPkgPath: ", path) pkgID := PkgIDFromPkgPath(path) pkgID.purePkg = !IsRealmPath(path) return ObjectIDFromPkgID(pkgID) @@ -137,7 +135,6 @@ type Realm struct { // Creates a blank new realm with counter 0. func NewRealm(path string) *Realm { id := PkgIDFromPkgPath(path) - debug2.Printf2("NewRealm: %s | purePkg: %t \n", path, id.purePkg) return &Realm{ ID: id, Path: path, @@ -161,8 +158,8 @@ func (rlm *Realm) String() string { // ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { debug2.Printf2( - "DidUpdate - po: %v (type: %v) | xo: %v (type: %v)\n", - po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), + "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", + po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), ) if rlm != nil { @@ -225,14 +222,15 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { // XXX, inc ref count everytime assignment happens co.IncRefCount() + debug2.Println2("co.GetRecCount() after inc: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsEscaped() { // already escaped } else { rlm.MarkNewEscapedCheckCrossRealm(store, co) } - // rlm.MarkNewEscapedCheckCrossRealm(store, co) } else { + debug2.Printf2("co.GetIsReal: %t \n", co.GetIsReal()) if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) } else { @@ -399,6 +397,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { ) if oo.GetOriginRealm() == rlm.ID { + debug2.Println2("1, mark oo new escaped: ", oo) + rlm.MarkNewEscaped(oo) // do nothing return } @@ -412,9 +412,8 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { } } // mark escaped - if !oo.GetIsEscaped() { - rlm.MarkNewEscaped(oo) - } + debug2.Println2("mark oo new escaped: ", oo) + rlm.MarkNewEscaped(oo) } func (rlm *Realm) MarkNewReal(oo Object) { @@ -529,13 +528,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -550,9 +549,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -944,9 +943,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } @@ -1592,7 +1591,6 @@ func fillType(store Store, typ Type) Type { } func fillTypesTV(store Store, tv *TypedValue) { - debug2.Println2("fillTypesTV, tv: ", tv) tv.T = fillType(store, tv.T) tv.V = fillTypesOfValue(store, tv.V) } @@ -1600,7 +1598,6 @@ func fillTypesTV(store Store, tv *TypedValue) { // Partially fills loaded objects shallowly, similarly to // getUnsavedTypes. Replaces all RefTypes with corresponding types. func fillTypesOfValue(store Store, val Value) Value { - debug2.Printf2("fillTypesOfValue, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: // do nothing return cv @@ -1809,6 +1806,8 @@ func refOrCopyValue(tv TypedValue) TypedValue { } func isUnsaved(oo Object) bool { + debug2.Printf2("check is Unsaved, oo: %v | oo.GetIsEscaped: %t | oo.GetIsNewEscaped: %t | oo.GetIsNewReal: %t | oo.getIsDirty: %t \n", + oo, oo.GetIsEscaped(), oo.GetIsNewEscaped(), oo.GetIsNewReal(), oo.GetIsDirty()) return oo.GetIsNewReal() || oo.GetIsDirty() } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 8eeb0515917..da917553fd9 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -398,7 +398,6 @@ func (ds *defaultStore) SetPackageRealm(rlm *Realm) { // all []TypedValue types and TypeValue{} types to be // loaded (non-ref) types. func (ds *defaultStore) GetObject(oid ObjectID) Object { - debug2.Printf2("GetObject %s, pure: %t \n", oid, oid.PkgID.purePkg) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -432,7 +431,6 @@ func (ds *defaultStore) GetObjectSafe(oid ObjectID) Object { // loads and caches an object. // CONTRACT: object isn't already in the cache. func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { - debug2.Println2("loadObjectSafe: ", oid, oid.PkgID.purePkg) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -463,7 +461,6 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { oid, oo.GetObjectID())) } } - debug2.Println2("oo loaded, objectID: ", oo.GetObjectID(), oo.GetObjectID().PkgID.purePkg) oo.SetHash(ValueHash{NewHashlet(hash)}) ds.cacheObjects[oid] = oo _ = fillTypesOfValue(ds, oo) @@ -475,7 +472,8 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - debug2.Println2("SetObject: ", oo) + debug2.Printf2("SetObject: %v | oo.GetIsNewReal: %t | oo.GetIsReal: %t \n", oo, oo.GetIsNewReal(), oo.GetIsReal()) + debug2.Println2("ds.opslog: ", ds.opslog) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -488,12 +486,10 @@ func (ds *defaultStore) SetObject(oo Object) { }() } oid := oo.GetObjectID() - debug2.Println2("oid: ", oid, oid.PkgID.purePkg) + //debug2.Println2("oid: ", oid, oid.PkgID.purePkg) // replace children/fields with Ref. o2 := copyValueWithRefs(oo) debug2.Println2("---o2: ", o2) - oid2 := o2.(Object).GetObjectID() - debug2.Println2("oid2: ", oid2, oid2.PkgID.purePkg) // marshal to binary. bz := amino.MustMarshalAny(o2) gas := overflow.Mul64p(ds.gasConfig.GasSetObject, store.Gas(len(bz))) @@ -513,8 +509,6 @@ func (ds *defaultStore) SetObject(oo Object) { ds.baseStore.Set([]byte(key), hashbz) size = len(hashbz) } - // ooo := ds.loadObjectSafe(oid) - // debug2.Printf2("check ooo: %v, ooo.GetObjectID: %v, pure: %t \n", ooo, ooo.GetObjectID(), ooo.GetObjectID().PkgID.purePkg) // save object to cache. if debug { if oid.IsZero() { @@ -537,9 +531,11 @@ func (ds *defaultStore) SetObject(oo Object) { } else { op = StoreOpMod } + debug2.Println2("op: ", op) ds.opslog = append(ds.opslog, StoreOp{Type: op, Object: o2.(Object)}) } + debug2.Println2("after add, ds.opslog: ", ds.opslog) // if escaped, add hash to iavl. if oo.GetIsEscaped() && ds.iavlStore != nil { var key, value []byte @@ -947,6 +943,7 @@ func (sop StoreOp) String() string { } func (ds *defaultStore) SetLogStoreOps(enabled bool) { + debug2.Println2("SetLogStoreOps, enabled: ", enabled) if enabled { ds.ResetStoreOps() } else { @@ -956,6 +953,7 @@ func (ds *defaultStore) SetLogStoreOps(enabled bool) { // resets .realmops. func (ds *defaultStore) ResetStoreOps() { + debug2.Println2("Reset store ops") ds.opslog = make([]StoreOp, 0, 1024) } @@ -969,6 +967,8 @@ func (ds *defaultStore) SprintStoreOps() string { } func (ds *defaultStore) LogSwitchRealm(rlmpath string) { + debug2.Println2("LogSwitchRealm, rlmpath: ", rlmpath) + debug2.Println2("LogSwitchRealm, opslog: ", ds.opslog) ds.opslog = append(ds.opslog, StoreOp{Type: StoreOpSwitchRealm, RlmPath: rlmpath}) } diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index c24c014a9ba..fb3af0abaf4 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -234,6 +234,7 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte m.RunFiles(n) m.RunStatement(gno.S(gno.Call(gno.X("main")))) } else { + fmt.Println("realm case...") // Realm case. gno.DisableDebug() // until main call. @@ -259,14 +260,21 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte // Clear store cache and reconstruct machine from committed info // (mimicking on-chain behaviour). tx.Write() + + fmt.Println("tx, opslog: ", m.Store.SprintStoreOps()) + m.Store = orig + fmt.Println("orig, opslog: ", m.Store.SprintStoreOps()) + pv2 := m.Store.GetPackage(pkgPath, false) m.SetActivePackage(pv2) gno.EnableDebug() // clear store.opslog from init function(s). m.Store.SetLogStoreOps(true) // resets. + fmt.Println("run statement...") m.RunStatement(gno.S(gno.Call(gno.X("main")))) + fmt.Println("final, opslog: ", m.Store.SprintStoreOps()) } return runResult{ diff --git a/gnovm/tests/files/heap_item_value.gno b/gnovm/tests/files/heap_item_value.gno index 22a2107495b..7a728d2c6f9 100644 --- a/gnovm/tests/files/heap_item_value.gno +++ b/gnovm/tests/files/heap_item_value.gno @@ -35,8 +35,8 @@ func main() { // c[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ // "ObjectInfo": { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "IsEscaped": true, // "ModTime": "0", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 3a66196ace8..11fe78f5b23 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -8,7 +8,7 @@ type S struct { var a, b *S func init() { - a = new(S) + a = new(S) // heapItemValue new real a.A = new(int) *a.A = 4 } diff --git a/gnovm/tests/files/zrealm16.gno b/gnovm/tests/files/zrealm16.gno index 5396afa36ee..e32e59a4d05 100644 --- a/gnovm/tests/files/zrealm16.gno +++ b/gnovm/tests/files/zrealm16.gno @@ -49,7 +49,7 @@ func main() { // "@type": "/gno.PointerValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "0d544f117e621748ff328095eeef0fb1e4cbc6f1", +// "Escaped": true, // "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5" // }, // "Index": "0", From e0eb2b356581d01b82f9a385203e3ac159998ef6 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Thu, 13 Feb 2025 23:15:00 +0800 Subject: [PATCH 73/88] fixup --- gnovm/pkg/gnolang/realm.go | 3 +++ gnovm/tests/files/heap_item_value_init.gno | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 38b2ffe13e1..ea05201b4ab 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -224,6 +224,9 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { co.IncRefCount() debug2.Println2("co.GetRecCount() after inc: ", co.GetRefCount()) if co.GetRefCount() > 1 { + if co.GetIsReal() { + rlm.MarkDirty(co) + } if co.GetIsEscaped() { // already escaped } else { diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 11fe78f5b23..747bac27d5d 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -19,3 +19,23 @@ func main() { // Realm: // switchrealm["gno.land/r/test"] +// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "IsEscaped": true, +// "ModTime": "6", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.S" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "a05e5e1e2d2a27d94408a9325a58068e60b504df", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5" +// } +// } +// } From 1d803880d904fb92364e399659eb74cd3cd45c9d Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sat, 15 Feb 2025 01:09:06 +0800 Subject: [PATCH 74/88] save, handle dirty oo --- gnovm/pkg/gnolang/debug_false.go | 4 +- gnovm/pkg/gnolang/ownership.go | 10 +- gnovm/pkg/gnolang/realm.go | 32 ++++-- gnovm/pkg/gnolang/store.go | 7 -- gnovm/pkg/gnolang/values.go | 2 +- gnovm/pkg/test/filetest.go | 6 -- gnovm/tests/files/heap_item_value_init.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 112 ++++++++++++++++++++- gnovm/tests/files/zrealm_crossrealm21e.gno | 4 +- 9 files changed, 145 insertions(+), 34 deletions(-) diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index bf213870a3a..ed949359db7 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,6 @@ package gnolang const debug debugging = false -//const debug2 debugging = true +const debug2 debugging = true -const debug2 debugging = false +//const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 4363d90fa0b..064e088dfca 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -431,11 +431,11 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) - if IsRealmPath(dt.Base.GetPkgPath()) { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - debug2.Println2("pkgId.purePkg: ", pkgId.purePkg) - return - } + //if IsRealmPath(dt.Base.GetPkgPath()) { + pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + debug2.Println2("pkgId.purePkg: ", pkgId.purePkg) + return + //} } return } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index ea05201b4ab..477935021b7 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -339,11 +339,21 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, seenObj if rlm.ID != oo.GetOriginRealm() { // crossing realm if isLastRef { if oo.GetIsReal() { - debug2.Println2("reference base is REAL, return") + debug2.Println2("reference base is REAL, NO return, check recursively") return - } else { - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) + checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) } + + //if !oo.GetIsReal() { + // panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) + //} + //if oo.GetIsDirty() { + // panic(fmt.Sprintf("cannot attach a reference to an dirty object from an external realm: %v", oo)) + //} + + // check children + checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) + } else { // not reference to object panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } @@ -413,6 +423,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { if !oo.GetIsAttachingRef() { panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", oo)) } + //checkCrossRealm(rlm, store, oo, true, nil) } // mark escaped debug2.Println2("mark oo new escaped: ", oo) @@ -957,12 +968,17 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { debug2.Println2("unsaved: ", unsaved) for _, uch := range unsaved { debug2.Println2("uch: ", uch) - if uch.GetIsEscaped() || uch.GetIsNewEscaped() { + // TODO: make it ahead of here. + if uch.GetOriginRealm() != rlm.ID { + debug2.Println2("uch cross realm, does NOT save here!!!") + } else if uch.GetIsEscaped() || uch.GetIsNewEscaped() { // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) } } + debug2.Println2("then, save self") + //if oo.GetOriginRealm() == rlm.ID { // then, save self. if oo.GetIsNewReal() { // save created object. @@ -989,13 +1005,14 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { rlm.saveObject(store, oo) oo.SetIsDirty(false, 0) } + //} } func (rlm *Realm) saveObject(store Store, oo Object) { - debug2.Println2("saveObject: ", oo) + fmt.Println("saveObject: ", oo) oid := oo.GetObjectID() - // debug2.Println2("---oid: ", oid) - // debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("---oid: ", oid) + debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) if oid.IsZero() { panic("unexpected zero object id") } @@ -1196,6 +1213,7 @@ func getUnsavedChildObjects(val Value) []Object { } else if obj, ok := val.(Object); ok { // if object... if isUnsaved(obj) { + debug2.Println2("obj is unsaved...") unsaved = append(unsaved, obj) } } else { diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index da917553fd9..21986ab4f78 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -473,7 +473,6 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // package values. func (ds *defaultStore) SetObject(oo Object) { debug2.Printf2("SetObject: %v | oo.GetIsNewReal: %t | oo.GetIsReal: %t \n", oo, oo.GetIsNewReal(), oo.GetIsReal()) - debug2.Println2("ds.opslog: ", ds.opslog) if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -531,11 +530,9 @@ func (ds *defaultStore) SetObject(oo Object) { } else { op = StoreOpMod } - debug2.Println2("op: ", op) ds.opslog = append(ds.opslog, StoreOp{Type: op, Object: o2.(Object)}) } - debug2.Println2("after add, ds.opslog: ", ds.opslog) // if escaped, add hash to iavl. if oo.GetIsEscaped() && ds.iavlStore != nil { var key, value []byte @@ -943,7 +940,6 @@ func (sop StoreOp) String() string { } func (ds *defaultStore) SetLogStoreOps(enabled bool) { - debug2.Println2("SetLogStoreOps, enabled: ", enabled) if enabled { ds.ResetStoreOps() } else { @@ -953,7 +949,6 @@ func (ds *defaultStore) SetLogStoreOps(enabled bool) { // resets .realmops. func (ds *defaultStore) ResetStoreOps() { - debug2.Println2("Reset store ops") ds.opslog = make([]StoreOp, 0, 1024) } @@ -967,8 +962,6 @@ func (ds *defaultStore) SprintStoreOps() string { } func (ds *defaultStore) LogSwitchRealm(rlmpath string) { - debug2.Println2("LogSwitchRealm, rlmpath: ", rlmpath) - debug2.Println2("LogSwitchRealm, opslog: ", ds.opslog) ds.opslog = append(ds.opslog, StoreOp{Type: StoreOpSwitchRealm, RlmPath: rlmpath}) } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index cb7d015f2b7..ce64293b2f9 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2724,7 +2724,7 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - debug2.Printf2("fillValueTV: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) + //debug2.Printf2("fillValueTV: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case RefValue: if cv.PkgPath != "" { // load package diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index fb3af0abaf4..28cb760fcb0 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -261,20 +261,14 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte // (mimicking on-chain behaviour). tx.Write() - fmt.Println("tx, opslog: ", m.Store.SprintStoreOps()) - m.Store = orig - fmt.Println("orig, opslog: ", m.Store.SprintStoreOps()) - pv2 := m.Store.GetPackage(pkgPath, false) m.SetActivePackage(pv2) gno.EnableDebug() // clear store.opslog from init function(s). m.Store.SetLogStoreOps(true) // resets. - fmt.Println("run statement...") m.RunStatement(gno.S(gno.Call(gno.X("main")))) - fmt.Println("final, opslog: ", m.Store.SprintStoreOps()) } return runResult{ diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 747bac27d5d..40f9752d22d 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -14,7 +14,7 @@ func init() { } func main() { - b = a + b = a // dirty, refCount change. } // Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index cd8d4ace1d6..0856dfb1e2d 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -5,20 +5,23 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm" ) -type container struct{ f *fooer } +type container struct { + name string + f *fooer +} func (container) Foo() { println("hello") } type fooer struct{ name string } -var c = &container{} +var c = &container{name: "local_container"} func main() { // the object attaching is heapItemValue, not escaped // while attempting to attach it to external realm, // check recursively. // also see xxx_crossrealm21.gno - ff := &fooer{name: "local_foo"} + ff := &fooer{name: "local_foo"} // should panic, while cross unreal, even ref... c.f = ff crossrealm.SetFooer(c) crossrealm.CallFooerFoo() @@ -28,3 +31,106 @@ func main() { // Output: // hello // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_foo" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "RefCount": "1" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "90e6414435c56b7ffa17bd575535b7a558b93e22", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" +// } +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_container" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "7d3bda685439b3989f18e824762f473f40c944fb", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21e.gno b/gnovm/tests/files/zrealm_crossrealm21e.gno index d0a97e3ba69..f39eb27b896 100644 --- a/gnovm/tests/files/zrealm_crossrealm21e.gno +++ b/gnovm/tests/files/zrealm_crossrealm21e.gno @@ -17,8 +17,8 @@ var f = fooer{name: "local_fooer"} var b = bar{name: "local_bar"} func main() { - f.bar = b // this makes f dirty - crossrealm.SetContainer2(&f) + f.bar = b // this makes f dirty + crossrealm.SetContainer2(&f) // can not attach, f may change, so currently it's not determined crossrealm.RunF() print(".") } From 938b3a431d79a95772773650ec67afc085fd987d Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sat, 15 Feb 2025 23:40:42 +0800 Subject: [PATCH 75/88] fixup --- .../r/demo/tests/crossrealm_b/crossrealm.gno | 6 +- gnovm/pkg/gnolang/debug_false.go | 4 +- gnovm/pkg/gnolang/ownership.go | 2 +- gnovm/pkg/gnolang/realm.go | 101 ++++++++++------- gnovm/pkg/gnolang/values.go | 3 + gnovm/tests/files/zrealm16.gno | 20 ++++ gnovm/tests/files/zrealm_crossrealm17.gno | 4 +- gnovm/tests/files/zrealm_crossrealm20j.gno | 20 ++++ gnovm/tests/files/zrealm_crossrealm21e.gno | 105 +++++++++++++++++- gnovm/tests/files/zrealm_crossrealm28c3.gno | 69 ++++++++++++ 10 files changed, 279 insertions(+), 55 deletions(-) diff --git a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno index c2df8396cad..d412b6ee6b1 100644 --- a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno @@ -19,9 +19,7 @@ func (f *fooer) Foo() { } var ( - Fooer = &fooer{s: "A"} - // this is already attached, so cannot be attached to external realm - FooerGetter = func() crossrealm.Fooer { return Fooer } - // same + Fooer = &fooer{s: "A"} + FooerGetter = func() crossrealm.Fooer { return Fooer } FooerGetterBuilder = func() crossrealm.FooerGetter { return func() crossrealm.Fooer { return Fooer } } ) diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index ed949359db7..bf213870a3a 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -4,6 +4,6 @@ package gnolang const debug debugging = false -const debug2 debugging = true +//const debug2 debugging = true -//const debug2 debugging = false +const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 064e088dfca..bb3698789e1 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -367,7 +367,7 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { - // debug2.Println2("GetFirstObject, tv, type ot tv.V: ", tv, reflect.TypeOf(tv.V)) + debug2.Printf2("GetFirstObject, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: // debug2.Println2("pointer value, base: ", cv.Base) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 477935021b7..9bee6f2f39d 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -170,7 +170,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { debug2.Println2("po.GetIsReal: ", po.GetIsReal()) } - // Combine debug logs for co (if not nil) if co != nil { debug2.Printf2( "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", @@ -237,6 +236,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) } else { + debug2.Printf2("set owner of %v to be %v \n", co, po) co.SetOwner(po) rlm.MarkNewReal(co) } @@ -338,22 +338,13 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, seenObj if rlm.ID != oo.GetOriginRealm() { // crossing realm if isLastRef { - if oo.GetIsReal() { + if !oo.GetIsReal() { + panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) + } else { debug2.Println2("reference base is REAL, NO return, check recursively") + //checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) return - checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) } - - //if !oo.GetIsReal() { - // panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) - //} - //if oo.GetIsDirty() { - // panic(fmt.Sprintf("cannot attach a reference to an dirty object from an external realm: %v", oo)) - //} - - // check children - checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) - } else { // not reference to object panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } @@ -431,6 +422,7 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { } func (rlm *Realm) MarkNewReal(oo Object) { + debug2.Printf2("MarkNewReal, rlm.ID: %s | oo: %v \n", rlm.ID, oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -463,6 +455,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { + debug2.Printf2("MarkDirty, rlm.ID: %s | oo: %v \n", rlm.ID, oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -542,13 +535,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -563,9 +556,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -690,6 +683,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { if child.GetIsReal() { // a deleted real became undeleted. child.SetOwner(oo) + debug2.Println2("mark dirty, rc == 1") rlm.MarkDirty(child) } else { // a (possibly pre-existing) new object @@ -701,6 +695,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { child.SetIsNewReal(true) } } else if rc > 1 { + debug2.Println2("mark dirty, rc: ", rc) rlm.MarkDirty(child) if child.GetIsEscaped() { // already escaped, do nothing. @@ -726,7 +721,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // to rlm.deleted. // Must run *after* processNewCreatedMarks(). func (rlm *Realm) processNewDeletedMarks(store Store) { + debug2.Println2("processNewDeletedMarks") for _, oo := range rlm.newDeleted { + debug2.Println2("oo: ", oo, oo.GetRefCount()) if debug { if oo.GetObjectID().IsZero() { panic("new deleted mark should have an object ID") @@ -744,6 +741,7 @@ func (rlm *Realm) processNewDeletedMarks(store Store) { // Like incRefCreatedDescendants but decrements. func (rlm *Realm) decRefDeletedDescendants(store Store, oo Object) { + debug2.Println2("decRefDeletedDescendants, oo: ", oo) if debug { if oo.GetObjectID().IsZero() { panic("cannot decrement references of deleted descendants of object with no object ID") @@ -770,11 +768,13 @@ func (rlm *Realm) decRefDeletedDescendants(store Store, oo Object) { // recurse for children more := getChildObjects2(store, oo) for _, child := range more { + debug2.Println2("child: ", child) child.DecRefCount() rc := child.GetRefCount() if rc == 0 { rlm.decRefDeletedDescendants(store, child) } else if rc > 0 { + debug2.Println2("mark dirty for refCount changes...") rlm.MarkDirty(child) } else { panic("deleted descendants should not have a reference count of less than zero") @@ -789,6 +789,7 @@ 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) { + debug2.Println2("processNewEscapedMarks") escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, @@ -919,7 +920,10 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - debug2.Println2("saveUnsavedObjects") + debug2.Printf2("saveUnsavedObjects, len(updated): %d | rlm.ID: %s \n", len(rlm.updated), rlm.ID) + for i, uo := range rlm.updated { + debug2.Printf2("uo[%d] is %v \n", i, uo) + } for _, co := range rlm.created { debug2.Println2("co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { @@ -933,7 +937,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { } } for _, uo := range rlm.updated { - debug2.Println2("uo: ", uo) + debug2.Println2("===uo: ", uo) if !uo.GetIsDirty() { // might have happened already as child // of something else created/dirty. @@ -946,7 +950,7 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { - debug2.Println2("saveUnsavedObjectRecursively", oo) + debug2.Println2("saveUnsavedObjectRecursively, oo, rlm.ID: ", oo, rlm.ID) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -957,29 +961,36 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } + unsaved := []Object(nil) // first, save unsaved children. - unsaved := getUnsavedChildObjects(oo) + // leave unreal external object + // to be attached in their own realm + if !isCrossRealm(oo.GetOriginRealm(), rlm.ID) { + unsaved = getUnsavedChildObjects(oo) + } + //unsaved := getUnsavedChildObjects(oo) debug2.Println2("unsaved: ", unsaved) for _, uch := range unsaved { debug2.Println2("uch: ", uch) // TODO: make it ahead of here. - if uch.GetOriginRealm() != rlm.ID { - debug2.Println2("uch cross realm, does NOT save here!!!") - } else if uch.GetIsEscaped() || uch.GetIsNewEscaped() { + if uch.GetIsEscaped() || uch.GetIsNewEscaped() { + debug2.Println2("uch is escaped or new escape") // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) } } - debug2.Println2("then, save self") - //if oo.GetOriginRealm() == rlm.ID { + debug2.Println2("then, save self, oo: ", oo) + // NOTE, won't be any external unreal here. + // then, save self. + // neither escaped nor new escaped if oo.GetIsNewReal() { // save created object. if debug { @@ -1005,17 +1016,22 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { rlm.saveObject(store, oo) oo.SetIsDirty(false, 0) } - //} } func (rlm *Realm) saveObject(store Store, oo Object) { - fmt.Println("saveObject: ", oo) + debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() debug2.Println2("---oid: ", oid) debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) + debug2.Println2("---oo.GetEscaped: ", oo.GetIsEscaped()) if oid.IsZero() { panic("unexpected zero object id") } + if isCrossRealm(oo.GetOriginRealm(), rlm.ID) { + if !oo.GetIsEscaped() && !oo.GetIsNewEscaped() { + panic("should not attach not escaped/new escaped object from external realm") + } + } // set hash to escape index. if oo.GetIsNewEscaped() { oo.SetIsNewEscaped(false) @@ -1212,7 +1228,7 @@ func getUnsavedChildObjects(val Value) []Object { // is already saved. } else if obj, ok := val.(Object); ok { // if object... - if isUnsaved(obj) { + if isUnsavedInRealm(obj) { debug2.Println2("obj is unsaved...") unsaved = append(unsaved, obj) } @@ -1826,7 +1842,7 @@ func refOrCopyValue(tv TypedValue) TypedValue { } } -func isUnsaved(oo Object) bool { +func isUnsavedInRealm(oo Object) bool { debug2.Printf2("check is Unsaved, oo: %v | oo.GetIsEscaped: %t | oo.GetIsNewEscaped: %t | oo.GetIsNewReal: %t | oo.getIsDirty: %t \n", oo, oo.GetIsEscaped(), oo.GetIsNewEscaped(), oo.GetIsNewReal(), oo.GetIsDirty()) return oo.GetIsNewReal() || oo.GetIsDirty() @@ -1856,3 +1872,8 @@ func getOwner(store Store, oo Object) Object { } return po } + +func isCrossRealm(originRealm, rlmID PkgID) bool { + debug2.Printf2("originRealm: %s | rlmID: %s \n", originRealm, rlmID) + return !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlmID +} diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index ce64293b2f9..495c2423b5e 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -310,6 +310,8 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty oo2.SetOriginRealm(originPkg) // attach origin package info } + debug2.Println2("oo2: ", oo2) + rlm.DidUpdate(store, pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) @@ -1074,6 +1076,7 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { + debug2.Printf2("Copy, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T diff --git a/gnovm/tests/files/zrealm16.gno b/gnovm/tests/files/zrealm16.gno index e32e59a4d05..b7bef5028b0 100644 --- a/gnovm/tests/files/zrealm16.gno +++ b/gnovm/tests/files/zrealm16.gno @@ -74,6 +74,26 @@ func main() { // "RefCount": "1" // } // } +// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", +// "IsEscaped": true, +// "ModTime": "11", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.A" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "7c9f93a63419d852f132afaf2245ddcac5e8c3fb", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6" +// } +// } +// } // u[a8ada09dee16d791fd406d629fe29bb0ed084a30:3]={ // "ObjectInfo": { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3", diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 0856dfb1e2d..5fb1c4a3f1f 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -10,7 +10,7 @@ type container struct { f *fooer } -func (container) Foo() { println("hello") } +func (container) Foo() { println("hello " + c.f.name) } type fooer struct{ name string } @@ -29,7 +29,7 @@ func main() { } // Output: -// hello +// hello local_foo // . // Realm: diff --git a/gnovm/tests/files/zrealm_crossrealm20j.gno b/gnovm/tests/files/zrealm_crossrealm20j.gno index d742e7fad2c..e3b29f671a4 100644 --- a/gnovm/tests/files/zrealm_crossrealm20j.gno +++ b/gnovm/tests/files/zrealm_crossrealm20j.gno @@ -24,6 +24,26 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "8222b763e9bc04b4b7805e165e9f1324a39f28b6", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// } +// } +// } // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] diff --git a/gnovm/tests/files/zrealm_crossrealm21e.gno b/gnovm/tests/files/zrealm_crossrealm21e.gno index f39eb27b896..1c87bd12d9c 100644 --- a/gnovm/tests/files/zrealm_crossrealm21e.gno +++ b/gnovm/tests/files/zrealm_crossrealm21e.gno @@ -11,18 +11,111 @@ type fooer struct { } type bar struct{ name string } -func (fooer) Foo() { println("hello") } +func (f fooer) Foo() { println("hello " + f.bar.name) } -var f = fooer{name: "local_fooer"} -var b = bar{name: "local_bar"} +var f = fooer{name: "local_fooer", bar: bar{name: "local_bar_1"}} +var b = bar{name: "local_bar_2"} // real func main() { - f.bar = b // this makes f dirty - crossrealm.SetContainer2(&f) // can not attach, f may change, so currently it's not determined + f.bar = b // this makes f dirty + crossrealm.SetContainer2(&f) crossrealm.RunF() print(".") } // Output: -// hello +// hello local_bar_2 // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "2", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_bar_2" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.bar" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "2653fb8c9edc489f07585ec600dfd1a968d81ca1", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// d[f5a516808f8976c33939133293d598ce3bca4e8d:4] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm28c3.gno b/gnovm/tests/files/zrealm_crossrealm28c3.gno index 45e4fd00ee8..15b03a65f64 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c3.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c3.gno @@ -36,4 +36,73 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "1", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "2", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "3", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "IsEscaped": true, +// "ModTime": "28", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// } +// } // switchrealm["gno.land/r/crossrealm_test"] From 5aeadd683278f99004ab8ee1c66da625d6922438 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 16 Feb 2025 13:32:09 +0800 Subject: [PATCH 76/88] fixup --- .../tests/crossrealm/func/crossrealm_func.gno | 10 +- .../crossrealm/slice/crossrealm_slice.gno | 4 +- gnovm/pkg/gnolang/realm.go | 2 +- gnovm/pkg/gnolang/values.go | 18 +-- gnovm/pkg/test/filetest.go | 2 +- gnovm/tests/files/zrealm_crossrealm1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 129 ++-------------- gnovm/tests/files/zrealm_crossrealm17a.gno | 132 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm19.gno | 4 +- gnovm/tests/files/zrealm_crossrealm20.gno | 43 ++++++ gnovm/tests/files/zrealm_crossrealm20b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20b1.gno | 9 +- gnovm/tests/files/zrealm_crossrealm20c3.gno | 4 - gnovm/tests/files/zrealm_crossrealm20f.gno | 4 +- gnovm/tests/files/zrealm_crossrealm20g.gno | 2 - gnovm/tests/files/zrealm_crossrealm20j.gno | 92 +++++++----- gnovm/tests/files/zrealm_crossrealm21.gno | 92 +++++------- gnovm/tests/files/zrealm_crossrealm21a.gno | 4 +- gnovm/tests/files/zrealm_crossrealm21c.gno | 41 ++++++ gnovm/tests/files/zrealm_crossrealm21d.gno | 93 ++++++++++++ gnovm/tests/files/zrealm_crossrealm21d1.gno | 100 +++++++++++++ gnovm/tests/files/zrealm_crossrealm21d2.gno | 41 ++++++ gnovm/tests/files/zrealm_crossrealm21f.gno | 92 +++++++++++- gnovm/tests/files/zrealm_crossrealm22a.gno | 4 + gnovm/tests/files/zrealm_crossrealm22b.gno | 4 +- gnovm/tests/files/zrealm_crossrealm22c.gno | 4 + gnovm/tests/files/zrealm_crossrealm22d.gno | 6 + gnovm/tests/files/zrealm_crossrealm22e.gno | 4 + .../tests/files/zrealm_crossrealm23_pure.gno | 5 +- gnovm/tests/files/zrealm_crossrealm23b.gno | 35 +++-- ...srealm20i.gno => zrealm_crossrealm23c.gno} | 5 +- gnovm/tests/files/zrealm_crossrealm28_0.gno | 22 --- gnovm/tests/files/zrealm_crossrealm28c.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28c1.gno | 4 - gnovm/tests/files/zrealm_crossrealm28c3.gno | 11 +- gnovm/tests/files/zrealm_crossrealm28c4.gno | 73 +++++++++ gnovm/tests/files/zrealm_crossrealm28c6.gno | 72 +++++++++ gnovm/tests/files/zrealm_crossrealm28c7.gno | 131 +++++++++++++++++ gnovm/tests/files/zrealm_crossrealm28c9.gno | 6 +- gnovm/tests/files/zrealm_crossrealm28d2.gno | 138 +++++++++++++++++- gnovm/tests/files/zrealm_crossrealm28f.gno | 3 + gnovm/tests/files/zrealm_crossrealm30.gno | 38 +++++ gnovm/tests/files/zrealm_crossrealm32.gno | 112 ++++++++++++++ gnovm/tests/files/zrealm_crossrealm33.gno | 62 +++++++- gnovm/tests/files/zrealm_crossrealm34a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm35a.gno | 56 ++++++- gnovm/tests/files/zrealm_crossrealm37a.gno | 36 +++++ gnovm/tests/files/zrealm_crossrealm37b.gno | 6 +- gnovm/tests/files/zrealm_crossrealm40_a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm40_b.gno | 14 -- .../files/zrealm_crossrealm40_method.gno | 2 +- ...o => zrealm_crossrealm41_method_local.gno} | 4 +- .../tests/files/zrealm_crossrealm46_array.gno | 34 +++++ 53 files changed, 1483 insertions(+), 340 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm17a.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm20.gno rename gnovm/tests/files/{zrealm_crossrealm20i.gno => zrealm_crossrealm23c.gno} (69%) delete mode 100644 gnovm/tests/files/zrealm_crossrealm28_0.gno delete mode 100644 gnovm/tests/files/zrealm_crossrealm40_b.gno rename gnovm/tests/files/{zrealm_crossrealm41_method.gno => zrealm_crossrealm41_method_local.gno} (96%) diff --git a/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno index af0a6ecabff..098a7e96e29 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno @@ -28,7 +28,7 @@ func GetFunc2() func() string { } type MyStruct struct{} -type MyStruct2 struct{} +type MyStruct2 struct{ name string } func (sv *MyStruct) M() string { return "a" } @@ -36,13 +36,7 @@ var mysv *MyStruct = &MyStruct{} func (sv2 MyStruct2) M2() string { return "a2" } -var mysv2 = MyStruct2{} - -//var f_local func() string -// -//func init() { -// f_local = mysv.M -//} +var mysv2 = MyStruct2{name: "struct_val"} func GetMethod() func() string { return mysv.M diff --git a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno index 240ae30bd57..50ac6b7abfa 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/slice/crossrealm_slice.gno @@ -9,7 +9,7 @@ var S []Fooer func SetSlice(fs []Fooer) { S = fs for _, f := range fs { - println(f) + f.Foo() } } @@ -80,7 +80,7 @@ func GetSlice3() []XYZ { func GetSlice4(f func(s []XYZ)) { s4 = append(s4, XYZ{"0"}) // this is real after this function - f(s4) // XYZ{"0"} is floating + f(s4) } func GetSlice5() []*XYZ { // TODO, unwrap diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 9bee6f2f39d..ffdc144bd20 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1029,7 +1029,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) { } if isCrossRealm(oo.GetOriginRealm(), rlm.ID) { if !oo.GetIsEscaped() && !oo.GetIsNewEscaped() { - panic("should not attach not escaped/new escaped object from external realm") + panic("cannot attach object from external realm: object must be either escaped or newly escaped") } } // set hash to escape index. diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 495c2423b5e..af560af012c 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -551,23 +551,7 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue { fields[i] = field.Copy(alloc) } - nsv := alloc.NewStruct(fields) - // debug2.Println2("sv.GetOriginRealm: ", sv.GetOriginRealm()) - // debug2.Println2("sv.GetObjectID(): ", sv.GetObjectID()) - // debug2.Println2("sv.GetRefCount: ", sv.GetRefCount()) - // debug2.Println2("sv...OwneID: ", sv.GetObjectInfo().OwnerID) - // append, unref copy... - - // this copy is needed, - // copy origin realm is necessary here because, for example, if `sv` is an embedded struct, - // assigning the containing struct will also copy the embedded struct. - pkgId := sv.GetOriginRealm() - if pkgId.IsZero() { - pkgId = sv.GetObjectID().PkgID - } - nsv.SetOriginRealm(pkgId) - return nsv - // return alloc.NewStruct(fields) + return alloc.NewStruct(fields) } // ---------------------------------------- diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index 28cb760fcb0..1682e1b70d5 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -234,7 +234,7 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte m.RunFiles(n) m.RunStatement(gno.S(gno.Call(gno.X("main")))) } else { - fmt.Println("realm case...") + //fmt.Println("realm case...") // Realm case. gno.DisableDebug() // until main call. diff --git a/gnovm/tests/files/zrealm_crossrealm1.gno b/gnovm/tests/files/zrealm_crossrealm1.gno index 6d66232f675..0c1b5fd92ff 100644 --- a/gnovm/tests/files/zrealm_crossrealm1.gno +++ b/gnovm/tests/files/zrealm_crossrealm1.gno @@ -5,7 +5,7 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. +// NOTE: it is invalid to persist external realm types. var somevalue tests.TestRealmObject func init() { diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 5fb1c4a3f1f..41c83b93493 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -2,135 +2,26 @@ package crossrealm_test import ( + "std" + crossrealm "gno.land/r/demo/tests/crossrealm" ) -type container struct { - name string - f *fooer -} +type container struct{ *fooer } -func (container) Foo() { println("hello " + c.f.name) } +func (container) Foo() { println("hello container " + std.CurrentRealm().PkgPath()) } -type fooer struct{ name string } +type fooer struct{} -var c = &container{name: "local_container"} +var f *fooer func main() { - // the object attaching is heapItemValue, not escaped - // while attempting to attach it to external realm, - // check recursively. - // also see xxx_crossrealm21.gno - ff := &fooer{name: "local_foo"} // should panic, while cross unreal, even ref... - c.f = ff + f = &fooer{} + c := &container{f} // heapItemValue not real, so trying attach by value crossrealm.SetFooer(c) crossrealm.CallFooerFoo() print(".") } -// Output: -// hello local_foo -// . - -// Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", -// "IsEscaped": true, -// "ModTime": "5", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.container" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" -// } -// } -// } -// switchrealm["gno.land/r/crossrealm_test"] -// c[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "local_foo" -// } -// } -// ], -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", -// "RefCount": "1" -// } -// } -// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "90e6414435c56b7ffa17bd575535b7a558b93e22", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" -// } -// } -// } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "local_container" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.fooer" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "7d3bda685439b3989f18e824762f473f40c944fb", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", -// "ModTime": "5", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", -// "RefCount": "1" -// } -// } -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/crossrealm_test"] +// Error: +// cannot attach a value of a type defined by another realm: heapitem((struct{(&(struct{} gno.land/r/crossrealm_test.fooer) *gno.land/r/crossrealm_test.fooer)} gno.land/r/crossrealm_test.container)) diff --git a/gnovm/tests/files/zrealm_crossrealm17a.gno b/gnovm/tests/files/zrealm_crossrealm17a.gno new file mode 100644 index 00000000000..f221b81f6aa --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm17a.gno @@ -0,0 +1,132 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm" +) + +type container struct { + name string + f *fooer +} + +func (container) Foo() { println("hello " + c.f.name) } + +type fooer struct{ name string } + +var c = &container{name: "local_container"} + +func main() { + ff := &fooer{name: "local_foo"} + c.f = ff + crossrealm.SetFooer(c) + crossrealm.CallFooerFoo() + print(".") +} + +// Output: +// hello local_foo +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_foo" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "RefCount": "1" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "90e6414435c56b7ffa17bd575535b7a558b93e22", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" +// } +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_container" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.fooer" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "7d3bda685439b3989f18e824762f473f40c944fb", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index f4c763d5738..6a19f04dbbf 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -17,8 +17,8 @@ func (f *fooer) Foo() { var f *fooer func init() { - f = &fooer{s: "A"} // unreal, refCount 1, owner f - crossrealm.SetFooer(f) // refCount2, escaped + f = &fooer{s: "A"} // unreal, refCount 1, owner f + crossrealm.SetFooer(f) crossrealm.CallFooerFoo() } diff --git a/gnovm/tests/files/zrealm_crossrealm20.gno b/gnovm/tests/files/zrealm_crossrealm20.gno new file mode 100644 index 00000000000..32fac2e95b9 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm20.gno @@ -0,0 +1,43 @@ +// 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"} + fg := func() crossrealm.Fooer { return f } + crossrealm.SetFooerGetter(fg) + crossrealm.CallFooerGetterFoo() + f.s = "C" + crossrealm.CallFooerGetterFoo() +} + +func main() { + print(".") +} + +// Output: +// hello B gno.land/r/crossrealm_test +// hello B gno.land/r/crossrealm_test +// . + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] + +// Error: +// diff --git a/gnovm/tests/files/zrealm_crossrealm20b.gno b/gnovm/tests/files/zrealm_crossrealm20b.gno index 31a1a6e4bbf..93a4e30a5df 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b.gno @@ -8,7 +8,7 @@ import ( // associate to a containing object type Container struct { name string - b crossrealm.Bar // panic while attaching(finalizing) + b crossrealm.Bar } var c Container diff --git a/gnovm/tests/files/zrealm_crossrealm20b1.gno b/gnovm/tests/files/zrealm_crossrealm20b1.gno index 61712343594..7148fee5b9c 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b1.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b1.gno @@ -8,17 +8,18 @@ import ( // associate to a containing object type Container struct { name string - b crossrealm.Bar // panic while attaching(finalizing) + b crossrealm.Bar } var c *Container func init() { - print("ok") + c = &Container{name: "Container", b: crossrealm.Bar{A: 1}} + println(c.b) } func main() { } -// Output: -// ok +// Error: +// cannot attach a value of a type defined by another realm: struct{(1 int)} diff --git a/gnovm/tests/files/zrealm_crossrealm20c3.gno b/gnovm/tests/files/zrealm_crossrealm20c3.gno index 4c7bcaded41..2e6d9ff668c 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c3.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c3.gno @@ -1,10 +1,6 @@ // PKGPATH: gno.land/r/crossrealm_test package crossrealm_test -import ( - crossrealm "gno.land/r/demo/tests/crossrealm/struct" -) - type Node struct { *Node } diff --git a/gnovm/tests/files/zrealm_crossrealm20f.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno index 3699372c9fa..52c86fa568f 100644 --- a/gnovm/tests/files/zrealm_crossrealm20f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -2,7 +2,6 @@ package crossrealm_test import ( - "fmt" crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) @@ -12,8 +11,7 @@ var b Dt func main() { b = &crossrealm.Bar{A: 22} // this should panic - //println(b) - fmt.Println(b) + println(b) } // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm20g.gno b/gnovm/tests/files/zrealm_crossrealm20g.gno index d52a6a1117d..8f54858867b 100644 --- a/gnovm/tests/files/zrealm_crossrealm20g.gno +++ b/gnovm/tests/files/zrealm_crossrealm20g.gno @@ -5,8 +5,6 @@ import ( crossrealm "gno.land/r/demo/tests/crossrealm/struct" ) -// TODO: should panic at once -// var b0 crossrealm.Bar = crossrealm.Bar3 var root interface{} func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm20j.gno b/gnovm/tests/files/zrealm_crossrealm20j.gno index e3b29f671a4..e47dcda0911 100644 --- a/gnovm/tests/files/zrealm_crossrealm20j.gno +++ b/gnovm/tests/files/zrealm_crossrealm20j.gno @@ -4,50 +4,67 @@ package crossrealm_test import ( "std" - "gno.land/r/demo/tests/crossrealm" - "gno.land/r/demo/tests/crossrealm_b" + crossrealm "gno.land/r/demo/tests/crossrealm/iface" ) +type fooer struct { + name string +} + +func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } + +var f fooer + func main() { - f := crossrealm_b.Fooer - crossrealm.SetFooer(f) - crossrealm.CallFooerFoo() - f.SetS("B") - crossrealm.CallFooerFoo() + f = fooer{name: "local_fooer"} // f is dirty + crossrealm.SetContainer2(&f) + crossrealm.RunF() print(".") } // Output: -// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm -// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// hello gno.land/r/crossrealm_test // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "IsEscaped": true, -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } // }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "8222b763e9bc04b4b7805e165e9f1324a39f28b6", -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "1", +// "TV": null +// } // } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" // } // } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ // "Fields": [ // { // "T": { @@ -56,20 +73,17 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "B" +// "value": "local_fooer" // } // } // ], // "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", -// "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "1" // } // } -// switchrealm["gno.land/r/demo/tests/crossrealm_b"] -// switchrealm["gno.land/r/demo/tests/crossrealm"] +// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] // switchrealm["gno.land/r/crossrealm_test"] - -// Error: -// diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index e47dcda0911..e3b29f671a4 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -4,67 +4,50 @@ package crossrealm_test import ( "std" - crossrealm "gno.land/r/demo/tests/crossrealm/iface" + "gno.land/r/demo/tests/crossrealm" + "gno.land/r/demo/tests/crossrealm_b" ) -type fooer struct { - name string -} - -func (fooer) Foo() { println("hello " + std.CurrentRealm().PkgPath()) } - -var f fooer - func main() { - f = fooer{name: "local_fooer"} // f is dirty - crossrealm.SetContainer2(&f) - crossrealm.RunF() + f := crossrealm_b.Fooer + crossrealm.SetFooer(f) + crossrealm.CallFooerFoo() + f.SetS("B") + crossrealm.CallFooerFoo() print(".") } // Output: -// hello gno.land/r/crossrealm_test +// hello A cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm +// hello B cur=gno.land/r/demo/tests/crossrealm_b prev=gno.land/r/demo/tests/crossrealm // . // Realm: -// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] -// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// } +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" // }, -// { -// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" -// }, -// "Index": "1", -// "TV": null -// } +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "8222b763e9bc04b4b7805e165e9f1324a39f28b6", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" // } -// ], -// "ObjectInfo": { -// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", -// "ModTime": "4", -// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", -// "RefCount": "1" // } // } -// switchrealm["gno.land/r/crossrealm_test"] -// c[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// u[0edc46caf30c00efd87b6c272673239eafbd051e:4]={ // "Fields": [ // { // "T": { @@ -73,17 +56,20 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "local_fooer" +// "value": "B" // } // } // ], // "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", -// "ModTime": "0", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:4", +// "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "RefCount": "1" // } // } -// d[f5a516808f8976c33939133293d598ce3bca4e8d:3] -// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/demo/tests/crossrealm_b"] +// switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] + +// Error: +// diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index d5fde82ec7f..ad586b47505 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -13,10 +13,10 @@ func (fooer) Foo() { println("hello") } func main() { // object attaching to external is main block, - // f is a value defined w/i this block, + // f is an unreal value defined w/i this block, // and invalid to attach to external, panic. f := fooer{name: "local_fooer"} - crossrealm.SetContainer2(&f) // refCount 1, f not owner + crossrealm.SetContainer2(&f) print(".") } diff --git a/gnovm/tests/files/zrealm_crossrealm21c.gno b/gnovm/tests/files/zrealm_crossrealm21c.gno index 1fe0344e783..4142dbdb173 100644 --- a/gnovm/tests/files/zrealm_crossrealm21c.gno +++ b/gnovm/tests/files/zrealm_crossrealm21c.gno @@ -22,3 +22,44 @@ func main() { // Output: // hello // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "1", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21d.gno b/gnovm/tests/files/zrealm_crossrealm21d.gno index 48807117673..233c4a3e335 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d.gno @@ -25,3 +25,96 @@ func main() { // Output: // hello // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "2", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_bar" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.bar" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "dac9452dd14f52ea03ff0d5898b481c8e993a412", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// d[f5a516808f8976c33939133293d598ce3bca4e8d:4] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21d1.gno b/gnovm/tests/files/zrealm_crossrealm21d1.gno index fef0063ef22..1fb1e4d565b 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d1.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d1.gno @@ -26,3 +26,103 @@ func main() { // Output: // hello // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "2", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "local_fooer" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.bar" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "IsEscaped": true, +// "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.bar" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "6d19add23dca2c83b923c7d597cefd31a2d5bd90", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// } +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21d2.gno b/gnovm/tests/files/zrealm_crossrealm21d2.gno index 5cf35101466..6d9da581ba9 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d2.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d2.gno @@ -25,3 +25,44 @@ func main() { // Output: // hello // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// u[5836d1a3cec217737a5553d4c1a03d8897d5f281:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// } +// }, +// { +// "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": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "3", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:4", +// "ModTime": "4", +// "OwnerID": "5836d1a3cec217737a5553d4c1a03d8897d5f281:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm/iface"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21f.gno b/gnovm/tests/files/zrealm_crossrealm21f.gno index 34c48369d55..2b7866126fd 100644 --- a/gnovm/tests/files/zrealm_crossrealm21f.gno +++ b/gnovm/tests/files/zrealm_crossrealm21f.gno @@ -10,8 +10,96 @@ func cb(c *crossrealm.C) { } func main() { crossrealm.GetStruct(cb) - println("ok") + println(s) } // Output: -// ok +// &(struct{(ref(5965ae851c02ab677bc8394b408535c1db9b2635:11) gno.land/r/demo/tests/crossrealm/struct.A),(ref(5965ae851c02ab677bc8394b408535c1db9b2635:12) gno.land/r/demo/tests/crossrealm/struct.B),(struct{("d" string)} gno.land/r/demo/tests/crossrealm/struct.D)} gno.land/r/demo/tests/crossrealm/struct.C) + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// u[5965ae851c02ab677bc8394b408535c1db9b2635:9]={ +// "ObjectInfo": { +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", +// "IsEscaped": true, +// "ModTime": "3", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/struct.C" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:10" +// } +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm/struct"] +// c[5965ae851c02ab677bc8394b408535c1db9b2635:14]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "d" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:14", +// "ModTime": "0", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:10", +// "RefCount": "1" +// } +// } +// u[5965ae851c02ab677bc8394b408535c1db9b2635:10]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/struct.A" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "77afd6587e56836f288520b275bebc4911b7ef57", +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:11" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/struct.B" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "c4e78b61af7cd5557452e3d22d20d1c3b1de4b41", +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:12" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/struct.D" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "70a58641e15bf62bf3d1d95ce2e8b2048286f42f", +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:14" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:10", +// "ModTime": "13", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", +// "RefCount": "1" +// } +// } +// d[5965ae851c02ab677bc8394b408535c1db9b2635:13] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22a.gno b/gnovm/tests/files/zrealm_crossrealm22a.gno index 70d6a63855e..8db4a7ad981 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a.gno @@ -23,3 +23,7 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index bc6cac1d9cb..30112f8aa8f 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -12,7 +12,7 @@ type Local_S struct { } func main() { - var ls Local_S // panic + ls := Local_S{name: "local_s"} // panic f := func() bool { c := b return true @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm: struct{("local_s" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm22c.gno b/gnovm/tests/files/zrealm_crossrealm22c.gno index 550a2279370..3dfb16f751e 100644 --- a/gnovm/tests/files/zrealm_crossrealm22c.gno +++ b/gnovm/tests/files/zrealm_crossrealm22c.gno @@ -23,3 +23,7 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22d.gno b/gnovm/tests/files/zrealm_crossrealm22d.gno index c781ad81285..638dcce3ff6 100644 --- a/gnovm/tests/files/zrealm_crossrealm22d.gno +++ b/gnovm/tests/files/zrealm_crossrealm22d.gno @@ -19,3 +19,9 @@ func main() { // Output: // callback // ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22e.gno b/gnovm/tests/files/zrealm_crossrealm22e.gno index 9c86862f4a8..26b970ff875 100644 --- a/gnovm/tests/files/zrealm_crossrealm22e.gno +++ b/gnovm/tests/files/zrealm_crossrealm22e.gno @@ -24,3 +24,7 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm23_pure.gno b/gnovm/tests/files/zrealm_crossrealm23_pure.gno index 2f0e9e1d6f2..a033cb0c3ee 100644 --- a/gnovm/tests/files/zrealm_crossrealm23_pure.gno +++ b/gnovm/tests/files/zrealm_crossrealm23_pure.gno @@ -15,7 +15,8 @@ func main() { print(".") } -// XXX, this works attach value with type defined in p - // Output: // . + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm23b.gno b/gnovm/tests/files/zrealm_crossrealm23b.gno index 825f48bc5a7..8c619564e35 100644 --- a/gnovm/tests/files/zrealm_crossrealm23b.gno +++ b/gnovm/tests/files/zrealm_crossrealm23b.gno @@ -7,16 +7,33 @@ import ( var root interface{} -// TODO: consider this -// should it be valid to attach -// an object by value with type -// from p? maybe yes, but it should -// be invalid if the type is from -// an another realm. func main() { - root = tests.F // already attached in p - println("done:", root) + root = tests.F + println(root) } // Output: -// done: (struct{("p" string)} gno.land/p/demo/tests.Foo) +// (struct{("p" string)} gno.land/p/demo/tests.Foo) + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "p" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm20i.gno b/gnovm/tests/files/zrealm_crossrealm23c.gno similarity index 69% rename from gnovm/tests/files/zrealm_crossrealm20i.gno rename to gnovm/tests/files/zrealm_crossrealm23c.gno index 23b1527fc20..59b45fe8b15 100644 --- a/gnovm/tests/files/zrealm_crossrealm20i.gno +++ b/gnovm/tests/files/zrealm_crossrealm23c.gno @@ -7,10 +7,9 @@ import ( var root = tests.Foo{"p"} -// TODO: also this. func main() { - println("done") + println(root) } // Output: -// done +// (struct{("p" string)} gno.land/p/demo/tests.Foo) diff --git a/gnovm/tests/files/zrealm_crossrealm28_0.gno b/gnovm/tests/files/zrealm_crossrealm28_0.gno deleted file mode 100644 index 4cc74b0361d..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm28_0.gno +++ /dev/null @@ -1,22 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -type foo struct { - name string -} - -var root interface{} - -func main() { - var arr []foo // unreal array with type from local realm - arr = append(arr, foo{name: "1"}) - arr = append(arr, foo{name: "2"}) - arr = append(arr, foo{name: "3"}) - - fs := arr[1:] - root = fs - println("ok") -} - -// Output: -// ok diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index cb309ef0a82..d282e706bd6 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -12,15 +12,13 @@ type foo struct { func (foo) Foo() { println("hello from crossrealm_test") } func main() { - var arr []crossrealm.Fooer // unreal array with type from external realm + var arr []crossrealm.Fooer arr = append(arr, foo{name: "1"}) arr = append(arr, foo{name: "2"}) arr = append(arr, foo{name: "3"}) fs := arr[1:] - // this works cuz it's not crossing realm, - // even underlying array is unreal - crossrealm.SetSlice(fs) // valid + crossrealm.SetSlice(fs) println("ok") } diff --git a/gnovm/tests/files/zrealm_crossrealm28c1.gno b/gnovm/tests/files/zrealm_crossrealm28c1.gno index b9c2fe45c8c..5170ef7362f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c1.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c1.gno @@ -11,12 +11,8 @@ type foo struct { func (foo) Foo() { println("hello from crossrealm_test") } -// TODO: think about these two -// array[(struct{("1" string)} gno.land/r/crossrealm_test.foo),(struct{("2" string)} gno.land/r/crossrealm_test.foo),(struct{("3" string)} gno.land/r/crossrealm_test.foo)] var arr = []crossrealm.Fooer{foo{name: "1"}, foo{name: "2"}, foo{name: "3"}} -//var arr2 = []foo{foo{name: "1"}, foo{name: "2"}, foo{name: "3"}} - func main() { println("ok") } diff --git a/gnovm/tests/files/zrealm_crossrealm28c3.gno b/gnovm/tests/files/zrealm_crossrealm28c3.gno index 15b03a65f64..e6875ec2111 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c3.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c3.gno @@ -15,7 +15,7 @@ var f1 = foo{name: "1"} var f2 = foo{name: "2"} var f3 = foo{name: "3"} -var arr []crossrealm.Fooer // unreal array +var arr []crossrealm.Fooer func init() { arr = append(arr, &f1) @@ -29,12 +29,15 @@ func main() { } // Output: -// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// hello from crossrealm_test +// hello from crossrealm_test +// hello from crossrealm_test // ok // Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm/slice"] // u[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ // "Data": null, diff --git a/gnovm/tests/files/zrealm_crossrealm28c4.gno b/gnovm/tests/files/zrealm_crossrealm28c4.gno index 382ad63e94f..0b2a3dfc596 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c4.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c4.gno @@ -30,3 +30,76 @@ func main() { // &(struct{("2" string)} gno.land/r/crossrealm_test.foo) // &(struct{("3" string)} gno.land/r/crossrealm_test.foo) // ok + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "1", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "2", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:2" +// }, +// "Index": "3", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "1" +// } +// } +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:4] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm28c6.gno b/gnovm/tests/files/zrealm_crossrealm28c6.gno index 80705d7f8fb..9598c3581dd 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c6.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c6.gno @@ -26,3 +26,75 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "1", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "2", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "8", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm28c7.gno b/gnovm/tests/files/zrealm_crossrealm28c7.gno index 9c2715161dd..fedee23ef92 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c7.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c7.gno @@ -25,3 +25,134 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "1", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "2", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "3", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "IsEscaped": true, +// "ModTime": "0", +// "RefCount": "2" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "1" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "RefCount": "1" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "2" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "RefCount": "1" +// } +// } +// c[f5a516808f8976c33939133293d598ce3bca4e8d:8]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "3" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:8", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "RefCount": "1" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm28c9.gno b/gnovm/tests/files/zrealm_crossrealm28c9.gno index 3a0fd198bec..c13be5b00de 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c9.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c9.gno @@ -26,7 +26,7 @@ func main() { } // Output: -// &(struct{("1" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("2" string)} gno.land/r/crossrealm_test.foo) -// &(struct{("3" string)} gno.land/r/crossrealm_test.foo) +// hello from crossrealm_test +// hello from crossrealm_test +// hello from crossrealm_test // ok diff --git a/gnovm/tests/files/zrealm_crossrealm28d2.gno b/gnovm/tests/files/zrealm_crossrealm28d2.gno index 574b2cc101d..30f3e600025 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d2.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d2.gno @@ -27,6 +27,140 @@ func main() { } // Output: -// &(ref(f5a516808f8976c33939133293d598ce3bca4e8d:6) gno.land/r/crossrealm_test.foo) -// &(ref(f5a516808f8976c33939133293d598ce3bca4e8d:8) gno.land/r/crossrealm_test.foo) +// hello from crossrealm_test +// hello from crossrealm_test // ok + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:7" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "5773aa703bad7f19a0b46088a3dee0e05264bc05", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:5]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", +// "IsEscaped": true, +// "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "c8796d0727128e5790ad98d57654f528404d8508", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:6" +// } +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:7]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", +// "IsEscaped": true, +// "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "4336baa01760651f4daf8ddf42c3d8b8db48161b", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:8" +// } +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm28f.gno b/gnovm/tests/files/zrealm_crossrealm28f.gno index 47aa3d3ed4f..cab59c01331 100644 --- a/gnovm/tests/files/zrealm_crossrealm28f.gno +++ b/gnovm/tests/files/zrealm_crossrealm28f.gno @@ -23,3 +23,6 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno index d889c6245f8..4f159a0a431 100644 --- a/gnovm/tests/files/zrealm_crossrealm30.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -14,3 +14,41 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// switchrealm["gno.land/r/crossrealm_test"] +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "c341f36102ff3f8e2f54df678a394e385459dadd", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:16" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "dd8ac5d5b483b2e2ae7fb7fff494674c82d99367", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:17" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15", +// "IsEscaped": true, +// "ModTime": "3", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "2" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm32.gno b/gnovm/tests/files/zrealm_crossrealm32.gno index 26a81fbe50c..18352d18ffc 100644 --- a/gnovm/tests/files/zrealm_crossrealm32.gno +++ b/gnovm/tests/files/zrealm_crossrealm32.gno @@ -14,3 +14,115 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "3" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "RefCount": "1" +// } +// } +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:31]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "0" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:31", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "RefCount": "1" +// } +// } +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "de4d4b9346995296fbd8210badf8bab1c111e60c", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "1570e95bdb3313b5a0656b56b9bba96c9c7704aa", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:31" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "1" +// } +// } +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:18] +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:19] +// switchrealm["gno.land/r/crossrealm_test"] +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "de4d4b9346995296fbd8210badf8bab1c111e60c", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:30" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "1570e95bdb3313b5a0656b56b9bba96c9c7704aa", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:31" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "IsEscaped": true, +// "ModTime": "3", +// "RefCount": "2" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index ffc8dabc2e1..d828bba22ce 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -16,10 +16,70 @@ func main() { // but the array is already attached to // external realm, so the elem has no // chance to attach to this realm. - // so it isd valid. + // so it is valid. crossrealm.GetSlice4(f) println(".") } // Output: // . + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// c[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "0" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29", +// "ModTime": "0", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5", +// "RefCount": "1" +// } +// } +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "9aac0359e72ff36096f642fc4c7d2e134f28993d", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:20" +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/slice.XYZ" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "ada47c453e82855b67936f208c6cc6a5c8698dad", +// "ObjectID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:29" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5", +// "IsEscaped": true, +// "ModTime": "28", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "2" +// } +// } +// d[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:7] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm34a.gno b/gnovm/tests/files/zrealm_crossrealm34a.gno index fa895bb10d9..4572cf2f70e 100644 --- a/gnovm/tests/files/zrealm_crossrealm34a.gno +++ b/gnovm/tests/files/zrealm_crossrealm34a.gno @@ -8,7 +8,7 @@ import ( var SS []*crossrealm.XYZ var f = func(s []*crossrealm.XYZ) { - SS = s // Note, s is dirty, but it's real, so it's ok + SS = s } func main() { diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno index c7cbd6f1988..0e5fb20eb6d 100644 --- a/gnovm/tests/files/zrealm_crossrealm35a.gno +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -16,9 +16,63 @@ var f = &foo{"foo"} var arr interface{} func main() { - arr = crossrealm.GetSlice9(f) // return value is unreal, elem is from local realm + arr = crossrealm.GetSlice9(f) println(".") } // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "de578df5354e812a94f64e23eed06e9705d2b4ef", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm37a.gno b/gnovm/tests/files/zrealm_crossrealm37a.gno index 3b5cd30a175..81ca3fabe0f 100644 --- a/gnovm/tests/files/zrealm_crossrealm37a.gno +++ b/gnovm/tests/files/zrealm_crossrealm37a.gno @@ -16,3 +16,39 @@ func main() { // Output: // ok + +// Realm: +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "List": { +// "List": [ +// { +// "Key": { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "a" +// } +// }, +// "Value": { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// }, +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// switchrealm["gno.land/r/demo/tests/crossrealm/map"] +// switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm37b.gno b/gnovm/tests/files/zrealm_crossrealm37b.gno index e455b0d8dcf..6be87c2a785 100644 --- a/gnovm/tests/files/zrealm_crossrealm37b.gno +++ b/gnovm/tests/files/zrealm_crossrealm37b.gno @@ -3,11 +3,11 @@ package crossrealm_test import crossrealm "gno.land/r/demo/tests/crossrealm/map" -var m1 crossrealm.MyMap +var local_m crossrealm.MyMap // default value is nil func main() { - m1 = crossrealm.GetMap() - println(m1) + local_m = crossrealm.GetMap3() + println("ok") } // Error: diff --git a/gnovm/tests/files/zrealm_crossrealm40_a.gno b/gnovm/tests/files/zrealm_crossrealm40_a.gno index c3cf5abf1e8..789f221776a 100644 --- a/gnovm/tests/files/zrealm_crossrealm40_a.gno +++ b/gnovm/tests/files/zrealm_crossrealm40_a.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{} +// cannot attach a value of a type defined by another realm: struct{("struct_val" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm40_b.gno b/gnovm/tests/files/zrealm_crossrealm40_b.gno deleted file mode 100644 index c3cf5abf1e8..00000000000 --- a/gnovm/tests/files/zrealm_crossrealm40_b.gno +++ /dev/null @@ -1,14 +0,0 @@ -// PKGPATH: gno.land/r/crossrealm_test -package crossrealm_test - -import crossrealm "gno.land/r/demo/tests/crossrealm/func" - -var f func() string - -func main() { - f = crossrealm.GetMethod2() - println(f) -} - -// Error: -// cannot attach a value of a type defined by another realm: struct{} diff --git a/gnovm/tests/files/zrealm_crossrealm40_method.gno b/gnovm/tests/files/zrealm_crossrealm40_method.gno index cfda4c92b89..2755f3e6eb2 100644 --- a/gnovm/tests/files/zrealm_crossrealm40_method.gno +++ b/gnovm/tests/files/zrealm_crossrealm40_method.gno @@ -6,7 +6,7 @@ import crossrealm "gno.land/r/demo/tests/crossrealm/func" var f func() string func main() { - f = crossrealm.GetMethod() // XXX, this attach boundmethodvalue to current realm, shoud panic + f = crossrealm.GetMethod() println(f) } diff --git a/gnovm/tests/files/zrealm_crossrealm41_method.gno b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno similarity index 96% rename from gnovm/tests/files/zrealm_crossrealm41_method.gno rename to gnovm/tests/files/zrealm_crossrealm41_method_local.gno index d2123975c48..83b0e93b52b 100644 --- a/gnovm/tests/files/zrealm_crossrealm41_method.gno +++ b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno @@ -26,7 +26,7 @@ func main() { // "Escaped": true, // "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:5" // }, -// "FileName": "files/zrealm_crossrealm41_method.gno", +// "FileName": "files/zrealm_crossrealm41_method_local.gno", // "IsMethod": true, // "Name": "M", // "NativeName": "", @@ -37,7 +37,7 @@ func main() { // "BlockNode": null, // "Location": { // "Column": "1", -// "File": "files/zrealm_crossrealm41_method.gno", +// "File": "files/zrealm_crossrealm41_method_local.gno", // "Line": "8", // "PkgPath": "gno.land/r/crossrealm_test" // } diff --git a/gnovm/tests/files/zrealm_crossrealm46_array.gno b/gnovm/tests/files/zrealm_crossrealm46_array.gno index 62f6128ef6b..947f301ac73 100644 --- a/gnovm/tests/files/zrealm_crossrealm46_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm46_array.gno @@ -14,3 +14,37 @@ func main() { // Output: // . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/array"] +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/array.Foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f429d463f62fe87134a149198611dfa41bd006ec:2" +// }, +// "Index": "1", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } From 3bdaab2414cb8c2b0ea9fb12a68c4d95a7236a48 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 16 Feb 2025 14:54:28 +0800 Subject: [PATCH 77/88] clean --- .../upgrade_e/v1impl/v1impl.gno | 2 +- gnovm/pkg/gnolang/debug.go | 12 -- gnovm/pkg/gnolang/debug_false.go | 4 - gnovm/pkg/gnolang/gno_test.go | 1 + gnovm/pkg/gnolang/machine.go | 5 - gnovm/pkg/gnolang/op_assign.go | 2 - gnovm/pkg/gnolang/op_call.go | 7 - gnovm/pkg/gnolang/op_decl.go | 2 - gnovm/pkg/gnolang/op_eval.go | 1 - gnovm/pkg/gnolang/op_exec.go | 1 - gnovm/pkg/gnolang/op_expressions.go | 2 - gnovm/pkg/gnolang/ownership.go | 30 +-- gnovm/pkg/gnolang/realm.go | 201 ++++++------------ gnovm/pkg/gnolang/store.go | 7 +- gnovm/pkg/gnolang/uverse.go | 7 - gnovm/pkg/gnolang/values.go | 33 +-- gnovm/pkg/test/filetest.go | 2 - ...rray.gno => zrealm_crossrealm24_array.gno} | 0 ...rray.gno => zrealm_crossrealm25_array.gno} | 0 ...rray.gno => zrealm_crossrealm26_array.gno} | 0 20 files changed, 87 insertions(+), 232 deletions(-) rename gnovm/tests/files/{zrealm_crossrealm44_array.gno => zrealm_crossrealm24_array.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm45_array.gno => zrealm_crossrealm25_array.gno} (100%) rename gnovm/tests/files/{zrealm_crossrealm46_array.gno => zrealm_crossrealm26_array.gno} (100%) diff --git a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno index 697b3be369b..759e20c86e4 100644 --- a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno +++ b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_e/v1impl/v1impl.gno @@ -14,7 +14,7 @@ func init() { home.SetImpl(impl) } -type Impl struct{} +type Impl struct{} // make it real first func (i Impl) Render(path string) string { return "hello from v1" } func (i Impl) Foo() error { return errors.New("not implemented") } diff --git a/gnovm/pkg/gnolang/debug.go b/gnovm/pkg/gnolang/debug.go index 91c5dc86603..0f9cb9a1f9c 100644 --- a/gnovm/pkg/gnolang/debug.go +++ b/gnovm/pkg/gnolang/debug.go @@ -47,18 +47,6 @@ func init() { var enabled bool = true -func (debugging) Println2(args ...interface{}) { - if debug2 { - fmt.Println(append([]interface{}{"DEBUG:"}, args...)...) - } -} - -func (debugging) Printf2(format string, args ...interface{}) { - if debug2 { - fmt.Printf("DEBUG: "+format, args...) - } -} - func (debugging) Println(args ...interface{}) { if debug { if enabled { diff --git a/gnovm/pkg/gnolang/debug_false.go b/gnovm/pkg/gnolang/debug_false.go index bf213870a3a..ce714452be7 100644 --- a/gnovm/pkg/gnolang/debug_false.go +++ b/gnovm/pkg/gnolang/debug_false.go @@ -3,7 +3,3 @@ package gnolang const debug debugging = false - -//const debug2 debugging = true - -const debug2 debugging = false diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index cc208d64c41..5a8c6faf315 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -311,6 +311,7 @@ func BenchmarkIfStatement(b *testing.B) { func main() { for i:=0; i<10000; i++ { if i > 10 { + } } }` diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 0fc36c42f27..7b89e98eb6d 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -257,7 +257,6 @@ func (m *Machine) RunMemPackageWithOverrides(memPkg *gnovm.MemPackage, save bool } func (m *Machine) runMemPackage(memPkg *gnovm.MemPackage, save, overrides bool) (*PackageNode, *PackageValue) { - debug2.Println2("runMemPackage, save: ", save) // parse files. files := ParseMemPackage(memPkg) if !overrides { @@ -545,7 +544,6 @@ func (m *Machine) runFileDecls(fns ...*FileNode) []TypedValue { // recursive function for var declarations. var runDeclarationFor func(fn *FileNode, decl Decl) runDeclarationFor = func(fn *FileNode, decl Decl) { - debug2.Println2("runDeclarationFor, decl: ", decl) // get fileblock of fn. // fb := pv.GetFileBlock(nil, fn.Name) // get dependencies of decl. @@ -639,20 +637,17 @@ func (m *Machine) runInitFromUpdates(pv *PackageValue, updates []TypedValue) { // Returns a throwaway realm package is not a realm, // such as stdlibs or /p/ packages. func (m *Machine) saveNewPackageValuesAndTypes() (throwaway *Realm) { - debug2.Println2("saveNewPackageValuesAndTypes...") // save package value and dependencies. pv := m.Package if pv.IsRealm() { rlm := pv.Realm rlm.MarkNewReal(pv) - debug2.Println2("===realm, finalizing throwaway") rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) // save package realm info. m.Store.SetPackageRealm(rlm) } else { // use a throwaway realm. rlm := NewRealm(pv.PkgPath) rlm.MarkNewReal(pv) - debug2.Println2("NOT realm, finalizing throwaway") rlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) throwaway = rlm } diff --git a/gnovm/pkg/gnolang/op_assign.go b/gnovm/pkg/gnolang/op_assign.go index 53cfbe5cad8..51328f2c509 100644 --- a/gnovm/pkg/gnolang/op_assign.go +++ b/gnovm/pkg/gnolang/op_assign.go @@ -2,7 +2,6 @@ package gnolang func (m *Machine) doOpDefine() { s := m.PopStmt().(*AssignStmt) - debug2.Println2("---doOpDefine, s: ", s) // Define each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. @@ -27,7 +26,6 @@ func (m *Machine) doOpDefine() { func (m *Machine) doOpAssign() { s := m.PopStmt().(*AssignStmt) - debug2.Println2("doOpAssign, s: ", s) // Assign each value evaluated for Lhs. // NOTE: PopValues() returns a slice in // forward order, not the usual reverse. diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index 36b407f5cc5..ba5b7507cff 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -62,7 +62,6 @@ func (m *Machine) doOpCall() { // Create new block scope. clo := fr.Func.GetClosure(m.Store) b := m.Alloc.NewBlock(fr.Func.GetSource(m.Store), clo) - debug2.Println2("doOpCall, b: ", b) // Copy *FuncValue.Captures into block // NOTE: addHeapCapture in preprocess ensures order. @@ -199,8 +198,6 @@ func (m *Machine) doOpCallDeferNativeBody() { // Assumes that result values are pushed onto the Values stack. func (m *Machine) doOpReturn() { - debug2.Println2("doOpReturn") - debug2.Println2("---done doOpReturn") cfr := m.PopUntilLastCallFrame() // See if we are exiting a realm boundary. // NOTE: there are other ways to implement realm boundary transitions, @@ -220,7 +217,6 @@ func (m *Machine) doOpReturn() { finalize = true } if finalize { - debug2.Println2("doOpReturn, finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -233,7 +229,6 @@ func (m *Machine) doOpReturn() { // Like doOpReturn, but with results from the block; // i.e. named result vars declared in func signatures. func (m *Machine) doOpReturnFromBlock() { - debug2.Println2("doOpReturnFromBlock") // Copy results from block. cfr := m.PopUntilLastCallFrame() ft := cfr.Func.GetType(m.Store) @@ -257,7 +252,6 @@ func (m *Machine) doOpReturnFromBlock() { finalize = true } if finalize { - debug2.Println2("finalizing") // Finalize realm updates! // NOTE: This is a resource intensive undertaking. crlm.FinalizeRealmTransaction(m.ReadOnly, m.Store) @@ -271,7 +265,6 @@ func (m *Machine) doOpReturnFromBlock() { // deferred statements can refer to results with name // expressions. func (m *Machine) doOpReturnToBlock() { - debug2.Println2("doOpReturnToBlock") cfr := m.MustLastCallFrame(1) ft := cfr.Func.GetType(m.Store) numParams := len(ft.Params) diff --git a/gnovm/pkg/gnolang/op_decl.go b/gnovm/pkg/gnolang/op_decl.go index 5a09bfabfe5..c9c04ccf76d 100644 --- a/gnovm/pkg/gnolang/op_decl.go +++ b/gnovm/pkg/gnolang/op_decl.go @@ -6,7 +6,6 @@ import ( func (m *Machine) doOpValueDecl() { s := m.PopStmt().(*ValueDecl) - debug2.Println2("doOpValueDecl, s: ", s) lb := m.LastBlock() nt := Type(nil) if s.Type != nil { @@ -27,7 +26,6 @@ func (m *Machine) doOpValueDecl() { } else { tv = TypedValue{T: nt, V: defaultValue(m.Alloc, nt)} } - debug2.Println2("rvs is nil, using default value,: ", tv) } else { tv = rvs[i] } diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index aed467c471a..2aa13b21753 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -23,7 +23,6 @@ func (m *Machine) doOpEval() { debug.Printf("EVAL: (%T) %v\n", x, x) // fmt.Println(m.String()) } - debug2.Printf2("EVAL: (%T) %v\n", x, x) // This case moved out of switch for performance. // TODO: understand this better. if nx, ok := x.(*NameExpr); ok { diff --git a/gnovm/pkg/gnolang/op_exec.go b/gnovm/pkg/gnolang/op_exec.go index d7425cf6d90..5f71ffefa0c 100644 --- a/gnovm/pkg/gnolang/op_exec.go +++ b/gnovm/pkg/gnolang/op_exec.go @@ -431,7 +431,6 @@ EXEC_SWITCH: if debug { debug.Printf("EXEC: %v\n", s) } - debug2.Printf2("EXEC: %v\n", s) switch cs := s.(type) { case *AssignStmt: switch cs.Op { diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index 87a9cd345c4..c0f6225740b 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -758,12 +758,10 @@ func (m *Machine) doOpStructLit() { } func (m *Machine) doOpFuncLit() { - debug2.Println2("doOpFuncLit") x := m.PopExpr().(*FuncLitExpr) ft := m.PopValue().V.(TypeValue).Type.(*FuncType) lb := m.LastBlock() m.Alloc.AllocateFunc() - debug2.Println2("lb: ", lb) // First copy closure captured heap values // to *FuncValue. Later during doOpCall a block diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index bb3698789e1..7fa65b39302 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -3,7 +3,6 @@ package gnolang import ( "encoding/hex" "fmt" - "reflect" "strconv" "strings" ) @@ -170,6 +169,7 @@ type ObjectInfo struct { owner Object // mem reference to owner. } +// Copy used for serialization of objects. // Note that "owner" is nil. func (oi *ObjectInfo) Copy() ObjectInfo { return ObjectInfo{ @@ -333,7 +333,6 @@ func (oi *ObjectInfo) GetOriginRealm() PkgID { } func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { - debug2.Println2("SetOriginRealm: ", pkgId, pkgId.purePkg) oi.originRealm = pkgId } @@ -367,10 +366,8 @@ func (oi *ObjectInfo) GetIsTransient() bool { // XXX, get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { - debug2.Printf2("GetFirstObject, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case PointerValue: - // debug2.Println2("pointer value, base: ", cv.Base) return cv.GetBase(store) case *ArrayValue: return cv @@ -406,36 +403,25 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // if the object is real, it's retrieved from objectID, // otherwise, it's inference from its type. func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { - debug2.Println2("GetOriginPkg, tv: ", tv, reflect.TypeOf(tv.V)) - - // attempting to retrieve the original package using the ObjectID + // attempting to retrieve the original package from ObjectID obj := tv.GetFirstObject(store) - debug2.Printf2("obj: %v (type: %v) \n", obj, reflect.TypeOf(obj)) if obj != nil { - debug2.Println2("GetIsReal: ", obj.GetIsReal()) - // origin realm maybe set while association, even - // it's un-real. originPkg = obj.GetOriginRealm() if !originPkg.IsZero() { - debug2.Println2("1, got originPkg from object: ", originPkg, originPkg.purePkg) return } originPkg = obj.GetObjectID().PkgID if !originPkg.IsZero() { - debug2.Println2("2, got originPkg from object: ", originPkg, originPkg.purePkg) return } } // attempting to infer original package using declared type + // if it does not have an objectID(unreal) getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { - debug2.Printf2("getPkgId, dt: %v, dt.Base: %v, dt.Base.PkgPath: %s \n", dt, dt.Base, dt.Base.GetPkgPath()) - //if IsRealmPath(dt.Base.GetPkgPath()) { pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) - debug2.Println2("pkgId.purePkg: ", pkgId.purePkg) return - //} } return } @@ -445,15 +431,11 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { originPkg = getPkgId(cv.Value.T) return case *BoundMethodValue: - debug2.Println2("BoundMethodValue, recv: ", cv.Receiver) - //if pv, ok := cv.Receiver.V.(PointerValue); ok { - // originPkg = getPkgId(pv.TV.T) - //} + // do nothing return case *MapValue, *StructValue, *ArrayValue: - // if it's declared type, - // origin package is deduced - // from type, otherwise zero. + // if it's a declared type, origin realm + // is deduced from type, otherwise zero. originPkg = getPkgId(tv.T) return default: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index ffdc144bd20..466d79b1f2c 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -155,29 +155,30 @@ func (rlm *Realm) String() string { //---------------------------------------- // ownership hooks -// ref value is the derived value from co, like a slice. func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { - debug2.Printf2( - "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", - po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), - ) + if debug { + debug.Printf( + "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", + po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), + ) - if rlm != nil { - debug2.Println2("rlm.ID: ", rlm.ID) - } + if rlm != nil { + debug.Println("rlm.ID: ", rlm.ID) + } - if po != nil { - debug2.Println2("po.GetIsReal: ", po.GetIsReal()) - } + if po != nil { + debug.Println("po.GetIsReal: ", po.GetIsReal()) + } - if co != nil { - debug2.Printf2( - "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", - co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), - ) + if co != nil { + debug.Printf( + "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", + co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), + ) - if b, ok := co.(*Block); ok { - debug2.Printf2("b.source: %v (type: %v) \n", b.Source, reflect.TypeOf(b.Source)) + if b, ok := co.(*Block); ok { + debug.Printf("b.source: %v (type: %v) \n", b.Source, reflect.TypeOf(b.Source)) + } } } @@ -197,7 +198,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } if po == nil || !po.GetIsReal() { // XXX, make sure po is attached - debug2.Println2("po not real, do nothing!!!") return // do nothing. } @@ -221,7 +221,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { // XXX, inc ref count everytime assignment happens co.IncRefCount() - debug2.Println2("co.GetRecCount() after inc: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsReal() { rlm.MarkDirty(co) @@ -232,16 +231,13 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { rlm.MarkNewEscapedCheckCrossRealm(store, co) } } else { - debug2.Printf2("co.GetIsReal: %t \n", co.GetIsReal()) if co.GetIsReal() { // TODO: how this happen? rlm.MarkDirty(co) } else { - debug2.Printf2("set owner of %v to be %v \n", co, po) co.SetOwner(po) rlm.MarkNewReal(co) } // check cross realm for non escaped objects - debug2.Println2("=========po is real, check cross realm========") checkCrossRealm(rlm, store, co, false, nil) // XXX, always false? } } @@ -258,37 +254,33 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } -// check cross realm recursively +// checkCrossRealm2 checks cross realm recursively func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, seenObjs []Object) { - debug2.Printf2("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) + if debug { + debug.Printf("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) + } tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { - debug2.Println2("is object, GetIsReal: ", oo.GetIsReal()) - // set origin realm for embedded value oo.SetOriginRealm(tv2.GetOriginPkg(store)) checkCrossRealm(rlm, store, oo, isLastRef, seenObjs) - } else { // reference to object + } else { switch tv.V.(type) { - case *SliceValue, PointerValue: // if reference object from external realm - // XXX: consider pkgId here, A -> B - > A?... + case *SliceValue, PointerValue: reo := tv.GetFirstObject(store) - debug2.Println2("is reference to object, reo: ", reo) - debug2.Println2("is reference to object, tv2.V, type of : ", tv2.V, reflect.TypeOf(tv2.V)) - - // if a pointer has a base in - // current realm, implies the - // current realm is finalizing, - // just skip as a recursive guard. + // if it is checking a pointer, and it + // has a base in current realm, implies + // the current realm is finalizing, + // just skip the next recursive step. if _, ok := tv2.V.(PointerValue); ok { // check recursive if slices.Contains(seenObjs, reo) { - debug2.Printf2("stack contains reo, return: ", reo) seenObjs = nil return } seenObjs = append(seenObjs, reo) } + // set origin realm info reo.SetOriginRealm(tv2.GetOriginPkg(store)) reo.SetIsAttachingRef(true) checkCrossRealm(rlm, store, reo, isLastRef, seenObjs) @@ -297,18 +289,18 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s } // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. -// refValue is required to handle cases where the value is a slice. -// The `len` and `offset` are needed to validate proper elements of the underlying array. -// NOTE, oo can be real or unreal. -func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, seenObjs []Object) { - debug2.Printf2("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v \n", - oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID) - - debug2.Printf2( - "isLastRef: %t | isCurrentRef: %t\n", - isLastRef, oo.GetIsAttachingRef(), - ) +func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, seenObjs []Object) { + if debug { + debug.Printf("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v \n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID) + debug.Printf( + "isLastRef: %t | isCurrentRef: %t\n", + isAttachingRef, oo.GetIsAttachingRef(), + ) + } + + // object from pure package is ok if oo.GetOriginRealm().IsPurePkg() { return } @@ -317,44 +309,37 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isLastRef bool, seenObj // If the last object was not a reference, but the current one is, // then the current object and its children are referenced. // refer 20c, 20c2 - if !isLastRef { - isLastRef = oo.GetIsAttachingRef() + if !isAttachingRef { + isAttachingRef = oo.GetIsAttachingRef() } - if oo.GetOriginRealm().IsZero() { - debug2.Println2("origin realm is zero, it's unreal, check elems...") - checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) - return - } - - if rlm.ID == oo.GetOriginRealm() { - debug2.Println2("oo Not crossing realm, recursively check for local realm") - // for local realm checking - // maybe a container not cross - // but embedded field does. - checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) + // for local realm checking, maybe a container not cross, + // but its children does. + if oo.GetOriginRealm().IsZero() || rlm.ID == oo.GetOriginRealm() { + checkCrossRealmChildren(rlm, store, oo, isAttachingRef, seenObjs) return } if rlm.ID != oo.GetOriginRealm() { // crossing realm - if isLastRef { + // When attaching a reference, ensure that the base object is real. + // The child objects do not need to be real at this stage; + // they can be attached(real) after. + if isAttachingRef { if !oo.GetIsReal() { panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) } else { - debug2.Println2("reference base is REAL, NO return, check recursively") - //checkCrossRealmChildren(rlm, store, oo, isLastRef, seenObjs) return } - } else { // not reference to object + } else { panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) } } } +// checkCrossRealmChildren check if children is crossing realm func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, seenObjs []Object) { switch v := oo.(type) { case *StructValue: - // check fields for _, fv := range v.Fields { checkCrossRealm2(rlm, store, &fv, isLastRef, seenObjs) // ref to struct is heapItemValue or block } @@ -368,11 +353,9 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, o2 := v.Func.Closure.(Object) // the closure must be a real fileBlock if !o2.GetIsReal() { - panic("bound method closure should be real") + panic("BoundMethod closure should be real") } case *Block: - // NOTE, it's not escaped until now, - // will set after check for _, tv := range v.Values { checkCrossRealm2(rlm, store, &tv, isLastRef, seenObjs) } @@ -395,13 +378,14 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, // MarkNewEscapedCheckCrossRealm mark new escaped object // and check cross realm func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { - debug2.Printf2( - "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetRefCount: %d | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", - oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsAttachingRef(), rlm.ID, - ) + if debug { + debug.Printf( + "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetRefCount: %d | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", + oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsAttachingRef(), rlm.ID, + ) + } if oo.GetOriginRealm() == rlm.ID { - debug2.Println2("1, mark oo new escaped: ", oo) rlm.MarkNewEscaped(oo) // do nothing return @@ -410,19 +394,16 @@ func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { // originRealm can be zero, e.g. an array value // in current realm, and it's referenced twice. originRealm := oo.GetOriginRealm() - if !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlm.ID { // crossing realm + if isCrossRealm(originRealm, rlm.ID) { if !oo.GetIsAttachingRef() { panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", oo)) } - //checkCrossRealm(rlm, store, oo, true, nil) } // mark escaped - debug2.Println2("mark oo new escaped: ", oo) rlm.MarkNewEscaped(oo) } func (rlm *Realm) MarkNewReal(oo Object) { - debug2.Printf2("MarkNewReal, rlm.ID: %s | oo: %v \n", rlm.ID, oo) if debug { if pv, ok := oo.(*PackageValue); ok { // packages should have no owner. @@ -455,7 +436,6 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - debug2.Printf2("MarkDirty, rlm.ID: %s | oo: %v \n", rlm.ID, oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -525,10 +505,6 @@ func (rlm *Realm) MarkNewEscaped(oo Object) { // to a realm gets attached here, which should panic. // OpReturn calls this when exiting a realm transaction. func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { - debug2.Println2("FinalizeRealmTransaction, rlm.ID: ", rlm.ID) - defer func() { - debug2.Println2("================done FinalizeRealmTransaction==================") - }() if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -598,16 +574,10 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { // All newly created objects become appended to .created, // and get assigned ids. func (rlm *Realm) processNewCreatedMarks(store Store) { - debug2.Println2("processNewCreatedMarks") - // fmt.Println("---len of newCreated objects:", len(rlm.newCreated)) // Create new objects and their new descendants. // for _, oo := range rlm.newCreated { for i := 0; i < len(rlm.newCreated); i++ { oo := rlm.newCreated[i] - debug2.Printf2("---oo[%d] is: %v (type: %v) \n", i, oo, reflect.TypeOf(oo)) - //if _, ok := oo.(*BoundMethodValue); ok { - // panic("should not happen persist bound method") - //} if debug { if oo.GetIsDirty() { panic("new created mark cannot be dirty") @@ -642,7 +612,6 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // oo must be marked new-real, and ref-count already incremented. func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { - debug2.Printf2("incRefCreatedDescendants, oo: %v (type: %v) \n", oo, reflect.TypeOf(oo)) if debug { if oo.GetIsDirty() { panic("cannot increase reference of descendants of dirty objects") @@ -657,7 +626,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // this happens when a node marked created was already // visited via recursion from a prior marked created. if !oo.GetObjectID().IsZero() { - debug2.Println2("not zero, do nothing, return") return } rlm.assignNewObjectID(oo) @@ -666,8 +634,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // recurse for children. more := getChildObjects2(store, oo) - for i, child := range more { - debug2.Printf2("---[%d]child: %v, (type: %v) \n", i, child, reflect.TypeOf(child)) + for _, child := range more { if _, ok := child.(*PackageValue); ok { if debug { if child.GetRefCount() < 1 { @@ -683,7 +650,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { if child.GetIsReal() { // a deleted real became undeleted. child.SetOwner(oo) - debug2.Println2("mark dirty, rc == 1") rlm.MarkDirty(child) } else { // a (possibly pre-existing) new object @@ -695,7 +661,6 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { child.SetIsNewReal(true) } } else if rc > 1 { - debug2.Println2("mark dirty, rc: ", rc) rlm.MarkDirty(child) if child.GetIsEscaped() { // already escaped, do nothing. @@ -721,9 +686,7 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) { // to rlm.deleted. // Must run *after* processNewCreatedMarks(). func (rlm *Realm) processNewDeletedMarks(store Store) { - debug2.Println2("processNewDeletedMarks") for _, oo := range rlm.newDeleted { - debug2.Println2("oo: ", oo, oo.GetRefCount()) if debug { if oo.GetObjectID().IsZero() { panic("new deleted mark should have an object ID") @@ -741,7 +704,6 @@ func (rlm *Realm) processNewDeletedMarks(store Store) { // Like incRefCreatedDescendants but decrements. func (rlm *Realm) decRefDeletedDescendants(store Store, oo Object) { - debug2.Println2("decRefDeletedDescendants, oo: ", oo) if debug { if oo.GetObjectID().IsZero() { panic("cannot decrement references of deleted descendants of object with no object ID") @@ -768,13 +730,11 @@ func (rlm *Realm) decRefDeletedDescendants(store Store, oo Object) { // recurse for children more := getChildObjects2(store, oo) for _, child := range more { - debug2.Println2("child: ", child) child.DecRefCount() rc := child.GetRefCount() if rc == 0 { rlm.decRefDeletedDescendants(store, child) } else if rc > 0 { - debug2.Println2("mark dirty for refCount changes...") rlm.MarkDirty(child) } else { panic("deleted descendants should not have a reference count of less than zero") @@ -789,7 +749,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) { - debug2.Println2("processNewEscapedMarks") escaped := make([]Object, 0, len(rlm.newEscaped)) // These are those marked by MarkNewEscaped(), // regardless of whether new-real or was real, @@ -851,7 +810,6 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // (ancestors) must be marked as dirty to update the // hash tree. func (rlm *Realm) markDirtyAncestors(store Store) { - debug2.Println2("markDirtyAncestors") markAncestorsOne := func(oo Object) { for { if pv, ok := oo.(*PackageValue); ok { @@ -920,12 +878,7 @@ func (rlm *Realm) markDirtyAncestors(store Store) { // Saves .created and .updated objects. func (rlm *Realm) saveUnsavedObjects(store Store) { - debug2.Printf2("saveUnsavedObjects, len(updated): %d | rlm.ID: %s \n", len(rlm.updated), rlm.ID) - for i, uo := range rlm.updated { - debug2.Printf2("uo[%d] is %v \n", i, uo) - } for _, co := range rlm.created { - debug2.Println2("co: ", co) // for i := len(rlm.created) - 1; i >= 0; i-- { // co := rlm.created[i] if !co.GetIsNewReal() { @@ -937,7 +890,6 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { } } for _, uo := range rlm.updated { - debug2.Println2("===uo: ", uo) if !uo.GetIsDirty() { // might have happened already as child // of something else created/dirty. @@ -950,7 +902,6 @@ func (rlm *Realm) saveUnsavedObjects(store Store) { // store unsaved children first. func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { - debug2.Println2("saveUnsavedObjectRecursively, oo, rlm.ID: ", oo, rlm.ID) if debug { if !oo.GetIsNewReal() && !oo.GetIsDirty() { panic("cannot save new real or non-dirty objects") @@ -967,26 +918,23 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { panic("cannot save deleted objects") } } - unsaved := []Object(nil) // first, save unsaved children. // leave unreal external object // to be attached in their own realm + unsaved := []Object(nil) + // if oo is from external realm, imply it's already real, + // and it's attaching by ref, (after the checkCrossReal logic) + // skip its unreal child, to be attached in respective realm if !isCrossRealm(oo.GetOriginRealm(), rlm.ID) { unsaved = getUnsavedChildObjects(oo) } - //unsaved := getUnsavedChildObjects(oo) - debug2.Println2("unsaved: ", unsaved) for _, uch := range unsaved { - debug2.Println2("uch: ", uch) - // TODO: make it ahead of here. if uch.GetIsEscaped() || uch.GetIsNewEscaped() { - debug2.Println2("uch is escaped or new escape") // no need to save preemptively. } else { rlm.saveUnsavedObjectRecursively(store, uch) } } - debug2.Println2("then, save self, oo: ", oo) // NOTE, won't be any external unreal here. // then, save self. @@ -1019,11 +967,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } func (rlm *Realm) saveObject(store Store, oo Object) { - debug2.Println2("saveObject: ", oo) oid := oo.GetObjectID() - debug2.Println2("---oid: ", oid) - debug2.Println2("---oo.GetRefCount: ", oo.GetRefCount()) - debug2.Println2("---oo.GetEscaped: ", oo.GetIsEscaped()) if oid.IsZero() { panic("unexpected zero object id") } @@ -1095,7 +1039,6 @@ func (rlm *Realm) clearMarks() { // Value is either Object or RefValue. // Shallow; doesn't recurse into objects. func getSelfOrChildObjects(val Value, more []Value) []Value { - // debug2.Printf2("getSelfOrChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) if _, ok := val.(RefValue); ok { return append(more, val) } else if _, ok := val.(Object); ok { @@ -1108,7 +1051,6 @@ func getSelfOrChildObjects(val Value, more []Value) []Value { // Gets child objects. // Shallow; doesn't recurse into objects. func getChildObjects(val Value, more []Value) []Value { - // debug2.Printf2("getChildObjects, val: %v (type: %v) \n", val, reflect.TypeOf(val)) switch cv := val.(type) { case nil: return more @@ -1177,7 +1119,6 @@ func getChildObjects(val Value, more []Value) []Value { // Generally the parent block must also be persisted. // Otherwise NamePath may not resolve when referencing // a parent block. - debug2.Println2("block value, get parent recursively") more = getSelfOrChildObjects(cv.Parent, more) return more case *HeapItemValue: @@ -1213,7 +1154,6 @@ func getChildObjects2(store Store, val Value) []Object { // Gets all unsaved child objects. // Shallow; doesn't recurse into objects. func getUnsavedChildObjects(val Value) []Object { - debug2.Println2("getUnsavedChildObjects, val: ", val) vals := getChildObjects(val, nil) unsaved := make([]Object, 0, len(vals)) for _, val := range vals { @@ -1229,7 +1169,6 @@ func getUnsavedChildObjects(val Value) []Object { } else if obj, ok := val.(Object); ok { // if object... if isUnsavedInRealm(obj) { - debug2.Println2("obj is unsaved...") unsaved = append(unsaved, obj) } } else { @@ -1733,15 +1672,11 @@ func (rlm *Realm) nextObjectID() ObjectID { // Object gets its id set (panics if already set), and becomes // marked as new and real. func (rlm *Realm) assignNewObjectID(oo Object) ObjectID { - debug2.Printf2("assignNewObjectID, rlm: %v | rlm.Path: %s | oo: %v \n", rlm, rlm.Path, oo) - debug2.Printf2("%s is Realm path: %t \n", rlm.Path, IsRealmPath(rlm.Path)) oid := oo.GetObjectID() - debug2.Println2("oid: ", oid) if !oid.IsZero() { panic("unexpected non-zero object id") } noid := rlm.nextObjectID() - debug2.Printf2("noid: %s | purePkg: %t \n", noid, noid.PkgID.purePkg) oo.SetObjectID(noid) return noid } @@ -1843,8 +1778,6 @@ func refOrCopyValue(tv TypedValue) TypedValue { } func isUnsavedInRealm(oo Object) bool { - debug2.Printf2("check is Unsaved, oo: %v | oo.GetIsEscaped: %t | oo.GetIsNewEscaped: %t | oo.GetIsNewReal: %t | oo.getIsDirty: %t \n", - oo, oo.GetIsEscaped(), oo.GetIsNewEscaped(), oo.GetIsNewReal(), oo.GetIsDirty()) return oo.GetIsNewReal() || oo.GetIsDirty() } @@ -1873,7 +1806,7 @@ func getOwner(store Store, oo Object) Object { return po } +// check if it's crossing realm func isCrossRealm(originRealm, rlmID PkgID) bool { - debug2.Printf2("originRealm: %s | rlmID: %s \n", originRealm, rlmID) return !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlmID } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 21986ab4f78..5d2970929b1 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -266,7 +266,6 @@ func (ds *defaultStore) SetPackageGetter(pg PackageGetter) { // Gets package from cache, or loads it from baseStore, or gets it from package getter. func (ds *defaultStore) GetPackage(pkgPath string, isImport bool) *PackageValue { - debug2.Printf2("GetPackage: %s \n", pkgPath) // helper to detect circular imports if isImport { if slices.Contains(ds.current, pkgPath) { @@ -472,7 +471,9 @@ func (ds *defaultStore) loadObjectSafe(oid ObjectID) Object { // NOTE: unlike GetObject(), SetObject() is also used to persist updated // package values. func (ds *defaultStore) SetObject(oo Object) { - debug2.Printf2("SetObject: %v | oo.GetIsNewReal: %t | oo.GetIsReal: %t \n", oo, oo.GetIsNewReal(), oo.GetIsReal()) + if debug { + debug.Printf("SetObject: %v | oo.GetIsNewReal: %t | oo.GetIsReal: %t \n", oo, oo.GetIsNewReal(), oo.GetIsReal()) + } if bm.OpsEnabled { bm.PauseOpCode() defer bm.ResumeOpCode() @@ -485,10 +486,8 @@ func (ds *defaultStore) SetObject(oo Object) { }() } oid := oo.GetObjectID() - //debug2.Println2("oid: ", oid, oid.PkgID.purePkg) // replace children/fields with Ref. o2 := copyValueWithRefs(oo) - debug2.Println2("---o2: ", o2) // marshal to binary. bz := amino.MustMarshalAny(o2) gas := overflow.Mul64p(ds.gasConfig.GasSetObject, store.Gas(len(bz))) diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index c02c6de1144..c91da114ed1 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -177,7 +177,6 @@ func makeUverseNode() { "res", GenT("X", nil), // res ), func(m *Machine) { - debug2.Println2("append") arg0, arg1 := m.LastBlock().GetParams2() // As a special case, if arg1 is a string type, first convert it into // a data slice type. @@ -304,7 +303,6 @@ func makeUverseNode() { // ---------------------------------------------------------------- // append(*SliceValue, ???) case *SliceValue: - debug2.Println2("SliceValue, ???") arg0Length := arg0Value.Length arg0Offset := arg0Value.Offset arg0Capacity := arg0Value.Maxcap @@ -322,12 +320,9 @@ func makeUverseNode() { // ------------------------------------------------------------ // append(*SliceValue, *SliceValue) case *SliceValue: - debug2.Println2("arg1 slice value") arg1Length := arg1Value.Length arg1Offset := arg1Value.Offset arg1Base := arg1Value.GetBase(m.Store) - debug2.Println2("arg1Base: ", arg1Base) - debug2.Println2("arg1Base.List: ", arg1Base.List) if arg0Length+arg1Length <= arg0Capacity { // append(*SliceValue, *SliceValue) w/i capacity ----- if 0 < arg1Length { // implies 0 < xvc @@ -342,8 +337,6 @@ func makeUverseNode() { newElem := arg1Base.List[arg1Offset+i].unrefCopy(m.Alloc, m.Store) list[arg0Offset+arg0Length+i] = newElem - // TODO: xxx - // XXX, DidUpdate2? m.Realm.DidUpdate( m.Store, arg0Base, diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index af560af012c..f77bf80829f 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -210,10 +210,6 @@ func (pv *PointerValue) GetBase(store Store) Object { // TODO: document as something that enables into-native assignment. // TODO: maybe consider this as entrypoint for DataByteValue too? func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) { - debug2.Println2("Assign2, pv: ", pv) - debug2.Println2("tv2: ", tv2, reflect.TypeOf(tv2.V)) - debug2.Println2("rlm: ", rlm) - // Special cases. if pv.Index == PointerIndexNative { // Special case if extended object && native. @@ -287,31 +283,27 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // General case if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) + // get origin pkgId, this should happen before assign, // because assign will discard original object info originPkg := tv2.GetOriginPkg(store) - debug2.Println2("originPkg: ", originPkg, originPkg.purePkg) pv.TV.Assign(alloc, tv2, cu) oo2 := pv.TV.GetFirstObject(store) - // originValue is needed for checking - // proper element in the base. - // e.g. refValue is a sliceValue - switch pv.TV.V.(type) { - case *SliceValue, PointerValue, *FuncValue: - if oo2.GetIsReal() { - oo2.SetIsAttachingRef(true) - } - } - + // set origin realm to object if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info + // used for checking cross realm after + switch pv.TV.V.(type) { + case *SliceValue, PointerValue: + if oo2.GetIsReal() { + oo2.SetIsAttachingRef(true) + } + } } - debug2.Println2("oo2: ", oo2) - rlm.DidUpdate(store, pv.Base.(Object), oo1, oo2) } else { pv.TV.Assign(alloc, tv2, cu) @@ -410,7 +402,6 @@ func (av *ArrayValue) GetPointerAtIndexInt2(store Store, ii int, et Type) Pointe } func (av *ArrayValue) Copy(alloc *Allocator) *ArrayValue { - debug2.Println2("Array copy, av: ", av) /* TODO: consider second ref count field. if av.GetRefCount() == 0 { return av @@ -535,7 +526,6 @@ func (sv *StructValue) GetSubrefPointerTo(store Store, st *StructType, path Valu } func (sv *StructValue) Copy(alloc *Allocator) *StructValue { - //debug2.Println2("StructValue copy, sv: ", sv) /* TODO consider second refcount field if sv.GetRefCount() == 0 { return sv @@ -1060,7 +1050,6 @@ func (tv *TypedValue) ClearNum() { } func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { - debug2.Printf2("Copy, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case BigintValue: cp.T = tv.T @@ -1083,7 +1072,6 @@ func (tv TypedValue) Copy(alloc *Allocator) (cp TypedValue) { // unrefCopy makes a copy of the underlying value in the case of reference values. // It copies other values as expected using the normal Copy method. func (tv TypedValue) unrefCopy(alloc *Allocator, store Store) (cp TypedValue) { - debug2.Println2("UnrefCopy, tv: ", tv) switch tv.V.(type) { case RefValue: cp.T = tv.T @@ -1660,7 +1648,6 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { // cu: convert untyped after assignment. pass false // for const definitions, but true for all else. func (tv *TypedValue) Assign(alloc *Allocator, tv2 TypedValue, cu bool) { - debug2.Println2("Assign, tv2: ", tv2) if debug { if tv.T == DataByteType { // assignment to data byte types should only @@ -2387,7 +2374,6 @@ type Block struct { // NOTE: for allocation, use *Allocator.NewBlock. func NewBlock(source BlockNode, parent *Block) *Block { - // fmt.Println("parent: ", parent) var values []TypedValue if source != nil { values = make([]TypedValue, source.GetNumNames()) @@ -2711,7 +2697,6 @@ func typedString(s string) TypedValue { } func fillValueTV(store Store, tv *TypedValue) *TypedValue { - //debug2.Printf2("fillValueTV: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) switch cv := tv.V.(type) { case RefValue: if cv.PkgPath != "" { // load package diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index 1682e1b70d5..c24c014a9ba 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -234,7 +234,6 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte m.RunFiles(n) m.RunStatement(gno.S(gno.Call(gno.X("main")))) } else { - //fmt.Println("realm case...") // Realm case. gno.DisableDebug() // until main call. @@ -260,7 +259,6 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte // Clear store cache and reconstruct machine from committed info // (mimicking on-chain behaviour). tx.Write() - m.Store = orig pv2 := m.Store.GetPackage(pkgPath, false) diff --git a/gnovm/tests/files/zrealm_crossrealm44_array.gno b/gnovm/tests/files/zrealm_crossrealm24_array.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm44_array.gno rename to gnovm/tests/files/zrealm_crossrealm24_array.gno diff --git a/gnovm/tests/files/zrealm_crossrealm45_array.gno b/gnovm/tests/files/zrealm_crossrealm25_array.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm45_array.gno rename to gnovm/tests/files/zrealm_crossrealm25_array.gno diff --git a/gnovm/tests/files/zrealm_crossrealm46_array.gno b/gnovm/tests/files/zrealm_crossrealm26_array.gno similarity index 100% rename from gnovm/tests/files/zrealm_crossrealm46_array.gno rename to gnovm/tests/files/zrealm_crossrealm26_array.gno From ec7b3fe56fab9a9117038263607d1028c1182eee Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Sun, 16 Feb 2025 15:28:42 +0800 Subject: [PATCH 78/88] more tests for pure --- gnovm/tests/files/zrealm_crossrealm23d.gno | 14 ++++++++++++++ gnovm/tests/files/zrealm_crossrealm23e.gno | 14 ++++++++++++++ gnovm/tests/files/zrealm_crossrealm23f.gno | 14 ++++++++++++++ gnovm/tests/files/zrealm_crossrealm23g.gno | 16 ++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm23d.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23e.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23f.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm23g.gno diff --git a/gnovm/tests/files/zrealm_crossrealm23d.gno b/gnovm/tests/files/zrealm_crossrealm23d.gno new file mode 100644 index 00000000000..4f843b0d5d4 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23d.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "errors" + "io" +) + +func main() { + io.EOF = errors.New("modified") +} + +// Error: +// cannot modify external-realm or non-realm object diff --git a/gnovm/tests/files/zrealm_crossrealm23e.gno b/gnovm/tests/files/zrealm_crossrealm23e.gno new file mode 100644 index 00000000000..e291733ba69 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23e.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "io" +) + +func main() { + a := io.EOF + println(a) +} + +// Output: +// EOF diff --git a/gnovm/tests/files/zrealm_crossrealm23f.gno b/gnovm/tests/files/zrealm_crossrealm23f.gno new file mode 100644 index 00000000000..57c3388958e --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23f.gno @@ -0,0 +1,14 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "io" +) + +func main() { + a := &io.EOF + println(a) +} + +// Output: +// &(&(ref(purePkg:4021fadf187fd2c8277aad0fbc5e8fc4e7f1c75f:10) errors.errorString) *errors.errorString) diff --git a/gnovm/tests/files/zrealm_crossrealm23g.gno b/gnovm/tests/files/zrealm_crossrealm23g.gno new file mode 100644 index 00000000000..d23be1c9038 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm23g.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + "errors" + "io" +) + +func main() { + a := &io.EOF + *a = errors.New("modified") + println(a) +} + +// Error: +// cannot modify external-realm or non-realm object From 7e0537425aafaff4d0d74ca2400a79da6af615af Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 17 Feb 2025 15:55:53 +0800 Subject: [PATCH 79/88] simplify --- gnovm/pkg/gnolang/ownership.go | 2 +- gnovm/pkg/gnolang/realm.go | 100 ++++++++++++--------------------- 2 files changed, 37 insertions(+), 65 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 246abe422c0..26ddb579474 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -387,7 +387,7 @@ func (oi *ObjectInfo) GetIsTransient() bool { return false } -// XXX, get first accessible object, maybe containing(parent) object, maybe itself. +// get first accessible object, maybe containing(parent) object, maybe itself. func (tv *TypedValue) GetFirstObject(store Store) Object { switch cv := tv.V.(type) { case PointerValue: diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 466d79b1f2c..372e5400b7c 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -166,19 +166,11 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { debug.Println("rlm.ID: ", rlm.ID) } - if po != nil { - debug.Println("po.GetIsReal: ", po.GetIsReal()) - } - if co != nil { debug.Printf( "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), ) - - if b, ok := co.(*Block); ok { - debug.Printf("b.source: %v (type: %v) \n", b.Source, reflect.TypeOf(b.Source)) - } } } @@ -201,9 +193,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { return // do nothing. } - // TODO: check unreal external here, if po is real, association is invalid, panic - - // else, defer to finalize??? if po.GetObjectID().PkgID != rlm.ID { panic("cannot modify external-realm or non-realm object") } @@ -228,17 +217,25 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - rlm.MarkNewEscapedCheckCrossRealm(store, co) + rlm.MarkNewEscaped(co) + // check cross realm + originRealm := co.GetOriginRealm() + if originRealm == rlm.ID { + } else if isCrossRealm(originRealm, rlm.ID) { + if !co.GetIsAttachingRef() { + panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", co)) + } + } } } else { - if co.GetIsReal() { // TODO: how this happen? + if co.GetIsReal() { // e.g. refCount change rlm.MarkDirty(co) } else { co.SetOwner(po) rlm.MarkNewReal(co) } // check cross realm for non escaped objects - checkCrossRealm(rlm, store, co, false, nil) // XXX, always false? + checkCrossRealm(rlm, store, co, false, nil) } } @@ -254,7 +251,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } -// checkCrossRealm2 checks cross realm recursively +// checkCrossRealm2 checks cross realm recursively. func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, seenObjs []Object) { if debug { debug.Printf("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) @@ -291,12 +288,9 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, seenObjs []Object) { if debug { - debug.Printf("checkCrossRealm, oo: %v, (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v \n", - oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID) - debug.Printf( - "isLastRef: %t | isCurrentRef: %t\n", - isAttachingRef, oo.GetIsAttachingRef(), + "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v | isLastRef: %t | isCurrentRef: %t\n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID, isAttachingRef, oo.GetIsAttachingRef(), ) } @@ -305,7 +299,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, se return } - // update isLastRef based on the current object's reference status + // update isAttachingRef based on the current object's reference status // If the last object was not a reference, but the current one is, // then the current object and its children are referenced. // refer 20c, 20c2 @@ -368,41 +362,13 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, } } default: - panic("should not happen, oo is not object") + panic("should not happen, oo is not an object") } } //---------------------------------------- // mark* -// MarkNewEscapedCheckCrossRealm mark new escaped object -// and check cross realm -func (rlm *Realm) MarkNewEscapedCheckCrossRealm(store Store, oo Object) { - if debug { - debug.Printf( - "MarkNewEscapedCheckCrossRealm - oo: %v | oo.GetRefCount: %d | oo.GetOriginRealm(): %v | isRef: %v | rlm.ID: %v\n", - oo, oo.GetRefCount(), oo.GetOriginRealm(), oo.GetIsAttachingRef(), rlm.ID, - ) - } - - if oo.GetOriginRealm() == rlm.ID { - rlm.MarkNewEscaped(oo) - // do nothing - return - } - - // originRealm can be zero, e.g. an array value - // in current realm, and it's referenced twice. - originRealm := oo.GetOriginRealm() - if isCrossRealm(originRealm, rlm.ID) { - if !oo.GetIsAttachingRef() { - panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", oo)) - } - } - // mark escaped - rlm.MarkNewEscaped(oo) -} - func (rlm *Realm) MarkNewReal(oo Object) { if debug { if pv, ok := oo.(*PackageValue); ok { @@ -511,13 +477,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { } if readonly { if true || - len(rlm.newCreated) > 0 || - len(rlm.newEscaped) > 0 || - len(rlm.newDeleted) > 0 || - len(rlm.created) > 0 || - len(rlm.updated) > 0 || - len(rlm.deleted) > 0 || - len(rlm.escaped) > 0 { + len(rlm.newCreated) > 0 || + len(rlm.newEscaped) > 0 || + len(rlm.newDeleted) > 0 || + len(rlm.created) > 0 || + len(rlm.updated) > 0 || + len(rlm.deleted) > 0 || + len(rlm.escaped) > 0 { panic("realm updates in readonly transaction") } return @@ -532,9 +498,9 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) { ensureUniq(rlm.newDeleted) ensureUniq(rlm.updated) if false || - rlm.created != nil || - rlm.deleted != nil || - rlm.escaped != nil { + rlm.created != nil || + rlm.deleted != nil || + rlm.escaped != nil { panic("realm should not have created, deleted, or escaped marks before beginning finalization") } } @@ -912,9 +878,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { } // deleted objects should not have gotten here. if false || - oo.GetRefCount() <= 0 || - oo.GetIsNewDeleted() || - oo.GetIsDeleted() { + oo.GetRefCount() <= 0 || + oo.GetIsNewDeleted() || + oo.GetIsDeleted() { panic("cannot save deleted objects") } } @@ -1806,7 +1772,13 @@ func getOwner(store Store, oo Object) Object { return po } -// check if it's crossing realm +// ---------------------------------------- +// misc + +// isCrossRealm checks if it's crossing realms. +// if the origin realm is zero, e.g. an unreal array, +// it is not considered a cross-realm scenario for now. +// however, further checks on children are required afterward. func isCrossRealm(originRealm, rlmID PkgID) bool { return !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlmID } From 06895d30b72171e09181146541ddb2e1e3525a8a Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Mon, 17 Feb 2025 17:55:20 +0800 Subject: [PATCH 80/88] test for 3693 --- gnovm/tests/files/zrealm_crossrealm22a1.gno | 28 +++++++++++ gnovm/tests/files/zrealm_crossrealm22a2.gno | 29 +++++++++++ gnovm/tests/files/zrealm_crossrealm22a3.gno | 53 +++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 gnovm/tests/files/zrealm_crossrealm22a1.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22a2.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm22a3.gno diff --git a/gnovm/tests/files/zrealm_crossrealm22a1.gno b/gnovm/tests/files/zrealm_crossrealm22a1.gno new file mode 100644 index 00000000000..b1ca30d652b --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a1.gno @@ -0,0 +1,28 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + var ls = Local_S{name: "Local_S"} + f := func() bool { + c := b + return true + } + crossrealm.SetCallback(f) + + ls.name = "modified" + + println("ok") +} + +// Error: +// cannot attach a value of a type defined by another realm: struct{("Local_S" string)} diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno new file mode 100644 index 00000000000..d6d2db2e619 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a2.gno @@ -0,0 +1,29 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +func main() { + ls := &Local_S{name: "Local_S"} + + f := func() bool { + c := b + return true + } + crossrealm.SetCallback(f) + + ls.name = "modified" + + println("ok") +} + +// Error: +// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("Local_S" string)} gno.land/r/crossrealm_test.Local_S)) diff --git a/gnovm/tests/files/zrealm_crossrealm22a3.gno b/gnovm/tests/files/zrealm_crossrealm22a3.gno new file mode 100644 index 00000000000..ca7669d7680 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm22a3.gno @@ -0,0 +1,53 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/func" +) + +var b = 1 + +type Local_S struct { + name string +} + +var ls = &Local_S{name: "Local_S"} + +func main() { + f := func() bool { + c := b + return true + } + crossrealm.SetCallback(f) + + ls.name = "modified" + + println(ls) +} + +// Output: +// &(struct{("modified" string)} gno.land/r/crossrealm_test.Local_S) + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/func"] +// switchrealm["gno.land/r/crossrealm_test"] +// u[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "modified" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "RefCount": "1" +// } +// } From 49eb014f85dcad368d4c47c28089197fcc1fc6d2 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 18 Feb 2025 23:29:58 +0800 Subject: [PATCH 81/88] only by type --- .../crossrealm/array/crossrealm_array.gno | 12 ++ .../tests/crossrealm/map/crossrealm_map.gno | 3 + gnovm/pkg/gnolang/ownership.go | 50 ++++---- gnovm/pkg/gnolang/realm.go | 25 ++-- gnovm/pkg/gnolang/values.go | 10 +- gnovm/tests/files/zrealm_crossrealm0.gno | 2 +- gnovm/tests/files/zrealm_crossrealm1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 2 +- gnovm/tests/files/zrealm_crossrealm2.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20b1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c2.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20f.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20g.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21g.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22a1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22a2.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22b.gno | 2 +- .../tests/files/zrealm_crossrealm24_array.gno | 2 +- .../tests/files/zrealm_crossrealm25_array.gno | 2 +- .../tests/files/zrealm_crossrealm27_array.gno | 16 +++ .../tests/files/zrealm_crossrealm28_array.gno | 45 ++++++++ gnovm/tests/files/zrealm_crossrealm28b1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c2.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c5.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c8.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm3.gno | 2 +- gnovm/tests/files/zrealm_crossrealm31.gno | 2 +- gnovm/tests/files/zrealm_crossrealm34b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm35.gno | 108 +++++++++++++++++- gnovm/tests/files/zrealm_crossrealm37_map.gno | 40 ++++++- gnovm/tests/files/zrealm_crossrealm37c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm40_a.gno | 2 +- 42 files changed, 296 insertions(+), 79 deletions(-) create mode 100644 gnovm/tests/files/zrealm_crossrealm27_array.gno create mode 100644 gnovm/tests/files/zrealm_crossrealm28_array.gno diff --git a/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno b/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno index e48255875e6..8f9af1f6142 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/array/crossrealm_array.gno @@ -4,6 +4,18 @@ type Foo struct{ name string } var f = Foo{"foo"} +var Arr = [2]Foo{Foo{"a"}, Foo{"b"}} + +var Arr2 = [2]int{1, 2} + +func GetArray5() [2]int { + return Arr2 +} + +func GetArray4() [2]Foo { + return Arr +} + func GetArray() [2]Foo { return [2]Foo{Foo{"a"}, Foo{"b"}} } diff --git a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno index 0588938a660..155badb2e2d 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno @@ -1,3 +1,4 @@ +// PKGPATH: gno.land/r/crossrealm_map package crossrealm_map type Foo struct{} @@ -35,3 +36,5 @@ func GetMap3() MyMap { } // TODO: add some map with elements of object + +// Realm: diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 26ddb579474..fd29e0581b2 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -179,7 +179,13 @@ type ObjectInfo struct { // realm where object is from originRealm PkgID - // if this object is attaching as a base of reference + // This flag indicates whether the object is being + // attached as a base of reference or as itself. + // For example: + // - If the object being attached is a struct value + // whose type is declared in another realm, it should panic. + // - If the object being attached is a pointer to such + // a struct value, it is allowed. isAttachingRef bool // XXX huh? @@ -196,15 +202,6 @@ 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, - originRealm: oi.originRealm, - */ } } @@ -269,6 +266,7 @@ func (oi *ObjectInfo) GetOwnerID() ObjectID { } else { return oi.owner.GetObjectID() } + //return oi.OwnerID } func (oi *ObjectInfo) GetIsOwned() bool { @@ -422,28 +420,14 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } } -// GetOriginPkg get origin pkg for real or unreal object -// if the object is real, it's retrieved from objectID, -// otherwise, it's inference from its type. -func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { - // attempting to retrieve the original package from ObjectID - obj := tv.GetFirstObject(store) - if obj != nil { - originPkg = obj.GetOriginRealm() - if !originPkg.IsZero() { - return - } - originPkg = obj.GetObjectID().PkgID - if !originPkg.IsZero() { - return - } - } - +// GetBoundRealmByType retrieves the bound realm for the object +// by checking its type. If the type is a declared type, it is +// considered bound to a specific realm; otherwise, it returns zero. +func (tv *TypedValue) GetBoundRealmByType(obj Object) (originPkg PkgID) { // attempting to infer original package using declared type - // if it does not have an objectID(unreal) getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { - pkgId = PkgIDFromPkgPath(dt.Base.GetPkgPath()) + pkgId = PkgIDFromPkgPath(dt.GetPkgPath()) return } return @@ -453,6 +437,14 @@ func (tv *TypedValue) GetOriginPkg(store Store) (originPkg PkgID) { case *HeapItemValue: originPkg = getPkgId(cv.Value.T) return + case *Block: + // assert to pointer value + if pv, ok := tv.V.(PointerValue); ok { + originPkg = getPkgId(pv.TV.T) + return + } else { + // XXX? + } case *BoundMethodValue: // do nothing return diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 372e5400b7c..703b1a89a8d 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -94,6 +94,7 @@ func PkgIDFromPkgPath(path string) PkgID { if !ok { pkgID = new(PkgID) *pkgID = PkgID{purePkg: !IsRealmPath(path), Hashlet: HashBytes([]byte(path))} + pkgIDFromPkgPathCache[path] = pkgID } return *pkgID @@ -210,6 +211,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { // XXX, inc ref count everytime assignment happens co.IncRefCount() + //fmt.Println("co.GetRefCount() after inc: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsReal() { rlm.MarkDirty(co) @@ -217,15 +219,19 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - rlm.MarkNewEscaped(co) + //rlm.MarkNewEscaped(co) // check cross realm originRealm := co.GetOriginRealm() + //fmt.Println("originRealm: ", originRealm) if originRealm == rlm.ID { + //rlm.MarkNewEscaped(co) } else if isCrossRealm(originRealm, rlm.ID) { if !co.GetIsAttachingRef() { panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", co)) } + //rlm.MarkNewEscaped(co) } + rlm.MarkNewEscaped(co) } } else { if co.GetIsReal() { // e.g. refCount change @@ -258,7 +264,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s } tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { - oo.SetOriginRealm(tv2.GetOriginPkg(store)) + oo.SetOriginRealm(tv2.GetBoundRealmByType(oo)) checkCrossRealm(rlm, store, oo, isLastRef, seenObjs) } else { switch tv.V.(type) { @@ -278,7 +284,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s } // set origin realm info - reo.SetOriginRealm(tv2.GetOriginPkg(store)) + reo.SetOriginRealm(tv2.GetBoundRealmByType(reo)) reo.SetIsAttachingRef(true) checkCrossRealm(rlm, store, reo, isLastRef, seenObjs) } @@ -320,12 +326,12 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, se // they can be attached(real) after. if isAttachingRef { if !oo.GetIsReal() { - panic(fmt.Sprintf("cannot attach a reference to an unreal object from an external realm: %v", oo)) + panic("cannot attach a reference to an unattached object from an external realm") } else { return } } else { - panic(fmt.Sprintf("cannot attach a value of a type defined by another realm: %v", oo)) + panic("cannot attach a value of a type defined by another realm") } } } @@ -402,6 +408,7 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { + //fmt.Println("MarkDirty, oo: ", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -723,6 +730,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // except for new-reals that get demoted // because ref-count isn't >= 2. for _, eo := range rlm.newEscaped { + //fmt.Println("eo: ", eo) if debug { if !eo.GetIsNewEscaped() { panic("new escaped mark not marked as new escaped") @@ -745,9 +753,11 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { // add to escaped, and mark dirty previous owner. po := getOwner(store, eo) + //fmt.Println("po: ", po) if po == nil { // e.g. !eo.GetIsNewReal(), // should have no parent. + //eo.SetOwner(nil) continue } else { if po.GetRefCount() == 0 { @@ -762,6 +772,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { panic("new escaped mark has no object ID") } // escaped has no owner. + //fmt.Println("set owner to be nil") eo.SetOwner(nil) } } @@ -935,7 +946,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { func (rlm *Realm) saveObject(store Store, oo Object) { oid := oo.GetObjectID() if oid.IsZero() { - panic("unexpected zero object id") + panic(fmt.Sprintf("unexpected zero object id: %v", oo)) } if isCrossRealm(oo.GetOriginRealm(), rlm.ID) { if !oo.GetIsEscaped() && !oo.GetIsNewEscaped() { @@ -1670,7 +1681,7 @@ func toRefValue(val Value) RefValue { PkgPath: pv.PkgPath, } } else if !oo.GetIsReal() { - panic("unexpected unreal object") + panic(fmt.Sprintf("unexpected unreal object: %v", val)) } else if oo.GetIsDirty() { // This can happen with some circular // references. diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 9f0028e0bc8..6ad3fcd3201 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -284,14 +284,12 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty if rlm != nil && pv.Base != nil { oo1 := pv.TV.GetFirstObject(store) - // get origin pkgId, this should happen before assign, - // because assign will discard original object info - originPkg := tv2.GetOriginPkg(store) - pv.TV.Assign(alloc, tv2, cu) oo2 := pv.TV.GetFirstObject(store) + originPkg := tv2.GetBoundRealmByType(oo2) + // set origin realm to object if oo2 != nil && !originPkg.IsZero() { oo2.SetOriginRealm(originPkg) // attach origin package info @@ -2393,8 +2391,8 @@ func (b *Block) StringIndented(indent string) string { } lines := make([]string, 0, 3) lines = append(lines, - fmt.Sprintf("Block(ID:%v,Addr:%p,Source:%s,Parent:%p)", - b.ObjectInfo.ID, b, source, b.Parent)) // XXX Parent may be RefValue{}. + fmt.Sprintf("Block(ID:%v,Source:%s,Parent:%p)", + b.ObjectInfo.ID, source, b.Parent)) // XXX Parent may be RefValue{}. if b.Source != nil { if _, ok := b.Source.(RefNode); ok { lines = append(lines, diff --git a/gnovm/tests/files/zrealm_crossrealm0.gno b/gnovm/tests/files/zrealm_crossrealm0.gno index 35c19a6efe6..b425344615e 100644 --- a/gnovm/tests/files/zrealm_crossrealm0.gno +++ b/gnovm/tests/files/zrealm_crossrealm0.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm1.gno b/gnovm/tests/files/zrealm_crossrealm1.gno index 0c1b5fd92ff..c22279fb324 100644 --- a/gnovm/tests/files/zrealm_crossrealm1.gno +++ b/gnovm/tests/files/zrealm_crossrealm1.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 41c83b93493..6871e16bc53 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -24,4 +24,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{(&(struct{} gno.land/r/crossrealm_test.fooer) *gno.land/r/crossrealm_test.fooer)} gno.land/r/crossrealm_test.container)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm2.gno b/gnovm/tests/files/zrealm_crossrealm2.gno index 5414711340e..69f548c7e70 100644 --- a/gnovm/tests/files/zrealm_crossrealm2.gno +++ b/gnovm/tests/files/zrealm_crossrealm2.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20a.gno b/gnovm/tests/files/zrealm_crossrealm20a.gno index 6ad7ee005a3..3bac413912d 100644 --- a/gnovm/tests/files/zrealm_crossrealm20a.gno +++ b/gnovm/tests/files/zrealm_crossrealm20a.gno @@ -12,4 +12,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{(0 int)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20b.gno b/gnovm/tests/files/zrealm_crossrealm20b.gno index 93a4e30a5df..4b8f7be8c75 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{(0 int)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20b1.gno b/gnovm/tests/files/zrealm_crossrealm20b1.gno index 7148fee5b9c..4653b701620 100644 --- a/gnovm/tests/files/zrealm_crossrealm20b1.gno +++ b/gnovm/tests/files/zrealm_crossrealm20b1.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{(1 int)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno index 5425c6d435b..dfec8344321 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c1.gno b/gnovm/tests/files/zrealm_crossrealm20c1.gno index 713947c1b98..da88ce8abae 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c1.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c1.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(1 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c2.gno b/gnovm/tests/files/zrealm_crossrealm20c2.gno index 52e52730eef..c5f15ef8503 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c2.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c2.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: struct{(1 int)} +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20d.gno b/gnovm/tests/files/zrealm_crossrealm20d.gno index c4c49313b45..20f19d299e3 100644 --- a/gnovm/tests/files/zrealm_crossrealm20d.gno +++ b/gnovm/tests/files/zrealm_crossrealm20d.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{(11 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20e.gno b/gnovm/tests/files/zrealm_crossrealm20e.gno index d867edff307..3d6b8f44402 100644 --- a/gnovm/tests/files/zrealm_crossrealm20e.gno +++ b/gnovm/tests/files/zrealm_crossrealm20e.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20f.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno index 52c86fa568f..e228611dce5 100644 --- a/gnovm/tests/files/zrealm_crossrealm20f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{(22 int)} gno.land/r/demo/tests/crossrealm/struct.Bar)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20g.gno b/gnovm/tests/files/zrealm_crossrealm20g.gno index 8f54858867b..fcdb3a842d9 100644 --- a/gnovm/tests/files/zrealm_crossrealm20g.gno +++ b/gnovm/tests/files/zrealm_crossrealm20g.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{(22 int)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index ad586b47505..b70619b0391 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("local_fooer" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno index 79ca820bf62..182437c57fb 100644 --- a/gnovm/tests/files/zrealm_crossrealm21b.gno +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{("local_fooer" string)} gno.land/r/crossrealm_test.fooer)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm21g.gno b/gnovm/tests/files/zrealm_crossrealm21g.gno index c0bcded157e..6883ec2e5e6 100644 --- a/gnovm/tests/files/zrealm_crossrealm21g.gno +++ b/gnovm/tests/files/zrealm_crossrealm21g.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: heapitem((struct{(struct{("a" string)} gno.land/r/demo/tests/crossrealm/struct.A),(struct{("b" string)} gno.land/r/demo/tests/crossrealm/struct.B),(struct{( string)} gno.land/r/demo/tests/crossrealm/struct.D)} gno.land/r/demo/tests/crossrealm/struct.C)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a1.gno b/gnovm/tests/files/zrealm_crossrealm22a1.gno index b1ca30d652b..7d8a9371660 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a1.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a1.gno @@ -25,4 +25,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("Local_S" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno index d6d2db2e619..ea6e1159865 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a2.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a2.gno @@ -26,4 +26,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("Local_S" string)} gno.land/r/crossrealm_test.Local_S)) +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22b.gno b/gnovm/tests/files/zrealm_crossrealm22b.gno index 30112f8aa8f..9245da84309 100644 --- a/gnovm/tests/files/zrealm_crossrealm22b.gno +++ b/gnovm/tests/files/zrealm_crossrealm22b.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("local_s" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm24_array.gno b/gnovm/tests/files/zrealm_crossrealm24_array.gno index 0d2c2ef4839..4fbd5704ae3 100644 --- a/gnovm/tests/files/zrealm_crossrealm24_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm24_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("a" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25_array.gno b/gnovm/tests/files/zrealm_crossrealm25_array.gno index 5bb8fe7e38b..6049136fd6d 100644 --- a/gnovm/tests/files/zrealm_crossrealm25_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm25_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("a" string)} gno.land/r/demo/tests/crossrealm/array.Foo)) +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm27_array.gno b/gnovm/tests/files/zrealm_crossrealm27_array.gno new file mode 100644 index 00000000000..b00555f0bb7 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm27_array.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/array" +) + +var root interface{} + +func main() { + root = crossrealm.GetArray4() + println(".") +} + +// Error: +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28_array.gno b/gnovm/tests/files/zrealm_crossrealm28_array.gno new file mode 100644 index 00000000000..f03a18dc641 --- /dev/null +++ b/gnovm/tests/files/zrealm_crossrealm28_array.gno @@ -0,0 +1,45 @@ +// PKGPATH: gno.land/r/crossrealm_test +package crossrealm_test + +import ( + crossrealm "gno.land/r/demo/tests/crossrealm/array" +) + +var root interface{} + +func main() { + root = crossrealm.GetArray5() + println(".") +} + +// Output: +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/array"] +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:4]={ +// "Data": null, +// "List": [ +// { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// { +// "N": "AgAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm28b1.gno b/gnovm/tests/files/zrealm_crossrealm28b1.gno index b467001ba8a..afce1ecbe20 100644 --- a/gnovm/tests/files/zrealm_crossrealm28b1.gno +++ b/gnovm/tests/files/zrealm_crossrealm28b1.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c.gno b/gnovm/tests/files/zrealm_crossrealm28c.gno index d282e706bd6..f18931b648f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("1" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c2.gno b/gnovm/tests/files/zrealm_crossrealm28c2.gno index a7adf08725f..58e6391e488 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c2.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c2.gno @@ -26,4 +26,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("1" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c5.gno b/gnovm/tests/files/zrealm_crossrealm28c5.gno index 29f9a948753..55806fee1a0 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c5.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c5.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: struct{("1" string)} +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c8.gno b/gnovm/tests/files/zrealm_crossrealm28c8.gno index 8b80a075299..e660665024c 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c8.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c8.gno @@ -26,4 +26,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("1" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index b8334756377..08d11eecc8f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a reference to an unreal object from an external realm: heapitem((struct{("1" string)} gno.land/r/crossrealm_test.foo)) +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm3.gno b/gnovm/tests/files/zrealm_crossrealm3.gno index 027a059a65f..e0c800aa624 100644 --- a/gnovm/tests/files/zrealm_crossrealm3.gno +++ b/gnovm/tests/files/zrealm_crossrealm3.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm31.gno b/gnovm/tests/files/zrealm_crossrealm31.gno index 877e1de46aa..22b02fefdc8 100644 --- a/gnovm/tests/files/zrealm_crossrealm31.gno +++ b/gnovm/tests/files/zrealm_crossrealm31.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("1" string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm34b.gno b/gnovm/tests/files/zrealm_crossrealm34b.gno index f772048687f..e898eb9f3df 100644 --- a/gnovm/tests/files/zrealm_crossrealm34b.gno +++ b/gnovm/tests/files/zrealm_crossrealm34b.gno @@ -17,4 +17,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{( string)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno index 1154e80d91a..1e39a579e4a 100644 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -20,5 +20,109 @@ func main() { println(".") } -// Error: -// cannot attach a value of a type defined by another realm: array[(&(ref(f5a516808f8976c33939133293d598ce3bca4e8d:4) gno.land/r/crossrealm_test.foo) *gno.land/r/crossrealm_test.foo)] +// Output: +// . + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/slice"] +// u[ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:14", +// "ModTime": "28", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "28", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "de578df5354e812a94f64e23eed06e9705d2b4ef", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } +// switchrealm["gno.land/r/crossrealm_test"] +// c[f5a516808f8976c33939133293d598ce3bca4e8d:6]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:3" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:6", +// "ModTime": "0", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// } +// } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "3" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.foo" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "de578df5354e812a94f64e23eed06e9705d2b4ef", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm37_map.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno index a1db21247e8..176248aad13 100644 --- a/gnovm/tests/files/zrealm_crossrealm37_map.gno +++ b/gnovm/tests/files/zrealm_crossrealm37_map.gno @@ -10,5 +10,41 @@ func main() { println(m1) } -// Error: -// cannot attach objects by value from external realm: map{("a" string):(1 int)} +// Output: +// map{("a" string):(1 int)} + +// Realm: +// switchrealm["gno.land/r/demo/tests/crossrealm/map"] +// switchrealm["gno.land/r/crossrealm_test"] +// u[5a06306c27263d4b9ae8f2f30e82f8ef014042cd:6]={ +// "List": { +// "List": [ +// { +// "Key": { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "a" +// } +// }, +// "Value": { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// } +// } +// ] +// }, +// "ObjectInfo": { +// "ID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:6", +// "IsEscaped": true, +// "ModTime": "3", +// "OwnerID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:2", +// "RefCount": "2" +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm37c.gno b/gnovm/tests/files/zrealm_crossrealm37c.gno index bbc3884d5c5..9429ab08d43 100644 --- a/gnovm/tests/files/zrealm_crossrealm37c.gno +++ b/gnovm/tests/files/zrealm_crossrealm37c.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm40_a.gno b/gnovm/tests/files/zrealm_crossrealm40_a.gno index 789f221776a..de761436444 100644 --- a/gnovm/tests/files/zrealm_crossrealm40_a.gno +++ b/gnovm/tests/files/zrealm_crossrealm40_a.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm: struct{("struct_val" string)} +// cannot attach a value of a type defined by another realm From 8e33a383b4e6420572ea9be87d23693ab58d5899 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 00:03:38 +0800 Subject: [PATCH 82/88] map test --- .../gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno | 4 ++++ gnovm/tests/files/zrealm_crossrealm37_map.gno | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno index 155badb2e2d..fd2890c3a8a 100644 --- a/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno +++ b/examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno @@ -16,6 +16,10 @@ func GetMap() map[string]int { return m } +func ModifyMap() { + m["a"] = 2 +} + func GetMap2(f func(map[string]int)) { m1 := map[string]int{"a": 1} f(m1) diff --git a/gnovm/tests/files/zrealm_crossrealm37_map.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno index 176248aad13..36f8fa4884c 100644 --- a/gnovm/tests/files/zrealm_crossrealm37_map.gno +++ b/gnovm/tests/files/zrealm_crossrealm37_map.gno @@ -8,13 +8,17 @@ var m1 map[string]int func main() { m1 = crossrealm.GetMap() println(m1) + crossrealm.ModifyMap() + println(m1) } // Output: // map{("a" string):(1 int)} +// map{("a" string):(2 int)} // Realm: // switchrealm["gno.land/r/demo/tests/crossrealm/map"] +// switchrealm["gno.land/r/demo/tests/crossrealm/map"] // switchrealm["gno.land/r/crossrealm_test"] // u[5a06306c27263d4b9ae8f2f30e82f8ef014042cd:6]={ // "List": { @@ -31,7 +35,7 @@ func main() { // } // }, // "Value": { -// "N": "AQAAAAAAAAA=", +// "N": "AgAAAAAAAAA=", // "T": { // "@type": "/gno.PrimitiveType", // "value": "32" From c82abd1e3d3f6d0c1b7327fd8c71991b04854b9c Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 09:45:52 +0800 Subject: [PATCH 83/88] fixup --- gnovm/pkg/gnolang/realm.go | 46 +++++++++------------ gnovm/tests/files/zrealm_crossrealm20c2.gno | 2 +- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 703b1a89a8d..b6ae9c0f607 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -241,7 +241,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { rlm.MarkNewReal(co) } // check cross realm for non escaped objects - checkCrossRealm(rlm, store, co, false, nil) + checkCrossRealm(rlm, store, co, nil) } } @@ -258,14 +258,14 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } // checkCrossRealm2 checks cross realm recursively. -func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, seenObjs []Object) { +func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object) { if debug { - debug.Printf("checkCrossRealm2, tv: %v (type: %v) | isLastRef: %t \n", tv, reflect.TypeOf(tv.V), isLastRef) + debug.Printf("checkCrossRealm2, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) } tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { oo.SetOriginRealm(tv2.GetBoundRealmByType(oo)) - checkCrossRealm(rlm, store, oo, isLastRef, seenObjs) + checkCrossRealm(rlm, store, oo, seenObjs) } else { switch tv.V.(type) { case *SliceValue, PointerValue: @@ -286,17 +286,17 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, s // set origin realm info reo.SetOriginRealm(tv2.GetBoundRealmByType(reo)) reo.SetIsAttachingRef(true) - checkCrossRealm(rlm, store, reo, isLastRef, seenObjs) + checkCrossRealm(rlm, store, reo, seenObjs) } } } // checkCrossRealm performs a deep crawl to determine if cross-realm conditions exist. -func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, seenObjs []Object) { +func checkCrossRealm(rlm *Realm, store Store, oo Object, seenObjs []Object) { if debug { debug.Printf( - "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v | isLastRef: %t | isCurrentRef: %t\n", - oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID, isAttachingRef, oo.GetIsAttachingRef(), + "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v | isCurrentRef: %t\n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), ) } @@ -305,18 +305,10 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, se return } - // update isAttachingRef based on the current object's reference status - // If the last object was not a reference, but the current one is, - // then the current object and its children are referenced. - // refer 20c, 20c2 - if !isAttachingRef { - isAttachingRef = oo.GetIsAttachingRef() - } - // for local realm checking, maybe a container not cross, // but its children does. if oo.GetOriginRealm().IsZero() || rlm.ID == oo.GetOriginRealm() { - checkCrossRealmChildren(rlm, store, oo, isAttachingRef, seenObjs) + checkCrossRealmChildren(rlm, store, oo, seenObjs) return } @@ -324,7 +316,7 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, se // When attaching a reference, ensure that the base object is real. // The child objects do not need to be real at this stage; // they can be attached(real) after. - if isAttachingRef { + if oo.GetIsAttachingRef() { if !oo.GetIsReal() { panic("cannot attach a reference to an unattached object from an external realm") } else { @@ -337,19 +329,19 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, isAttachingRef bool, se } // checkCrossRealmChildren check if children is crossing realm -func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, seenObjs []Object) { +func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, seenObjs []Object) { switch v := oo.(type) { case *StructValue: for _, fv := range v.Fields { - checkCrossRealm2(rlm, store, &fv, isLastRef, seenObjs) // ref to struct is heapItemValue or block + checkCrossRealm2(rlm, store, &fv, seenObjs) // ref to struct is heapItemValue or block } case *MapValue: for cur := v.List.Head; cur != nil; cur = cur.Next { - checkCrossRealm2(rlm, store, &cur.Key, isLastRef, seenObjs) - checkCrossRealm2(rlm, store, &cur.Value, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &cur.Key, seenObjs) + checkCrossRealm2(rlm, store, &cur.Value, seenObjs) } case *BoundMethodValue: - checkCrossRealm2(rlm, store, &v.Receiver, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &v.Receiver, seenObjs) o2 := v.Func.Closure.(Object) // the closure must be a real fileBlock if !o2.GetIsReal() { @@ -357,14 +349,14 @@ func checkCrossRealmChildren(rlm *Realm, store Store, oo Object, isLastRef bool, } case *Block: for _, tv := range v.Values { - checkCrossRealm2(rlm, store, &tv, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &tv, seenObjs) } case *HeapItemValue: - checkCrossRealm2(rlm, store, &v.Value, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &v.Value, seenObjs) case *ArrayValue: if v.Data == nil { for _, e := range v.List { - checkCrossRealm2(rlm, store, &e, isLastRef, seenObjs) + checkCrossRealm2(rlm, store, &e, seenObjs) } } default: @@ -571,7 +563,7 @@ func (rlm *Realm) processNewCreatedMarks(store Store) { // from package block, recursively if pv, ok := oo.(*PackageValue); ok { if IsRealmPath(pv.PkgPath) { - checkCrossRealm(rlm, store, pv.Block.(Object), false, nil) + checkCrossRealm(rlm, store, pv.Block.(Object), nil) } } rlm.incRefCreatedDescendants(store, oo) diff --git a/gnovm/tests/files/zrealm_crossrealm20c2.gno b/gnovm/tests/files/zrealm_crossrealm20c2.gno index c5f15ef8503..136c95881b4 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c2.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c2.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm From 2bbe3983adebe568835621c10ecd314cba6c1411 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 10:11:32 +0800 Subject: [PATCH 84/88] fix owner ID --- gnovm/pkg/gnolang/ownership.go | 12 +-- gnovm/pkg/gnolang/realm.go | 22 +++-- gnovm/tests/files/heap_item_value_init.gno | 1 - gnovm/tests/files/zrealm16.gno | 1 - gnovm/tests/files/zrealm_avl1.gno | 92 +++++++++++++++++++ gnovm/tests/files/zrealm_crossrealm17a.gno | 20 +++- gnovm/tests/files/zrealm_crossrealm21.gno | 20 +++- gnovm/tests/files/zrealm_crossrealm21d1.gno | 1 - gnovm/tests/files/zrealm_crossrealm21f.gno | 20 +++- .../tests/files/zrealm_crossrealm22_func.gno | 59 +++++++++++- gnovm/tests/files/zrealm_crossrealm22a3.gno | 19 ++++ gnovm/tests/files/zrealm_crossrealm28c3.gno | 1 - gnovm/tests/files/zrealm_crossrealm28c6.gno | 1 - gnovm/tests/files/zrealm_crossrealm28d2.gno | 3 - gnovm/tests/files/zrealm_crossrealm30.gno | 1 - gnovm/tests/files/zrealm_crossrealm33.gno | 1 - gnovm/tests/files/zrealm_crossrealm35.gno | 2 - gnovm/tests/files/zrealm_crossrealm35a.gno | 1 - gnovm/tests/files/zrealm_crossrealm37_map.gno | 1 - .../zrealm_crossrealm41_method_local.gno | 1 - gnovm/tests/files/zrealm_example.gno | 19 ++++ gnovm/tests/files/zrealm_tests0.gno | 1 - 22 files changed, 266 insertions(+), 33 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index fd29e0581b2..0b74a64e794 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -261,12 +261,12 @@ func (oi *ObjectInfo) SetOwner(po Object) { } func (oi *ObjectInfo) GetOwnerID() ObjectID { - if oi.owner == nil { - return ObjectID{} - } else { - return oi.owner.GetObjectID() - } - //return oi.OwnerID + //if oi.owner == nil { + // return ObjectID{} + //} else { + // return oi.owner.GetObjectID() + //} + return oi.OwnerID } func (oi *ObjectInfo) GetIsOwned() bool { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index b6ae9c0f607..4da8c5de2ed 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -157,6 +157,22 @@ func (rlm *Realm) String() string { // ownership hooks func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { + //fmt.Printf( + // "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", + // po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), + //) + // + //if rlm != nil { + // fmt.Println("rlm.ID: ", rlm.ID) + //} + // + //if co != nil { + // fmt.Printf( + // "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", + // co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), + // ) + //} + if debug { debug.Printf( "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", @@ -400,7 +416,6 @@ func (rlm *Realm) MarkNewReal(oo Object) { // mark dirty == updated func (rlm *Realm) MarkDirty(oo Object) { - //fmt.Println("MarkDirty, oo: ", oo) if debug { if !oo.GetIsReal() && !oo.GetIsNewReal() { panic("cannot mark unreal object as dirty") @@ -1077,11 +1092,6 @@ func getChildObjects(val Value, more []Value) []Value { } return more case *Block: - //fmt.Println("block, cv: ", cv) - //if _, ok := cv.Parent.(*Block); ok { - // fmt.Println("block, cv.parent: ", cv.Parent) - // fmt.Println("parent.Source: ", cv.Parent.(*Block).Source) - //} for _, ctv := range cv.Values { more = getSelfOrChildObjects(ctv.V, more) } diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 40f9752d22d..1de1ee3e3ad 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -24,7 +24,6 @@ func main() { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm16.gno b/gnovm/tests/files/zrealm16.gno index b7bef5028b0..1752e442800 100644 --- a/gnovm/tests/files/zrealm16.gno +++ b/gnovm/tests/files/zrealm16.gno @@ -79,7 +79,6 @@ func main() { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", // "IsEscaped": true, // "ModTime": "11", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_avl1.gno b/gnovm/tests/files/zrealm_avl1.gno index 572c49333bc..b6d580c082f 100644 --- a/gnovm/tests/files/zrealm_avl1.gno +++ b/gnovm/tests/files/zrealm_avl1.gno @@ -326,5 +326,97 @@ func main() { // } // } // } +// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "16" +// }, +// "V": { +// "@type": "/gno.StringValue", +// "value": "key1" +// } +// }, +// {}, +// { +// "N": "AQAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "64" +// } +// }, +// { +// "N": "AgAAAAAAAAA=", +// "T": { +// "@type": "/gno.PrimitiveType", +// "value": "32" +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/avl.Node" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "4e56eeb96eb1d9b27cf603140cd03a1622b6358b", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6" +// }, +// "Index": "0", +// "TV": null +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/avl.Node" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "cafae89e4d4aaaefe7fdf0691084508d4274a981", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8" +// }, +// "Index": "0", +// "TV": null +// } +// } +// ], +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", +// "ModTime": "15", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "RefCount": "0" +// } +// } +// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "ModTime": "15", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", +// "RefCount": "0" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/avl.Node" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "e5c7483db73560f1baf6c46a30a91b0594da9c68", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5" +// } +// } +// } // d[a8ada09dee16d791fd406d629fe29bb0ed084a30:4] // d[a8ada09dee16d791fd406d629fe29bb0ed084a30:5] diff --git a/gnovm/tests/files/zrealm_crossrealm17a.gno b/gnovm/tests/files/zrealm_crossrealm17a.gno index f221b81f6aa..b91eb4beff7 100644 --- a/gnovm/tests/files/zrealm_crossrealm17a.gno +++ b/gnovm/tests/files/zrealm_crossrealm17a.gno @@ -35,7 +35,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "5", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -128,5 +127,24 @@ func main() { // "RefCount": "1" // } // } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "IsEscaped": true, +// "ModTime": "7", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.container" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "ef7d0f54195eff59079f178206ba725d07f095a7", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index e3b29f671a4..6001a73666f 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -29,7 +29,6 @@ func main() { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "5", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "2" // }, // "Value": { @@ -67,6 +66,25 @@ func main() { // "RefCount": "1" // } // } +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d2ed801c0f8a7400a4078f780dcc37ab8027bd07", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// } +// } +// } // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21d1.gno b/gnovm/tests/files/zrealm_crossrealm21d1.gno index 1fb1e4d565b..9b7a53f81da 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d1.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d1.gno @@ -109,7 +109,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm21f.gno b/gnovm/tests/files/zrealm_crossrealm21f.gno index 2b7866126fd..a26b969ca39 100644 --- a/gnovm/tests/files/zrealm_crossrealm21f.gno +++ b/gnovm/tests/files/zrealm_crossrealm21f.gno @@ -23,7 +23,6 @@ func main() { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", // "IsEscaped": true, // "ModTime": "3", -// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:2", // "RefCount": "2" // }, // "Value": { @@ -101,5 +100,24 @@ func main() { // "RefCount": "1" // } // } +// u[5965ae851c02ab677bc8394b408535c1db9b2635:9]={ +// "ObjectInfo": { +// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", +// "IsEscaped": true, +// "ModTime": "14", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm/struct.C" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "4cf8da80d5dec249a7b325ad5608c4e8187f60ac", +// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:10" +// } +// } +// } // d[5965ae851c02ab677bc8394b408535c1db9b2635:13] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22_func.gno b/gnovm/tests/files/zrealm_crossrealm22_func.gno index dd303addcbb..32a5542c33b 100644 --- a/gnovm/tests/files/zrealm_crossrealm22_func.gno +++ b/gnovm/tests/files/zrealm_crossrealm22_func.gno @@ -43,7 +43,6 @@ func main() { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "2" // }, // "Value": { @@ -82,6 +81,25 @@ func main() { // "RefCount": "1" // } // } +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d2ed801c0f8a7400a4078f780dcc37ab8027bd07", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// } +// } +// } // switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] @@ -106,13 +124,31 @@ func main() { // "RefCount": "1" // } // } +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "2" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "759fd5b507fff8ea1b18d401550d918387a63445", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// } +// } +// } // switchrealm["gno.land/r/demo/tests/crossrealm"] // u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ // "ObjectInfo": { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "1" // }, // "Value": { @@ -151,6 +187,25 @@ func main() { // "RefCount": "1" // } // } +// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ +// "ObjectInfo": { +// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", +// "IsEscaped": true, +// "ModTime": "5", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "63315e8945ea6a71e326ed6d680ac3c5e405906d", +// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" +// } +// } +// } // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] diff --git a/gnovm/tests/files/zrealm_crossrealm22a3.gno b/gnovm/tests/files/zrealm_crossrealm22a3.gno index ca7669d7680..00e96048af8 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a3.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a3.gno @@ -51,3 +51,22 @@ func main() { // "RefCount": "1" // } // } +// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ +// "ObjectInfo": { +// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", +// "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/crossrealm_test.Local_S" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "d436c9ee2f7cf94dd3e9e665ab79cd5fdf1583ee", +// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" +// } +// } +// } diff --git a/gnovm/tests/files/zrealm_crossrealm28c3.gno b/gnovm/tests/files/zrealm_crossrealm28c3.gno index e6875ec2111..f638d0ac140 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c3.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c3.gno @@ -104,7 +104,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", // "IsEscaped": true, // "ModTime": "28", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm28c6.gno b/gnovm/tests/files/zrealm_crossrealm28c6.gno index 9598c3581dd..c7311a435e4 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c6.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c6.gno @@ -94,7 +94,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "8", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm28d2.gno b/gnovm/tests/files/zrealm_crossrealm28d2.gno index 30f3e600025..a1eae20226f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d2.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d2.gno @@ -108,7 +108,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "29", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -128,7 +127,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", // "IsEscaped": true, // "ModTime": "29", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -148,7 +146,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", // "IsEscaped": true, // "ModTime": "29", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno index 4f159a0a431..7dd3f722b60 100644 --- a/gnovm/tests/files/zrealm_crossrealm30.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -48,7 +48,6 @@ func main() { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15", // "IsEscaped": true, // "ModTime": "3", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index d828bba22ce..e6e9bf0c1a5 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -77,7 +77,6 @@ func main() { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5", // "IsEscaped": true, // "ModTime": "28", -// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno index 1e39a579e4a..212e0fd6fdf 100644 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -60,7 +60,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "28", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -111,7 +110,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "3" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno index 0e5fb20eb6d..fcf1218c78f 100644 --- a/gnovm/tests/files/zrealm_crossrealm35a.gno +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -61,7 +61,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm37_map.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno index 36f8fa4884c..c1b48e23559 100644 --- a/gnovm/tests/files/zrealm_crossrealm37_map.gno +++ b/gnovm/tests/files/zrealm_crossrealm37_map.gno @@ -48,7 +48,6 @@ func main() { // "ID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:6", // "IsEscaped": true, // "ModTime": "3", -// "OwnerID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm41_method_local.gno b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno index 83b0e93b52b..7370869bc84 100644 --- a/gnovm/tests/files/zrealm_crossrealm41_method_local.gno +++ b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno @@ -103,7 +103,6 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_example.gno b/gnovm/tests/files/zrealm_example.gno index 45aeb7c5ddb..a179e8984ad 100644 --- a/gnovm/tests/files/zrealm_example.gno +++ b/gnovm/tests/files/zrealm_example.gno @@ -259,3 +259,22 @@ func main() { // "RefCount": "1" // } // } +// u[1ffd45e074aa1b8df562907c95ad97526b7ca187:4]={ +// "ObjectInfo": { +// "ID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:4", +// "ModTime": "11", +// "OwnerID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:2", +// "RefCount": "1" +// }, +// "Value": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/p/demo/dom.Plot" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "55cdade76217efb79610717408f633577326b29a", +// "ObjectID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:5" +// } +// } +// } diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 4ef3e0840dd..2624fb83bb6 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -137,7 +137,6 @@ func main() { // "ID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:7", // "IsEscaped": true, // "ModTime": "13", -// "OwnerID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:2", // "RefCount": "2" // }, // "Value": { From 419ec8f840ab6d614545b0974420af0fe44a9f87 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 10:18:33 +0800 Subject: [PATCH 85/88] rename --- gnovm/pkg/gnolang/ownership.go | 8 ++++---- gnovm/pkg/gnolang/realm.go | 32 ++++++++++++++++---------------- gnovm/pkg/gnolang/values.go | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 0b74a64e794..c7c222d6ea2 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -125,8 +125,8 @@ type Object interface { SetIsDeleted(bool, uint64) GetIsNewReal() bool SetIsNewReal(bool) - GetOriginRealm() PkgID - SetOriginRealm(pkgID PkgID) + GetBoundRealm() PkgID + SetBoundRealm(pkgID PkgID) GetIsAttachingRef() bool SetIsAttachingRef(bool) GetIsNewEscaped() bool @@ -349,11 +349,11 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { oi.isNewReal = x } -func (oi *ObjectInfo) GetOriginRealm() PkgID { +func (oi *ObjectInfo) GetBoundRealm() PkgID { return oi.originRealm } -func (oi *ObjectInfo) SetOriginRealm(pkgId PkgID) { +func (oi *ObjectInfo) SetBoundRealm(pkgId PkgID) { oi.originRealm = pkgId } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 4da8c5de2ed..cbcfa8bbe8b 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -185,8 +185,8 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co != nil { debug.Printf( - "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", - co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), + "co: %v (type: %v) | GetBoundRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", + co, reflect.TypeOf(co), co.GetBoundRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), ) } } @@ -237,11 +237,11 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } else { //rlm.MarkNewEscaped(co) // check cross realm - originRealm := co.GetOriginRealm() + boundRealm := co.GetBoundRealm() //fmt.Println("originRealm: ", originRealm) - if originRealm == rlm.ID { + if boundRealm == rlm.ID { //rlm.MarkNewEscaped(co) - } else if isCrossRealm(originRealm, rlm.ID) { + } else if isCrossRealm(boundRealm, rlm.ID) { if !co.GetIsAttachingRef() { panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", co)) } @@ -280,7 +280,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object } tv2 := fillValueTV(store, tv) if oo, ok := tv2.V.(Object); ok { - oo.SetOriginRealm(tv2.GetBoundRealmByType(oo)) + oo.SetBoundRealm(tv2.GetBoundRealmByType(oo)) checkCrossRealm(rlm, store, oo, seenObjs) } else { switch tv.V.(type) { @@ -300,7 +300,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object } // set origin realm info - reo.SetOriginRealm(tv2.GetBoundRealmByType(reo)) + reo.SetBoundRealm(tv2.GetBoundRealmByType(reo)) reo.SetIsAttachingRef(true) checkCrossRealm(rlm, store, reo, seenObjs) } @@ -311,24 +311,24 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object func checkCrossRealm(rlm *Realm, store Store, oo Object, seenObjs []Object) { if debug { debug.Printf( - "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetOriginRealm: %v (purePkg? %t) | rlm.ID: %v | isCurrentRef: %t\n", - oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetOriginRealm(), oo.GetOriginRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), + "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetBoundRealm: %v (purePkg? %t) | rlm.ID: %v | isCurrentRef: %t\n", + oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetBoundRealm(), oo.GetBoundRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), ) } // object from pure package is ok - if oo.GetOriginRealm().IsPurePkg() { + if oo.GetBoundRealm().IsPurePkg() { return } // for local realm checking, maybe a container not cross, // but its children does. - if oo.GetOriginRealm().IsZero() || rlm.ID == oo.GetOriginRealm() { + if oo.GetBoundRealm().IsZero() || rlm.ID == oo.GetBoundRealm() { checkCrossRealmChildren(rlm, store, oo, seenObjs) return } - if rlm.ID != oo.GetOriginRealm() { // crossing realm + if rlm.ID != oo.GetBoundRealm() { // crossing realm // When attaching a reference, ensure that the base object is real. // The child objects do not need to be real at this stage; // they can be attached(real) after. @@ -909,7 +909,7 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) { // if oo is from external realm, imply it's already real, // and it's attaching by ref, (after the checkCrossReal logic) // skip its unreal child, to be attached in respective realm - if !isCrossRealm(oo.GetOriginRealm(), rlm.ID) { + if !isCrossRealm(oo.GetBoundRealm(), rlm.ID) { unsaved = getUnsavedChildObjects(oo) } for _, uch := range unsaved { @@ -955,7 +955,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) { if oid.IsZero() { panic(fmt.Sprintf("unexpected zero object id: %v", oo)) } - if isCrossRealm(oo.GetOriginRealm(), rlm.ID) { + if isCrossRealm(oo.GetBoundRealm(), rlm.ID) { if !oo.GetIsEscaped() && !oo.GetIsNewEscaped() { panic("cannot attach object from external realm: object must be either escaped or newly escaped") } @@ -1792,6 +1792,6 @@ func getOwner(store Store, oo Object) Object { // if the origin realm is zero, e.g. an unreal array, // it is not considered a cross-realm scenario for now. // however, further checks on children are required afterward. -func isCrossRealm(originRealm, rlmID PkgID) bool { - return !originRealm.IsZero() && !originRealm.IsPurePkg() && originRealm != rlmID +func isCrossRealm(boundRealm, rlmID PkgID) bool { + return !boundRealm.IsZero() && !boundRealm.IsPurePkg() && boundRealm != rlmID } diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 6ad3fcd3201..3fadb35b73b 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -292,7 +292,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty // set origin realm to object if oo2 != nil && !originPkg.IsZero() { - oo2.SetOriginRealm(originPkg) // attach origin package info + oo2.SetBoundRealm(originPkg) // attach origin package info // used for checking cross realm after switch pv.TV.V.(type) { case *SliceValue, PointerValue: From 56513bd0fd0083440ebb5ec976a02f570f40bd86 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 11:26:56 +0800 Subject: [PATCH 86/88] refactor --- gnovm/pkg/gnolang/ownership.go | 61 +++++++++++-- gnovm/pkg/gnolang/realm.go | 85 ++++++++----------- gnovm/pkg/gnolang/values.go | 16 +--- .../files/zrealm_crossrealm15_struct.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22a2.gno | 2 +- .../tests/files/zrealm_crossrealm25_array.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c5.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm37d.gno | 2 +- 14 files changed, 105 insertions(+), 79 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index c7c222d6ea2..3a9d3fac223 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -177,7 +177,7 @@ type ObjectInfo struct { isNewDeleted bool // realm where object is from - originRealm PkgID + boundRealm PkgID // This flag indicates whether the object is being // attached as a base of reference or as itself. @@ -350,11 +350,11 @@ func (oi *ObjectInfo) SetIsNewReal(x bool) { } func (oi *ObjectInfo) GetBoundRealm() PkgID { - return oi.originRealm + return oi.boundRealm } func (oi *ObjectInfo) SetBoundRealm(pkgId PkgID) { - oi.originRealm = pkgId + oi.boundRealm = pkgId } func (oi *ObjectInfo) GetIsAttachingRef() bool { @@ -420,15 +420,66 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } } +func (tv *TypedValue) GetFirstObject2(store Store) Object { + //fmt.Println("GetFirstObject2, tv: ", tv, reflect.TypeOf(tv.V)) + obj := tv.GetFirstObject(store) + + // infer original package using declared type + getPkgId := func(t Type) (pkgId PkgID) { + if dt, ok := t.(*DeclaredType); ok { + pkgId = PkgIDFromPkgPath(dt.GetPkgPath()) + } + return + } + + var originPkg PkgID + + switch cv := obj.(type) { + case *HeapItemValue: + originPkg = getPkgId(cv.Value.T) + case *Block: + // assert to pointer value + if pv, ok := tv.V.(PointerValue); ok { + originPkg = getPkgId(pv.TV.T) + } else { + // XXX? + } + case *BoundMethodValue: + // do nothing + case *MapValue, *StructValue, *ArrayValue: + // if it's a declared type, origin realm + // is deduced from type, otherwise zero. + originPkg = getPkgId(tv.T) + default: + // do nothing + } + + // set origin realm to object + if obj != nil && !originPkg.IsZero() { + // attach bound package info + // used for checking cross realm after + obj.SetBoundRealm(originPkg) + switch tv.V.(type) { + case *SliceValue, PointerValue: + //fmt.Println("match!!!") + //fmt.Println("real? ", obj.GetIsReal()) + //obj.SetIsAttachingRef(true) + if obj.GetIsReal() { // if not real, is attaching by value, e.g. heapItemValue + obj.SetIsAttachingRef(true) + } + } + } + return obj +} + // GetBoundRealmByType retrieves the bound realm for the object // by checking its type. If the type is a declared type, it is // considered bound to a specific realm; otherwise, it returns zero. func (tv *TypedValue) GetBoundRealmByType(obj Object) (originPkg PkgID) { - // attempting to infer original package using declared type + // infer original package using declared type getPkgId := func(t Type) (pkgId PkgID) { if dt, ok := t.(*DeclaredType); ok { pkgId = PkgIDFromPkgPath(dt.GetPkgPath()) - return } return } diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index cbcfa8bbe8b..eaff59102bf 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -157,22 +157,6 @@ func (rlm *Realm) String() string { // ownership hooks func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { - //fmt.Printf( - // "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", - // po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), - //) - // - //if rlm != nil { - // fmt.Println("rlm.ID: ", rlm.ID) - //} - // - //if co != nil { - // fmt.Printf( - // "co: %v (type: %v) | GetOriginRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", - // co, reflect.TypeOf(co), co.GetOriginRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), - // ) - //} - if debug { debug.Printf( "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", @@ -191,9 +175,26 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } + //fmt.Printf( + // "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", + // po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), + //) + // + //if rlm != nil { + // fmt.Println("rlm.ID: ", rlm.ID) + //} + // + //if co != nil { + // fmt.Printf( + // "co: %v (type: %v) | GetBoundRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", + // co, reflect.TypeOf(co), co.GetBoundRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), + // ) + //} + if rlm == nil { return } + if debug { if co != nil && co.GetIsDeleted() { panic("cannot attach a deleted object") @@ -235,17 +236,12 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - //rlm.MarkNewEscaped(co) // check cross realm boundRealm := co.GetBoundRealm() - //fmt.Println("originRealm: ", originRealm) - if boundRealm == rlm.ID { - //rlm.MarkNewEscaped(co) - } else if isCrossRealm(boundRealm, rlm.ID) { + if isCrossRealm(boundRealm, rlm.ID) { if !co.GetIsAttachingRef() { - panic(fmt.Sprintf("cannot attach objects by value from external realm: %v", co)) + panic("cannot attach a value of a type defined by another realm") } - //rlm.MarkNewEscaped(co) } rlm.MarkNewEscaped(co) } @@ -279,31 +275,19 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object debug.Printf("checkCrossRealm2, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) } tv2 := fillValueTV(store, tv) - if oo, ok := tv2.V.(Object); ok { - oo.SetBoundRealm(tv2.GetBoundRealmByType(oo)) - checkCrossRealm(rlm, store, oo, seenObjs) - } else { - switch tv.V.(type) { - case *SliceValue, PointerValue: - reo := tv.GetFirstObject(store) - // if it is checking a pointer, and it - // has a base in current realm, implies - // the current realm is finalizing, - // just skip the next recursive step. - if _, ok := tv2.V.(PointerValue); ok { - // check recursive - if slices.Contains(seenObjs, reo) { - seenObjs = nil - return - } - seenObjs = append(seenObjs, reo) - } + oo2 := tv2.GetFirstObject2(store) - // set origin realm info - reo.SetBoundRealm(tv2.GetBoundRealmByType(reo)) - reo.SetIsAttachingRef(true) - checkCrossRealm(rlm, store, reo, seenObjs) + if oo2 != nil { + // if it is checking a pointer, and it + // has a base in current realm, implies + // the current realm is finalizing, + // just skip the next recursive step. + if slices.Contains(seenObjs, oo2) { + seenObjs = nil + return } + seenObjs = append(seenObjs, oo2) + checkCrossRealm(rlm, store, oo2, seenObjs) } } @@ -311,11 +295,16 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object func checkCrossRealm(rlm *Realm, store Store, oo Object, seenObjs []Object) { if debug { debug.Printf( - "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetBoundRealm: %v (purePkg? %t) | rlm.ID: %v | isCurrentRef: %t\n", + "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetBoundRealm: %v (purePkg? %t) | rlm.ID: %v | isAttachingRef: %t\n", oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetBoundRealm(), oo.GetBoundRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), ) } + //fmt.Printf( + // "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetBoundRealm: %v (purePkg? %t) | rlm.ID: %v | isAttachingRef: %t\n", + // oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetBoundRealm(), oo.GetBoundRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), + //) + // object from pure package is ok if oo.GetBoundRealm().IsPurePkg() { return @@ -776,7 +765,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store) { rlm.MarkDirty(po) } if eo.GetObjectID().IsZero() { - panic("new escaped mark has no object ID") + panic("new escaped object has no object ID") } // escaped has no owner. //fmt.Println("set owner to be nil") diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 3fadb35b73b..543dd68a6dd 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -286,21 +286,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty pv.TV.Assign(alloc, tv2, cu) - oo2 := pv.TV.GetFirstObject(store) - - originPkg := tv2.GetBoundRealmByType(oo2) - - // set origin realm to object - if oo2 != nil && !originPkg.IsZero() { - oo2.SetBoundRealm(originPkg) // attach origin package info - // used for checking cross realm after - switch pv.TV.V.(type) { - case *SliceValue, PointerValue: - if oo2.GetIsReal() { - oo2.SetIsAttachingRef(true) - } - } - } + oo2 := pv.TV.GetFirstObject2(store) rlm.DidUpdate(store, pv.Base.(Object), oo1, oo2) } else { diff --git a/gnovm/tests/files/zrealm_crossrealm15_struct.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno index 9c8f3517d3d..779699c9ca2 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_struct.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_struct.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index 77562f0049d..62895f77b0f 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm: heapitem((struct{} gno.land/r/crossrealm_test.fooer)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index 6a19f04dbbf..0985e07db71 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm: heapitem((struct{("A" string)} gno.land/r/crossrealm_test.fooer)) +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c1.gno b/gnovm/tests/files/zrealm_crossrealm20c1.gno index da88ce8abae..2b66bff4999 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c1.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c1.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm20d.gno b/gnovm/tests/files/zrealm_crossrealm20d.gno index 20f19d299e3..60779844976 100644 --- a/gnovm/tests/files/zrealm_crossrealm20d.gno +++ b/gnovm/tests/files/zrealm_crossrealm20d.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno index ea6e1159865..57aaddadade 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a2.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a2.gno @@ -26,4 +26,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm25_array.gno b/gnovm/tests/files/zrealm_crossrealm25_array.gno index 6049136fd6d..5d868a3abde 100644 --- a/gnovm/tests/files/zrealm_crossrealm25_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm25_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c5.gno b/gnovm/tests/files/zrealm_crossrealm28c5.gno index 55806fee1a0..e04b77c0a83 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c5.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c5.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index 08d11eecc8f..c20cec96458 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a reference to an unattached object from an external realm +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm37b.gno b/gnovm/tests/files/zrealm_crossrealm37b.gno index 6be87c2a785..7c9a31c126f 100644 --- a/gnovm/tests/files/zrealm_crossrealm37b.gno +++ b/gnovm/tests/files/zrealm_crossrealm37b.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm: map{("a" string):(1 int)} +// cannot attach a value of a type defined by another realm diff --git a/gnovm/tests/files/zrealm_crossrealm37d.gno b/gnovm/tests/files/zrealm_crossrealm37d.gno index cc7f0890709..00110da9ef7 100644 --- a/gnovm/tests/files/zrealm_crossrealm37d.gno +++ b/gnovm/tests/files/zrealm_crossrealm37d.gno @@ -11,4 +11,4 @@ func main() { } // Error: -// cannot attach objects by value from external realm: map{("a" string):(1 int)} +// cannot attach a value of a type defined by another realm From 10ff84cee0cb36d241dd4e331228ea0ad74453f5 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 14:44:49 +0800 Subject: [PATCH 87/88] simplify --- gnovm/pkg/gnolang/ownership.go | 55 ++----------------- gnovm/pkg/gnolang/realm.go | 49 +++++------------ gnovm/pkg/gnolang/values.go | 4 +- .../files/zrealm_crossrealm15_struct.gno | 2 +- gnovm/tests/files/zrealm_crossrealm16.gno | 2 +- gnovm/tests/files/zrealm_crossrealm17.gno | 2 +- gnovm/tests/files/zrealm_crossrealm19.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20c1.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20d.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20e.gno | 2 +- gnovm/tests/files/zrealm_crossrealm20f.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21a.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21b.gno | 2 +- gnovm/tests/files/zrealm_crossrealm21g.gno | 2 +- gnovm/tests/files/zrealm_crossrealm22a2.gno | 2 +- .../tests/files/zrealm_crossrealm25_array.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28c5.gno | 2 +- gnovm/tests/files/zrealm_crossrealm28d.gno | 2 +- 19 files changed, 39 insertions(+), 101 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 3a9d3fac223..c1410808ada 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -421,7 +421,6 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { } func (tv *TypedValue) GetFirstObject2(store Store) Object { - //fmt.Println("GetFirstObject2, tv: ", tv, reflect.TypeOf(tv.V)) obj := tv.GetFirstObject(store) // infer original package using declared type @@ -455,57 +454,15 @@ func (tv *TypedValue) GetFirstObject2(store Store) Object { } // set origin realm to object - if obj != nil && !originPkg.IsZero() { - // attach bound package info - // used for checking cross realm after - obj.SetBoundRealm(originPkg) + if obj != nil { + if !originPkg.IsZero() { + obj.SetBoundRealm(originPkg) + } + switch tv.V.(type) { case *SliceValue, PointerValue: - //fmt.Println("match!!!") - //fmt.Println("real? ", obj.GetIsReal()) - //obj.SetIsAttachingRef(true) - if obj.GetIsReal() { // if not real, is attaching by value, e.g. heapItemValue - obj.SetIsAttachingRef(true) - } + obj.SetIsAttachingRef(true) } } return obj } - -// GetBoundRealmByType retrieves the bound realm for the object -// by checking its type. If the type is a declared type, it is -// considered bound to a specific realm; otherwise, it returns zero. -func (tv *TypedValue) GetBoundRealmByType(obj Object) (originPkg PkgID) { - // infer original package using declared type - getPkgId := func(t Type) (pkgId PkgID) { - if dt, ok := t.(*DeclaredType); ok { - pkgId = PkgIDFromPkgPath(dt.GetPkgPath()) - } - return - } - - switch cv := obj.(type) { - case *HeapItemValue: - originPkg = getPkgId(cv.Value.T) - return - case *Block: - // assert to pointer value - if pv, ok := tv.V.(PointerValue); ok { - originPkg = getPkgId(pv.TV.T) - return - } else { - // XXX? - } - case *BoundMethodValue: - // do nothing - return - case *MapValue, *StructValue, *ArrayValue: - // if it's a declared type, origin realm - // is deduced from type, otherwise zero. - originPkg = getPkgId(tv.T) - return - default: - // do nothing - } - return -} diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index eaff59102bf..b32bea2db9a 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -175,22 +175,6 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { } } - //fmt.Printf( - // "DidUpdate - po: %v (type: %v) | xo: %v (type: %v) | co: %v (type: %v) \n", - // po, reflect.TypeOf(po), xo, reflect.TypeOf(xo), co, reflect.TypeOf(co), - //) - // - //if rlm != nil { - // fmt.Println("rlm.ID: ", rlm.ID) - //} - // - //if co != nil { - // fmt.Printf( - // "co: %v (type: %v) | GetBoundRealm: %v | GetIsRef: %v | GetRefCount: %v | GetIsReal: %v\n", - // co, reflect.TypeOf(co), co.GetBoundRealm(), co.GetIsAttachingRef(), co.GetRefCount(), co.GetIsReal(), - // ) - //} - if rlm == nil { return } @@ -226,9 +210,7 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { rlm.MarkDirty(po) if co != nil { - // XXX, inc ref count everytime assignment happens co.IncRefCount() - //fmt.Println("co.GetRefCount() after inc: ", co.GetRefCount()) if co.GetRefCount() > 1 { if co.GetIsReal() { rlm.MarkDirty(co) @@ -236,17 +218,11 @@ func (rlm *Realm) DidUpdate(store Store, po, xo, co Object) { if co.GetIsEscaped() { // already escaped } else { - // check cross realm - boundRealm := co.GetBoundRealm() - if isCrossRealm(boundRealm, rlm.ID) { - if !co.GetIsAttachingRef() { - panic("cannot attach a value of a type defined by another realm") - } - } + checkCrossRealm(rlm, store, co, nil) rlm.MarkNewEscaped(co) } } else { - if co.GetIsReal() { // e.g. refCount change + if co.GetIsReal() { rlm.MarkDirty(co) } else { co.SetOwner(po) @@ -300,23 +276,28 @@ func checkCrossRealm(rlm *Realm, store Store, oo Object, seenObjs []Object) { ) } - //fmt.Printf( - // "checkCrossRealm, oo: %v (type: %v) | GetIsReal: %t | oo.GetBoundRealm: %v (purePkg? %t) | rlm.ID: %v | isAttachingRef: %t\n", - // oo, reflect.TypeOf(oo), oo.GetIsReal(), oo.GetBoundRealm(), oo.GetBoundRealm().purePkg, rlm.ID, oo.GetIsAttachingRef(), - //) - // object from pure package is ok if oo.GetBoundRealm().IsPurePkg() { return } - // for local realm checking, maybe a container not cross, - // but its children does. - if oo.GetBoundRealm().IsZero() || rlm.ID == oo.GetBoundRealm() { + // same realm recursive check + if rlm.ID == oo.GetBoundRealm() { checkCrossRealmChildren(rlm, store, oo, seenObjs) return } + // if object does not have a + // bound realm. e.g. array, map, struct... + if oo.GetBoundRealm().IsZero() { + if oo.GetIsReal() && oo.GetIsAttachingRef() { + return + } else { + checkCrossRealmChildren(rlm, store, oo, seenObjs) + return + } + } + if rlm.ID != oo.GetBoundRealm() { // crossing realm // When attaching a reference, ensure that the base object is real. // The child objects do not need to be real at this stage; diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 543dd68a6dd..01feca12f6d 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2377,8 +2377,8 @@ func (b *Block) StringIndented(indent string) string { } lines := make([]string, 0, 3) lines = append(lines, - fmt.Sprintf("Block(ID:%v,Source:%s,Parent:%p)", - b.ObjectInfo.ID, source, b.Parent)) // XXX Parent may be RefValue{}. + fmt.Sprintf("Block(ID:%v,Addr:%p,Source:%s,Parent:%p)", + b.ObjectInfo.ID, b, source, b.Parent)) // XXX Parent may be RefValue{}. if b.Source != nil { if _, ok := b.Source.(RefNode); ok { lines = append(lines, diff --git a/gnovm/tests/files/zrealm_crossrealm15_struct.gno b/gnovm/tests/files/zrealm_crossrealm15_struct.gno index 779699c9ca2..3244ab560e3 100644 --- a/gnovm/tests/files/zrealm_crossrealm15_struct.gno +++ b/gnovm/tests/files/zrealm_crossrealm15_struct.gno @@ -22,4 +22,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm16.gno b/gnovm/tests/files/zrealm_crossrealm16.gno index 62895f77b0f..e9d79fb8f4d 100644 --- a/gnovm/tests/files/zrealm_crossrealm16.gno +++ b/gnovm/tests/files/zrealm_crossrealm16.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm17.gno b/gnovm/tests/files/zrealm_crossrealm17.gno index 6871e16bc53..3e1802177da 100644 --- a/gnovm/tests/files/zrealm_crossrealm17.gno +++ b/gnovm/tests/files/zrealm_crossrealm17.gno @@ -24,4 +24,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm19.gno b/gnovm/tests/files/zrealm_crossrealm19.gno index 0985e07db71..1a560daf32d 100644 --- a/gnovm/tests/files/zrealm_crossrealm19.gno +++ b/gnovm/tests/files/zrealm_crossrealm19.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c.gno b/gnovm/tests/files/zrealm_crossrealm20c.gno index dfec8344321..00cd8eb7228 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20c1.gno b/gnovm/tests/files/zrealm_crossrealm20c1.gno index 2b66bff4999..da88ce8abae 100644 --- a/gnovm/tests/files/zrealm_crossrealm20c1.gno +++ b/gnovm/tests/files/zrealm_crossrealm20c1.gno @@ -18,4 +18,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20d.gno b/gnovm/tests/files/zrealm_crossrealm20d.gno index 60779844976..20f19d299e3 100644 --- a/gnovm/tests/files/zrealm_crossrealm20d.gno +++ b/gnovm/tests/files/zrealm_crossrealm20d.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20e.gno b/gnovm/tests/files/zrealm_crossrealm20e.gno index 3d6b8f44402..7fb72906c19 100644 --- a/gnovm/tests/files/zrealm_crossrealm20e.gno +++ b/gnovm/tests/files/zrealm_crossrealm20e.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm20f.gno b/gnovm/tests/files/zrealm_crossrealm20f.gno index e228611dce5..11cf80fa0ec 100644 --- a/gnovm/tests/files/zrealm_crossrealm20f.gno +++ b/gnovm/tests/files/zrealm_crossrealm20f.gno @@ -15,4 +15,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21a.gno b/gnovm/tests/files/zrealm_crossrealm21a.gno index b70619b0391..017bbe0f748 100644 --- a/gnovm/tests/files/zrealm_crossrealm21a.gno +++ b/gnovm/tests/files/zrealm_crossrealm21a.gno @@ -21,4 +21,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21b.gno b/gnovm/tests/files/zrealm_crossrealm21b.gno index 182437c57fb..26a6d9ebc2f 100644 --- a/gnovm/tests/files/zrealm_crossrealm21b.gno +++ b/gnovm/tests/files/zrealm_crossrealm21b.gno @@ -19,4 +19,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm21g.gno b/gnovm/tests/files/zrealm_crossrealm21g.gno index 6883ec2e5e6..3aaef2dd2c9 100644 --- a/gnovm/tests/files/zrealm_crossrealm21g.gno +++ b/gnovm/tests/files/zrealm_crossrealm21g.gno @@ -14,4 +14,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm22a2.gno b/gnovm/tests/files/zrealm_crossrealm22a2.gno index 57aaddadade..ea6e1159865 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a2.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a2.gno @@ -26,4 +26,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm25_array.gno b/gnovm/tests/files/zrealm_crossrealm25_array.gno index 5d868a3abde..6049136fd6d 100644 --- a/gnovm/tests/files/zrealm_crossrealm25_array.gno +++ b/gnovm/tests/files/zrealm_crossrealm25_array.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28c5.gno b/gnovm/tests/files/zrealm_crossrealm28c5.gno index e04b77c0a83..55806fee1a0 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c5.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c5.gno @@ -27,4 +27,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm diff --git a/gnovm/tests/files/zrealm_crossrealm28d.gno b/gnovm/tests/files/zrealm_crossrealm28d.gno index c20cec96458..08d11eecc8f 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d.gno @@ -23,4 +23,4 @@ func main() { } // Error: -// cannot attach a value of a type defined by another realm +// cannot attach a reference to an unattached object from an external realm From bb084a5b9ca613fece4a4041e63d737aece186ae Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Wed, 19 Feb 2025 14:51:55 +0800 Subject: [PATCH 88/88] revert ownerID logic --- gnovm/pkg/gnolang/ownership.go | 11 +-- gnovm/pkg/gnolang/realm.go | 4 +- gnovm/tests/files/heap_item_value_init.gno | 1 + gnovm/tests/files/zrealm16.gno | 1 + gnovm/tests/files/zrealm_avl1.gno | 92 ------------------- gnovm/tests/files/zrealm_crossrealm17a.gno | 20 +--- gnovm/tests/files/zrealm_crossrealm21.gno | 20 +--- gnovm/tests/files/zrealm_crossrealm21d1.gno | 1 + gnovm/tests/files/zrealm_crossrealm21f.gno | 20 +--- .../tests/files/zrealm_crossrealm22_func.gno | 59 +----------- gnovm/tests/files/zrealm_crossrealm22a3.gno | 19 ---- gnovm/tests/files/zrealm_crossrealm28c3.gno | 1 + gnovm/tests/files/zrealm_crossrealm28c6.gno | 1 + gnovm/tests/files/zrealm_crossrealm28d2.gno | 3 + gnovm/tests/files/zrealm_crossrealm30.gno | 1 + gnovm/tests/files/zrealm_crossrealm33.gno | 1 + gnovm/tests/files/zrealm_crossrealm35.gno | 2 + gnovm/tests/files/zrealm_crossrealm35a.gno | 1 + gnovm/tests/files/zrealm_crossrealm37_map.gno | 1 + .../zrealm_crossrealm41_method_local.gno | 1 + gnovm/tests/files/zrealm_example.gno | 19 ---- gnovm/tests/files/zrealm_tests0.gno | 1 + 22 files changed, 27 insertions(+), 253 deletions(-) diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index c1410808ada..23b9ee79cfd 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -261,12 +261,11 @@ func (oi *ObjectInfo) SetOwner(po Object) { } func (oi *ObjectInfo) GetOwnerID() ObjectID { - //if oi.owner == nil { - // return ObjectID{} - //} else { - // return oi.owner.GetObjectID() - //} - return oi.OwnerID + if oi.owner == nil { + return ObjectID{} + } else { + return oi.owner.GetObjectID() + } } func (oi *ObjectInfo) GetIsOwned() bool { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index b32bea2db9a..3f4d0f85eb5 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -250,9 +250,7 @@ func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, seenObjs []Object if debug { debug.Printf("checkCrossRealm2, tv: %v (type: %v) \n", tv, reflect.TypeOf(tv.V)) } - tv2 := fillValueTV(store, tv) - oo2 := tv2.GetFirstObject2(store) - + oo2 := tv.GetFirstObject2(store) if oo2 != nil { // if it is checking a pointer, and it // has a base in current realm, implies diff --git a/gnovm/tests/files/heap_item_value_init.gno b/gnovm/tests/files/heap_item_value_init.gno index 1de1ee3e3ad..40f9752d22d 100644 --- a/gnovm/tests/files/heap_item_value_init.gno +++ b/gnovm/tests/files/heap_item_value_init.gno @@ -24,6 +24,7 @@ func main() { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm16.gno b/gnovm/tests/files/zrealm16.gno index 1752e442800..b7bef5028b0 100644 --- a/gnovm/tests/files/zrealm16.gno +++ b/gnovm/tests/files/zrealm16.gno @@ -79,6 +79,7 @@ func main() { // "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", // "IsEscaped": true, // "ModTime": "11", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_avl1.gno b/gnovm/tests/files/zrealm_avl1.gno index b6d580c082f..572c49333bc 100644 --- a/gnovm/tests/files/zrealm_avl1.gno +++ b/gnovm/tests/files/zrealm_avl1.gno @@ -326,97 +326,5 @@ func main() { // } // } // } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ -// "Fields": [ -// { -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "16" -// }, -// "V": { -// "@type": "/gno.StringValue", -// "value": "key1" -// } -// }, -// {}, -// { -// "N": "AQAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "64" -// } -// }, -// { -// "N": "AgAAAAAAAAA=", -// "T": { -// "@type": "/gno.PrimitiveType", -// "value": "32" -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/avl.Node" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "4e56eeb96eb1d9b27cf603140cd03a1622b6358b", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:6" -// }, -// "Index": "0", -// "TV": null -// } -// }, -// { -// "T": { -// "@type": "/gno.PointerType", -// "Elt": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/avl.Node" -// } -// }, -// "V": { -// "@type": "/gno.PointerValue", -// "Base": { -// "@type": "/gno.RefValue", -// "Hash": "cafae89e4d4aaaefe7fdf0691084508d4274a981", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:8" -// }, -// "Index": "0", -// "TV": null -// } -// } -// ], -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", -// "ModTime": "15", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", -// "RefCount": "0" -// } -// } -// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ -// "ObjectInfo": { -// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", -// "ModTime": "15", -// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", -// "RefCount": "0" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/avl.Node" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "e5c7483db73560f1baf6c46a30a91b0594da9c68", -// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5" -// } -// } -// } // d[a8ada09dee16d791fd406d629fe29bb0ed084a30:4] // d[a8ada09dee16d791fd406d629fe29bb0ed084a30:5] diff --git a/gnovm/tests/files/zrealm_crossrealm17a.gno b/gnovm/tests/files/zrealm_crossrealm17a.gno index b91eb4beff7..f221b81f6aa 100644 --- a/gnovm/tests/files/zrealm_crossrealm17a.gno +++ b/gnovm/tests/files/zrealm_crossrealm17a.gno @@ -35,6 +35,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "5", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -127,24 +128,5 @@ func main() { // "RefCount": "1" // } // } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", -// "IsEscaped": true, -// "ModTime": "7", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.container" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "ef7d0f54195eff59079f178206ba725d07f095a7", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" -// } -// } -// } // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21.gno b/gnovm/tests/files/zrealm_crossrealm21.gno index 6001a73666f..e3b29f671a4 100644 --- a/gnovm/tests/files/zrealm_crossrealm21.gno +++ b/gnovm/tests/files/zrealm_crossrealm21.gno @@ -29,6 +29,7 @@ func main() { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "5", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "2" // }, // "Value": { @@ -66,25 +67,6 @@ func main() { // "RefCount": "1" // } // } -// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "IsEscaped": true, -// "ModTime": "5", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "d2ed801c0f8a7400a4078f780dcc37ab8027bd07", -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" -// } -// } -// } // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm21d1.gno b/gnovm/tests/files/zrealm_crossrealm21d1.gno index 9b7a53f81da..1fb1e4d565b 100644 --- a/gnovm/tests/files/zrealm_crossrealm21d1.gno +++ b/gnovm/tests/files/zrealm_crossrealm21d1.gno @@ -109,6 +109,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:4", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm21f.gno b/gnovm/tests/files/zrealm_crossrealm21f.gno index a26b969ca39..2b7866126fd 100644 --- a/gnovm/tests/files/zrealm_crossrealm21f.gno +++ b/gnovm/tests/files/zrealm_crossrealm21f.gno @@ -23,6 +23,7 @@ func main() { // "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", // "IsEscaped": true, // "ModTime": "3", +// "OwnerID": "5965ae851c02ab677bc8394b408535c1db9b2635:2", // "RefCount": "2" // }, // "Value": { @@ -100,24 +101,5 @@ func main() { // "RefCount": "1" // } // } -// u[5965ae851c02ab677bc8394b408535c1db9b2635:9]={ -// "ObjectInfo": { -// "ID": "5965ae851c02ab677bc8394b408535c1db9b2635:9", -// "IsEscaped": true, -// "ModTime": "14", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm/struct.C" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "4cf8da80d5dec249a7b325ad5608c4e8187f60ac", -// "ObjectID": "5965ae851c02ab677bc8394b408535c1db9b2635:10" -// } -// } -// } // d[5965ae851c02ab677bc8394b408535c1db9b2635:13] // switchrealm["gno.land/r/crossrealm_test"] diff --git a/gnovm/tests/files/zrealm_crossrealm22_func.gno b/gnovm/tests/files/zrealm_crossrealm22_func.gno index 32a5542c33b..dd303addcbb 100644 --- a/gnovm/tests/files/zrealm_crossrealm22_func.gno +++ b/gnovm/tests/files/zrealm_crossrealm22_func.gno @@ -43,6 +43,7 @@ func main() { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "2" // }, // "Value": { @@ -81,25 +82,6 @@ func main() { // "RefCount": "1" // } // } -// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "IsEscaped": true, -// "ModTime": "5", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "d2ed801c0f8a7400a4078f780dcc37ab8027bd07", -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" -// } -// } -// } // switchrealm["gno.land/r/crossrealm_test"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] @@ -124,31 +106,13 @@ func main() { // "RefCount": "1" // } // } -// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "IsEscaped": true, -// "ModTime": "5", -// "RefCount": "2" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "759fd5b507fff8ea1b18d401550d918387a63445", -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" -// } -// } -// } // switchrealm["gno.land/r/demo/tests/crossrealm"] // u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ // "ObjectInfo": { // "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "0edc46caf30c00efd87b6c272673239eafbd051e:2", // "RefCount": "1" // }, // "Value": { @@ -187,25 +151,6 @@ func main() { // "RefCount": "1" // } // } -// u[0edc46caf30c00efd87b6c272673239eafbd051e:3]={ -// "ObjectInfo": { -// "ID": "0edc46caf30c00efd87b6c272673239eafbd051e:3", -// "IsEscaped": true, -// "ModTime": "5", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/demo/tests/crossrealm_b.fooer" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "63315e8945ea6a71e326ed6d680ac3c5e405906d", -// "ObjectID": "0edc46caf30c00efd87b6c272673239eafbd051e:4" -// } -// } -// } // switchrealm["gno.land/r/demo/tests/crossrealm_b"] // switchrealm["gno.land/r/demo/tests/crossrealm"] // switchrealm["gno.land/r/demo/tests/crossrealm_b"] diff --git a/gnovm/tests/files/zrealm_crossrealm22a3.gno b/gnovm/tests/files/zrealm_crossrealm22a3.gno index 00e96048af8..ca7669d7680 100644 --- a/gnovm/tests/files/zrealm_crossrealm22a3.gno +++ b/gnovm/tests/files/zrealm_crossrealm22a3.gno @@ -51,22 +51,3 @@ func main() { // "RefCount": "1" // } // } -// u[f5a516808f8976c33939133293d598ce3bca4e8d:3]={ -// "ObjectInfo": { -// "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", -// "ModTime": "5", -// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/r/crossrealm_test.Local_S" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "d436c9ee2f7cf94dd3e9e665ab79cd5fdf1583ee", -// "ObjectID": "f5a516808f8976c33939133293d598ce3bca4e8d:4" -// } -// } -// } diff --git a/gnovm/tests/files/zrealm_crossrealm28c3.gno b/gnovm/tests/files/zrealm_crossrealm28c3.gno index f638d0ac140..e6875ec2111 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c3.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c3.gno @@ -104,6 +104,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", // "IsEscaped": true, // "ModTime": "28", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm28c6.gno b/gnovm/tests/files/zrealm_crossrealm28c6.gno index c7311a435e4..9598c3581dd 100644 --- a/gnovm/tests/files/zrealm_crossrealm28c6.gno +++ b/gnovm/tests/files/zrealm_crossrealm28c6.gno @@ -94,6 +94,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "8", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm28d2.gno b/gnovm/tests/files/zrealm_crossrealm28d2.gno index a1eae20226f..30f3e600025 100644 --- a/gnovm/tests/files/zrealm_crossrealm28d2.gno +++ b/gnovm/tests/files/zrealm_crossrealm28d2.gno @@ -108,6 +108,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -127,6 +128,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:5", // "IsEscaped": true, // "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -146,6 +148,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:7", // "IsEscaped": true, // "ModTime": "29", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm30.gno b/gnovm/tests/files/zrealm_crossrealm30.gno index 7dd3f722b60..4f159a0a431 100644 --- a/gnovm/tests/files/zrealm_crossrealm30.gno +++ b/gnovm/tests/files/zrealm_crossrealm30.gno @@ -48,6 +48,7 @@ func main() { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:15", // "IsEscaped": true, // "ModTime": "3", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm33.gno b/gnovm/tests/files/zrealm_crossrealm33.gno index e6e9bf0c1a5..d828bba22ce 100644 --- a/gnovm/tests/files/zrealm_crossrealm33.gno +++ b/gnovm/tests/files/zrealm_crossrealm33.gno @@ -77,6 +77,7 @@ func main() { // "ID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:5", // "IsEscaped": true, // "ModTime": "28", +// "OwnerID": "ff34c6500d0daee58e4ac9899c0e7ecc131db63e:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm35.gno b/gnovm/tests/files/zrealm_crossrealm35.gno index 212e0fd6fdf..1e39a579e4a 100644 --- a/gnovm/tests/files/zrealm_crossrealm35.gno +++ b/gnovm/tests/files/zrealm_crossrealm35.gno @@ -60,6 +60,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "28", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { @@ -110,6 +111,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "3" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm35a.gno b/gnovm/tests/files/zrealm_crossrealm35a.gno index fcf1218c78f..0e5fb20eb6d 100644 --- a/gnovm/tests/files/zrealm_crossrealm35a.gno +++ b/gnovm/tests/files/zrealm_crossrealm35a.gno @@ -61,6 +61,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_crossrealm37_map.gno b/gnovm/tests/files/zrealm_crossrealm37_map.gno index c1b48e23559..36f8fa4884c 100644 --- a/gnovm/tests/files/zrealm_crossrealm37_map.gno +++ b/gnovm/tests/files/zrealm_crossrealm37_map.gno @@ -48,6 +48,7 @@ func main() { // "ID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:6", // "IsEscaped": true, // "ModTime": "3", +// "OwnerID": "5a06306c27263d4b9ae8f2f30e82f8ef014042cd:2", // "RefCount": "2" // } // } diff --git a/gnovm/tests/files/zrealm_crossrealm41_method_local.gno b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno index 7370869bc84..83b0e93b52b 100644 --- a/gnovm/tests/files/zrealm_crossrealm41_method_local.gno +++ b/gnovm/tests/files/zrealm_crossrealm41_method_local.gno @@ -103,6 +103,7 @@ func main() { // "ID": "f5a516808f8976c33939133293d598ce3bca4e8d:3", // "IsEscaped": true, // "ModTime": "6", +// "OwnerID": "f5a516808f8976c33939133293d598ce3bca4e8d:2", // "RefCount": "2" // }, // "Value": { diff --git a/gnovm/tests/files/zrealm_example.gno b/gnovm/tests/files/zrealm_example.gno index a179e8984ad..45aeb7c5ddb 100644 --- a/gnovm/tests/files/zrealm_example.gno +++ b/gnovm/tests/files/zrealm_example.gno @@ -259,22 +259,3 @@ func main() { // "RefCount": "1" // } // } -// u[1ffd45e074aa1b8df562907c95ad97526b7ca187:4]={ -// "ObjectInfo": { -// "ID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:4", -// "ModTime": "11", -// "OwnerID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:2", -// "RefCount": "1" -// }, -// "Value": { -// "T": { -// "@type": "/gno.RefType", -// "ID": "gno.land/p/demo/dom.Plot" -// }, -// "V": { -// "@type": "/gno.RefValue", -// "Hash": "55cdade76217efb79610717408f633577326b29a", -// "ObjectID": "1ffd45e074aa1b8df562907c95ad97526b7ca187:5" -// } -// } -// } diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 2624fb83bb6..4ef3e0840dd 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -137,6 +137,7 @@ func main() { // "ID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:7", // "IsEscaped": true, // "ModTime": "13", +// "OwnerID": "f643af0964f4fc0bfa4d9d204506cc75a00fac2d:2", // "RefCount": "2" // }, // "Value": {