-
-
Notifications
You must be signed in to change notification settings - Fork 667
do not emit mangling for inferred 'return' attribute #9476
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,7 +500,8 @@ bool checkAssignEscape(Scope* sc, Expression e, bool gag) | |
| if (!va.isScope() && inferScope) | ||
| { //printf("inferring scope for %s\n", va.toChars()); | ||
| va.storage_class |= STC.scope_ | STC.scopeinferred; | ||
| va.storage_class |= v.storage_class & STC.return_; | ||
| if (v.storage_class & STC.return_) | ||
| va.storage_class |= STC.return_ | STC.returninferred; | ||
|
Member
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. Bad indentation. Doesn't this need a check for pre-existing If |
||
| } | ||
| continue; | ||
| } | ||
|
|
@@ -1071,7 +1072,7 @@ private bool checkReturnEscapeImpl(Scope* sc, Expression e, bool refs, bool gag) | |
| * Because dg.ptr points to x, this is returning dt.ptr+offset | ||
| */ | ||
| if (global.params.vsafe) | ||
| sc.func.storage_class |= STC.return_; | ||
| sc.func.storage_class |= STC.return_ | STC.returninferred; | ||
| } | ||
|
|
||
| } | ||
|
|
@@ -1141,14 +1142,14 @@ private void inferReturn(FuncDeclaration fd, VarDeclaration v) | |
| // v is a local in the current function | ||
|
|
||
| //printf("for function '%s' inferring 'return' for variable '%s'\n", fd.toChars(), v.toChars()); | ||
| v.storage_class |= STC.return_; | ||
| v.storage_class |= STC.return_ | STC.returninferred; | ||
|
|
||
| TypeFunction tf = cast(TypeFunction)fd.type; | ||
| if (v == fd.vthis) | ||
| { | ||
| /* v is the 'this' reference, so mark the function | ||
| */ | ||
| fd.storage_class |= STC.return_; | ||
| fd.storage_class |= STC.return_ | STC.returninferred; | ||
| if (tf.ty == Tfunction) | ||
| { | ||
| //printf("'this' too %p %s\n", tf, sc.func.toChars()); | ||
|
|
@@ -1166,7 +1167,7 @@ private void inferReturn(FuncDeclaration fd, VarDeclaration v) | |
| Parameter p = tf.parameterList[i]; | ||
| if (p.ident == v.ident) | ||
| { | ||
| p.storageClass |= STC.return_; | ||
| p.storageClass |= STC.return_ | STC.returninferred; | ||
| break; // there can be only one | ||
| } | ||
| } | ||
|
|
@@ -1807,7 +1808,7 @@ void eliminateMaybeScopes(VarDeclaration[] array) | |
| // v cannot be scope since it is assigned to a non-scope va | ||
| notMaybeScope(v); | ||
| if (!(v.storage_class & (STC.ref_ | STC.out_))) | ||
| v.storage_class &= ~STC.return_; | ||
| v.storage_class &= ~(STC.return_ | STC.returninferred); | ||
| changes = true; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // PERMUTE_ARGS: -dip1000 | ||
|
|
||
| // Mangling should be the same with or without inference of `return scope` | ||
|
|
||
| @safe: | ||
|
|
||
| auto foo(void* p) { return 0; } | ||
| static assert(typeof(foo).mangleof == "FNaNbNiNfPvZi"); | ||
|
|
||
| auto bar(void* p) { return p; } | ||
| static assert(typeof(bar).mangleof == "FNaNbNiNfPvZQd"); | ||
|
Member
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. Please also add tests that show explicit annotations make it to the mangling.
Member
Author
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. see testscope2.d
Member
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. testscope2.d only runs with -dip25, but some of the code only affects -dip1000 AFAICT.
Member
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. BTW: you can also use core.demangle with CTFE for more readable asserts. |
||
|
|
||
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.
Wouldn't it be better to have just one STCinferred?
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.
Either return or scope or both can be present or inferred.
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'd not have expected inference to happen if either is explicitly given, but Ok.
Some of the bit flags may require a little pruning as there aren't many available left now.