-
-
Notifications
You must be signed in to change notification settings - Fork 718
Implement fast DFA's escape analysis #23314
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| The fast DFA engine has gained escape analysis capabilities | ||
|
|
||
| The engine works on the fundamental concept on "cells", a cell is a location in memory that holds something. | ||
| So a variable that is on the stack has a cell that provides it, but also may point to another cell if its typed as a pointer. | ||
|
|
||
| Due to the fast DFA engine not being able to model indirection, the cell of a variable and its containing pointer is considered separately from cells seen via indirection. | ||
| This is particularly interesting with how by-ref parameters handle it. | ||
| The cell pointed at by the by-ref is the outer cell, even if its typed as a pointer. | ||
|
|
||
| ```d | ||
| // Think of parameter as int* not int, so the outer cell is the container for the int. | ||
| int* pointToRefCell(ref int arg) => &arg; | ||
| ``` | ||
| This allows you to escape values that come from indirection: | ||
|
|
||
| ```d | ||
| struct Animal { | ||
| int* datem; | ||
| } | ||
|
|
||
| int* grabFromAnimal(scope Animal* animal) => animal.datem; | ||
| ``` | ||
|
|
||
| Partial violations of ``scope`` is allowed in non-@safe functions. | ||
| Escaping via a throw statement will still error. | ||
|
|
||
| The first 29 parameters may be treated as outputs, all others must be inputs only. | ||
| This does not include the this pointer. | ||
|
|
||
| No attributes have been added at this time for users to use, you must rely solely on existing ones and inference. | ||
|
|
||
| Experimentally it may promote stack variables that are typed as a class to stack automatically. | ||
| This may be disabled in the future if it is shown to cause problems. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's not clear what this changelog item is for.
scopeis only mentioned here - presumably it does some kind of enforcement ofscope, plus inferringscope? That should be explained in the changelog. What does this do that DIP1000 cannot?Uh oh!
There was an error while loading. Please reload this page.
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.
Escape analysis is already merged with its own changelog.
The main difference is it models the unknown, and won't error when information is missing.
Dmd cannot do strong guarantees for effects analysis due to compiler architecture limitations.
It is why we have had "attribute soup" for so long.
EDIT: Oh wait this is the escape analysis PR, not borrow checker.