Live data from Hacker News

What to do with C++ modules?

nibblestew.blogspot.com

241–250 of 269 posts

Re: What to do with C++ modules?

#241

Earlier quoted context omitted.

> It avoid instantiating the same templates over and over in every translation unit, instead caching the first instantiation of each. ccache doesn't do this: it only caches complete object files, but does not avoid repeated instantiation costs in each object file. I'm afraid this feature is at best a very minor improvement that hardly justifies migrating a whole compiler. To be blunt, it's not even addressing a probl…

> I'm afraid this feature is at best a very minor improvement that hardly justifies migrating a whole compiler. Here are some performance numbers: https://www.phoronix.com/news/Zapcc-Quick-Benchmarks > To be blunt, it's not even addressing a problem that exists or makes sense to even think about. I will explain to you why. Do you talk down to people like this IRL as well? > I've been using ccache for years and I neve…

> Here are some performance numbers: https://www.phoronix.com/news/Zapcc-Quick-Benchmarks

If you look at the benchmarks you just quoted, you see cache-based compilations outperforming zapcc in quite a few tests. I wonder why you missed that.

The ones that ccache fares as well as builds that don't employ caching at all are telling. Either ccache was somehow not used, or there was a critical configuration issue that prevented ccache from caching anything. This typically happens when projects employ other optimization strategies that mess with ccache, such as pipelining builds being enabled or extensive use of precompiled headers.

The good news is that in both cases these issues are fixed by either by actually configuring ccache or disabling these other conflicting optimization strategies. To be able to tell, it would be necessary to troubleshooting the build and take a look at ccache logs.

> Do you talk down to people like this IRL as well?

Your need to resort to personal attacks is not cool. What do you hope to achieve, other than not sounding like an adult?

And do you believe that pointing out critical design flaws is "talking down to people"?

My point is very clear: your baseline compiler cache system, something that exists for two decades, already supports caching template code. How? Because it was never an issue to begin with. I explained why: because a compiler cache fundamentally caches the resulting binary given a cache key, which is comprised of data such as the source file provided as input (basically the state of the translation unit) and the set of compiler flags used to compile it. What features in the translation unit is immaterial. It doesn't matter.

Do you understand why caching template code is a problem that effectively never existed?

> What I said is that zapcc has a different approach that offers even more performance benefits, answering the question of what zapcc offers that ccache doesn't offer.

It's perfectly fine if you personally have a desire to explore whatever idea springs to mind. There is no harm in that.

If you are presenting said pet project as any kind of solution, the very least that is required of you is to review the problem space, and also perform a honest review of the solution space. You might very well discover that your problem effectively does not exist, because some of your key assumptions do not hold.

I repeat: with pretty basic compiler caches, such as ccache which exists for over two decades, the only thing you need to do to be able to cache template code is to install ccache and set a flag in your build system. Tools such as cmake already support it out of the box, so onboarding work is negligible. Benchmarks already show builds with ccache outperforming builds with the likes of zapcc. What does this tell you?

Re: What to do with C++ modules?

#242
post #240

Earlier quoted context omitted.

Edited to inject: Actually on second thoughts maybe none of these even do what you thought they did, they're even sillier than I'd assumed. So funny thing, your C++ 26 solution doesn't do what my Rust function does. Actually even the first one doesn't, but you likely don't really care about a std::unique_ptr, so it doesn't feel like a difference, and the negligence only really bites when it's not "just" that pointer…

> You see that Rust function destroyed the T. It's gone, no more T. But your C++ function makes a new T, then destroys the old one, so there's still a T, it's not gone after all. Perhaps your idea of C++ semantics is a bit off?

After more consideration I think probably your functions don't do anything at all?

Is that the joke here? That despite everything you didn't understand why core::mem::drop has that definition and so reading the empty body you assumed that you can just not do anything and that'll work in C++ ?

Re: What to do with C++ modules?

#243
post #143

Earlier quoted context omitted.

> It avoid instantiating the same templates over and over in every translation unit, instead caching the first instantiation of each. ccache doesn't do this: it only caches complete object files, but does not avoid repeated instantiation costs in each object file. I'm afraid this feature is at best a very minor improvement that hardly justifies migrating a whole compiler. To be blunt, it's not even addressing a probl…

It isn't only about template code. zapcc speeds up compilation when there's no cache. I tried it 10 years ago and it really reduced build times from minutes to seconds. For full builds.

> It isn't only about template code. zapcc speeds up compilation when there's no cache.

Someone else in this thread already pasted benchmarks. The observation was, and I quote:

> Zapcc focuses on super fast compile times albeit the speed of the generated code tends to be comparable with Clang itself, at least based upon last figures.

Re: What to do with C++ modules?

#244

Earlier quoted context omitted.

