67 points · by matt_d · 2y ago · 47 comments
Meanwhile the compiler still can't compile many even mildly complex SwiftUI views and expressions with the "The compiler is unable to type-check this expression in reasonable time" error.
It does not even tell you what part of code it is having issues with so you could change it. You have to comment/uncomment blocks of code to find the problematic part.
> Meanwhile the compiler still can't compile many even mildly complex SwiftUI views and expressions with the "The compiler is unable to type-check this expression in reasonable time" error.
That seems like a bug in language design? What's the story behind that? Did they inadvertently make something that was quadratic or worse and then realized it was too late or too fundamental to fix it properly so they patched it over with an error message?
It's unfortunate but I would honestly be ok with a "strict mode" that requires extra annotations from the programmer if it would prevent this stupid error in practice.
This is what I would like to know, too, but you phrased it way better than I did.
Naturally there are those that would rather keep the status quo.
Lol this sounds funny, any other compilers that do this? Why does this happen exactly?
> It does not even tell you what part of code it is having issues with so you could change it. You have to comment/uncomment blocks of code to find the problematic part.
Awful.
TypeScript has a notorious "Type instantiation is excessively deep and possibly infinite" warning that can often be unsafely ignored with a `@ts-expect-error` comment
My question stands: why does this happen and how come it is still so primitive that you do not even get to know the location of the issue?
The problem you describe is more with the design of SwiftUI, which makes massive, complex, extenuated use of the type system. The types quickly become too complex to reason about. It's a mess that hinders the developer instead of helping them.
Not what you're going for when you design an API. Apple really screwed this one up, though I doubt they will backtrack to fix it, so we're probably stuck with it.
As someone who has worked in both Swift and C++ I’m grateful for those that choose to make an effort in this space. And of course, just because some do doesn’t take away from others that work on SwiftUI. Both can be true at the same time.
Safe FFI with lifetime support is definitely lower priority though, given that FFI is usually in a thin layer of application code that can sort out safety itself.
Apple is aiming far higher. They want [1] the ability to seamlessly replace C++ code anywhere with Swift code, to write subclasses of C++ classes in Swift, etc. without giving up performance.
See https://github.com/swiftlang/swift-evolution/blob/main/visio...
and the video linked to in https://forums.swift.org/t/video-swift-as-c-successor-in-fou..., which shows how far they were a year ago.
[1] they likely won’t get there for all C++ code, but if they get to “with a few manual annotations” without giving up efficiency, that would be a major accomplishment.
The type inference time explosion issue is a known and well-documented flaw. Fixing it would require an overhaul of the type system, which is possible, but I’m not sure if there is appetite for it.
C++ interop is probably more important for Apple itself.
Swift compiler speed and error reporting are abysmal and improving them would have a much bigger impact. So far it's not getting any better at all.
If I could give up some level of type inferrence and get the build time from 3 minutes to 20 seconds, I would.
Swift has originally been designed as an ObjC replacement, mostly for UI glue code, with conveniences more like a scripting language.
So now they're working on making Swift support more low-level low-overhead code.
Naturally they couldn't tackle everything at once.
I take their old statements about replacing C and C++ as the same aspiration that Golang had to be a systems programming language.