How to diagnose typechecking timeouts

I'm contributing to a library module, and test code is causing the type solver to time out. The error is the usual "The compiler is unable to type-check this expression in reasonable time."

I understand this error (at least at the general level) and I know how to split or rewrite code to avoid it. But that isn't what I want to do. Instead, I want to understand the specific reasons for the complexity and possibly adjust the library API so as to minimize the chance of users running into this same problem.

Is there any diagnostic tool, compiler flag, troubleshooting guide, or method of analysis that would help me to get more insight into what exactly is going on?

I'm guessing that type resolution boils down to constructing a (possibly branching) chain of "input types -> output types" transformations, where there are multiple options for each transformation with different type information.

What I'd like to see is a dump of this chain after it has been pruned down to omit the incompatible adjacencies (e.g., I'm assuming there's a winnowing step where a transformation whose output is "-> Int" would be eliminated if no following transformation had input type "Int ->").

Take a look at https://github.com/apple/swift/blob/master/docs/DebuggingTheCompiler.rst

2 Likes

Perfect! Just what I was looking for, thanks!

Terms of Service

Privacy Policy

Cookie Policy