But oth, nothing is better at dealing with edge cases and weird things than writing your build scripts in an actual programming language. All that an integrated C++ build system would do is add a new std::build API, and for the compiler to discover a build.cpp file, compile and run that to perform the build. All the interesting "build system stuff" stuff would be implemented as regular stdlib code. See Zig for a work…

Real build systems need to deal with any language. Cargo is a negative on large projects because it has opinions that make things easy for small rust only projects and falls flat on complex projects- good build systems need to bea real programming language. The more declaritive the better - this is different from the project that often should be a different style

As long as the build system can run external programs, you're really not limited to a single language (or even compiling source code). In the end build systems are just fancy task runners, no matter if they are integrated with a language toolchain or separate products.

Re: What to do with C++ modules?

#245

Earlier quoted context omitted.

Real build systems need to deal with any language. Cargo is a negative on large projects because it has opinions that make things easy for small rust only projects and falls flat on complex projects- good build systems need to bea real programming language. The more declaritive the better - this is different from the project that often should be a different style

As long as the build system can run external programs, you're really not limited to a single language (or even compiling source code). In the end build systems are just fancy task runners, no matter if they are integrated with a language toolchain or separate products.

Sortof. If the build system doesn't understand the dependencies you have inefficient builds as it can't schedule all cores effectively at all times. On a large complex project this matters

Re: What to do with C++ modules?

#246
post #240

Earlier quoted context omitted.

> You see that Rust function destroyed the T. It's gone, no more T. But your C++ function makes a new T, then destroys the old one, so there's still a T, it's not gone after all. Perhaps your idea of C++ semantics is a bit off?

After more consideration I think probably your functions don't do anything at all? Is that the joke here? That despite everything you didn't understand why core::mem::drop has that definition and so reading the empty body you assumed that you can just not do anything and that'll work in C++ ?

Are you trolling? Or do you genuinely not understand why it might work in C++?

https://godbolt.org/z/58TqTTM37

Re: What to do with C++ modules?

#247
post #231

Earlier quoted context omitted.

See the other versions I added. > dispose of something "early". This is a bit of an anti pattern in C++, but doable of course.

> See the other versions I added. I don't think those work either. Not only do neither of those actually end the lifetime of what's passed in, but they have other flaws as well. > template void drop(T &&) {} This literally does nothing. Reference parameters don't affect what's passed in on their own - you need at least something on the other end (e.g., a move constructor) to do anything. For example, consider how thi…

> Not only do neither of those actually end the lifetime of what's passed in

>For example, consider how this would be instantiated for std::vector:

Great, here you go.

https://godbolt.org/z/9v66n6Ta4

And yes, the compiler will not prevent you from using this value. (clang will eventually, I think)

But clang static analyzer will happily detect it.

https://stackoverflow.com/questions/72532377/g-detect-use-af...

Re: What to do with C++ modules?

#248
post #186

Earlier quoted context omitted.

So what you’re saying is that it takes time, but works out? I agree.

> So what you’re saying is that it takes time, but works out? Probably depends on what you mean by "works out". I don't think GP would agree that delivering a less capable alternative qualifies. For example, one major feature C++0x concepts was supposed to have but got removed was definition-time checking - i.e., checking that your template only used capabilities promised by the concepts it uses, so if you defined a…

C++0x was ~5 years ago.

C++26 concepts has more or less everything you mention, and you can try it out with all the major compilers right now.

Re: What to do with C++ modules?

#249
post #13

Earlier quoted context omitted.

C++ has a habit of incorporating all the best ideas from it's 'succcessor' languages once these ideas are mature.

...and unfortunately butchering those good features beyond recognition, see C++20 vs C99 designated init. Typical "design by committee" outcome though :/

Agreed. Design by committee has been the thorn for a long time, hence efforts like Carbon, Circle, and cpp2.

But as it stands, I expect that whatever innovations these languages produce will be picked up by C++ in ~5 years.

Re: What to do with C++ modules?

#250
post #231

Earlier quoted context omitted.

See the other versions I added. > dispose of something "early". This is a bit of an anti pattern in C++, but doable of course.

It’s not just for disposing things, it’s also used to decompose things into their constituent parts… like if I had something representing an HTTP response and it contains headers and a body, I could write a `fn into_parts(self) -> (Headers, Body)` that returns the parts you care about while destroying the response object. This is useful in the grpc library I use, which has a response type with some metadata about the…

> compiler will reject programs that use the moved-from value.

Yes, this is something the C++ 'language' is not going to specify other than claiming that it is undefined behavior.

Doesn't prevent compilers from doing it though, clang will happily do this for you right now in most cases.

https://discourse.llvm.org/t/rfc-intra-procedural-lifetime-a...

Post reply on HN