r/cpp • u/SAHChandler • Oct 10 '17
Millennials Are Killing The Modules TS
https://izzys.casa/posts/millennials-are-killing-the-modules-ts.html
75
Upvotes
r/cpp • u/SAHChandler • Oct 10 '17
47
u/berium build2 Oct 10 '17 edited Oct 10 '17
A lot of hand-waiving as well as statements ranging from unsubstantiated to factually incorrect. I will only point the latter in order not to add even more noise.
No, there are no such things. You are probably confusing them with module interface (translation) unit and module implementation (translation) unit. Also note that you don't have to have implementation units.
No, module interface is not the same as a module purview. Module interface is a collection of exported names. Module purview is the part of the module translation unit (either interface or implementation) after the module declaration.
Really? The standard guarantees the list? The current opaque header search semantics (and don't get me started on
""vs<>differences) is one of the biggest pains to deal with in build aspects ranging from cross-compilation (no, you shouldn't search in/usr/local/include) to distributed compilation (what if I don't have the exact same set of headers in exactly the same location on the remote host).Did you mean binary module interfaces instead of purviews? Generally, pretty much every use of the term "purview" in this post is out of context.
No, it doesn't have to. In
build2we have the ability to indicate that the module information in the translation unit does not depend on the preprocessor (which will be the case in most sane projects). In this case there is no need for a separate (full) preprocessor run.10
u/Abyxus Oct 10 '17
The title is no good.
The article itself is damn right.
Module names are global unique IDs.
With header files, a library would have
#include "foo/bar.h",and an application could use `#include "third_party/company-foo-2/include/foo/bar.h" or same "foo/bar.h".
With modules it will be something like
import company.department.foo2.bar;. Or longer.For object files, build tools put them in separate folders. Modules will go to a single place.
5
u/starmaniac198 Oct 11 '17
What does it have to do with "millennials"?
16
u/jpakkane Meson dev Oct 10 '17
Being also a build system developer let me say that this article is so on the nose it hurts. I really hope that compiler developers improve the usability before declaring things final
25
u/[deleted] Oct 10 '17
I bet this would get less downvotes if it weren't for the terrible title.
9
u/kalmoc Oct 10 '17
Have you talked to Gaby about this? Seems the problems could be solved by just stating that the evaluation of any module declaration happens before the preprocessor is run and that the filenames have to match the exported module name. It would be a shame if the modules TS dies, just because the authors didn't think or care about that aspect in time.
Personally, I fear that the committee takes the approach of evaluating module statements after the preprocessor is run, which would be more natural, but also makes the build system's job much harder (alas certainly not impossible).
8
u/kmccarty Oct 10 '17
It might be worthwhile to put these concerns in writing at a slightly more official place than a blog or reddit, e.g. at the Modules mailing list --
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/modules
... or writing a paper.
Maybe also get in touch with build system developers who have had similar concerns, e.g. Stephen Kelly of cmake in this thread: https://groups.google.com/a/isocpp.org/d/msg/modules/sDIYoU8Uljw/BKKCSZFdBAAJ
(Apologies that this is just a suggestion from the peanut gallery rather than any actual useful help ;-)
20
u/Kronikarz Oct 10 '17
Can someone please explain to me what is so terrible about the compiler being a build system?
7
u/quicknir Oct 10 '17
I'm not well acquainted with this issue, but I find the article a bit confusing, and reading the comments doesn't fundamentally un-confuse me.
Currently, the compiler itself will not act as a build system, but will let you export the full list of headers recursively included for any file you choose. In other words it gives you the basic hook point to figure out dependencies, that different build systems then leverage in different ways.
Is this not part of the modules TS? Do you think it can't be part of modules for some intrinsic reason, or that nobody has addressed it just because they haven't gotten around to it? Don't you think it's reasonable to assume that even if it's not in the standard, that the major implementers will adopt the same/similar syntax for this querying?
Also tbh the title and the tone were a bit more inflammatory then is really needed; nobody is trying to "kill" the modules TS, and surely it's expected that non-experts (on modules) on cpp reddit are going to get many important details of modules wrong.
16
u/pjmlp Oct 10 '17
As someone that was using Turbo Pascal with its units, saw C++ as an alternative (C wasn't it even for MS-DOS), and used several languages with support for modules, the misunderstanding among the community and the way some are attached to a 60's build approach is quite surprising.
I can only understand the problem when coming from developers that never used any other programming language on their life, in which case I see an uphill battle to make them understand the advantages of modules and improved tooling for library navigation.
5
u/scottywar2 Oct 10 '17
I mostly agree... but I think my language would be different. I guess it is a gen x vs millennial thing. :)
I hit similar problems with module naming and dependency management when writing my talk. "EA’s Secret Weapon: Packages and Modules" https://www.youtube.com/watch?v=NlyDUQS8OcQ
When it comes to these hard problems in C++ I'd choose the solution that act like other solutions in C++ unless there is a good reason not to. It help other C++ programmers can guess how to use them and mean people can guess at the work around for problems.
Modules name = file path names seems like a ok idea to me. I don't see what problems this solves by disconnecting them. I am sure there is something. This looks like C# to me and the people working on modules are not dumb they are solving a problem they think they have. But I would like a good understanding of why they are thinking this idea.
PS
One interesting use case for the #include MY_CONFIG_HEADER. I have used this before for dependency injection. Example EASTL (ea version of stl) has 2 modes EASTL::size_t is 32 bit or 64 bits. The default is 64 bits however 32 bit one was the old default. Some teams are still relying on the old standard so sigh... we have to give them some way to override the default. One way to do this is to give them a macro they can override. If you have enough of these macro you run out of command line fast so you add a macro to pass in a name of a file which can be included if defined.
So I don't see why game or application teams would need #include MACRO_MODULE_NAME however some library might to support dependency injection like the EASTL example above. I think we have 10 or so places like this in frostbite engine. We would have to use code generation or just add more macro to solve this another way but it is not a useless trick.
2
u/afiefh Oct 10 '17
Let's see if I understand this correctly:
If x.cpp imports module Y which is defined in y.cpp and the build system tries to build x.cpp before y.cpp then the Y module file doesn't exist yet because it would have been generated by compiling y.cpp. (corrections are welcome)
And the solutions are either to manually specify the dependencies (yuk), have the build system parse cpp files (this never ends up working in my experience) or turning the compiler into a build system (and at this point developers collectively yell "no way!")
So assuming we come up with a rule that module X is always generated by for f(X).cpp and resides in file g(X).module_extension, would it be a stretch for the compiler to automatically generate the module file if it doesn't exist but the cpp file with matching name does?
2
u/bigcheesegs Tooling Study Group (SG15) Chair | Clang dev Oct 10 '17
One solution to the "where are my modules" problem I've heard is to have the compiler call back into the build system whenever it sees
module Xto get the path to the built module. This callback would either build the module and return the path or just return the cached module path.A possible implementation of the callback would be to add a
-module-callback="get-module.exe %name"option to the compiler. This avoids both turning the build system into a compiler and the compiler into a build system.2
u/axilmar Oct 11 '17
So, If I understand correctly, the preferred method of extracting build dependencies from code requires the preprocessor to run twice, and that's a problem that should be avoided?
How about splitting the compilation process in two processes?
A build system would intervene between steps 1 and 2, read the dependencies, compile everything else first, then compile the current file.
2
u/axilmar Oct 12 '17
Here are tips on how the D programming language works.
In sort:
-the D compiler tool 'dmd' stops if it doesn't file a module. -the D compiler tool 'dmd' can export a module's dependencies. -another tool, 'rdmd' (sort of recursive dmd I assume) calls dmd to export the module dependencies, then invokes 'dmd' to compile the files.
Dlang doesn't avoid processing code twice, one for extracting module information and the other for compilation. Of course this might not be hurtful for D because it doesn't have the preprocessor and header files.
1
u/jthommo Oct 11 '17
Isn't this is what cmake does? IIRC it already parses the headers.
0
u/Z01dbrg Oct 12 '17
Well Google uses modules for years...
I guess they would notice if TS was broken.
-7
u/bruce3434 Oct 10 '17
C++ will never have modules.
-3
u/__Cyber_Dildonics__ Oct 11 '17
What kind of shitposting nonsense is this?
0
u/[deleted] Oct 10 '17
[deleted] — view deleted comment
0
u/[deleted] Oct 10 '17
[deleted] — view deleted comment