-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve template constraint error messages #9715
Conversation
Thanks for your pull request and interest in making D better, @dayllenger! 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 + dmd#9715" |
This looks pretty awesome. Perhaps only print the non-failing constraints in verbose mode. Then the |
Not yet. We should really add a flag for JSON error messages. We could use the existing BTW I hope you knew about |
I updated, but before rebase. After rebase I'm getting such errors on
I guess it wasn't necessary to rebase... |
If you get such errors, it always helps to do a full clean. |
@dayllenger see also dlang/DIPs#131 (will be discussed at dconf) it would be good to coordinate with these improvements (in part so that we only have to update the test suite once). |
Awesome. I would like to also have links to the failing restrictions be printed somehow so I can navigate to them inside my favorite editor or IDE. |
here's my idea for something similar btw: One thing I like with mine is it shows what value the template parameters evaluate to, so like:
Shows that |
At first I printed those expressions after substitution, but sometimes it looks like It should be easy to add a line like About loops - this task is somewhat deeper than I can think over now. |
See Update section in the first post. I guess, I need to pack tests in a single file and put it into |
@thewilsonator did you discuss your DIP at DConf? This PR is ready, I guess people can try it out. |
@dayllenger, could this be extended to include transitive diagnostics of mismatched qualifiers Example: User calls "Cannot call unpure function when it instead should hint that the non-purity of I guess a separate PR is preferred for that. But the logic for producing such diagnostics might share code with this PR... |
It's a good idea, and it looks complicated for me. The logic is unlikely similar: my function recursively decompose the constraint expression, but in case of function bodies it needs to intervene somehow in the mechanism of attribute inference; it requires deep knowledge of this part of the compiler I don't have currently. |
Given the large amount of code added over 3 files, please consider organizing this functionality into one place. |
Currently the code in Should I rewrite the existing commits or append a new one, for review fixes? |
I recommend adding fixes as new commits to review those specific changes. Use $ git commit --fixup... To be able to cleanup history quickly afterwards. |
Ping for attention! :) |
Slightly more insistent ping for attention! <(`^´)> |
@WalterBright I don't see here a point of arranging the code into one place. Why it should be so? What is that place? |
This looks good to me. The code is logically organized, I don't see the point in trying to put it in one place. There is no reason to stall this. Adding auto-merge. |
Thank you @dayllenger for this awesome work. |
Hello. I suppose, everyone agrees that the output on unsatisfied template constraints is very poor. This PR proposes a simple way to tell actually what's gone wrong on template matching.
Related to issue 9626.
Example
This code
gives such error message:
"WHAT? Char array cannot be sorted?"
Now let's see how it will look with this PR:
The output is structured like a tree. It shares exact information about which clauses have failed. Here we can read that our
char[]
does not have swappable and/or assignable elements, which is true, because it's UTF-8 string. Not obvious though, so thinking from the user perspective, we should move the last three checks to the beginning to improve the message.Another (artificial) example:
Output:
The output is colored. It would be prettier if I didn't care about possible breakages (e.g. it needs to move signatures that don't fit to the next line).
Why my solution is cool:
static assert
and probably, in some way, tostatic if
!
,&&
,||
, and?:
The drawback is that it is shallow, it cannot say "does not implement
popFront()
", it can only point to the constraintisInputRange!R
, though their names are mostly quite descriptive.Old
&&
approach to make assert messages can work here to produce some readable results, for example:will print something like
I could handle this case specially and print it better, in one line (edit: and print evaluated expression), but it's too much for this PR.
Tools
Do we have any special output for them?
IDE can simply show that message in a tooltip. Theoretically, it can parse it and highlight failed clauses (because the message contains all parts of the constraint in order from left to right). Brittle thing, we should define a special compiler flag for error formats, and form JSON.
Then we can greatly improve the error messages for humans.
Update
Now the full tree view with the tip message is shown only in verbose mode. In the usual, it only shows failed constraints in a compact form.
A new section was added. It clarifies what type/value the passed parameters have. It prints well usual and variadic parameters, except for lambdas (
__lambda1
), enum members (cast(Enum)0
), maybe something else.Examples:
(omitted other 5 iota variants)