-
-
Notifications
You must be signed in to change notification settings - Fork 608
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 20674, 23208, 23300 - improve scope inference
#14492
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14492" |
d0995af
to
60fb263
Compare
7c53905
to
ef49402
Compare
ef49402
to
cdaed00
Compare
feb2023
to
e8329d4
Compare
| @@ -1105,7 +1105,7 @@ extern (C++) class VarDeclaration : Declaration | |||
| VarDeclaration lastVar; // Linked list of variables for goto-skips-init detection | |||
| Expression edtor; // if !=null, does the destruction of the variable | |||
| IntRange* range; // if !=null, the variable is known to be within the range | |||
| VarDeclarations* maybes; // maybeScope variables that are assigned to this maybeScope variable | |||
| VarDeclaration lifetimeParent; // the declaration with represents the lifetime of this variable, null = its own root | |||
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 doing this. This, as far as the comment goes, seems much easier to reason about.
|
Will this refactoring make it easier to implement automatic scope inference of variables? Even including parameters of function templates? An idea Walter has approved of. |
This is not a refactoring, it is the new implementation of automatic Currently
The new system treats both the same, and puts every 'maybe scope' variable in a set. When one maybe scope variable is assigned to another, it joins the two sets. As soon as any of them is inferred The new system is still a bit pessimistic, but:
Scope inference of parameters is only enabled in templates, nested functions and |
e8329d4
to
08d3318
Compare
|
src/dmd/frontend.h needs update as per https://auto-tester.puremagic.com/show-run.ghtml?projectid=1&runid=5352408&isPull=true. To update
|
I know, see the WIP tag ;) I'm currently focusing on making my test case for return scope inference after assignment pass. |
Ahh, sorry. |
2e3bead
to
e9fcab1
Compare
e9fcab1
to
4ef374f
Compare
|
This work appears to be much more important than just scope inference. Having a way to tie a variable to its lifetime root, means we have a way to ensure the correct order of destruction of memory; this means we can very easily do a "borrow checker" with only the owner being able to be destroyed automatically. 😄 |
Remove the complex and broken
eliminateMaybeScopessystem for parameters, and use a simpler scheme for both parameters and local variables. When you assignva = v, then add a link fromvatovand whenvabecomesreturn scopeornotMaybeScope, then do the same forv.It's not complete yet, I still need to go the other way and test more thoroughly, but I'm already opening a PR to get feedback from the test suite, and so that I can link to this central PR when making smaller PRs.