Skip to content
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

Replaced aligned/algin compiler attributes with C++ 11 alignas #842

Closed
wants to merge 1 commit into from

Conversation

kohei306
Copy link
Contributor

No description provided.

@google-cla google-cla bot added the cla: yes label Nov 12, 2020
@derekmauro
Copy link
Member

Thank you for the pull request. It would be nice if we could accept this, but the problem we have is that this file is included in some Google-internal files that are compiled in C, not C++. Maybe one day this can be cleaned-up.

@kohei306
Copy link
Contributor Author

kohei306 commented Nov 13, 2020

Thank you for the pull request. It would be nice if we could accept this, but the problem we have is that this file is included in some Google-internal files that are compiled in C, not C++. Maybe one day this can be cleaned-up.

I see. Thanks for reviewing anyway.
Then does it make sense to change the comment to reflect the situation, maybe adding what you wrote "this file is included in some Google-internal files that are compiled in C, not C++. Maybe one day this can be cleaned-up."

@mbxx
Copy link
Member

mbxx commented Nov 13, 2020

Yes, at a minimum this needs to be documented. I don't have a sense of how big the cleanup would be, though, so it might be possible to just do it. I'll check out what needs to be done and get back to you next week.

@mbxx mbxx self-assigned this Nov 13, 2020
@mbxx
Copy link
Member

mbxx commented Dec 16, 2020

My apologies for the slow response, this looks like a bigger cleanup than I'd suspected.

The files that are compiled as both C and C++ turn out not to be a problem, or at least not something I see as a problem through the other problems I've run into.

The first is the attribute is accepted in more positions than the alignas specifier. That means there's a lot of mechanical cleanup needed pushing ABSL_CACHELINE_ALIGNEDs around to avoid widespread build breakages.

The second is alignas just can't be applied to everything that ABSL_CACHELINE_ALIGNED is currently applied to. There's an example in TCMalloc: https://github.com/google/tcmalloc/blob/c06632feb8dedbd7cf41666b50c8a98f92837904/tcmalloc/tcmalloc.cc#L1914 Here it's being applied to a function's return value. It's not obvious what the best way to fix that would be. Offhand, I suspect the attribute will still be needed.

I'll start a conversation in the team to see what we'd like to do.

@kohei306
Copy link
Contributor Author

Hi @mbxx, Thanks for taking a deep look into it. I was not aware of the difference in the accepted position between them.
It sounds like the clean up takes some efforts as you pointed out and I cannot tell if it is worthwhile the effort. Maybe if the usages of ABSL_CACHELINE_ALIGNED for things that cannot be replaced with alignas are minor cases and they can be swapped for the majority of the cases, it is a shame that the clean up is blocked due to the minor cases.
Of course even then, the clean up steps should be done in a way no to break the minor cases. Anyway, thanks for taking it to team discussion.

@mbxx
Copy link
Member

mbxx commented Dec 21, 2020

I'm not actually scared of the internal cleanup: it's a few hundred files to fix, which won't actually take me that long, and making Abseil more portable is a good thing. The documentation in the header file also explicitly warns about the placement of the attribute explicitly, so I believe this change is okay for open source users. I think this PR is the right direction to go in.

I seem to have been wrong about what the TCMalloc usage I mentioned before (https://github.com/google/tcmalloc/blob/c06632feb8dedbd7cf41666b50c8a98f92837904/tcmalloc/tcmalloc.cc#L1914) was really doing: it seems to be an attribute on the function (https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes). We still need to figure out what to do in cases like that, and I'm afraid folks have started to take time off for the holidays. I'll keep pushing on this and post an update in January. Thanks for your patience :)

@kohei306
Copy link
Contributor Author

Hi @mbxx,
Yes, I agree that it will make Abseil more portable by adhering to standard. Thanks for sharing the link. It looks very informative.
Sure, I can totally understand that it is better to wait till people come back from holidays :-) Thanks again for looking into that!

@mbxx
Copy link
Member

mbxx commented Mar 9, 2021

My apologies for letting this go so long. We chatted about this and came to the conclusion that the implementation is going to be difficult to change and a better route for callers to migrate from ABSL_CACHELINE_ALIGNED to the equivalent C++17 idioms when they're able to do so. We haven't quite decided what to do about ABSL_CACHELINE_ALIGNED itself in the long term (maybe it continues to exist in its current form or maybe it becomes deprecated), but there's no pressing need to come to a decision (Abseil supports C++11 so we'll need ABSL_CACHELINE_ALIGNED for the foreseeable future).

