-
Notifications
You must be signed in to change notification settings - Fork 379
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(gnovm): prevent cyclic references in type declarations #2081
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2081 +/- ##
==========================================
+ Coverage 60.11% 60.21% +0.09%
==========================================
Files 560 561 +1
Lines 74911 75060 +149
==========================================
+ Hits 45036 45198 +162
+ Misses 26500 26485 -15
- Partials 3375 3377 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This might be solvable by adding some logic in transcribe, without a dependency graph. This might be a better place than transcribe. var runDeclarationFor func(fn *FileNode, decl Decl) I don't know. Try it out and see what is the most appropriate place for this. |
This is great and proves to be the right way to go. It's already updated, please take a look @petar-dambovaliev . |
this PR is updated:
@mvertes @petar-dambovaliev @thehowl @ajnavarro would you please conduct a second review, Thank you! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I tried to break it but wasn't able to 😄. Just a suggestion for changing the panic message.
Co-authored-by: deelawn <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ltzmaxwell the code looks goods and testing cases are well defined.
Have we considered this cyclic dependency case? The Go compiler caught it.
package main
func main() {
}
var a = f1()
var b = f2()
func f1() int {
return b + 1
}
func f2() int {
return a + 1
}
// https://go.dev/play/p/FqTP7KNKQ0E?v=goprev
$ go tool compile cyclefunc.go
cyclefunc.go:7:5: initialization cycle for a
cyclefunc.go:7:5: a refers to
cyclefunc.go:10:6: f1 refers to
cyclefunc.go:8:5: b refers to
cyclefunc.go:14:6: f2 refers to
cyclefunc.go:7:5: a
@piux2 Thank you for your review! This particular case isn't included in the current PR, as it focuses on cycles in type declarations, whereas the issue above pertains to value declarations. Nonetheless, it's an excellent catch. I propose we track it with a separate issue and address it in a subsequent PR, what do you think? |
) Address gnolang#2008. In this pull request, we're implementing a special handling for type declarations to check cynic dependency. Due to their unique nature, we must meticulously search through their fields to identify potential cyclic reference. <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 - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: deelawn <[email protected]>
Address #2008.
In this pull request, we're implementing a special handling for type declarations to check cynic dependency. Due to their unique nature, we must meticulously search through their fields to identify potential cyclic reference.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description