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

feat(gnovm): sync code AssignStmt - ValueDecl #3017

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

Conversation

hthieu1110
Copy link
Contributor

@hthieu1110 hthieu1110 commented Oct 24, 2024

This PR aims at fixing this issue 1958

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 the 📦 🤖 gnovm Issues or PRs gnovm related label Oct 24, 2024
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.27%. Comparing base (bd1d76e) to head (4adcf7b).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3017      +/-   ##
==========================================
- Coverage   63.79%   63.27%   -0.52%     
==========================================
  Files         549      548       -1     
  Lines       78819    78390     -429     
==========================================
- Hits        50279    49598     -681     
- Misses      25150    25441     +291     
+ Partials     3390     3351      -39     
Flag Coverage Δ
contribs/gnofaucet 14.82% <ø> (ø)
misc/genstd 79.72% <ø> (ø)

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.

@hthieu1110 hthieu1110 changed the title Feat/sync assignstmt valuedecl 1958 feat(gnovm) sync assignstmt - valuedecl Oct 25, 2024
@hthieu1110 hthieu1110 changed the title feat(gnovm) sync assignstmt - valuedecl feat(gnovm): sync assignstmt - valuedecl Oct 25, 2024
@hthieu1110 hthieu1110 changed the title feat(gnovm): sync assignstmt - valuedecl feat(gnovm): sync AssignStmt - ValueDecl Oct 25, 2024
@hthieu1110 hthieu1110 changed the title feat(gnovm): sync AssignStmt - ValueDecl feat(gnovm): sync code AssignStmt - ValueDecl Oct 25, 2024
Copy link
Contributor

@MikaelVallenet MikaelVallenet 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 🔥

gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
@hthieu1110
Copy link
Contributor Author

thanks @mvertes for your time and your reviews , I've addressed all your feedbacks. Please re-check the PR, please. Thanksssss.

Comment on lines 2262 to 2263
if len(n.Values) > 1 && len(n.NameExprs) != len(n.Values) {
panic(fmt.Sprintf("assignment mismatch: %d variable(s) but %d value(s)", len(n.NameExprs), len(n.Values)))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry my last request. What do you think about moving this check into the defineOrDecl function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think it's good idea. Because it was done in AssertCompatible for Define so it's kind of duplicated check but regroup all needed check in defineOrDecl is OK I think

gnovm/tests/files/assign25c.gno Outdated Show resolved Hide resolved
gnovm/tests/files/assign25d.gno Outdated Show resolved Hide resolved
gnovm/tests/files/assign33.gno Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
@ltzmaxwell
Copy link
Contributor

ltzmaxwell commented Nov 8, 2024

When handling assignStmt and valueDecl, there are two main tasks:

  • Ensuring the compatibility of the statement(in type_check.go)
    func (x *AssignStmt) AssertCompatible(store Store, last BlockNode) {
  • Performing declarations for nameExprs(in preprocess.go, defineOrDecl)

To unify the specifications for assignStmt and valueDecl, these tasks should be handled consistently for both.

For example:

package main

func main() {
    var a int = "hello" // valueDecl

    var a int
    a = "hello" // assignStmt
}

In this code, both valueDecl and assignStmt should follow the same logic during type checking to ensure compatibility(in type_check.go).

To summarize, we should apply both AssertCompatible(step1) and defineOrDecl (step2) operations to handle assignStmt and valueDecl consistently.

what do you think?

@ltzmaxwell
Copy link
Contributor

ltzmaxwell commented Nov 8, 2024

Related: #2695

@hthieu1110
Copy link
Contributor Author

When handling assignStmt and valueDecl, there are two main tasks:

  • Ensuring the compatibility of the statement(in type_check.go)
    func (x *AssignStmt) AssertCompatible(store Store, last BlockNode) {
  • Performing declarations for nameExprs(in preprocess.go, defineOrDecl)

To unify the specifications for assignStmt and valueDecl, these tasks should be handled consistently for both.

For example:

package main

func main() {
    var a int = "hello" // valueDecl

    var a int
    a = "hello" // assignStmt
}

In this code, both valueDecl and assignStmt should follow the same logic during type checking to ensure compatibility(in type_check.go).

To summarize, we should apply both AssertCompatible(step1) and defineOrDecl (step2) operations to handle assignStmt and valueDecl consistently.

what do you think?

Thanks for your review.

I've checked the code, there is only one re-usable code in AssignStmt assertCompatible is:

if numNames != len(cft.Results) {
panic(fmt.Sprintf(
	"assignment mismatch: "+
		"%d variables but %s returns %d values",
	numNames, cx.Func.String(), len(cft.Results)))
}

Which is already handled in defineOrDecl.

Other processings are mostly for Assign.

I've tried to refactor to be able to share the code even more (refactor/reuse assertCompatible) but don't find any "happy/good" solution. Do you have any idea on that ?

@jefft0 jefft0 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Nov 14, 2024
@jefft0
Copy link
Contributor

jefft0 commented Nov 14, 2024

Removed the review/triage-pending label because this PR was reviewed by core devs mvertes and ltzmaxwell.

@jefft0
Copy link
Contributor

jefft0 commented Nov 14, 2024

Hello @hthieu1110 . Many of the CI checks failed because of a misconfiguration. This has now been fixed. Can you please push an empty commit? This will make the CI checks run again and hopefully fix them.

@Kouteki Kouteki added the in focus Core team is prioritizing this work label Nov 17, 2024
@Kouteki Kouteki requested review from mvertes and ltzmaxwell and removed request for thehowl November 17, 2024 08:43
@Kouteki Kouteki added this to the 🚀 Mainnet launch milestone Nov 17, 2024
@Kouteki
Copy link
Contributor

Kouteki commented Nov 17, 2024

Can you please push an empty commit? This will make the CI checks run again and hopefully fix them.

We're having issues with Codecov, ignore failed Codecov tests for now.

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 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

7 participants