Sound reasonable to you?

If so, the next step is for me to update the comment to reflect this plan.

@kohei306 kohei306 closed this Mar 10, 2021
@kohei306 kohei306 reopened this Mar 10, 2021
@kohei306
Copy link
Contributor Author

Hi @mbxx ,
(sorry, I closed the PR by mistake.) No problem. Yes, I agree that we reflect the outcome of our discussion/your investigation to the comment so that it does not go wasted and then keep the existing code as it is. Thanks for your investigation and explanation, it definitely helped to understand the context for external contributors :-)

absl-federation-github pushed a commit that referenced this pull request Mar 18, 2021
--
8e75347c10d85112296811be6ef35761744ad9bc by Derek Mauro <dmauro@google.com>:

Big update to LTS release process
  * Add create_lts.py script to to the LTS modification
    This is simpler than copybara since very few changes are needed
  * Use the default installation paths instead of a versioned path.
    If a versioned path is needed, this is easy to change on the commandline.
  * Make the integration test use the LTS transformed version
  * Test both static and dynamic linking (fixes pkg-config dynamic linking)

PiperOrigin-RevId: 363566934

--
e00e971a2de3138861f5e1900201c9cc7788f714 by Laramie Leavitt <lar@google.com>:

Add a non-compile test to absl::BitGenRef for temporaries.

PiperOrigin-RevId: 363437284

--
3685644ec115d99789de32aceb76c32a00756fea by Derek Mauro <dmauro@google.com>:

Make OSS code consistent with internal code by using the forward
declaration of absl::Status that contains ABSL_MUST_USE_RESULT.

PiperOrigin-RevId: 363426906

--
b85fec142c3aa3f632fa985f9f8f73a253819723 by Evan Brown <ezb@google.com>:

Move raw_hash_set::infoz_ into raw_hash_set::settings_. This reduces the size of raw_hash_sets by alignof(size_t) bytes when hashtablez is disabled.

PiperOrigin-RevId: 363034264

--
c6fde3b17e5845191eb8b2bfc1760c8bfb9573ff by Mark Barolak <mbar@google.com>:

Internal change

PiperOrigin-RevId: 362990378

--
81713cf964905b43d1cbe32ce5fed97539029625 by Abseil Team <absl-team@google.com>:

Fix typo in comment (execeptions -> exceptions).

PiperOrigin-RevId: 362946191

--
3ee92ca470feca44da417b03ee45a915c6eb5155 by Abseil Team <absl-team@google.com>:

Add absl::FindAndReportLeaks and routes it to the corresponding
__lsan_do_recoverable_leak_check.

PiperOrigin-RevId: 362622199

--
b95b7194b20e02c20d72289fbc79a0d35b82e256 by Abseil Team <absl-team@google.com>:

Add `kWithEverything` to StatusToStringMode

PiperOrigin-RevId: 362595218

--
0a960d96a0014eab7e1c55b479269450ed8e98d7 by Abseil Team <absl-team@google.com>:

Accept e.g. ".__uniq" as a valid clone name.  Further, bring the implementation
on par with libiberty's demangler grammar.

Clang introduced option -funique-internal-linkage-names that adds the suffix
".__uniq.[0-9]+" to internal linkage functions to give them a globally unique
identifier.  The suffix was designed to work with existing demanglers which do
recognize a "_" along with the alphanumeric string. This change enhances the
demangler to allow "_" with the alphanumeric string.

Please refer to libiberty's cp-demangle.c where function d_clone_suffix
implements the demangling of clone suffixes :

1.  '_' is accepted as a valid character with the alphanumeric sequence.
2.  The alphanumberic sequence is optional.
3.  The digit sequence is optional.

PiperOrigin-RevId: 362557420

--
2ac5ea212c150afd2f58025a5cab8c45d16949c6 by Abseil Team <absl-team@google.com>:

Change variable name 'slots' to 'slot_count' to avoid name-clash with Qt builds.

PiperOrigin-RevId: 362556289

--
934f0f409c9c548716a46363d6e243406fad4028 by Mark Barolak <mbar@google.com>:

Clarify the comment on ABSL_CACHELINE_SIZE to indicate that the macro definition itself shouldn't change, but rather that call sites should change when possible.

