-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various cleanups: Simplify ios_base
and locale
constants
#4125
Merged
StephanTLavavej
merged 4 commits into
microsoft:main
from
StephanTLavavej:dry-cleaning-9-danger-is-my-middle-name
Oct 26, 2023
Merged
Various cleanups: Simplify ios_base
and locale
constants
#4125
StephanTLavavej
merged 4 commits into
microsoft:main
from
StephanTLavavej:dry-cleaning-9-danger-is-my-middle-name
Oct 26, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We need to retain _Locbase and comment it as TRANSITION, ABI because it affects sizeof(locale) due to MSVC's deficient EBCO. (On x64, sizeof(locale) is 16, but removing _Locbase would shrink it to 8.) However, there appears to be nothing stopping us from moving the constants into locale, as depicted in the Standard. I've verified that the DLL's exports are unaffected, and they don't mention _Locbase at all. (They also don't mention the names of these constants, excluding std::collate, std::ctype, and std::messages which are different.) I don't believe we need `_PGLOBAL` - it's rarely used in the STL, and never for new code. crtdefs.h defines it to be `__declspec(process)` for `_M_CEE` (i.e. `/clr` and `/clr:pure`). https://learn.microsoft.com/en-us/cpp/cpp/process?view=msvc-170 explains "When compiling with `/clr`, global and static variables are per-process by default and do not need to use `__declspec(process)`." so this doesn't affect `/clr` at all, which is what matters. (As for `/clr:pure`, it's vanishingly unlikely to matter - these are *constants*, so if multiple application domains start getting multiple copies, who cares?) `using category = int;` is mandated by the Standard. We previously said `int` for the constants, but the Standard depicts `category`, so I'm following that now that the typedef is in scope. Finally, I'm upgrading `const` to `constexpr` - this is not depicted in the Standard, but I believe it's more consistent with the `static constexpr` variables we use everywhere these days. Note that \[constexpr.functions\] forbids constexpr-strengthening functions, but it doesn't care about variables. Using `static constexpr` is what allows the major improvement of dropping the out-of-line definitions - see GH 3381 which made that change to ios_base's base class _Iosb.
Despite the TRANSITION, ABI comments, the DLL's exports don't mention any of `_Dummy_enum`, `_Dummy_enum_val`, `_Stdio`, `_Openmode`, `_Openmask`, `_Seekdir`, `_Seekbeg`, `_Seekcur`, `_Seekend`, `_Openprot`. `_Dummy_enum` was commented "don't ask" before I got here, and I never knew why. I remember that at some point I tried to mess with it and encountered trouble, which is when the "TRANSITION, ABI" comment was added, but I no longer remember what the problem was. I'm willing to try again, with our vastly increased knowledge of ABI concerns. The `_Seekdir` enumerators were being used exactly once; we can simply hardcode their values.
CaseyCarter
approved these changes
Oct 24, 2023
Co-authored-by: Casey Carter <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
CaseyCarter
approved these changes
Oct 24, 2023
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
I had to push a change to retain the enums in |
CaseyCarter
approved these changes
Oct 25, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Using
static constexpr
is what allows the major improvement of dropping out-of-line definitions - see #3381 which made that change toios_base
's base class_Iosb
.<xiosbase>
_Dummy_enum
,_Dummy_enum_val
,_Stdio
,_Openmode
,_Openmask
,_Seekdir
,_Seekbeg
,_Seekcur
,_Seekend
,_Openprot
._Iosb
with an improved comment._Stdio
entirely (it's not an enumerator).meowfield
constants (I verified that this doesn't change them)._Seekdir
enumerators were being used exactly once; we can simply hardcode their values.<xlocale>
Simplify
locale
's category constants.We need to retain
_Locbase
and comment it as TRANSITION, ABI because it affectssizeof(locale)
due to MSVC's deficient EBCO. (On x64,sizeof(locale)
is 16, but removing_Locbase
would shrink it to 8.)However, there appears to be nothing stopping us from moving the constants into
locale
, as depicted in the Standard. I've verified that the DLL's exports are unaffected, and they don't mention_Locbase
at all. (They also don't mention the names of these constants, excludingstd::collate
,std::ctype
, andstd::messages
which are different.)I don't believe we need
_PGLOBAL
- it's rarely used in the STL, and never for new code.crtdefs.h
defines it to be__declspec(process)
for_M_CEE
(i.e./clr
and/clr:pure
). https://learn.microsoft.com/en-us/cpp/cpp/process?view=msvc-170 explains "When compiling with/clr
, global and static variables are per-process by default and do not need to use__declspec(process)
." so this doesn't affect/clr
at all, which is what matters. (As for/clr:pure
, it's vanishingly unlikely to matter - these are constants, so if multiple application domains start getting multiple copies, who cares?)using category = int;
is mandated by the Standard. We previously saidint
for the constants, but the Standard depictscategory
, so I'm following that now that the typedef is in scope.Finally, I'm upgrading
const
toconstexpr
- this is not depicted in the Standard, but I believe it's more consistent with thestatic constexpr
variables we use everywhere these days. Note that [constexpr.functions] forbids constexpr-strengthening functions, but it doesn't care about variables.