swift
b5a69c72 - Add a size heuristic to the Space Engine

Commit
8 years ago
Add a size heuristic to the Space Engine <rdar://32480026> This is a particularly tricky tradeoff to have to make here. On the one hand, we want diagnostics about incomplete patterns to provide as much information as possible. On the other, pattern matrices grow quasi-factorially in the size of the argument. That is, an enum with 10 cases that is switched on as a 2-tuple/argument list creates a total subspace covering of size 100. For sufficiently large inputs, this can DOS the Swift compiler. It is simply not useful to present more than about 100 notes to the user, nor is it useful to waste an enormous amount of time trying to compute these subspaces for the limited information the diagnostic will provide. Instead, short circuit if the size of the enum is above some arbitrary threshold (currently 128) and just offer to add a 'default'. Notably, this change is not *technically* source compatible in that it ignores the new '@_downgrade_exhaustivity_check'. However to hit up against this heuristic would require the user to be switching over four DispatchTimeIntervals in a quadruple or using an equivalently-sized enormous enum case. At which point we're hitting on the very reason this heuristic exists. There are definitely other, more informative, paths that we can take here. GHC, for example, seems to run a highly limited form of space subtraction when the input space is too large, and simply reports the top 3 missing cases along with some ellipses. For now, I just want to cut off this hang in the compiler.
Author
Robert Widmann
Committer
Robert Widmann
Parents
Loading