From 0d2c203ee067649c6575137bca132d3813ccf3a4 Mon Sep 17 00:00:00 2001 From: ltzMaxwell Date: Tue, 26 Nov 2024 18:48:22 +0900 Subject: [PATCH] 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