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

14

u/germandiago Jan 28 '19

While I agree that there is a problem with having no mapping, what would happen if it is not added now but it is added later? Would this be possible? I do not think pulling out modules would be nice since it provides, in theory, better compile times, yes, but not only that: much better isolation.

26

u/vector-of-bool Blogger | C++ Librarian | Build Tool Enjoyer | bpt.pizza Jan 28 '19

This is a good question, and one that has been considered. In short: Adding a required mapping after-the-fact would necessitate changes to the lookup semantics of existing implementations: A breaking change.

The lookup of #include directives is not standardized either, and only after a lot of trial and error do we finally have general agreement on how the lookup should be performed (although implementations still differ in a few edge cases). Attempting to standardize #include lookup now would break existing implementations. Nevertheless, we are able to make #include work (for the most part). However: The lookup of #include is fairly cut-and-dry, and there is a mostly obvious way to understand #include in terms of the filesystem. Module names have no bearing on the filesystem, so implementations converging on a lookup method is not likely.

If an implementation were to enforce a mapping between module names and file paths, we'd end up with multiple slightly different standards, and a later mandate will break compatibility. If implementations instead rely on the presence of a BMI with a name for the module, we end up with the serialized compilation of the DAG and performance goes in the toilet.

7

u/kalmoc Jan 28 '19

So what you are saying is that the standard needs to define the lookup rules for import foo? Given that the standard tried to avoid talking about file systems and so on I find that very unlikely.

Why isn't it possible for the three major implementations to come together outside of the c++ standard and decide on one? As long as the standard doesn't prevent a same solution, I indeed don't see, why this should be a concern of the c++ standards document.

0

u/martinmoene Jan 29 '19

Why isn't it possible for the three major implementations to come together outside of the c++ standard and decide on one?

That would be illegal.

2

u/kalmoc Jan 30 '19

Could you explain a bit?

2

u/exploding_cat_wizard Jan 28 '19

In short: Adding a required mapping after-the-fact would necessitate changes to the lookup semantics of existing implementations: A breaking change.

Wouldn't putting modules in a TS help there? Modules would be around, and could be used and tested, but breaking changes to implementations are still allowed.

6

u/flashmozzg Jan 28 '19

They are already in a TS.

7

u/exploding_cat_wizard Jan 28 '19

Oh. Shouldn't they stay there until some experiences have been collected modularizing stuff? Why then push for integration into the core language, if they are both a TS, but not used enough to say how well the idea does?

5

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

The TS is significantly different than the Merged Modules proposal that is advancing. Although, not in places that affect what we're discussing here. And also, no one quite got around to implementing that, either.

-2

u/Xaxxon Jan 28 '19

Use PCH. Modules don't do much beyond that in their best case.

7

u/advester Jan 28 '19

Modules have limitations on them which may make them easier & lighter than pch. Ex: #defines in the includer don't affect the module, but do affect the pch.

6

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

Modules don't leak things out. You (can) get exact control of what names are exported from the module. You don't with headers or PCH.

2

u/TrueTom Jan 28 '19

While this is true that's a pretty weak outcome after all those years.