This addresses the request for improved documentation in #842.

PiperOrigin-RevId: 362354288
GitOrigin-RevId: 8e75347c10d85112296811be6ef35761744ad9bc
Change-Id: I33ec8561d8d645c3353e9d2dd447501d0e1825a7
@mbxx
Copy link
Member

mbxx commented Mar 24, 2021

Cool, I've update the comment here:

// NOTE: callers should replace uses of this macro with `alignas()` using
// `std::hardware_constructive_interference_size` and/or
// `std::hardware_destructive_interference_size` when C++17 becomes available to
// them.

I hope this helps. If not, please let me know how I could tweak it to make it a little more clear.

@mbxx mbxx closed this Mar 24, 2021
razmser pushed a commit to razmser/abseil-cpp that referenced this pull request Sep 12, 2023
--
8e75347c10d85112296811be6ef35761744ad9bc by Derek Mauro <dmauro@google.com>:

Big update to LTS release process
  * Add create_lts.py script to to the LTS modification
    This is simpler than copybara since very few changes are needed
  * Use the default installation paths instead of a versioned path.
    If a versioned path is needed, this is easy to change on the commandline.
  * Make the integration test use the LTS transformed version
  * Test both static and dynamic linking (fixes pkg-config dynamic linking)

PiperOrigin-RevId: 363566934

--
e00e971a2de3138861f5e1900201c9cc7788f714 by Laramie Leavitt <lar@google.com>:

Add a non-compile test to absl::BitGenRef for temporaries.

PiperOrigin-RevId: 363437284

--
3685644ec115d99789de32aceb76c32a00756fea by Derek Mauro <dmauro@google.com>:

Make OSS code consistent with internal code by using the forward
declaration of absl::Status that contains ABSL_MUST_USE_RESULT.

PiperOrigin-RevId: 363426906

--
b85fec142c3aa3f632fa985f9f8f73a253819723 by Evan Brown <ezb@google.com>:

Move raw_hash_set::infoz_ into raw_hash_set::settings_. This reduces the size of raw_hash_sets by alignof(size_t) bytes when hashtablez is disabled.

PiperOrigin-RevId: 363034264

--
c6fde3b17e5845191eb8b2bfc1760c8bfb9573ff by Mark Barolak <mbar@google.com>:

Internal change

PiperOrigin-RevId: 362990378

--
81713cf964905b43d1cbe32ce5fed97539029625 by Abseil Team <absl-team@google.com>:

Fix typo in comment (execeptions -> exceptions).

PiperOrigin-RevId: 362946191

--
3ee92ca470feca44da417b03ee45a915c6eb5155 by Abseil Team <absl-team@google.com>:

Add absl::FindAndReportLeaks and routes it to the corresponding
__lsan_do_recoverable_leak_check.

PiperOrigin-RevId: 362622199

--
b95b7194b20e02c20d72289fbc79a0d35b82e256 by Abseil Team <absl-team@google.com>:

Add `kWithEverything` to StatusToStringMode

PiperOrigin-RevId: 362595218

--
0a960d96a0014eab7e1c55b479269450ed8e98d7 by Abseil Team <absl-team@google.com>:

Accept e.g. ".__uniq" as a valid clone name.  Further, bring the implementation
on par with libiberty's demangler grammar.

Clang introduced option -funique-internal-linkage-names that adds the suffix
".__uniq.[0-9]+" to internal linkage functions to give them a globally unique
identifier.  The suffix was designed to work with existing demanglers which do
recognize a "_" along with the alphanumeric string. This change enhances the
demangler to allow "_" with the alphanumeric string.

Please refer to libiberty's cp-demangle.c where function d_clone_suffix
implements the demangling of clone suffixes :

1.  '_' is accepted as a valid character with the alphanumeric sequence.
2.  The alphanumberic sequence is optional.
3.  The digit sequence is optional.

PiperOrigin-RevId: 362557420

--
2ac5ea212c150afd2f58025a5cab8c45d16949c6 by Abseil Team <absl-team@google.com>:

Change variable name 'slots' to 'slot_count' to avoid name-clash with Qt builds.

PiperOrigin-RevId: 362556289

--
934f0f409c9c548716a46363d6e243406fad4028 by Mark Barolak <mbar@google.com>:

