Replace AssociativeArray struct with UFCS methods #668
Conversation
Nice. |
Shouldn't we merge it right away, since we're at the beginning of a release cycle? And this of course. |
We've been waiting for the templated AA to be fixed for years. Now that we have UFCS for AAs, we can go back to a sane implementation without breaking code. There is no reason this should be a problem for re-doing the templated version, in fact I suspect it will help. |
Yes, it won't be a problem for the templated version, just wanted to get you informed. |
The idea was to focus on stability and release at end of december (Agenda). |
I think this is important enough that we should do it as soon as possible. It has been far too long already, and a lot of the ctfe stuff that is tested in the dmd pull doesn't currently work. (although some of it may have worked before the templated changes) |
@yebblies Why you want to remove
Second row add new elem to Thus we need to stay some
All those |
I'm not against improving the AA situation, but the current implementation is wrong. The compiler should not have two types that are aliased internally. The addition of I think it's a far more stable solution to extend AAs via UFCS, as this doesn't violate the type system in the same way. I fully expect all AA magic can be translated to UFCS methods if needed. Does your new AA implementation have any horrible hacks like the old one? eg I don't think your incoming changes should block this. If they are sufficient, this can easily be reverted. I would of course prefer to not bring back any of this half-builtin nonsense. |
+1 - and I'd be extremely happy to remove all special casing for this in the backend code. It's not fun at all to run into bugs where you have correct codegen sent from the front-end. :o( |
Now I work on independent |
Having the compiler think |
The problem here is, that the compiler treats Value[Key] as special type and some of it's functions as intrinsics. |
The issue with this is providing correct error messages. I don't think I've seen a solution to this yet. |
@yebblies can you rebase (in your own time, of course :) - think I might try this out in gdc. |
Done. |
Breaks cases where the property is called. int[int] foo;
auto len = foo.length();
auto keys = foo.keys(); |
@dawgfoto - I never realised that people actually use |
If you say that |
Of course, the spec doesn't say that and nobody expects that. If |
Can you add a deprecated alias so that the tests pass and code that explicitly used AssociativeArray doesn't break. alias AssociativeArray(Key, Value) = Value[Key]; |
Taking a delegate won't work with UFCS, but I guess it has little impact. |
Added alias. |
Doesn't work with AA pointers. int[int]* p;
auto keys = p.keys; You'll need to add overloads. Key[] keys(T : Value[Key], Value, Key)(T* aa)
{
return (*aa).keys();
}
Value[] values(T : Value[Key], Value, Key)(T* aa)
{
return (*aa).values();
}
Value get(T : Value[Key], Value, Key)(T* aa, Key key, lazy Value defaultValue)
{
return (*aa).get(key, defaultValue);
} |
This will also need a phobos fix (dlang/phobos#1741). |
Replace AssociativeArray struct with UFCS methods
Guys, not sure if this is related but I can't build Druntime from git any more.
Edit: ah, it was caused by an old |
As Martin posted 3 months ago:
The issue isn't fixed but the pull is merged breaking builds with |
This pull request (or dlang/dmd#2856) introduced a regression: |
We need to revert this. We have 3 regressions with AAs in 2.065: https://d.puremagic.com/issues/show_bug.cgi?id=12167 |
No, we don't. Even with those regressions we're still better off. I will fix those in the next couple of days. |
Please let's figure out how to make a smooth transition. |
Those are regression in master, nobody was so crazy to merge this into 2.065. |
This pull request (or dlang/dmd#2856) introduced a regression: |
No description provided.