-
Notifications
You must be signed in to change notification settings - Fork 23
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
result assignment should stay optional, except for var/lent result #241
Comments
...or simply deprecate and eventually remove |
The only advantage I see in result return value optimization. It seems to me (but I don't know the internals of the compiler) that if all code paths only assign to It may be the case that this is difficult to do in general, or that it is easy to do with other ways of returning. But the picture I have in my mind is that If |
Definite assignment analysis (DAA) has little to do with var x: int # please check for me every branch assigns a value to 'x'
case selector
of caseA:
if cond:
x = 3
else:
# more complex logic here
# oops I forgot to assign to 'x'
of caseB:
x = 4
of caseC:
x = 8 Nim's case statement checks for exhaustiveness, DAA is a nice extension. See https://docs.oracle.com/javase/specs/jls/se6/html/defAssign.html for the rules we could simply take over from Java. It works. Before Nim got |
Closing because it misrepresents my proposal which is #49 |
goal: discuss this topic here and not in unrelated issues like nim-lang/Nim#14777 (comment)
proposal
var result
Nim#13975 which accepts invalid code where result is not initialized in a trivial case(var int, int)
currently work with iterators (in RT, not VM), but not with procs; when they do, the proposal should apply to the components that arevar
, so that onlyvar
components should be initalized before use (and initialization stays optional for other components)lent result
, the rules are the same as forvar result
example
rationale for P2,P3,P4
should not be controversial, it's just correctness (otherwise you get SIGSEGV at runtime); ditto with
lent result
rationale for P1
nimZeroMem
calls Nim#14602), instead of forcing every function to intialize its result which seems pointless, since codegen can do it.The analysis is simple, and behaves as if
result = default(typeof(result))
was the first statement.links
var result
Nim#13975nimZeroMem
calls Nim#14602The text was updated successfully, but these errors were encountered: