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

fix: global var dependencies #2077

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open

fix: global var dependencies #2077

wants to merge 57 commits into from

Conversation

petar-dambovaliev
Copy link
Contributor

@petar-dambovaliev petar-dambovaliev commented May 13, 2024

fixes this by adding missing logic in in findUndefined2

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label May 13, 2024
@petar-dambovaliev petar-dambovaliev marked this pull request as ready for review May 13, 2024 12:16
Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 53.01455% with 226 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/preprocess.go 53.01% 209 Missing and 17 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Left some nitty comments 🙏

Overall looks good, thank you for the fix 🙏

gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

Please also add more tests to check for different cases, thanks!

@petar-dambovaliev petar-dambovaliev requested review from a team, gfanton and leohhhn as code owners June 12, 2024 13:02
@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Jun 12, 2024
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Dec 9, 2024

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

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

✅ Automated Checks (for Contributors):

No automated checks match this pull request.

☑️ 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
Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@Kouteki
Copy link
Contributor

Kouteki commented Jan 16, 2025

@petar-dambovaliev I've moved this PR to draft until it's ready for review.

@petar-dambovaliev petar-dambovaliev marked this pull request as ready for review January 16, 2025 22:24
@petar-dambovaliev
Copy link
Contributor Author

petar-dambovaliev commented Jan 16, 2025

Only codecov failing. Its ready. @Kouteki

Copy link
Contributor

@ltzmaxwell ltzmaxwell left a comment

Choose a reason for hiding this comment

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

LGTM! A few requests, mostly regarding comments, so we can avoid reviewing this as a brand new PR each time. :)

Comment on lines +4038 to +4045
func getGlobalValueRef(sb BlockNode, store Store, n Name) *TypedValue {
sbb := sb.GetStaticBlock()
idx, ok := sb.GetLocalIndex(n)
bb := &sb.GetStaticBlock().Block
bp := sb.GetParentNode(store)

for {
if ok && sbb.Types[idx] != nil && (bp == nil || bp.GetParentNode(store) == nil) {
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
func getGlobalValueRef(sb BlockNode, store Store, n Name) *TypedValue {
sbb := sb.GetStaticBlock()
idx, ok := sb.GetLocalIndex(n)
bb := &sb.GetStaticBlock().Block
bp := sb.GetParentNode(store)
for {
if ok && sbb.Types[idx] != nil && (bp == nil || bp.GetParentNode(store) == nil) {
func getGlobalValueRef(sb BlockNode, store Store, n Name) *TypedValue {
sbb := sb.GetStaticBlock()
bb := &sb.GetStaticBlock().Block
bp := sb.GetParentNode(store)
idx, exist := sb.GetLocalIndex(n)
for {
if exist && sbb.Types[idx] != nil && (bp == nil || bp.GetParentNode(store) == nil) {

}
}

func findUndefinedGlobal(store Store, last BlockNode, x Expr, t Type) (un Name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

will findUndefinedFromGlobal be more directional?


// finds the next undefined identifier and returns it if it is global
func findUndefined2SkipLocals(store Store, last BlockNode, x Expr, t Type) Name {
name := findUndefinedGlobal(store, last, x, t)
Copy link
Contributor

Choose a reason for hiding this comment

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

as the base logic of the PR, please add comments to this function. to better illustrate the searching logic:
for my understanding: searching from initialized global -> uninitialized global decls -> local...

Comment on lines +3838 to +3840
if _, _, ok := pkg.FileSet.GetDeclForSafe(name); !ok {
return ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

also need comments here.

return ""
}

isLocal := existsLocal(name, last)
Copy link
Contributor

Choose a reason for hiding this comment

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

and here.

bp := sb.GetParentNode(store)

for {
if ok && sbb.Types[idx] != nil && (bp == nil || bp.GetParentNode(store) == nil) {
Copy link
Contributor

@ltzmaxwell ltzmaxwell Jan 17, 2025

Choose a reason for hiding this comment

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

sbb.Types[idx] != nil implies it's defined rather than predefined, right? please add a comment here.

for {
currNames := curr.GetBlockNames()

for _, currName := range currNames {
Copy link
Contributor

@ltzmaxwell ltzmaxwell Jan 17, 2025

Choose a reason for hiding this comment

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

searching (only)by name implies predefined(only names, no types) is good, right? please also add comment here.

@ltzmaxwell
Copy link
Contributor

and what we do with the codecov? @petar-dambovaliev @zivkovicmilos

return ""
}

func getGlobalValueRef(sb BlockNode, store Store, n Name) *TypedValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

better make it a method like the existing one:
func (sb *StaticBlock) GetValueRef(store Store, n Name, skipPredefined bool),

bp := sb.GetParentNode(store)

for {
if ok && sbb.Types[idx] != nil && (bp == nil || bp.GetParentNode(store) == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if it must reach bp == nil to make sure it's global, then bp.GetParentNode(store) == nil is not needed/reachable.

gnovm/pkg/gnolang/preprocess.go Show resolved Hide resolved
@ltzmaxwell
Copy link
Contributor

Perhaps the logic in findUndefined2SkipLocals could be simplified further by modifying it to only find the name without type (which would imply that the predefined name is enough). In that case, GetDeclForSafe would no longer be necessary, correct?

@ltzmaxwell
Copy link
Contributor

Perhaps the logic in findUndefined2SkipLocals could be simplified further by modifying it to only find the name without type (which would imply that the predefined name is enough). In that case, GetDeclForSafe would no longer be necessary, correct?

maybe the difference won't be big, just some food for thoughts.

@petar-dambovaliev
Copy link
Contributor Author

Perhaps the logic in findUndefined2SkipLocals could be simplified further by modifying it to only find the name without type (which would imply that the predefined name is enough). In that case, GetDeclForSafe would no longer be necessary, correct?

maybe the difference won't be big, just some food for thoughts.

At first, i tried having a single function but it became too many changes and too messy

@petar-dambovaliev petar-dambovaliev enabled auto-merge (squash) January 18, 2025 19:30
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 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ 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: In Progress
Status: No status
Status: In Review
Development

Successfully merging this pull request may close these issues.

in variable initialization, dependencies within functions are not recursively resolved
10 participants