Hello everyone, after recent threads around importing a few absl types in //base to avoid reinventing the wheel, seems we were only lacking a concrete proposal, so here it is.Intent to Add //base dependency on absl for unavailable-but-approved STL types
Status: In Review
Authors: g...@chromium.org
Reviewers: c...@chromium.org
Last Updated: 2019-03-08
PUBLIC
Use third_party/abseil-cpp/absl/types to avoid reinventing the wheel for types already accepted in the STL versions of C++ Chromium doesn’t yet support (e.g. C++17 types like std::optional, std::variant, etc.).
Ban all absl:: usage outside of src/base/ via presubmit errors (enforced by CQ unless NOPRESUBMIT=True). Expose allowed absl:: types in base:: through using declarations in base headers.
jdoerrie@ has already attempted to do this for base/optional.h and base/thread_annotations.h (CL). A few custom modifications are required on abseil-cpp, i.e.:
alexclarke@ proposed doing this for base/variant.h (cxx email thread); no decision taken but general feeling that if we did this we should do it for all relevant types, not just one-off for base::variant (hence this doc)
LON interpreted the above email thread as a no-go on importing absl and alexclarke@ implemented base::variant from scratch in 8 CLs totalling >5000LOCs (inc. tests):
gab@ still thinks strongly that reinventing the wheel is the wrong thing and spurred a side-discussion on slack to coalesce thoughts : seems that besides a few minor concerns needing a doc (this), nothing is really blocking importing absl
It’s unfortunate that alexclarke@ ended up writing all this code but if anything it reinforces the need to import absl as reinventing 5000LOCs (and reviewing + maintaining it) doesn’t seem like the right move.
Enforce that only** //base can use absl:: via presubmits errors.
** webrtc/ is the only other exception per already being a user (and we can drop unfortunate conversion utils like ToBaseOptional)
Only expose absl types which are STL types documented on cppreference.com but merely not available to us yet in our supported C++ version (e.g. C++17 constructs). This will be made explicit in third_party/abseil-cpp/README.chromium.
Users of, e.g., base::optional would include base/optional.h and rely on it forwarding the absl type via:
namespace base {
using optional = absl::optional;
}
Concerns mentioned on the various threads.
Code size: allegedly absl::variant results in more generated code[a]. Is it that substantial? Can we fix it upstream?
We need to make sure absl has the same level of security guarantees as Chromium as far out-of-bound/invalid-memory-access CHECKs go. It looks like they do, but base unittests will be added to verify and maintain.
This seems like much less work than reviewing/iterating-on and then maintaining 5000LOCs of base::variant code (and it gets more beneficial every new desired STL type we import this way).
Immediate compliance with the STL when Chromium begins supporting new versions of C++.
[a]+alexc...@chromium.org to document this further
_Assigned to Alex Clarke_
This is a courtesy copy of an email for your record only. It's not the same email your collaborators received. Click here to learn more.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAJTZ7L%2BqytPKVyFOL23fFfvEUvpG12gtOxLa7h29TrhB_k_ATQ%40mail.gmail.com.
I left a few comments on the document. The high level comment is that the document doesn't really say what problem it's attempting to solve, or even what exactly it's proposing.