-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
return scope: first support #5972
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0de3e4d
return scope: first support
WalterBright 62be2fb
check assignments to globals
WalterBright eb4d6fe
allow 'return scope' parameters that return by 'ref'
WalterBright 7c3e47a
fix Issue 14238 - DIP25: escape checks can be circumvented with delegate
WalterBright 56b904c
create EscapeByResults struct
WalterBright e61378a
fix Issue 15544 - Escaping fields to a heap delegate must be disallow…
WalterBright 66187b5
fix Issue 8838 - Slicing static arrays should be considered unsafe (@…
WalterBright 128f3fa
add parameterStorageClass()
WalterBright d612c94
add inference of 'scope' for parameters for inferrable functions
WalterBright 57a0b21
refactor: add Parameter.isCovariant()
WalterBright 1cce2ee
add 'scope' support to 'this'
WalterBright 75647f5
add lifetime checks
WalterBright 6d4de39
fix checking for struct fields
WalterBright 225c713
know when to not infer 'scope'
WalterBright 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 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 |
|---|---|---|
|
|
@@ -95,7 +95,7 @@ enum STCout = (1L << 12); // out parameter | |
| enum STClazy = (1L << 13); // lazy parameter | ||
| enum STCforeach = (1L << 14); // variable for foreach loop | ||
| // (1L << 15) | ||
| enum STCvariadic = (1L << 16); // variadic function argument | ||
| enum STCvariadic = (1L << 16); // the 'variadic' parameter in: T foo(T a, U b, V variadic...) | ||
| enum STCctorinit = (1L << 17); // can only be set inside constructor | ||
| enum STCtemplateparameter = (1L << 18); // template parameter | ||
| enum STCscope = (1L << 19); | ||
|
|
@@ -123,10 +123,11 @@ enum STCtemp = (1L << 40); // temporary variable | |
| enum STCrvalue = (1L << 41); // force rvalue for variables | ||
| enum STCnogc = (1L << 42); // @nogc | ||
| enum STCvolatile = (1L << 43); // destined for volatile in the back end | ||
| enum STCreturn = (1L << 44); // 'return ref' for function parameters | ||
| enum STCreturn = (1L << 44); // 'return ref' or 'return scope' for function parameters | ||
| enum STCautoref = (1L << 45); // Mark for the already deduced 'auto ref' parameter | ||
| enum STCinference = (1L << 46); // do attribute inference | ||
| enum STCexptemp = (1L << 47); // temporary variable that has lifetime restricted to an expression | ||
| enum STCmaybescope = (1L << 48); // parameter might be 'scope' | ||
|
|
||
| enum STC_TYPECTOR = (STCconst | STCimmutable | STCshared | STCwild); | ||
| enum STC_FUNCATTR = (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem); | ||
|
|
@@ -1015,6 +1016,8 @@ extern (C++) class VarDeclaration : Declaration | |
| { | ||
| Initializer _init; | ||
| uint offset; | ||
| uint sequenceNumber; // order the variables are declared | ||
| __gshared uint nextSequenceNumber; // the counter for sequenceNumber | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also seems to work for nested scopes. Could we have some weird semantic order of nested functions or so that conflicts with this sequence number scheme? |
||
| FuncDeclarations nestedrefs; // referenced by these lexically nested functions | ||
| bool isargptr; // if parameter that _argptr points to | ||
| structalign_t alignment; | ||
|
|
@@ -1028,6 +1031,7 @@ extern (C++) class VarDeclaration : Declaration | |
| int canassign; // it can be assigned to | ||
| bool overlapped; // if it is a field and has overlapping | ||
| bool overlapUnsafe; // if it is an overlapping field and the overlaps are unsafe | ||
| bool doNotInferScope; // do not infer 'scope' for this variable | ||
| ubyte isdataseg; // private data for isDataseg 0 unset, 1 true, 2 false | ||
| Dsymbol aliassym; // if redone as alias to another symbol | ||
| VarDeclaration lastVar; // Linked list of variables for goto-skips-init detection | ||
|
|
@@ -1047,7 +1051,7 @@ extern (C++) class VarDeclaration : Declaration | |
| final extern (D) this(Loc loc, Type type, Identifier id, Initializer _init, StorageClass storage_class = STCundefined) | ||
| { | ||
| super(id); | ||
| //printf("VarDeclaration('%s')\n", id->toChars()); | ||
| //printf("VarDeclaration('%s')\n", id.toChars()); | ||
| assert(id); | ||
| debug | ||
| { | ||
|
|
@@ -1057,12 +1061,14 @@ extern (C++) class VarDeclaration : Declaration | |
| //*(char*)0=0; | ||
| } | ||
| } | ||
|
|
||
| assert(type || _init); | ||
| this.type = type; | ||
| this._init = _init; | ||
| this.loc = loc; | ||
| ctfeAdrOnStack = -1; | ||
| this.storage_class = storage_class; | ||
| sequenceNumber = ++nextSequenceNumber; | ||
| } | ||
|
|
||
| override Dsymbol syntaxCopy(Dsymbol s) | ||
|
|
@@ -2405,6 +2411,19 @@ extern (C++) class VarDeclaration : Declaration | |
| { | ||
| v.visit(this); | ||
| } | ||
|
|
||
| /********************************** | ||
| * Determine if `this` has a lifetime that lasts past | ||
| * the destruction of `v` | ||
| * Params: | ||
| * v = variable to test against | ||
| * Returns: | ||
| * true if it does | ||
| */ | ||
| final bool enclosesLifetimeOf(VarDeclaration v) const pure | ||
| { | ||
| return sequenceNumber < v.sequenceNumber; | ||
| } | ||
| } | ||
|
|
||
| /*********************************************************** | ||
|
|
||
This file contains 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
This file contains 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.
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.
order the variables are declared???
Thought you were the native speaker :).
Did you mean order the declaration of variables?