News for hackers. Stuff that matters.
Re:Why Swift's type checker is so slow by lovasoa on Saturday June 22, 2024 @06:17AM (#40757832)

    let result: Double = -(1 + 1) + -(1 + 1) - 1
Swift 6 takes 6.2 seconds to compile this one line.

That's crazy...

Swift programmers: do you face this kind of issues often?

Re:Why Swift's type checker is so slow by marvag on Saturday June 22, 2024 @07:46AM (#40758315)
That is outrageous. It also cannot be blamed on Hindley Milner. While HM in theory has exponential worst case time, the constructs to trigger it for OCaml and Standard ML are far more complex, carefully constructed and never occur in practice.

OCaml does have +. for floats to make type checking easier, but Standard ML does not. Also, if Swift has operator overloading, why isn't it instantly clear that the RHS is an int, which can be assigned to a double?

This just looks like a performance bug in the type checker, and nothing that is inherent to HM.

Re:Why Swift's type checker is so slow by zarzavat on Saturday June 22, 2024 @08:10AM (#40758495)
People have been complaining about this issue for 10 years. Presumably if there were an easy fix they would have fixed it by now. They painted themselves into a corner somehow with HM, polymorphic literals and function overloading. Haskell doesn’t have function overloading (except for type classes) and OCaml doesn’t have polymorphic literals.
Re:Why Swift's type checker is so slow by marvag on Saturday June 22, 2024 @08:32AM (#40758654)
Ok, but then they should explain this particular case better. The RHS can be figured out just by choosing the overloaded operators.

In C++ terms, if you have int& operator+(const int&x, const int& y) then (1 + 1) is not ambiguous and can be selected fast. Same for unary minus etc.

The Swift devs should then blog about this example and explain step by step what is going on. If the literal "1" can be both an int and a float, that of course would be insane. Is that what you meant by "polymorphic literals"?

Re:Why Swift's type checker is so slow by nequo on Saturday June 22, 2024 @09:37AM (#40759051)
It seems like it’s not only function overloading (which, as you point out, Haskell does too by way of typeclasses) but also the implicit conversion between Int and Double. OCaml, Haskell, and Rust all require you to convert between them explicitly so they don’t need to figure out whether each 1 in the expression is an Int or a Double.

Am I seeing this correctly? Is HM + polymorphic literals + implicit type conversion the cause of Swift’s exploding compile time in such cases?

Re:Why Swift's type checker is so slow by ks2048 on Saturday June 22, 2024 @07:21AM (#40758157)
Wow, that is crazy. For me (Swift 5.10) that single line is taking 11 seconds. Meanwhile, I have a 16,000 line app (importing AppKit, SceneKit and more) that compiles in 8 seconds.
Re:Why Swift's type checker is so slow by ks2048 on Saturday June 22, 2024 @08:04AM (#40758441)
Following up with compile time of a few variations.

    let result:Double = -(1 + 1) + -(1 + 1) - 1 // 10.829s
    let result:Double = -(1 + 1) + -(1 + 1)     // 1.724s
    let result:Double =  (1 + 1) +  (1 + 1) - 1 // 1.721s
    let result:Double = -(1 + 1)            - 1 // 0.763s
    let result:Int    = -(1 + 1) + -(1 + 1) - 1 // 0.571s

    let result:Double = -(1 + 1) + -(1 + 1) + 1
    //error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Re:Why Swift's type checker is so slow by machinekob on Saturday June 22, 2024 @07:50AM (#40758340)
Nope this never happened to me but i'm always writing explicit types in every language :]
Re:Why Swift's type checker is so slow by Hamuko on Saturday June 22, 2024 @07:30AM (#40758210)
I've been doing a lot of SwiftUI stuff lately and the compilation times are pretty crap even for simple applications. Change one line and it's a minute or two of compilation again.

Then there's this fucker for whenever you make a programming error involving types:

>The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Basically, your code has a type error somewhere in it, and you need to figure out where and how it's wrong.

Re:Why Swift's type checker is so slow by cageface on Saturday June 22, 2024 @07:51AM (#40758347)
The devx is terrible. I came back to native iOS and SwiftUI. to upgrade some of my old apps after working in flutter for the last six months and I've been astonished at how slow and clunky it is. Runtime performance can also be quite bad if you do things in a straightforward way and optimizing things is not very straightforward.

Xcode is still awful too.

Re:Why Swift's type checker is so slow by emadda on Saturday June 22, 2024 @10:22AM (#40759338)
One minute compiling Swift UI code - is that without the worst case line above?

So every edit you need to take a minute to see how it renders?

Re:Why Swift's type checker is so slow by Hamuko on Saturday June 22, 2024 @11:09AM (#40759620)
If you're just doing UI changes, I think you can do pretty fast iterations using just the Xcode preview canvas. And while some light edits actually build in seconds, it does feel like it needs that minute compilation surprisingly often when doing fast iterations.
Re:Why Swift's type checker is so slow by timeon on Saturday June 22, 2024 @07:56AM (#40758379)
I don't know Swift, but you are declaring Double while using Int. 6.2 seconds seem pretty quick for something that I would expect to be: never.
Re:Why Swift's type checker is so slow by Hamuko on Saturday June 22, 2024 @08:08AM (#40758481)

  let x: Double = 2
  let y = 5 / x
y is a Double with a value of 2.5.

  let x: Int = 2
  let y = 5 / x
y is an Int with a value of 2.

  let x: Int = 2
  let y: Double = 5 / x
Code doesn't compile.
Re:Why Swift's type checker is so slow by happytoexplain on Saturday June 22, 2024 @09:46AM (#40759118)
They are using integer literals, not Ints. Any type can declare the ability to be representable by any literal. Double can be represented by floating point literals or integer literals (since Double, the type, can represent integers, the category of number).
[dead]
Re:Why Swift's type checker is so slow by supriyo-biswas on Saturday June 22, 2024 @07:09AM (#40758101)
Personally I believe HN could do with some enforcement of the rule against self-promotion.

