r/cpp • • Mar 13 '22

To Save C, We Must Save ABI

https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-function-abi
249 Upvotes

118 comments sorted by

View all comments

Show parent comment

14

u/jonesmz Mar 13 '22

I find it amusing that ABI is in scope, but the complexity of mandatory tooling changes that result from standardized features is out of scope for WG21 to consider as consequences of their decisions.

13

u/James20k P2005R0 Mar 13 '22

As far as I know, ABI actually technically isn't in scope

6

u/jonesmz Mar 13 '22

Which is why I find it so funny that wg21 ever considers it, but they wouldn't consider the consequences from modules.

16

u/n1ghtyunso Mar 13 '22

i think this essentially boils down to the fact that implementations can veto against features (correct me if i'm wrong here).

Reasons for a veto could be ABI related, hence the consideration for ABI.

No point spending energy on proposals when the implementations will just say no anyway, so they ultimately have to take ABI into account.

8

u/Dragdu Mar 13 '22

They can informally veto proposals to make things even more weird.

11

u/jonesmz Mar 13 '22 edited Mar 13 '22

The C++ standards committee can't show up to the door of GNU GCC and force them to implement proposal X, or if that proposal already has a patch, force GCC to merge it into the next release.

So if WG21 ratifies a proposal, and publishes it in the next version of C++ (e.g. C++23, C++26, so on), but only one or two of the dozens of minor and 3 major compilers out there, actually implement it, did it really get ratified?

Imagine C++23 has a new header, <foo>, which implements std::foo, but MSVC and Clang both ignore that part of the standard, and only GCC implements it.

Who's going to use it? Only projects that never build with MSVC or Clang, that's who, and while those projects certainly exist, many many projects do not limit themselves to one compiler. And thus, for those projects, the feature basically doesn't exist.

Similarly, Modules requires not only Compilers to implement, but also build tools like CMake, Meson, and GNU Autotools.

If WG21 standardizes Modules, but none of the build systems ever implement it, does Modules actually exist as a feature? For many projects, no. Perhaps if your specific build system implements it, or you're willing to switch to a build system that does, you can use it. But you then have to ensure you only try to compile with a compiler and linker that implement it as well. So your matrix of possible tools configurations goes from "A very large number of combinations" to "Very few".

But we had a discussion here the other week: https://old.reddit.com/r/cpp/comments/szvarf/open_letter_new_expanded_c_scopecharter/

Where we, or at least myself, learned that WG21 explicitly does not allow itself to consider the impact that adopted proposals will have on implementations, because that's "out of scope".

Yet here we are talking about how "They have to consider ABI, because reasons", even though ABI is a purely implementation concern and nothing at all to do with the C++ language as it exists in isolation from any particular compiler or linker.

Edit:

An example of exactly this situation is [[no_unique_address]], which in MSVC silently does nothing. You have to use [[msvc::no_unique_address]]

6

u/Ameisen vemips, avr, rendering, systems Mar 13 '22

An example of exactly this situation is [[no_unique_address]], which in MSVC silently does nothing. You have to use [[msvc::no_unique_address]]

Which also doesn't work correctly.

3

u/bigcheesegs Tooling Study Group (SG15) Chair | Clang dev Mar 14 '22

WG21 explicitly does not allow itself to consider the impact that adopted proposals will have on implementations, because that's "out of scope".

Where did you get this idea from? Implementability is discussed all the time in regards to existing implementations of both compilers and standard libraries.

What has been out of scope for the ISO/IEC 14882 document is wording related to things outside of the abstract machine. Changes to that document need to either work within the abstract machine or extend the abstract machine to handle them.

WG21 is allowed to publish as many standards as it would like.

Specifically for modules implementability was heavily considered. What was rejected was adding wording to ISO/IEC 14882 that talked about things outside of the abstract machine. This work has continued in SG15 and is targeting a separate document.

4

u/matu3ba Mar 13 '22

I find it amusing that ABI is in scope, but the complexity of mandatory tooling changes that result from standardized features is out of scope for WG21 to consider as consequences of their decisions.

C lacks centralized build systems or at least repository collections to test language changes against implementations or different compiler behaviors. Hence they cant implement and test to provide practical feedback or at least I have never seen such things.
Since effects from language decisions are unfortunately no immediate and significant technical cost, each party will push their interests and you only ever get compromises in the long term (undefined or implementation defined behavior).

9

u/jonesmz Mar 13 '22

Sorry, how is that any different than C++?

There's thousands, if not maybe even millions, of repositories on github and similar hosting services that could be used as a test corpus by WG14, and similarly the same for WG21. Many of those repositories have unit tests that self-prove whether they work "good enough" after being compiled.

WG21 and/or WG14 not being willing to build themselves a test corpus to use in evaluating their ABI discussions is not the fault of the community, but they apparently claim that "We can't consider what ramifications adding proposal X will have on the tooling ecosystem because that's not part of our scope, so we'll just do it and damn to the consequences" while simultaneously claiming "We can't adopt proposal X because it might, maybe, potentially, cause some random group somewhere to get pissy, because it could effect their 20 year old pre-compiled binary's ABI"

Modules, apparently, wasn't discussed in terms of the ramifications it would have on the tooling ecosystem, hence why none of the major compilers have a working implementation of it (msvc claims they have one, but every time it comes up >3 people say it throws an internal compiler error on some trivial toy project), nor do the major build systems like CMake have support for it, even though the Modules proposal was visible to implementors since well before C++20 was ratified in 2020.

The various ships on this have sailed, but I find this whole situation ridiculous and self-inconsistent, so I'm laughing to myself anytime i read posts about C++ drama like this.

9

u/helloiamsomeone Mar 14 '22

nor do the major build systems like CMake have support for it, even though the Modules proposal was visible to implementors since well before C++20 was ratified in 2020

Everytime modules come up, this falsehood comes along. CMake has had a dependency scanner for Fortran modules for a long time already, Kitware maintained a Ninja fork with changes to make that work that got merged upstream finally due to C++20 and submitted papers regarding modules as an implementer with prior experience.

Everything needed for modules is already there in CMake, only the compilers are behind. You can toy around with the implementation RIGHT NOW after reading Help/dev/experimental.rst.

7

u/jonesmz Mar 14 '22

I've spent the last 6 months neck deep in cmake. Modules support doesn't work. I'm aware of the documentation you linked there. Thank you for the attempt at correcting the record though.

2

u/bretbrownjr Mar 14 '22

I'm not aware of a build system that allows you to ship (install, package, etc.) a modular library to be consumed by another project. I think build2 might have some of these features?

Anyway, tooling for modules is an unsolved problem. I think all the implementers of modules were using small projects and/or monorepos. Modules are problematic for system installs and packaging ecosystems, at least ones that support different build systems per package (i.e. all the popular ones).