1,170 karma · joined Jan 26, 2017 (9y ago) · 328 submissions
comment 9mo ago · link · parent
What does it mean to “use” subtyping vs typeclasses? Swift protocols are essentially typeclasses with associated types, just like Rust traits.
comment 9mo ago · link · parent
comment 1y ago · link · parent
My original reply was just to point out that constraint solving, in the abstract, can be a very effective and elegant approach to these problems. There’s always a tradeoff, and it all depends on the combination of other features that go along with it. For example, without bidirectional inference, certain patterns involving closures become more awkward to express. You can have that, without overloading, and it doesn’t lead to intractability.
comment 1y ago · link · parent
That’s really only true if you have overloading though! Without overloading there are no disjunction choices to attempt, and if you also have principal typing it makes the problem of figuring out diagnostics easier, because each expression has a unique most general type in isolation (so your old CSDiag design would actually work in such a language ;-) )
But perhaps a language where you have to rely on generics for everything instead of just overloading a function to take either an Int or a String is a bridge too far for mainstream programmers.
comment 1y ago · link · parent
These days though the type checker is not where compile time is mostly spent in Swift; usually it’s the various SIL and LLVM optimization passes. While the front end could take care to generate less redundant IR upfront, this seems like a generally unavoidable issue with “zero cost abstraction” languages, where the obvious implementation strategy is to spit out a ton of IR, inline everything, and then reduce it to nothing by transforming the IR.
comment 1y ago · link · parent
> Still fails on a very recent version of Swift, Swift 6.1.2, if my test works.
FWIW, the situation with this expression (and others like it) has improved recently:
- 6.1 fails to type check in ~4 seconds
- 6.2 fails to type check in ~2 seconds (still bad obviously, but it's doing the same amount of work in less time)
- latest main successfully type checks in 7ms. That's still a bit too slow though, IMO. (edit: it's just first-time deserialization overhead; if you duplicate the expression multiple times, subsequent instances type check in <1ms).
comment 1y ago · link · parent
Nah. Slow type checking in Swift is primarily caused by the fact that functions and operators can be overloaded on type.
Separately-compiled generics don't introduce any algorithmic complexity and are actually good for compile time, because you don't have to re-type check every template expansion more than once.
comment 1y ago · link · parent
You mean 6 years ago? https://www.swift.org/blog/swift-5-released/
comment 2y ago · link · parent
comment 2y ago · link · parent
comment 2y ago · link · parent
Citation needed on the performance loss. So far only a handful of SIL optimizer passes have been rewritten in Swift.
comment 3y ago · link · parent
Modern frontend architecture comes to Fortran! Awesome.
comment 3y ago · link · parent
This is true of everything, of course. Everyone knows that “practical applications” is just a flimsy excuse to get funding for your cool math project.
I’ve found that the main benefit of learning math is not the practical applications of the theorems and algorithms themselves, but just the practice you get from using this approach to thinking. This also frees you up to learn the math you find interesting and not what you think might be immediately useful in your day job.
comment 3y ago · link · parent
comment 3y ago · link · parent