Convert range constraints to Conjunctive Normal Form#5461
Convert range constraints to Conjunctive Normal Form#5461andralex wants to merge 1 commit intodlang:masterfrom
Conversation
|
For some reason I can't squash the commits together with |
Should I squash everything into one or only the last four? |
|
|
Somehow, you ended up with a series of merges: I just did |
|
(EEEEVERYTHING is squashed!) |
|
Leaving any implementation details aside, this looks to be a good change. The opaque test blocks have alway irked me, precisely because they make better error messages impossible. (It sounds like you have a concrete compiler patch in the works?) |
std/range/primitives.d
Outdated
| enum bool isInputRange(R) = | ||
| is(typeof((ref R r) => r)) | ||
| && is(ReturnType!((R r) => r.empty) == bool) | ||
| && is(typeof(lvalueOf!R.front)) |
There was a problem hiding this comment.
Didn't the original code also require the front to be copyable?
There was a problem hiding this comment.
is(typeof((ref R r) => r)) requires the range to be copyable.
There was a problem hiding this comment.
I was referring to front (i.e. the element type, not the range itself).
std/range/primitives.d
Outdated
| })); | ||
| } | ||
| enum bool isInputRange(R) = | ||
| is(typeof((ref R r) => r)) |
There was a problem hiding this comment.
Doesn't this check for copyability, whereas the original checked for non-@disabled init?
There was a problem hiding this comment.
hmmmm... you may be on to something. How would init be disabled?
|
Seems this broke DScanner: https://ci.dlang.io/blue/organizations/jenkins/dlang-org%2Fphobos/detail/PR-5461/3/pipeline/160 |
|
@klickverbot changed the input range constraint to the original |
|
This is a huge improvement in style, debuggability, and comprehensibility. |
|
How do I repro the dscanner error locally? Thanks. |
It's libdparse, which is failing - not Dscanner ;-)
In this case libdparse has a custom test suite: But usually running the tests with DUB is more convenient (works here as well): |
6fd9846 to
4a7bc13
Compare
|
For an odd reason libdparse doesn't like |
|
So... vibed seems to have trouble with this. I tried: (search the net...) Tried the same command again, got: And again after |
I think that's just yet another dub bug. Try nuking ~/.dub I guess. |
Yes, |
|
FWIW deleted ~/.dub, same problem |
Weird - btw if you were looking at the ICE on Jenkins in vibe.d, Walter already has you covered: dlang/dmd#6875 There's still a regression manifesting from #5427 though ... |
| } | ||
| enum bool isInputRange(R) = | ||
| is(typeof((R r) => R.init)) | ||
| && is(ReturnType!((R r) => r.empty) == bool) |
There was a problem hiding this comment.
This constraint is stronger than before. (The old constraint checked for cast(bool)r.empty being valid.)
There was a problem hiding this comment.
Correct. I'd like to keep it that way.
| enum bool isInputRange(R) = | ||
| is(typeof((R r) => R.init)) | ||
| && is(ReturnType!((R r) => r.empty) == bool) | ||
| && is(typeof((R r) => r.front)) |
There was a problem hiding this comment.
This constraint is weaker than before. (front can now return 'void').
std/range/primitives.d
Outdated
| })); | ||
| } | ||
| enum bool isInputRange(R) = | ||
| is(typeof((R r) => R.init)) |
There was a problem hiding this comment.
The delegate seems redundant.
There was a problem hiding this comment.
The previous constraint verified that this works: R r = R.init;. That passes even for ranges with both this() and this(this) disabled, so you're right about that.
The only types rejected by this would be those that play shenanigans with init, i.e. have it return a different type etc. We don't want to support such styles. I'll remove the line.
There was a problem hiding this comment.
@tgehr std.algoritm.mutation, std.algoritm.iteration, and std.algoritm.searching don't pass unittests without this line. I'll leave it here for this PR and will investigate separately.
There was a problem hiding this comment.
My suggestion was not to delete the line entirely; I don't see why it should be typeof((R r) => R.init) (with unused parameter r) instead of something like is(typeof(R.init) == R).
There was a problem hiding this comment.
The only types rejected by this would be those that play shenanigans with init, i.e. have it return a different type etc. We don't want to support such styles. I'll remove the line.
I thought that we were going to make it illegal to redefine init (certainly, changes were made to TypeInfo so that we could move towards doing that). Until we do, we do need to be a bit careful, but allowing it to be redefined just seems like a disaster waiting to happen - especially when you consider code like this.
There was a problem hiding this comment.
Yes, that property should become reserved at some point.
std/range/primitives.d
Outdated
| @property bool empty(); | ||
| void front(); | ||
| } | ||
| //static assert(!isInputRange!VoidFront); |
Well, if we would ever get some form of https://issues.dlang.org/show_bug.cgi?id=7177 implemented, then requiring that |
3f2e3c7 to
0c2d36a
Compare
|
OK, so I did a bit of git cleanup and now everything is nicely in one commit. Ready to merge? |
|
@andralex Looks like the reuse of the git hash is confusing circle and the doc builder. Can you change the commit message and then force push? |
|
@JackStouffer much obliged |
|
Uhh ... it didn't work. Let's try this trick then |
|
Thanks for your pull request, @andralex! 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. |
|
Well, that did get circle to start, but it looks like the problem with the git history is worse than I thought. Any ideas @wilzbach @CyberShadow? |
|
Closing an reopening a PR has zero effect on the documentation tester. I'm not sure what went wrong yet (I added more logging yesterday) but to force a retest you can either rebase/amend (to change the tip commit SHA1) or wait until something else is merged, so that it's tested with a new merge target. |
It seems to be a recent problem that I have seen on a few other PRs lately - not so sure on what's going on ... |
|
I just answered that in another PR not 5 minutes ago. |
Didn't see that until now. Sorry |
|
OK what would be a reasonable course of action here? |
- rebased diff of dlang#5461

Convert the currently opaque and unstructured constraints for ranges to simple CNF formulae. This makes the constraints simpler and clearer. But the largest opportunity is having the compiler recognize these formulae and print the failing clause. There are plans to include a mechanism for user-defined messages, too.