Clarify the comment on ABSL_CACHELINE_SIZE to indicate that the macro definition itself shouldn't change, but rather that call sites should change when possible.

This addresses the request for improved documentation in abseil#842.

PiperOrigin-RevId: 362354288
GitOrigin-RevId: 8e75347c10d85112296811be6ef35761744ad9bc
Change-Id: I33ec8561d8d645c3353e9d2dd447501d0e1825a7
razmser pushed a commit to razmser/abseil-cpp that referenced this pull request Sep 12, 2023
--
8e75347c10d85112296811be6ef35761744ad9bc by Derek Mauro <dmauro@google.com>:

Big update to LTS release process
  * Add create_lts.py script to to the LTS modification
    This is simpler than copybara since very few changes are needed
  * Use the default installation paths instead of a versioned path.
    If a versioned path is needed, this is easy to change on the commandline.
  * Make the integration test use the LTS transformed version
  * Test both static and dynamic linking (fixes pkg-config dynamic linking)

PiperOrigin-RevId: 363566934

--
e00e971a2de3138861f5e1900201c9cc7788f714 by Laramie Leavitt <lar@google.com>:

Add a non-compile test to absl::BitGenRef for temporaries.

PiperOrigin-RevId: 363437284

--
3685644ec115d99789de32aceb76c32a00756fea by Derek Mauro <dmauro@google.com>:

Make OSS code consistent with internal code by using the forward
declaration of absl::Status that contains ABSL_MUST_USE_RESULT.

PiperOrigin-RevId: 363426906

--
b85fec142c3aa3f632fa985f9f8f73a253819723 by Evan Brown <ezb@google.com>:

Move raw_hash_set::infoz_ into raw_hash_set::settings_. This reduces the size of raw_hash_sets by alignof(size_t) bytes when hashtablez is disabled.

PiperOrigin-RevId: 363034264

--
c6fde3b17e5845191eb8b2bfc1760c8bfb9573ff by Mark Barolak <mbar@google.com>:

Internal change

PiperOrigin-RevId: 362990378

--
81713cf964905b43d1cbe32ce5fed97539029625 by Abseil Team <absl-team@google.com>:

Fix typo in comment (execeptions -> exceptions).

PiperOrigin-RevId: 362946191

--
3ee92ca470feca44da417b03ee45a915c6eb5155 by Abseil Team <absl-team@google.com>:

Add absl::FindAndReportLeaks and routes it to the corresponding
__lsan_do_recoverable_leak_check.

PiperOrigin-RevId: 362622199

--
b95b7194b20e02c20d72289fbc79a0d35b82e256 by Abseil Team <absl-team@google.com>:

Add `kWithEverything` to StatusToStringMode

PiperOrigin-RevId: 362595218

--
0a960d96a0014eab7e1c55b479269450ed8e98d7 by Abseil Team <absl-team@google.com>:

Accept e.g. ".__uniq" as a valid clone name.  Further, bring the implementation
on par with libiberty's demangler grammar.

Clang introduced option -funique-internal-linkage-names that adds the suffix
".__uniq.[0-9]+" to internal linkage functions to give them a globally unique
identifier.  The suffix was designed to work with existing demanglers which do
recognize a "_" along with the alphanumeric string. This change enhances the
demangler to allow "_" with the alphanumeric string.

Please refer to libiberty's cp-demangle.c where function d_clone_suffix
implements the demangling of clone suffixes :

1.  '_' is accepted as a valid character with the alphanumeric sequence.
2.  The alphanumberic sequence is optional.
3.  The digit sequence is optional.

PiperOrigin-RevId: 362557420

--
2ac5ea212c150afd2f58025a5cab8c45d16949c6 by Abseil Team <absl-team@google.com>:

Change variable name 'slots' to 'slot_count' to avoid name-clash with Qt builds.

PiperOrigin-RevId: 362556289

--
934f0f409c9c548716a46363d6e243406fad4028 by Mark Barolak <mbar@google.com>:

Clarify the comment on ABSL_CACHELINE_SIZE to indicate that the macro definition itself shouldn't change, but rather that call sites should change when possible.

This addresses the request for improved documentation in abseil#842.

PiperOrigin-RevId: 362354288
GitOrigin-RevId: 8e75347c10d85112296811be6ef35761744ad9bc
Change-Id: I33ec8561d8d645c3353e9d2dd447501d0e1825a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants