190 points•g0xA52A2A•4 days ago•24 comments•

24 comments

cogman1031 minutes ago
I was curious to figure out exactly why the new trait solver was needed.

Apparently it's easier to work with and more correct. Future type system changes are blocked on it. These 2 in particular were called out as being blocked by the new trait solver [1]

[1] https://goals.rust-lang.org/2026/rtn.html

cbarrickabout 3 hours ago
Nit: "et cetera" is two words.

It is a latin phrase that literally translates to "and the rest." "Et" means "and," and "cetera" means "the rest."

This is a great article! Apologies for being pedantic. I'm just noting this fun fact here in case the author is checking this thread.

autarchabout 2 hours ago
https://www.merriam-webster.com/dictionary/etcetera

It's very commonly written as one word in English. Just do a web search for "etcetera" to find many examples.

virtualritz1 minute ago
Just write &c.
AlotOfReadingabout 10 hours ago
It's interesting how much of the next gen compiler improves borrow heavily from logic programming. I don't know if any other compilers that have made the connection to logic programming as explicit as rustc.
timhhabout 7 hours ago
There are compilers that use Z3 for type checking. I'd say that's even more explicit!
tkz1312about 10 hours ago
I mean any compiler that has a typeclass system basically does the same, since there is quits a deep connection between the two.

Of course any theorem prover will have an even deeper connection to logic in it's compiler and we've been building those since the 70s.

auggieroseabout 7 hours ago
Even those theorem provers that are not compilers.
frutigerabout 10 hours ago
> I don't know if any other compilers that have made the connection to logic programming

Which other compilers do you know?

rurbanabout 4 hours ago
My C compiler rcc uses a handwritten solver in -O3 to solve contracts. I've tried z3 and others, but my own was way faster, no overhead. It's like MySQL vs sqlite in-proc.
pjmlpabout 6 hours ago
C++ compilers when doing a mix of template and overload resolution?

Swift compilers when doing the same?

Haskell compilers when doing the same?

Idris, F*, Dafny, Koka,..... compilers doing the same?

nurettinabout 9 hours ago
If you name it constraint based programming, it all makes more sense.
nagaiaidaabout 10 hours ago
type systems correspond to logics so this tends to be how it goes
ahartmetzabout 4 hours ago
Types are pretty much like values, except at compile time instead of runtime.
ozgrakkurtabout 4 hours ago
Rust compilation is impossible to solve for some reason.

I have a 4k line project that depends on serde-json, xxhash, crossbeam and rand.

It takes several seconds to compile in release mode.

This is insane compared to my 20k line project in C++ which compiles everything and runs all tests in 0.7 seconds.

The C++ project doesn't depend on libc or any external libraries but that is not a practical option in rust.

I tried bunch of different options and actually removed some dependencies but it seems like it is not possible to get the rust program to compile fast.

Does anyone know why it is this slow comparatively?

bilkow17 minutes ago
In addition to what PudgePacket has said, and although LOC isn't a great proxy for the project complexity, it doesn't seem like you're counting your dependencies' LOC. Serde has more than 20 kLOC and serde_json more than 15 kLOC. serde_derive pulls in syn which has ~50 kLOC and is famously slow to compile.

Also the point of the release profile is to trade compilation performance for runtime performance (you'd be better off iterating on the dev profile).

There are also many other details that interfere and can't be inferred from your comment like: what's your OS, which linker are you using, are you using opt-level 3 on C++, which compiler are you using on C++, are you using heavily using templates in C++ or macros in Rust, etc.

nicoburns29 minutes ago
> The C++ project doesn't depend on libc or any external libraries but that is not a practical option in rust.

Aside from the std library (which you're not paying for in compile time because it's precompiled). Why is this different in Rust vs. C++? Sure, it's inconvenient not to use e.g. serde, but it's equally inconvenient in C++...

Taffy (https://github.com/DioxusLabs/taffy) which is ~26k LoC + a handful of dependencies compiles in release mode in ~1.6s

PudgePacketabout 3 hours ago
serde, crossbeam, and rand all involve generics so you may be getting a decent amount more code than 4k lines after macro expansion (aka #[derive(Serialize, Hash)) and generic instantiation.

you might also be able to drop crossbeam for stdlib types and rand for much smaller random library if you don't need it's comprehensive features.

cargo's release profile also uses opt level 3 and thin-local lto by default. Whether you need those is up to you, hard to say more without knowing your project!

but yes it is somewhat easy to allow rust projects to creep up in compile times especially with how easy it is to bring in big useful libraries that often come with a lot of features. disabling features where possible is the go to if you have big dependencies.

eosisabout 8 hours ago
Awesome work, seems an odyssey.

I think there is a little error in the code snippets near the caching section start where it claims variables are swapped but they are not? Though maybe I have just misunderstood something.

RossBencinaabout 7 hours ago
Agreed on both counts. I thought the swap was absent too.

Read the full thread on Hacker News →

Related stories