-
Notifications
You must be signed in to change notification settings - Fork 375
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: Terminating analysis #1750
Conversation
It looks good. Like package strconv
func Itoa(n int) string You need to identify |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1750 +/- ##
==========================================
- Coverage 47.44% 45.26% -2.19%
==========================================
Files 384 464 +80
Lines 61220 68515 +7295
==========================================
+ Hits 29045 31010 +1965
- Misses 29745 34902 +5157
- Partials 2430 2603 +173 ☔ View full report in Codecov by Sentry. |
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.
300 lines (without the tests). I like it.
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.
I agree that the terminating statement analysis proposed here is complying to the Go specification and seems correct in its implementation.
However I'm not sure that it is the best response (or at least not sufficient) to the class of errors we want to address here: missing or wrong return statements.
We should have instead a check of each return statement to be compliant with the function signature (including the special case of pre-declared returned values allowing an empty return), and the detection of a missing return at the end of function body.
This check will still be necessary, even if we implement termination analysis.
If we have this check, then termination analysis becomes much less useful, except to catch the possibility of skipping a return if all the previous branches have one, which is just an optimisation.
To me the gain of termination analysis in this context is marginal. I don't know if it is justified in the context of an interpreter. Or maybe I missed something ?
This is exactly what this PR does
The idea of this was to catch bad code like func foo(b bool) int {
if b {
return 1
}
} Which corrupts the VM stack. |
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.
After discussing and thinking more, I agree that your solution is the way to go 👍 .
Could you add also the following test which should pass ?
func f(a int) int {
switch a {
case 1:
return 1
default:
return 0
}
// no return needed here
}
Also the same for if
:
func f(a int) int {
if a > 0 {
return 1
} else {
return 0
}
// no return needed
}
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.
Thank you for the contribution 🙏
I've left some comments that should be addressed before we go ahead and merge -- they're mostly style related, but also address some sketchy parts of the PR
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.
Thank you for resolving the comments 🙏
I've just left a single point about a typo, otherwise we are good to go 🚀
@KemalBekir we host a weekly developer call and would love to have you join if you're interested. Are you also on our Discord channe? |
This PR solves: This issue