There is a new blog post on Swift.org titled "New Diagnostic Architecture Overview" that talks about investments in Swift 5.1and the upcoming Swift 5.2 release to improve the diagnostics from the compiler:
The post is written by @xedin. Please feel free to ask questions about the blog post here!
Omg better error messages! That's so awesome! Right now error messages are the worst part of swift, I'm excited. I hope it will be the end of types called _ in error messages
@xedin what do you think about adding a copy of this to the compiler's docs/ directory? I think it'd be a really great resource for contributors writing a fix for the first time.
Awesome work @xedin! The blog post is highly informative and I thoroughly enjoyed reading it. I very much look forward to seeing the new diagnostic architecture in action.
I did notice a number of places in the text where small words like âtheâ were missing, and a few places where extraneous words could be removed, so I took the liberty of doing some proofreading.
Proofreading comments
Also, the term âFix-Itâ appears in a few places with both the F and I capitalized, and it stuck out as odd though I wasnât sure if it was intentional.
Would it be possible to document where community members might be able to help porting and improving error diagnostics? I feel like this is one place where the rust community shines.
Yes! I'm preparing changes to documentation which are going to talk about ConstraintFix and FailureDiagnostic interfaces and give examples of how to create a new fix/diagnostic and integrate it into the solver.
I said it somewhere else, but I find it ironic that the blog post features examples of SwiftUI as itâs not part of the open source project and was pushed back in the forums by admins a little.
I find PromiseKit to really tax the type inference engine, so itâd be great if it could do better, but at the very least getting better diagnostics would be a huge help when using it.
If you're able to do so, please file an issue (or more than one!) with a code example.
Having real world examples where the type inference is struggling is good from the compiler-side as that gives us more realistic test cases and helps evaluate changes to the type checker much better.
We actually attempted to do something like that before, but the hard problem here is way to accurately estimate how much space has been explored and how much remains to be explored.
My understanding of Lantuaâs suggestion is that, if we have some time limit on type checking that produces an error if an expression goes beyond x seconds, then we could raise a warning for expressions which do type check successfully, but take more than, say, x/2 seconds.
There are existing flags for that already as @suyashsrijan points out, but using timers/memory is unreliable and we couldn't find a better algorithmic criteria to estimate how complex the expression is going to be (for now).
Hope this revival my enthusiasm about Swift because the bad errors were absolutely frustrating. I would prefer to have this instead of SwiftUI or PromiseKit.
I have one question, could we consume these diagnostic information with an API? I'm thinking in an integration with SourceKit for example to suggest smart quick fixes.
This was a fascinating read - and a reminder that I am not nearly smart enough to write a compiler.
I stumbled into this after spending over 2 hours chasing phantom errors (like "Double cannot be converted to CGFloat") when the real problem was that I missed a $ when passing a binding in a SwiftUI view somewhere else. Very much looking forward to the 5.2 release!