add AliasAssign declarations#11846
Conversation
|
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. 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#11846" |
8a3e3fd to
2e48598
Compare
|
@thewilsonator I know, but most of that info is in the AliasAssign.md file, and I'll do the work for the spec PR once this is a go. |
|
I'm more thinking documentation. |
a49fcf0 to
44ba28b
Compare
|
Buildkit heisenbug strikes again. Can't we fix these networking failures with "if it was a networking failure, sleep for a few seconds and try again?" |
44ba28b to
82e18b1
Compare
|
Seems to stop just short of type functions? |
|
|
||
| --- | ||
| AliasAssign: | ||
| Identifier = Type; |
There was a problem hiding this comment.
Why is reassignment limited to types? What about aliases for other symbols?
There was a problem hiding this comment.
Because if this doesn't work, it isn't worth the effort to extend it.
|
You are rebuilding typefunctions.
We should talk about this.
Manipulating tupleexps directly is dangerous.
…On Sat, Oct 10, 2020, 1:45 PM Florian ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In changelog/AliasAssign.md
<#11846 (comment)>:
> + static foreach (t; T)
+ A = AliasSeq!(A, F!t); // alias assignment here
+ alias staticMap = A;
+}
+---
+
+Using the iterative approach will eliminate the combinatorial explosion of recursive
+template instantiations, eliminating the associated high memory and runtime costs,
+as well as eliminating the issues with limits on the nesting depth of templates.
+It will eliminate the obtuse error messages generated when deep in recursion.
+
+The grammar:
+
+---
+AliasAssign:
+ Identifier = Type;
Why is reassignment limited to types? What about aliases for other symbols?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#11846 (review)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVWSCF3GJV6AR7QRXARC2LSKBCNRANCNFSM4SK6WCIQ>
.
|
Really? There issue, that I have with this approach, is that I don't have proofs that guarantee this will not alter the langauge. Type-functions are essentially a shell around this ability, because this is shaky ground. |
|
The changelog entry says:
How does this interact with on-demand semantic analysis of forward references? For example, what is the output of this program: template Example()
{
alias A = int;
alias B = S!string;
A value;
struct S(T)
{
A = T;
}
}
void main()
{
import std.stdio;
writeln(typeof(Example!().value).stringof);
}If we're going to add declarations that depend on the order of semantic processing, the language spec should specify what that order actually is. (Edit: added a template so that |
Yes, that's right. If it resolves the problem, then it's a much simpler solution. |
Compile time error, because the alias assignment's immediate parent is not the same template as the alias declaration. |
|
@UplinkCoder please provide a link to your description of type functions, and a link to your implementation code, and I will be happy to cite them as prior work. |
|
I proposed something similar, but not exactly the same, in a couple of recent forum threads. [1][2] I'm not overly worried about attribution, but you're welcome to cite them if you like. [1] https://forum.dlang.org/thread/peatuezvcarhkjbsqqsv@forum.dlang.org?page=8#post-drybmowizcakksuvgraz:40forum.dlang.org |
|
@pbackus Your first cite looks like the same idea to me, though with the |
82e18b1 to
7667969
Compare
|
Azure pipelines (Windows_LDC_MinGW win32-ldc): I find this baffling. |
It's your make ;) |
The implementation is here: The spec is still upcoming. I can write a preliminary description though.
And that's it. |
|
Nice. Not much time to look into this, but a few concerns. I'm trying to convince myself that this is removal of surprising limitations, as opposed to a large change. On the face of it, allowing reassignment of alias names is in keeping with the rest of D (mutability is the default). So I could imagine how we can consider that as removing a limitation. However, there are other things that D users expect. The problem is, as @pbackus noted, order dependency. Consider this code: alias X = int;
void f(X);
X = float;
void f(X);AFAIU this will compile into declarations
I think it would make sense to disallow reassigning an alias as soon as it's been "read", i.e. used in another declaration: That way (at least in such simple cases) the semantics of |
The difficulty with that is iteration such as from the example: Note the use of |
The trouble is that this AliasAssign only allows for assigning types to an alias. AliasDeclarations allow types and symbols to be aliased, hence the failures in the std.meta unittests. It's not a problem adding this code, except that this PR is already 440 lines and is getting fairly hard to review because of its size. Adding the symbol support is adding a lot of code. It would be much better to add the symbol support in a followup PR. |
6963cf6 to
3b07f1b
Compare
3b07f1b to
fa31879
Compare
|
Where's the spec PR ? |
|
Who approved this being merged? |
|
@atilaneves have approve this. Also, I concur @Geod24 response here, this needs a spec pr. |
I'll add one, after I do the followup alias assign symbols. In the meantime, the changelog will do. BTW, could use some help on existing spec PRs. |
Geod24
left a comment
There was a problem hiding this comment.
This SEGV the compiler:
import std.meta;
template Swap (alias A, alias B)
{
alias C = A;
B = A;
A = B;
enum Swap = true;
}
alias A = int;
alias B = string;
static assert(Swap!(A, B));
pragma(msg, A);|
|
||
| if (!aliassym.type) | ||
| { | ||
| ds.error("alias assignment can only apply to type aliases"); |
There was a problem hiding this comment.
This prints:
test.d(9): Error: aliasAssign `test.staticMap!(Identity, int, string).__anonymous.__anonymous` alias assignment can only apply to type aliases
aliasAssign shouldn't be user-facing
| } | ||
| if (!aliassymParent.isTemplateInstance()) | ||
| { | ||
| ds.error("must be a member of a template"); |
There was a problem hiding this comment.
Same here, this said "aliasAssign"
There was a problem hiding this comment.
This also triggers when using mixin template.
|
|
||
| override const(char)* kind() const | ||
| { | ||
| return "aliasAssign"; |
|
It would be great if we could stop putting experimental stuff straight into the language. |
I'll ask again in a better way. Who approved this to be merged when there are still outstanding reviews to be addressed, some of which highlight broken code? |
|
(Yes, this change caused a build regression in master). |
|
@ibuclaw I missed the regression. How come CI didn't catch it? This was approved in a "let's see where this goes" fashion and might be reverted. |
It's not something that can really be tested unless you pull in building ldc/gdc bootstrap into the fold (not feasible due to time it takes). Though the auto-generated frontend.h header highlighted many additions that simply weren't added, or were added incorrectly to the headers used by gdc and ldc. I pointed some of these out as well in my review. |
This evolved from a conversation with Andrei when he asked "why not just allow assignment to an alias?" Why not, indeed:
becomes:
Combining this with D's already powerful features
static foreach, tuple slicing and tuple concatenation we should be able to re-implement thestd.metatemplates using this, and eliminating the recursion and recursion's problems.Implementing it turned out to be straightforward, once I figured out that making the
A = AliasSeq!(A, F!t);an anonymous Dsymbol was the way to go. Most of the implementation is all of the boilerplate needed to add a new Dsymbol type, the actual implementation is minimal.