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

Merged

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

Attention: Patch coverage is 97.20280% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/preprocess.go 97.20% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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

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

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

Could you take a look on this pls :) thanks

@ltzmaxwell
Copy link
Contributor

sorry keep you waiting, gonna finalize my review tomorrow. 🙏

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.

mostly nits, but otherwise LGTM. thank you for the work.

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

look good to me. Thanks for addressing my remarks.

@ltzmaxwell
Copy link
Contributor

merge this, cc:/ @thehowl if you want review this in future.

@ltzmaxwell ltzmaxwell merged commit dc65f91 into gnolang:master Nov 21, 2024
101 checks passed
ltzmaxwell pushed a commit that referenced this pull request Nov 25, 2024
…tion which does not return any value (#3049)

This PR aims at resolving this issue:
#1082

This depends on #3017 because it
refactored the code to sync the logic/code between AssignStmt vs
ValueDecl.

Related #2695

<details><summary>Contributors' checklist...</summary>

- [ ] 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
</details>

---------

Co-authored-by: hieu.ha <[email protected]>
Co-authored-by: Mikael VALLENET <[email protected]>
n0izn0iz pushed a commit to n0izn0iz/gno that referenced this pull request Nov 26, 2024
…tion which does not return any value (gnolang#3049)

This PR aims at resolving this issue:
gnolang#1082

This depends on gnolang#3017 because it
refactored the code to sync the logic/code between AssignStmt vs
ValueDecl.

Related gnolang#2695

<details><summary>Contributors' checklist...</summary>

- [ ] 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
</details>

---------

Co-authored-by: hieu.ha <[email protected]>
Co-authored-by: Mikael VALLENET <[email protected]>
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: Done
Development

Successfully merging this pull request may close these issues.

7 participants