Make some traits iterative using static foreach#6402
Conversation
|
Thanks for your pull request and interest in making D better, @nordlow! 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#6402" |
Yeah that would be really cool. It also comes up in the NG from time to time: https://forum.dlang.org/post/mailman.2099.1515541202.9493.digitalmars-d-learn@puremagic.com |
wilzbach
left a comment
There was a problem hiding this comment.
Nice work!
Interestingly this triggers an ICE when building the docs for std.meta (see DAutoTest)
std/meta.d
Outdated
| // [internal] | ||
| private template genericIndexOf(args...) | ||
| if (args.length >= 1) | ||
| if (args.length >= 1) |
There was a problem hiding this comment.
std/meta.d(304:9)[warn]: If constraints should have the same indentation as the function
| enum index = 0; | ||
| } | ||
| else | ||
| static if (is(typeof(genericIndexOf) == void) && // not yet defined |
std/meta.d
Outdated
| alias tuple = args[1 .. $]; | ||
|
|
||
| static if (tuple.length) | ||
| static foreach (idx, argi; args[1 .. $]) |
There was a problem hiding this comment.
Nit: Why not "arg" instead of "args" (it's a typical convention to denote the array with a "s" postfix.
std/traits.d
Outdated
| static foreach (Ti; T) | ||
| { | ||
| static if (!is(typeof(isExpressions) == bool) && // not yet defined | ||
| !is(T[0]) && __traits(compiles, { auto ex = T[0]; })) |
There was a problem hiding this comment.
Shouldn't this be Ti here?
There was a problem hiding this comment.
Correct. Fixed. Thanks!
std/meta.d
Outdated
| // [internal] | ||
| private template genericIndexOf(args...) | ||
| if (args.length >= 1) | ||
| if (args.length >= 1) |
There was a problem hiding this comment.
we keep constraints flush with the declaration they constrain
| enum index = 0; | ||
| } | ||
| else | ||
| static if (is(typeof(genericIndexOf) == void) && // not yet defined |
b7df9de to
2240075
Compare
nordlow
left a comment
There was a problem hiding this comment.
All comments fixed.
std/meta.d
Outdated
| // [internal] | ||
| private template genericIndexOf(args...) | ||
| if (args.length >= 1) | ||
| if (args.length >= 1) |
std/meta.d
Outdated
| // [internal] | ||
| private template genericIndexOf(args...) | ||
| if (args.length >= 1) | ||
| if (args.length >= 1) |
std/meta.d
Outdated
| alias tuple = args[1 .. $]; | ||
|
|
||
| static if (tuple.length) | ||
| static foreach (idx, argi; args[1 .. $]) |
| enum index = 0; | ||
| } | ||
| else | ||
| static if (is(typeof(genericIndexOf) == void) && // not yet defined |
std/traits.d
Outdated
| static foreach (Ti; T) | ||
| { | ||
| static if (!is(typeof(isExpressions) == bool) && // not yet defined | ||
| !is(T[0]) && __traits(compiles, { auto ex = T[0]; })) |
There was a problem hiding this comment.
Correct. Fixed. Thanks!
|
Should be ready now. Can you find any other traits that can be made iterative? Found one: |
2240075 to
486d7e0
Compare
|
Ready now! |
| static if (!is(typeof(allSameType) == bool)) | ||
| { | ||
| enum bool allSameType = is(T[0] == T[1]) && allSameType!(T[1..$]); | ||
| enum bool allSameType = true; |
There was a problem hiding this comment.
Hmm looks like DScanner's check is bogus here:
std/traits.d(8419:19)[warn]: Variable "allSameType" has the same name as a variable defined on line 8414.
I don't know why the other very similar code is accepted though.
However, you can ignore this module for this check by adding the following to the ModuleFilter blacklist in the .dscanner.ini
label_var_same_name_check="-std.traits"
(Ideally preceded by a reference to a DScanner issue)
486d7e0 to
a5cb835
Compare
|
Thanks, @wilzbach. |
|
I don't know why Win32 fails... |
|
@nordlow try wine |
|
There's an ICE on Linux too (when run with -D): reported -> https://issues.dlang.org/show_bug.cgi?id=18721 |
|
@nordlow you could also try to split this PR into smaller ones, e.g. the documentation ICE comes from |
|
Oh and I think the persistent Windows 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 ... |
|
@wilzbach, can I run ddoc generation on phobos via a CLI-call to `make``? |
Well you need to clone dlang.org first, e.g. and then check Though for the failure you don't need any macros, just
BTW my noobish attempt: dlang/dmd#8128 (though the ICE I reduced looks a bit different) |
|
status? |
|
Made a merge against master to see if something has changed (for the better). @andralex, see @wilzbach comments regarding too many symbois in the OMF symbols file. I assume a split of this PR will still (in the end) result in the same Win32-only linking problem, right? @WalterBright ? |
|
I did a merge against master to see if the linking error still occurs on Windows. What's the best way of fixing the too-many-symbol-problem @wilzbach mentioned above? |
|
Build passes. Ok to merge @andralex? |
|
Please rebase instead of merging for a slicker git history. |
|
Regarding the linker error: looks like you are lucky and symbols have been moved around in the last six months. As long as auto-tester is green, everything should be okay. |
4d3b9bf to
fc96b0a
Compare
|
Great @wilzbach. Rebase done. |
| ;imports_sortedness="-etc.c.curl,-std.algorithm.comparison,-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.c.freebsd.socket,-std.c.linux.pthread,-std.c.process,-std.complex,-std.concurrency,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.systime,-std.datetime.timezone,-std.digest,-std.digest.hmac,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.common,-std.experimental.allocator.mallocator,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.math.biguintcore,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.utf,-std.uuid,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip" | ||
| ; Checks for labels with the same name as variables | ||
| label_var_same_name_check="-std.algorithm.iteration,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.conv,-std.encoding,-std.experimental.allocator.building_blocks.segregator,-std.experimental.typecons,-std.format,-std.internal.digest.sha_SSSE3,-std.parallelism,-std.process,-std.typecons,-std.utf" | ||
| label_var_same_name_check="-std.algorithm.iteration,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.conv,-std.encoding,-std.experimental.allocator.building_blocks.segregator,-std.experimental.typecons,-std.format,-std.internal.digest.sha_SSSE3,-std.parallelism,-std.process,-std.typecons,-std.utf,-std.traits" |
There was a problem hiding this comment.
I can't recall that this would have been fixed on the dscanner side. Though opening an issue there might help.
There was a problem hiding this comment.
Ok, ok to keep as is then so we can pull this?
|
Thanks. |
Will this keep on hindering us in development? |
Port more efficient allSatisfy/anySatisfy from dlang/phobos#6402 merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
|
This introduced an undocumented change: https://issues.dlang.org/show_bug.cgi?id=19560 I'm not really sure that I want to call it a regression because the new behavior makes more sense than the old, and the old behavior wasn't really specified. |
|
Good catch. I think what was not specified and becomes specified should be documented carefully but not count as a regression. |
This reduces the number of template instantiations needed and is measured to be at least as fast as the recursive variants here.
The refactored traits are:
genericIndexOf,allSatisfy,anySatisfy,isExpressionandallSameType.There a probably more traits that could benefit from this refactoring. Proposals are welcome.
if we added a
static break;to exit astatic foreachprematurely, would that speed up the compilation even further, @WalterBright?