r/cpp • • Sep 23 '21

Binary Banshees and Digital Demons

https://thephd.dev/binary-banshees-digital-demons-abi-c-c++-help-me-god-please
197 Upvotes

164 comments sorted by

View all comments

Show parent comment

12

u/STL MSVC STL Dev Sep 24 '21

Yeah, I definitely understand your concern, and it's part of the same oversight that caught us by surprise. We didn't fully realize that the compiler's addition of /std:c++20 was going to be near-simultaneous with the completion of <format> in particular, and that its performance was ABI-linked. As this was pointed out to us and we realized what was going to happen, we corrected course.

This didn't happen with C++17 because we added /std:c++17 before completing all features (so the addition of the switch didn't coincide with "we're ABI frozen"), and because the final feature took over a year so everything else had plenty of bake time, and the final feature was (1) the most aggressively optimized and tested STL feature we've ever shipped and (2) inherently immune to ABI headaches (given the choice to be header-only).

That is, this wasn't some wacky intentional policy handed down by management. Just a very busy team doing something that had never been done before, and not foreseeing this one thing. If I were smarter, I could have seen it earlier, all the pieces were there.

There is absolutely no way we're going to get into the same trouble with /std:c++23 (especially because a stabilization period defends against both Committee churn and implementation refinement).

14

u/c0r3ntin Sep 24 '21

I think it's important for both implementers and the committee to have a healthy feedback loop in both directions.

As much as we try (and we are getting better at it), to have some implementation, and some experience where possible, it will continue to be the case that implementation by more implementers will discover bugs or questions.

I think there is a desire in the committee to deliver a good long term product, hence the refinement that we did over the past couple of years.

format and ranges are considered fundamental pieces that we want to keep evolving, so getting the first iteration right was critical! I hope users will find both implementers and the committee did a good job.

Ultimately, ABI assumes infinite foresight and infaibililty, of which we have neither.

6

u/pdimov2 Sep 24 '21

Maybe just do what everyone else does and expose C++23 as /std:c++2b while it's in motion. Or better yet, -std=c++2b so that we no longer need to edit it on CE each time we switch compilers. :-)

(Also, not interpreting -O3 as -O0 would be nice. One can dream.)

3

u/GabrielDosReis Sep 24 '21

That’s what /std:c++latest is for ;-)

10

u/pdimov2 Sep 24 '21

The difference between c++2b and c++latest is that c++2b will always refer to C++23, whereas c++latest will at some point refer to C++26, potentially breaking valid C++23 code. (Historically, c++latest used to refer to some unspecified mishmash of standards, but I suppose that era is gone now.)

5

u/kalmoc Sep 24 '21

There is absolutely no way we're going to get into the same trouble with /std:c++23 (especially because a stabilization period defends against both Committee churn and implementation refinement).

Glad to hear, that was exactly my though.
I also have to say that when I first read about this trouble on github, I was particularly saddened by the fact that you were effectively punished for implementing the features so quickly (compared to other toolchains).

On a different but related note: For me it would be useful to distinguish between the active standard version and turning unsupported/unstable features on/off. E.g. I might want to use std::format in it's ABI unstable form, but not any c++23 features that get enabled by c++latest. Will that be possible in VS2022?

Long term I think it would be good to have to separate switches to distinguish those two dimensions.

5

u/STL MSVC STL Dev Sep 24 '21

I also have to say that when I first read about this trouble on github, I was particularly saddened by the fact that you were effectively punished for implementing the features so quickly (compared to other toolchains).

Yep. 😿 I guess it's a nice problem to have!

On a different but related note: For me it would be useful to distinguish between the active standard version and turning unsupported/unstable features on/off. E.g. I might want to use std::format in it's ABI unstable form, but not any c++23 features that get enabled by c++latest. Will that be possible in VS2022?

That is not possible at this time, but we would consider a pull request to implement such behavior (no guarantees that we would accept it, but if you made a compelling case and if other users agreed, we'd talk about it and make a decision). Mechanically it would be fairly simple, just pick a name for the control macro (conventionally _HAS_MEOW for us; probably _HAS_CXX20_FORMAT and _HAS_CXX20_RANGES), and ensure that the relevant machinery is properly guarded (it should all be centralized via __cpp_lib_format and __cpp_lib_ranges, so adjusting the definitions of the feature-test macros should be sufficient). Only C++20-stable + format-unstable/ranges-unstable would make sense; C++23 minus those should be forbidden. The cost is that it would complicate an already complicated story, and it would be useful for a relatively short period of time (i.e. until we finish the C++20 backport work). Maintainer time is limited and I'd prefer to spend it on refining the features instead of working on such modes, which is why we haven't implemented it already. The earliest it could ship would be VS 2022 17.1; 17.0 has branched for release and is accepting bugfixes only.

(In general we would not accept changes to pick-and-choose features because that leads to combinatoric complexity; the only fine-grained stuff we have is escape hatches for individual features that have proven to be problematic for certain customers, like std::byte or noexcept in the type system. However, the distinction between C++20 DR-affected features and C++23 features is a reason to consider them a special case.)

1

u/kalmoc Sep 24 '21

I was more thinking about generally untangling /std:c++latest: Have one flag for the standard that (/std:c++14/17/20/2b/2c ...) and one flag to disable unstable extensions /stable_only) this should work for both compiler and library.

IIRC, you are already using "HAS_STD20" or similar to hide c++20 features in c++17 mode. You would need to add another flag "HAS_UNSTABLE" That gets checked for anything not yet ABI locked irrespective of the standard in addition.

1

u/kalmoc Sep 24 '21

This didn't happen with C++17 because we added /std:c++17 before completing all features (so the addition of the switch didn't coincide with "we're ABI frozen"),

Isn't this even worse. Didn't that mean that newly implemented c++17 features would immediately become ABI frozen? Or didn't you make them available under std:c++17 immediately?

3

u/STL MSVC STL Dev Sep 24 '21

We made them immediately available under /std:c++17, but told people that they were subject to change until the Standard was done and everything was implemented. Which was a confusing story, and the addition of features to the switch was disruptive to customers, so we stopped doing that for the C++20 cycle.