(Edit: I think this is simple enough, just use HN's existing canonical link algorithm and see if the comments for a particular destination exceed the desired rate.)

Re:Why Swift's type checker is so slow by MatejKafka on Saturday June 22, 2024 @07:00AM (#40758032)
Not a good comparison, given how bad of a track record in "adapting" the truth the vlang author has.
Re:Why Swift's type checker is so slow by amedvednikov on Saturday June 22, 2024 @07:37AM (#40758258)
This is a myth.

V compiles itself in <1s, can translate entire DOOM, has a working kernel/OS (Vinix), 10k+ PRs, 600+ contributors etc.

While the bad track record you mention is about junk like git/libc dependencies and system("curl") (doesn't happen).

Can you list actual lies?

Re:Why Swift's type checker is so slow by sureglymop on Saturday June 22, 2024 @07:09AM (#40758094)
Never heard of V, looks very interesting...
Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @07:18AM (#40758145)
Be warned that V is infamous for over-promising and under-delivering. None of the features which sound interesting actually work, and there's no sign that anyone working on the language has any idea how they'll make them work.
Re:Why Swift's type checker is so slow by amedvednikov on Saturday June 22, 2024 @07:35AM (#40758243)
Every single feature on the website works.

Why are you making such false claims? Which features don't work? Please list them.

*edit*

Just like I thought.

You will write walls of text about it being a scam, but you cannot list a single example of such a scam.

Only point to "complete takedown" articles with lies like V not being open source, or nonsense like V depending on git/libc/opengl/make.

You even say that every single feature mentioned on the website is a lie, while it can be verified in a couple of minutes.

Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @07:50AM (#40758341)
I'm not arguing with the perpetrator of a scam about why his scam is a scam. There have been complete take-downs of the claims made by the V language. I'm 100% sure you've seen them as well. I have nothing more to say.
Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @06:59AM (#40758023)
What the hell is up with HN people's fascination with V? HN is the only place I ever see people who have drank the V kool-aid. Why is the HN crowd seemingly so gullible? It's the same thing with cryptocurrencies and AI and NFTs; if there is a tech-adjacent hype train, you can bet there's constant spam from HN commenters who have bought it hook, line and sinker.

Stop. It's boring.

Re:Why Swift's type checker is so slow by maleldil on Saturday June 22, 2024 @07:01AM (#40758042)
You replied to the creator of the V language.
Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @07:07AM (#40758079)
Ah.

And therein may lie the source of my frustration: HN is full of not only gullible people who fall for these scams, but also the very perpetrators of these scams, using HN as a tool to generate hype.

Re:Why Swift's type checker is so slow by videogreg93 on Saturday June 22, 2024 @07:43AM (#40758299)
Why is v a scam? Genuinely curious, I don't know much about it besides it being a c++ competitor.
Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @08:01AM (#40758422)
There has been a lot of ink spilled about how V is not as advertised. I am not going to repeat everything here, but here are some articles you can have a look at:

* "V Language Review (2022)": https://mawfig.github.io/2022/06/18/v-lang-in-2022.html

* "V is for Vaporware": https://xeiaso.net/blog/v-vaporware-2019-06-23/ (and its follow-up, "V is for Vvork in Progress": https://xeiaso.net/blog/v-vvork-in-progress-2020-01-03/)

* This comment on Reddit: https://old.reddit.com/r/ProgrammingLanguages/comments/vq4ul...

There's a whole lot more out there too.

Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:10AM (#40758490)
The same good old 5 year old article that claims V's networking uses system("curl"), complaints that V doesn't run on every single Linux distro on release, uses debug builds with slow backend to measure performance, and complaints about V using git/make/libc and even electricity.

The 2022 article about type checker bugs that have been fixed years ago, and with false claims like the string.len one.

First sentence in the reddit comment:

> V initially made some promises that seemed completely unrealistic (automatically translating any C or C++ program to V)

lol

https://github.com/vlang/c2v

https://github.com/vlang/doom

Completely unrealistic while they literally exist and work.

Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @08:24AM (#40758600)
The fact that these things were lies at the time should frame any reading of any current promises made by the V project. I have written the project off and am not aware of its current status, but I believe that its recent history (that article from 2022 is not 5 years old) should frame anyone's reading of current promises made by the project.
Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:30AM (#40758635)
There were no lies at the time.

V not running on every single Linux distro on release is not a lie.

V compiling without deps is not a lie (cc v.c).

etc

The 2019 article is 5 years old. Easy to count.

Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @08:38AM (#40758695)
To bystanders who are interested in V: I recommend that you read the articles (especially the most recent one from 2022) and alex-m's response here, and decide for yourself which side you find the most trustworthy. I have nothing more to add and will not respond further. Goodbye.
Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:40AM (#40758705)
Yes and please run the examples from the 2022 articles to verify that these type checker bugs have all been fixed.

(Not that having type checker bugs makes a language a scam in the first place.)

@mort96

It's very unfortunate that you make strong claims like "None of the features which sound interesting actually work, and there's no sign that anyone working on the language has any idea how they'll make them work."

and fail to post a single proof of such features.

Re:Why Swift's type checker is so slow by mardifoufs on Saturday June 22, 2024 @02:45PM (#40761172)
So, is the 2023 version also a lie? https://n-skvortsov-1997.github.io/reviews/

At the time I was able to reproduce pretty much everything that was said I. This article.

Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:08AM (#40758477)
It's not a scam. Read the posts by this person on this page. They're obsessed with the language and make up all these lies.
Re:Why Swift's type checker is so slow by bowsamic on Saturday June 22, 2024 @08:23AM (#40758585)
“My haters are just obsessed with me”

“My haters are just jealous”

Or maybe you and your product are actually bad

Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:25AM (#40758603)
Well can you please list the actual reasons the product is a scam?
Re:Why Swift's type checker is so slow by mort96 on Saturday June 22, 2024 @08:29AM (#40758622)
I believe you have been given links which explain that in great detail.
Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:33AM (#40758658)
I don't want links to articles that claim V is a scam because it uses git and electricity.

I want examples of actual false claims on the website. Because you originally said every single claim on the website is a lie.

Re:Why Swift's type checker is so slow by bowsamic on Saturday June 22, 2024 @08:35AM (#40758678)
The link I sent gives precise claims compared with advertised features. Anyway I realise I’m feeding a troll here so good luck
Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:49AM (#40758771)
Like I said, a self proclaimed V hater

for example:

> Another lie, Alex himself wrote to me in Telegram, not the moderator.

the entire thing isn't even about him, but a different person, and that person was contacted by the moderator. Yet this guy thinks it's about him.

Not a very unbiased source.

Bugs and leaks don't make the project a scam. Every project has bugs.

Re:Why Swift's type checker is so slow by bowsamic on Saturday June 22, 2024 @01:12PM (#40760509)
Re:Why Swift's type checker is so slow by amedvednikov on Saturday June 22, 2024 @07:42AM (#40758297)
Ironic coming from a gullible person calling a legit open source project a scam.
Re:Why Swift's type checker is so slow by amedvednikov on Saturday June 22, 2024 @07:39AM (#40758269)
So much hate yet I'm sure you can't even list 3 reasons to hate V.
Re:Why Swift's type checker is so slow by bowsamic on Saturday June 22, 2024 @07:51AM (#40758350)
Seems you’re just going around lying to people in order to get them to pay you https://n-skvortsov-1997.github.io/reviews/

Isn’t this fraud?

Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:13AM (#40758521)
What on earth are you talking about?

This is an article by a guy who calls himself a "V hater" and the stuff from discord sreenshots wasn't even addressed to him.

What are the lies? Please list them here, I'm genuinely interested. Bugs in experimental coroutines, a new WIP feature no even mentioned on the home page yet?

Again, please list just 3 reasons V is a scam.

Re:Why Swift's type checker is so slow by bowsamic on Saturday June 22, 2024 @08:20AM (#40758568)
I mean the whole article gives a huge number of ways in which you have lied about the language, and the whole internet is full of “V haters” who seem to be able to give solid evidence that it’s a scam

I’m sorry but this is kind of reading like a paranoid conspiracy level of denial. There is a reason why everyone hates your product and organisation. It’s not some conspiracy against you. It’s that you lied and it sucks

Re:Why Swift's type checker is so slow by alex-m on Saturday June 22, 2024 @08:24AM (#40758597)
Can you please list 3 of those ways. I'm not seeing it.
Re:Why Swift's type checker is so slow by happytoexplain on Saturday June 22, 2024 @09:57AM (#40759199)
>do you face this kind of issues often

In my personal experience, no. That doesn't mean it's not a weakness of the language, but in practice you very rarely write a real expression with more than one or two type inferences in it. And when you do, you can just add explicit typing.