157 points · by todsacerdoti · 3y ago · 137 comments
It allows them to enable the "unity build" stuff automatically for example, and on a per file basis as well. If you have a file checked out locally (in Perforce terms), it won't include it into the usual unity compilation unit for it and will compile it on its own as it's likely it's one you're going to edit a lot if it's one you've got checked out.
Anyway, I thought it was an interesting datapoint as I think it's quite unique. To the level of Boost using a modified fork of Jam at some point...
It has a nasty habit of getting itself stuck, and it's got a horrific architectural decision of only allowing one instance of the process to run at a time (and see previous point, it gets stuck). Combine those two with modern IDEs that call the build tool in the background and you bet a messy situation.
But the adaptive unity build is probably one of the coolest features I've ever seen in a build system
I figured this was possible but haven't seen anything that does it. I hate writing function signatures twice with subtle differences like default args and overrides. Waste of my time.
Doing a full compile, has been known to bring even the most powerful machines to their knees.
They’ve employed a lot of the referenced article’s suggestions and it still is a massive code-base to compile.
[0]: https://wiki.documentfoundation.org/Development/BuildingOnLi...
cd $(mktemp -d)
fedpkg clone -a -b f38 libreoffice && cd libreoffice
fedpkg mockbuild
This requires the 'fedpkg' and 'mock' packages be installed, and that your user is in the 'mock' groupCompiling is one of many benchmarks I do, lol
Edit: note for posterity -- the branch will change as time goes by. Fedora 38 is the current release, so f38 is used.
The source for the code and the target for the build don't have to match. Look into different 'mock roots' at /etc/mock/*.cfg
You don’t need to do a full clone to have multiple working copies of your repo checked out. You can use the git worktree command to create these working copies:
A task could be any small thing that requires its own checkout for some possibly stupid reason, like running the regression tester or temporarily running an old version of a binary out of your dev checkout over NFS if there was a bad deploy.
https://www.git-scm.com/docs/git-clone#Documentation/git-clo...
Also, all branches stay in sync between worktrees. For example, I do git fetch on one worktree, and remote branches are up to date on all of them.
The only downside is that they don't work with submodules, if you are unfortunate enough to be using submodules.
For big repositories with long histories (like Qt), worktrees also save some disk space.
I’ll grant that saving disk space is a concern for many - not for me - the largest repo I use is 2-3 million LOC with about 10 or 15 years history and the 4-5GB per clone doesn’t bother me.
What we actually need is tooling to help recommend how to refactor or split headers in a way to reduce having to parse a ton of dead code.
Or even better, tooling that would generate one off headers per TU. I think it could be done.
Anyone have experience with PCHs? Good or bad?
Looks like https://include-what-you-use.org/ might do that.
One major deficiency in IWYU that we will have to solve is that IWYU only understands post-preprocessed sources.
If you have preprocessor guards for some code (as is done extensively in the Linux kernel) IWYU can recommend changes that break the build for other configurations than the one used when running IWYU.
stick everything in a single compilation unit automagically and have a flag to let bad legacy code that reuses global symbols produce errors/warnings so they are easy to fix, or be ignored so that we can still have backwards compatibility.
that is just the "hacky" way of doing things and it indeed works wonderfully, although often breaking any kind of incremental build - this is because we implement incremental build wrong, which is suitably easy to fix as well.
So then what does the goal become? Splitting the codebase into 8 equally-difficult-to-compile translation units? What about someone with 6 cores, or 12? Or 32?
I think devs working on large systems in soft-realtime domains are the ones to look at. There you'll often find build systems that are mostly unity builds, but that allow ad-hoc source files to be separately compiled, often with separate compilation options (such as with debug symbols and optimizations, etc.) that are too onerous to enable globally.
As far as problems with constructs like anonymous namespaces and name clashes are concerned, I think they're relatively easily resolved for new code, and these techniques are quite old. Many have been using this "new" approach for decades, so the "legacy" code is also clean in this regard.
But it's unfortunate that the net result is that anonymous namespaces are effectively useless. However, that's just case number 99 for "stuff added to the standard that you can't really use because of 5 or so other major problems with the language". And most new languages don't improve on any of this stuff, they just buy you off with other novel features -- admittedly sometimes quite intriguing ones.
Most "modern" languages are designed around building the whole world and statically linking it into your program. As you say, they don't improve on any of this stuff.
I would gladly use a new version of C++ that breaks compatibility but solve this problem.
This is the largest barrier for C++ right now.
It doesn't really have anything to do with compatibility (not entirely, but the things that are the biggest issue to good optimization quality and are fixable are things that need a system-level rethinking on how hardware exceptions happen). It just isn't reasonable to expect developers to know how to optimize, and it doesn't scale.
Well...
https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.htm...
And support for ccache is not an option to some build systems. For instance, Visual Studio projects in general and the msvc compiler require a lot of fighting to get it to work.
Also, ccache is renowned for not supporting precompiled headers.
With the module, the giant list of names is compiled once into a large file, and then imported into consumers as necessary.
[1]: https://github.com/KhronosGroup/Vulkan-Headers/blob/main/inc...
[2]: https://github.com/KhronosGroup/Vulkan-Headers/blob/main/inc...
There's no good, fundamental reason why #include caching can't be done with similar mechanisms to import, resulting in similar perfornance.
Certainly, modules are cleaner than headers. That's a language improvement and a fine reason to switch to them. Headers leak more definitions, macros etc that are part of the implementation, and their interpretation is affected by definitions before the header is included.
But in normal situations those header semantic leaks need only add a very small or negligible time overhead to symbol resolution compared with modules, both from a compiler-friendly precompiled form. Articles I've see explaining why modules are faster tend to talk about parsing headers, repeatedly, and if not parse then still process a precompiled syntax in some complicated way, as opposed to modules storing a compiler-friendly data structure. But those are merely describing how things are already done, not what's possible.
I'm wondering if anyone here remembers that article.
The way to do it is to never have any `#include` directives in headers. Put them all in the implementation source files.
You have a function in a `foo.h` which returns a `bar_t` type, that is defined in `bar.h`? Then each source (.cpp or .c) file that includes `foo.h` must first include `bar.h`.
While this does not completely alleviate the problem of reading the same header 10x in a project with 10 source files, it does mean that at least you don't read the same same 50x in a project with 10 source files.
Each header is read once, and only once, for each translation unit. When using header guards or #pragmas, a single header file will be read multiple times because it can (and usually will) include other headers.
https://en.cppreference.com/w/cpp/language/pimpl
Pimpl greatly reduce build times by removing includes from the interface header at the expense of requiring pointer dereferencing, and it's a tried and true technique.
Another old school technique which still has some impact in build times is to stash build artifacts in RAM drives.
It is not a language flaw. C++ requires types to be complete when defining them because it needs to have access to their internal structure and layout to be in a position to apply all the optimizations that C++ is renowned for. Knowing this, at most it's a design tradeoff, and one where C++ came out winning.
For the rare cases where these irrelevant details are relevant, C++ also offers workarounds. The pimpl family of techniques is one of them, and type erasure techniques are also useful, and protocol classes with final implementations are clearly another one. Nevertheless, the fact that these techniques are far from being widely used demonstrates that there is zero need to implement them at the core language level.
This statement is incorrect. "Definition resolution" (my made up term for FE Stuff(TM) (not what I work on)) happens during the frontend compilation phase. Optimization is a backend phase, and we don't use source level info on type layout there. The FE does all that layout work and gives the BE an IR which uses explicit offsets.
C++ doesn't allow two phase lookup (at least originally); that's why definitions must precede uses.
And private methods aren't exactly "rare cases". The situation is bad to the point that most good codebases make less use of classes, and many average code bases avoid adding private methods and resort to code duplication to a degree.
Not really. There are two main flavours of pimpls: one where the impl class is a pod that only holds member variables, and one where the impl class holds both member variables and private member functions.
On both, the implementation can and does stay in the very same translation unit. On the former, the code stays in the very same class,without any change.
You only experience the sort problems you describe if you bring them upon yourself. That's hardly the idiom's fault.
https://news.ycombinator.com/item?id=24537267
https://www.cppstories.com/2018/01/pimpl/#pros-and-cons
It used to be a widely advertised technique maybe a decade ago, but it has long gone out of style.
I'm going to make it simple for you: take a Qt widget. You define its widget layout with Qt a designer, save a UI form file, and get Qt's UIC to generate a header file that implements that widget tree. You have three options to include the object in that header: either inherit from it, composition, and pimpl. So you swore off a pimpl. Pray tell, how do you use a Pure virtual interface in this case?
What leads you to believe they can’t?
> I'm going to make it simple for you: take a Qt widget. You define its widget layout with Qt a designer, save a UI form file, and get Qt's UIC to generate a header file that implements that widget tree. You have three options to include the object in that header: either inherit from it, composition, and pimpl. So you swore off a pimpl. Pray tell, how do you use a Pure virtual interface in this case?
Never worked with Qt. Can you give me FooBar example where pimpl is superior to pure abstract class, please?
It just feels great to be able to totally refactor the implementation without touching the header.
As work, now, we mostly use C++11 and C++14, some projects are C++17, but I am not aware of a single C++20 project, I think all active projects that are C++03 or below have been migrated to something more recent.
Just a data point.
I was quite surprised to read this in their roadmap, as Unreal's codebase is quite massive and also uses some custom build tools.
2. Why do you dislike Java? Most of FAANGMULA uses it in some capacity no?
2. I was unfortunate to write some Java in the past. Strong dislike of it since. Nowadays I prefer natively compiled languages.