Skip to content

feat(gnovm): initial inter-realm spec implementation #2958

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 120 commits into from

Conversation

ltzmaxwell
Copy link
Contributor

@ltzmaxwell ltzmaxwell commented Oct 16, 2024

address: the inter realm spec part from #2743.

Please refer to the original doc, and #2743 (comment)

And please see the comments below for details of implementation .

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

@ltzmaxwell ltzmaxwell requested review from jaekwon, moul, piux2, thehowl, mvertes and a team as code owners October 16, 2024 10:22
@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related labels Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 83.40249% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/realm.go 78.14% 28 Missing and 5 partials ⚠️
gnovm/pkg/gnolang/store.go 0.00% 2 Missing and 1 partial ⚠️
gnovm/pkg/gnolang/uverse.go 40.00% 3 Missing ⚠️
gnovm/pkg/gnolang/ownership.go 98.43% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jefft0 jefft0 added review/triage-pending PRs opened by external contributors that are waiting for the 1st review and removed review/triage-pending PRs opened by external contributors that are waiting for the 1st review labels Oct 16, 2024
@jefft0
Copy link
Contributor

jefft0 commented Oct 17, 2024

(The "review team" label was added by mistake. This PR is opened by a core dev.)

@leohhhn
Copy link
Contributor

leohhhn commented Mar 6, 2025

@thehowl @ltzmaxwell

Are there any specific behavioral patterns in Gno that would be introduced by this PR? If yes, let me know, so I can document them and share with the community.

@ltzmaxwell
Copy link
Contributor Author

@thehowl @ltzmaxwell

Are there any specific behavioral patterns in Gno that would be introduced by this PR? If yes, let me know, so I can document them and share with the community.

there is, I'll provide a short doc for you so that you can expand, as soon as possible.

@thehowl thehowl changed the title feat: PoC of inter-realm spec feat: initial inter-realm spec implementation Mar 6, 2025
@thehowl thehowl changed the title feat: initial inter-realm spec implementation feat(gnovm): initial inter-realm spec implementation Mar 6, 2025
@jaekwon
Copy link
Contributor

jaekwon commented Mar 7, 2025

look'n

Copy link
Contributor

@mvertes mvertes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me
Mainly cosmetic suggestions.

// If the object is unreal but already owned,
// it means the object is bound to this realm
// and must be attached to it.
// otherwise it zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// otherwise it zero

pkgIDFromPkgPathCache[path] = pkgID
}
return *pkgID
}

// Returns the ObjectID of the PackageValue associated with path.
// ObjectIDFromPkgPath the [ObjectID] of the [PackageValue] associated with path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ObjectIDFromPkgPath the [ObjectID] of the [PackageValue] associated with path.
// ObjectIDFromPkgPath returns the ObjectID of the PackageValue associated with path.

Using [ for emphasis can be confusing. I had to verify that you were not dealing with []ObjecID or []PackageValue.

func ObjectIDFromPkgPath(path string) ObjectID {
pkgID := PkgIDFromPkgPath(path)
return ObjectIDFromPkgID(pkgID)
}

// Returns the ObjectID of the PackageValue associated with pkgID.
// ObjectIDFromPkgID the [ObjectID] of the [PackageValue] associated with pkgID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ObjectIDFromPkgID the [ObjectID] of the [PackageValue] associated with pkgID.
// ObjectIDFromPkgID returns the ObjectID of the PackageValue associated with pkgID.


created []Object // about to become real.
updated []Object // real objects that were modified.
deleted []Object // real objects that became deleted.
escaped []Object // real objects with refcount > 1.
}

// Creates a blank new realm with counter 0.
// NewRealm a blank new [Realm] with counter 0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NewRealm a blank new [Realm] with counter 0.
// NewRealm creates a blank new Realm.

Comment on lines +118 to +119
// during a transaction, these actions are recorded through [Realm.DidUpdate].
// When a realm boundary is exited, then [Realm.FinalizeRealmTransaction] is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// during a transaction, these actions are recorded through [Realm.DidUpdate].
// When a realm boundary is exited, then [Realm.FinalizeRealmTransaction] is
// during a transaction, these actions are recorded through Realm.DidUpdate.
// When a realm boundary is crossed, then Realm.FinalizeRealmTransaction is

ID PkgID
// ID is a constant-sized hash for the realm's package path.
ID PkgID
// The realm package path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The realm package path.
// Path is the realm package path.

Comment on lines +128 to +129
// The "Time" of a realm; a variable increased for each new object, in order
// to assign it a unique [ObjectID].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The "Time" of a realm; a variable increased for each new object, in order
// to assign it a unique [ObjectID].
// Time is a counter to provide a unique ObjectID to each new object.

ltzmaxwell and others added 4 commits March 7, 2025 18:54
Co-authored-by: Marc Vertes <mvertes@free.fr>
Co-authored-by: Marc Vertes <mvertes@free.fr>
@@ -112,15 +114,16 @@ type Object interface {
SetIsDeleted(bool, uint64)
GetIsNewReal() bool
SetIsNewReal(bool)
GetBoundRealm() PkgID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "bound" is not used in the inter-realm spec; it is "attached" to the realm.
Confusing vs BoundMethod

// is deduced from type, otherwise zero.
boundRealm = getPkgId(tv.T)
default:
// do nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic, so future object types (if any) can be implemented and the panic help ensure to consider the logic here.

case *Block:
// assert to pointer value
if pv, ok := tv.V.(PointerValue); ok {
boundRealm = getPkgId(pv.TV.T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tv.V.(PointerValue), and tv.GetFirstObject() is *Block,
pv.TV is the thing being pointed to,
but getPkgId(pv.TV.T) has no relation to the block obj.

attachment comes from the LHS, all this logic is coming from the RHS

@@ -46,7 +46,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should be necessary to pass store in for inter-realm logic.
There's nothing in the spec that would necessitate loading anything from the store.
https://docs.google.com/document/d/1eCgGPCJ8fMhNc_vc_pbgCxP10X7jGKLC89nBUGatsD4/edit?tab=t.0

If something is in the store it is a RefValue, and from the RefValue you can tell what realm it's attached (stored) to. No need to load anything.

Probably because it's trying to do things from the RHS, and not purely from the LHS, as described here: https://github.com/gnolang/gno/pull/2958/files#r1986207268

I'm making another PR to demonstrate a simpler impl.

@ltzmaxwell
Copy link
Contributor Author

close as fixed by #4037 .

@ltzmaxwell ltzmaxwell closed this Apr 3, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in 💪 Bounties & Worx Apr 3, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team Apr 3, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

setting a closure across realm boundaries marks an entire block as owned by the called realm Gno Realm and Ownership Spec