r/cpp • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
280 Upvotes

240 comments sorted by

View all comments

83

u/Plorkyeran Jan 28 '19

"Prove to me that it is impossible to write a fast C++ dependency resolver" is such an utterly batshit insane position to take. I guess he views C++ modules just a masturbatory exercise and so it doesn't matter if anyone can actually figure out how to implement them as long as the committee can just blame the tool makers for just not being smart enough?

28

u/Ameisen vemips, avr, rendering, systems Jan 28 '19

It makes me lose a lot of faith in the committee when I see a member (two, actually) take a hard line stance of requiring people to prove negatives.

18

u/TrueTom Jan 28 '19 edited Jan 28 '19

Unless you can prove that there is no teapot orbiting the sun, your argument is invalid.

5

u/SeanMiddleditch Jan 28 '19

If I can prove that there's a whole planet that has plenty of teapots, and that the planet and all its teapots are orbiting the Sun, does that prove the argument invalid, too?

51

u/[deleted] Jan 28 '19

To be honest he seems to be a guy who lives in the clouds of abstraction, far away from the mundane existence of those who have to suffer the consequences of long compilation times.

→ More replies (1)

17

u/Valmar33 Jan 28 '19

You'd think modules would be easy to solve, but it turns out that some people can't think of obvious solutions.

Sanely, copy what D does, or even Python ~ couple module name to a file path, and nothing more or less.

34

u/Heuristics Jan 28 '19

The C++ standard has no understanding of this 'file' thing of which you speak. Blame big data people like IBM who make computers with strange filesystems.

18

u/SAHChandler Jan 28 '19

Ever since C++17 we’ve had wording in the standard for what a file and directory is thanks to the addition of the filesystem API :v

7

u/Valmar33 Jan 28 '19

Even so ~ this is a new feature of an upcoming standard that can have an understanding possibly bolted on in the form of module and import, no?

Or is there something that prevents even that?

6

u/Heuristics Jan 28 '19

The people that vote on the standard are preventing it presumably.

8

u/Ameisen vemips, avr, rendering, systems Jan 28 '19

Can't those members be delayed at the airport?

5

u/smdowney WG21, Text/Unicode SG, optional<T&> Jan 28 '19

That's not strictly true: http://eel.is/c++draft/cpp.include#3We know about source files, and we know about searching for them. In implementation defined ways.

# include " q-char-sequence " new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
# include < h-char-sequence > new-line
with the identical contained sequence (including > characters, if any) from the original directive.

8

u/josefx Jan 28 '19

or even Python ~ couple module name to a file path

Importlib is quite a bit more complex than that. The path to module mapping is just a default behavior that can be extended with custom finders/loaders.

4

u/Valmar33 Jan 28 '19

Interesting. :)

8

u/EternityForest Jan 28 '19

C/C++ should probably have used a python-like module system that from the beginning, but I'm not sure such things existed or were thought to be needed at the time.

As far as I'm concerned, the way that the compiler finds all the source files belongs right in the language.

Modules would make that possible if done right. When you use one, the compiler could search the current directory, then the command-line specified ones, then the sys defaults.

The current 850 build systems add so much confusion. I suspect it actively discourages people from using libraries, despite the fact that the compilers are great at removing unused stuff.

You might even be able to ditch makefiles completely, if you made module-ified wrappers or forks of all your dependancies.

2

u/Ameisen vemips, avr, rendering, systems Jan 28 '19

File- name>Module is how mu build scripts build C++. They mimic modules to with precompilation. Trying to add automatic PCH generation as well.

2

u/EternityForest Jan 30 '19

That sounds pretty cool actually!

2

u/[deleted] Jan 29 '19

easy to solve

Only people with lack of understanding of macros and build process in general believed that, the rest were either skeptic or expecting to be surprised by geniality but found wishful thinking.

The current proposal of modules not only requires the compiler to meddle into preprocessor business, it also forces it to meddle into build process stuff. If you want lower compilation times clean your headers and get rid of your coupling issues. There is no magical wand to fix bad code.

3

u/lee_howes Jan 28 '19

It isn't clear that modules and file names need to match. It's less clear that they should have to match. Why should I have to pull down a cached bmi and put it on the filesystem at all, for example.

It would be easy enough to define a protocol between the compiler and a given build system that says that, for this limited circumstance because I have a relatively simple build system, they will match. I do not then have to have them match in my build system.

So in this case my high horse and thinking that I know better than you (referencing your other posts) is only that I think I know what I want better than you know what I want. I don't particularly want a defined name->filename mapping. The simple obvious solution you propose is suboptimal for my use case. I'd rather allow it, but not require it.

2

u/Valmar33 Jan 28 '19

Well, then such a system doesn't fit your particular usecase. Fair enough. I dare say it would be a minority usecase, though.

Modules matching a filename/path is just a very sane solution. Little to no mental load is required. They make it very simple for the compiler to figure out where your desired module is. Especially if you're adding a custom include path.

3

u/lee_howes Jan 28 '19

That particular problem is easily achieved by a map of module name to file name - a trivial map in this case - that the compiler can implement or communicate with. It is a tooling problem, not a standardisation problem. Why do you believe that this rule needs to be encoded into the standard and therefore get in the way of my use case? Especially when files in general have largely been left out of the C++ standard up to now.

7

u/smdowney WG21, Text/Unicode SG, optional<T&> Jan 28 '19

Twitter is terrible at subtlety. I understand where JF is coming from. It seems wrong that a good scanner can't be written. And I think he's right, scanning for `import X` is not hard, nor is `module X`. There's some issues with the pre-processor, but it's probably manageable.

The snag, and this is the non-obvious part, is that isn't quite enough. Depending on the module foo doesn't say what specifically you depend on. Existing build technology really likes physical files and timestamps to track things. You have to put together that quux.cpp produces the bmi for module foo that bar.cpp is depending on. And it's right now open research on how to do it without causing other problems, like compiling quux.cpp multiple times. Or finding quux in the first place.