Implement aliasSeqOf for all iterables#5630
Conversation
|
Thanks for your pull request and interest in making D better, @John-Colvin! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. 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 fetch digger
dub run digger -- build "master + phobos#5630" |
| { | ||
| static assert(false, "Cannot transform range of type " ~ ArrT.stringof ~ " into a AliasSeq."); | ||
| } | ||
| static foreach (size_t i, el; iter.array) |
There was a problem hiding this comment.
Solutions that didn't use std.array.array seemed more complicated than they were worth (which is probably not much, thinking of how current CTFE and newCTFE work).
There was a problem hiding this comment.
don't use .array please.
instead introduce a counter variable into the parent-scope.
There was a problem hiding this comment.
also.
Keep that: alias aliasSeqOf = AliasSeq!(aliasSeqOf!(range[0 .. $/2]), aliasSeqOf!(range[$/2 .. $]));
As it avoids factorial blow-up.
There was a problem hiding this comment.
I'm pretty sure a counter variable isn't an option unless I take the whole struct contents in to one big mixin. array is also handing autodecoding (makes me sad).
W.r.t. the recursive template, I was afraid you'd say that. So the story with static foreach is "here's a great new feature, don't use it, it's too slow"?
There was a problem hiding this comment.
ping @UplinkCoder, I'd like to understand this better, because static foreach is just so very convenient.
There was a problem hiding this comment.
Don't be afraid too of using static foreach.
Entire Phobos uses it nowadays (-> #5989) and there was no measurable difference in the build time of the entire testsuite.
(Granted this doesn't say much about the extra-allocation of .array)
There was a problem hiding this comment.
I love how much more concise and simple this code is with static foreach.
Edit: it also looks like it's consistently segfaulting on Win32. Not sure if that's related to this PR or not... may be due to some weird interaction between static foreach and the CT heap allocation.
std/meta.d
Outdated
| if (isIterable!(typeof(iter))) | ||
| { | ||
| import std.traits : isArray, isNarrowString; | ||
| import std.traits : isNarrowString; |
There was a problem hiding this comment.
Please remove the unneeded imports.
std/meta.d
Outdated
| } | ||
| } | ||
|
|
||
| import std.traits : isIterable; |
There was a problem hiding this comment.
Maybe the self-important template idiom could be used here to avoid the top level import.
There was a problem hiding this comment.
Let's better wait for https://github.com/dlang/DIPs/blob/master/DIPs/DIP1005.md and its result / decision.
| { | ||
| static assert(false, "Cannot transform range of type " ~ ArrT.stringof ~ " into a AliasSeq."); | ||
| } | ||
| static foreach (size_t i, el; iter.array) |
| } | ||
| } | ||
|
|
||
| @safe unittest |
There was a problem hiding this comment.
It could stand to have a few more unittests testing different types of iterables.
There was a problem hiding this comment.
There are already quite a few existing that cover the range types, did have anything specific in mind?
There was a problem hiding this comment.
Yes. Specifically, infinite ranges. I believe isIterable will let those through, because all it checks is:
is(typeof({ foreach (elem; T.init) {} }))
There was a problem hiding this comment.
Ok, infinite ranges were allowed with the previous implementation as well but obviously that's very bad. Done
|
Do we have any numbers on the slowness of |
785bcb8 to
b77e021
Compare
|
Ping @John-Colvin |
b77e021 to
484c1e2
Compare
std/meta.d
Outdated
|
|
||
| /** | ||
| * Converts an input range `range` to an alias sequence. | ||
| * Converts any foreach-iterable (e.g. an input range) $(D range) to an alias sequence. |
There was a problem hiding this comment.
I assume you accidentally converted the backticks back to $(D?
There was a problem hiding this comment.
Must have a been a mistake when rebasing. Also, it should have been iter anyway
462a113 to
57598bd
Compare
std/meta.d
Outdated
| } | ||
| } | ||
|
|
||
| import std.traits : isIterable; |
There was a problem hiding this comment.
Imports go at the top of the file.
There was a problem hiding this comment.
The only existing top-level import in the file was not at the top, so I tried to stay in keeping. I will move both.
|
I took the liberty of adding a |
|
I think you added whitespace with this: |
|
Hmm, yeah I did. Very annoying that the Github editor does that. |
|
Looks like we are running into an ICE when building the docs - it's probably the same as recently seen in |
|
Oh and the persistent Win32 access violation means that there are now too many symbols in the OMF object file (the maximum is 32768).
We really need to switch to a more modern, actively maintained linker ... |
|
@MetaLang seeing as iterable is both an adjective and a noun*, I would say foreach-iterable is also both. It's ok, I'm fine with it written either way :) * or at least it's commonly used that way and this is english after all, inventing words is fine haha @wilzbach do you know of a workaround for either of those, or will the PR have to wait for them both to be fixed? |
Well I tried to reduce and fix the ICE, but I came out with this (dlang/dmd#8128), not really a solution :/
I don't think that OMF will ever be fixed. I even asked Walter once:
AFAICT the "workaround" against the OMF maximum symbol limit was to build the unittests separately e.g. Lines 420 to 424 in 307dd15 Now, I'm not sure whether this is possible, but in theory the same could be done with Lines 397 to 398 in 307dd15 So I think this could work: (I don't use Windows either) |
6f0382a to
329cd6e
Compare
|
(rebased) |
|
Well this is a PR I'd completely forgotten about! Nice to see it merged. |
Hooray for
static foreach👍