Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP fix(gnovm): correct map key persistence #3127

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

ltzmaxwell
Copy link
Contributor

@ltzmaxwell ltzmaxwell commented Nov 14, 2024

closes: #2060 and some other issues, by:

  • correct map key computation when it's a pointer;
  • make key object owned by map value.
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

@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Nov 14, 2024
@ltzmaxwell
Copy link
Contributor Author

ltzmaxwell commented Nov 15, 2024

another bug identified:

// PKGPATH: gno.land/r/ptr_map
package ptr_map

import "fmt"

type MyStruct struct {
	Name string
}

var (
	m = map[[1]*MyStruct]string{}

	i1   = &MyStruct{Name: "alice"}
	key1 = [1]*MyStruct{i1}
)

func init() {
	m[key1] = "first key"
}

func main() {
	fmt.Println("Value for key1:", m[key1])
}

// Error:
// interface conversion: gnolang.Value is gnolang.RefValue, not *gnolang.ArrayValue

this if fixed.

@ltzmaxwell
Copy link
Contributor Author

ltzmaxwell commented Nov 15, 2024

also this, is it counterintuitive?

// PKGPATH: gno.land/r/ptr_map
package ptr_map

type MyStruct struct {
	Name string
}

var (
	m = map[[1]*MyStruct]string{}

	i1 = &MyStruct{Name: "alice"}
)

func main() {
	// Create an array of pointers to MyStruct
	key1 := [1]*MyStruct{i1}
	m[key1] = "first key"
}
// Error:
// unexpected unreal object

this is fixed but should consider the side effects on storage.

XXX, the right way to fix it should me make map key object owned by map.

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/machine.go 0.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Kouteki Kouteki added the in focus Core team is prioritizing this work label Nov 15, 2024
@Kouteki Kouteki added this to the 🚀 Mainnet launch milestone Nov 15, 2024
@ltzmaxwell ltzmaxwell marked this pull request as draft November 18, 2024 03:00
@ltzmaxwell
Copy link
Contributor Author

ltzmaxwell commented Nov 27, 2024

also this, is it counterintuitive?

// PKGPATH: gno.land/r/ptr_map
package ptr_map

type MyStruct struct {
	Name string
}

var (
	m = map[[1]*MyStruct]string{}

	i1 = &MyStruct{Name: "alice"}
)

func main() {
	// Create an array of pointers to MyStruct
	key1 := [1]*MyStruct{i1}
	m[key1] = "first key"
}
// Error:
// unexpected unreal object

this is fixed but should consider the side effects on storage.

XXX, the right way to fix it should me make map key object owned by map.

This one should be fixed in another scope.

// update:
It's fixed in this PR.

@ltzmaxwell ltzmaxwell changed the title WIP fix(gnovm): correct map key persistence fix(gnovm): correct map key persistence Nov 28, 2024
Comment on lines 17 to 21
key1 := [1]*MyStruct{i1}
m[key1] = "first key"
println(m[key1])
m[key1] = "second key"
println(m[key1])
Copy link
Contributor Author

@ltzmaxwell ltzmaxwell Nov 29, 2024

Choose a reason for hiding this comment

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

In the current solution, assigning i1.Age = 3 creates a new key, leaving the old one dangling, which is not the expected behavior.

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Nov 30, 2024

🛠 PR Checks Summary

🔴 The pull request head branch must be up-to-date with its base (more info)

Manual Checks (for Reviewers):
  • SKIP: Do not block the CI for this PR
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 The pull request head branch must be up-to-date with its base (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: ltzmaxwell/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

The pull request head branch must be up-to-date with its base (more info)

If

🟢 Condition met
└── 🟢 On every pull request

Then

🔴 Requirement not satisfied
└── 🔴 Head branch (ltzmaxwell:fix/maxwell/mapkey-persistence) is up to date with base (master): behind by 110 / ahead by 34

Manual Checks
**SKIP**: Do not block the CI for this PR

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@ltzmaxwell ltzmaxwell changed the title fix(gnovm): correct map key persistence WIP fix(gnovm): correct map key persistence Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in focus Core team is prioritizing this work 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[GnoVM] bug: inconsistent map key
3 participants