4 ms·
My most frustating error with swiftc is the switch on enum "not being able to complete in acceptable time" (or something like that). Basically, when you want an
by bsaul 3y ago
My most frustating error with swiftc is the switch on enum "not being able to complete in acceptable time" (or something like that). Basically, when you want an exhaustive check on combination of enums, you're often reaching the limits of the compiler.
something like this
enum State { case A, … }
switch (fromState, toState) { case (.A, .B): … }
in which you want to make sure you didn't forget a combination.
- cellularmitosis 3y agoAt what sort of combinatorial size are you encountering this?
- bsaul 3y agoa switch over a pair of two values of the same enum type, containing 18 cases (some with associated values). It breaks at around 50 cases in the switch.
- littlestymaar 3y agoLooks like swiftc needs to embed a performant SAT solver ;) (I could not find the link anymore, but I remember reading a blog post about how Rust `match` statement are in fact solving an instance of SAT).
- slavapestov 3y agoSwift uses the algorithm from this paper: https://os.unil.cloud.switch.ch/tind-customer-epfl/07596cb2-d52f-4f11-9ae5-fb00f6276bbf?response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27p61-liu.pdf&response-content-type=application%2Fpdf&AWSAccessKeyId=ded3589a13b4450889b2f728d54861a6&Expires=1685543026&Signature=UN7oSRJf6O5eCZ%2FFHjMB6%2FN%2BwpU%3D https://os.unil.cloud.switch.ch/tind-customer-epfl/07596cb2-...
- munificent 3y agoI implemented a prototype version of the algorithm in that paper when exploring exhaustiveness checking for pattern matching in Dart. I found it pretty easy to understand, but also really easy to get it to generate huge combinatorially large spaces. Some careful memoization and deduplication helped, but even so I never got the performance to a state I felt comfortable with. Instead, I went with Luc Maranget's classic approach and figured out a way to adapt it to a language with subtyping (with a ton of work from Johnni Winther to figure out all of the hard complex cases around generics): https://github.com/dart-lang/language/blob/main/accepted/future-releases/0546-patterns/exhaustiveness.md https://github.com/dart-lang/language/blob/main/accepted/fut... The performance (in the prototype!) was dramatically better. You can always make pattern matching go combinatorial, but I haven't seen any real-world switches get particularly slow with our approach yet, and we have some fairly large tests of matching on tuples of enums.