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 39 commits into
base: master
Choose a base branch
from
Open

fix: global var dependencies #2077

wants to merge 39 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 61.15702% with 47 lines in your changes missing coverage. Please review.

Project coverage is 54.96%. Comparing base (0dc4b6d) to head (cea5e78).

Files Patch % Lines
gnovm/pkg/gnolang/preprocess.go 61.15% 42 Missing and 5 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2077    +/-   ##
========================================
  Coverage   54.96%   54.96%            
========================================
  Files         595      595            
  Lines       79568    79689   +121     
========================================
+ Hits        43731    43805    +74     
- Misses      32529    32571    +42     
- Partials     3308     3313     +5     
Flag Coverage Δ
contribs/gnodev 26.00% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
contribs/gnokeykc 0.00% <ø> (ø)
contribs/gnomd 0.00% <ø> (ø)
gno.land 63.14% <ø> (ø)
gnovm 60.32% <61.15%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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!

@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
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.

The tests are still not covering a bunch of the cases:

https://app.codecov.io/gh/gnolang/gno/pull/2077?src=pr&el=tree

DeferStmt, BlockStmt and other are not tested entirely. Please address the issues and add test cases which check against their conditions, as well as error conditions.

For a feature like this, there cannot be only 1 filetest.


func findUndefinedStmt(store Store, last BlockNode, stmt Stmt, t Type) Name {
switch s := stmt.(type) {
case *BranchStmt:
Copy link
Member

Choose a reason for hiding this comment

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

Can this be placed next to the case for nil, as they have the same result?

Comment on lines +2813 to +2814
curr := bn
for {
Copy link
Member

Choose a reason for hiding this comment

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

This code is quite convoluted, to do a for loop which should run at most twice

I also don't understand what's going on. Shouldn't this iterate through the parents? (Consider the case of a local declared in a function, accessed in a nested for loop / if block)

}
}

if name != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Can this not be a if name == "" { return "" } earlier on?

pkg := packageOf(last)

if _, _, ok := pkg.FileSet.GetDeclForSafe(name); !ok {
// skip it if it's a local identifier
Copy link
Member

Choose a reason for hiding this comment

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

This comment does not match what's going on

Copy link
Member

Choose a reason for hiding this comment

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

Can we also test for some error conditions?

Like, if there is actually a circular variable dependency when declaring closures.

Copy link
Member

Choose a reason for hiding this comment

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

There is no code handling ForStmt

return un
}
}
case *IfStmt:
Copy link
Member

Choose a reason for hiding this comment

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

There is no code handling the Init stmt

func findUndefinedStmt(store Store, last BlockNode, stmt Stmt, t Type) Name {
switch s := stmt.(type) {
case *BranchStmt:
case *ValueDecl:
Copy link
Member

Choose a reason for hiding this comment

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

The .Type field is not handled

return name
}

func findUndefinedStmt(store Store, last BlockNode, stmt Stmt, t Type) Name {
Copy link
Member

Choose a reason for hiding this comment

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

Type expressions are generally not handled, both for ValueDecl, but also TypeDecl's. (Types can be declared within a function block).

This code panics, for instance:

package main

var a = func() int {
	type B b
	x := B(1)
	return int(x)
}

type b int

func main() {
	println(a())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 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
6 participants