Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
97faa5fdfa4cd5d7a74cd9332cddd8a7c1e67b89 by Abseil Team <absl-team@google.com>:

Internal changes

PiperOrigin-RevId: 295164378

--
74990f100b3f4172c770ef8c76c05c8e99febdde by Xiaoyi Zhang <zhangxy@google.com>:

Release `absl::Cord`.

PiperOrigin-RevId: 295161959

--
6018c57f43c45c31dc1a61c0cd75fa2aa9be8dab by Gennadiy Rozental <rogeeff@google.com>:

Introduce independent notion of FlagStaticTypeID.

This change separates static flag value type identification from the type specific "vtable" with all the operations specific to value type. This change allows us to do the following:
* We can move most of "vtable" implementation from handle header, which will become public soon, into implementation details of Abseil Flag.
* We can combine back marshalling ops and general ops into a single vtable routine. They were split previously to facilitate type identification without requiring marshalling routines to be exposed in header.
* We do not need to store two vtable pointers. We can now store only one. The static type id can be deduced on request.

Overall we are saving 24 bytes per flag according to size_tester run.

PiperOrigin-RevId: 295149687

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

Update internal comments.

PiperOrigin-RevId: 295030681

--
825412b29fd6015027bbc3e5f802706eee0d2837 by Matthew Brown <matthewbr@google.com>:

Change str_format_internal::ConversionChar to an enum (from a struct-wrapped enum).

PiperOrigin-RevId: 294987462

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

Use more precise wording in the question on live-at-head

PiperOrigin-RevId: 294957679
GitOrigin-RevId: 97faa5fdfa4cd5d7a74cd9332cddd8a7c1e67b89
Change-Id: I081e70d148ffac7296d65e2a2f775f643eaf70bf
  • Loading branch information
Abseil Team authored and mbxx committed Feb 14, 2020
1 parent c44657f commit 3c81410
Show file tree
Hide file tree
Showing 27 changed files with 5,348 additions and 336 deletions.
32 changes: 26 additions & 6 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ instructions](https://github.com/abseil/abseil-cpp/blob/master/CMake/README.md)
for more information.

For a longer answer to this question and to understand why some other approaches
don't work, see the answer to "What is ABI and why don't you recommend using a
pre-compiled version of Abseil?"
don't work, see the answer to ["What is ABI and why don't you recommend using a
pre-compiled version of
Abseil?"](#what-is-abi-and-why-dont-you-recommend-using-a-pre-compiled-version-of-abseil)

## What is ABI and why don't you recommend using a pre-compiled version of Abseil?

Expand Down Expand Up @@ -117,7 +118,8 @@ to make it compatible. In practice, the need to use an automated tool is
extremely rare. This means that upgrading from one source release to another
should be a routine practice that can and should be performed often.

We recommend you update to the latest release of Abseil as often as
We recommend you update to the [latest commit in the `master` branch of
Abseil](https://github.com/abseil/abseil-cpp/commits/master) as often as
possible. Not only will you pick up bug fixes more quickly, but if you have good
automated testing, you will catch and be able to fix any [Hyrum's
Law](https://www.hyrumslaw.com/) dependency problems on an incremental basis
Expand All @@ -130,9 +132,27 @@ feature, updating the
[`http_archive`](https://docs.bazel.build/versions/master/repo/http.html#http_archive)
rule in your
[`WORKSPACE`](https://docs.bazel.build/versions/master/be/workspace.html) for
`com_google_abseil` to point to the latest release is all you need to do. You
can commit the updated `WORKSPACE` file to your source control every time you
update, and if you have good automated testing, you might even consider
`com_google_abseil` to point to the [latest commit in the `master` branch of
Abseil](https://github.com/abseil/abseil-cpp/commits/master) is all you need to
do. For example, on February 11, 2020, the latest commit to the master branch
was `98eb410c93ad059f9bba1bf43f5bb916fc92a5ea`. To update to this commit, you
would add the following snippet to your `WORKSPACE` file:

```
http_archive(
name = "com_google_absl",
urls = ["https://github.com/abseil/abseil-cpp/archive/98eb410c93ad059f9bba1bf43f5bb916fc92a5ea.zip"], # 2020-02-11T18:50:53Z
strip_prefix = "abseil-cpp-98eb410c93ad059f9bba1bf43f5bb916fc92a5ea",
sha256 = "aabf6c57e3834f8dc3873a927f37eaf69975d4b28117fc7427dfb1c661542a87",
)
```

To get the `sha256` of this URL, run `curl -sL --output -
https://github.com/abseil/abseil-cpp/archive/98eb410c93ad059f9bba1bf43f5bb916fc92a5ea.zip
| sha256sum -`.

You can commit the updated `WORKSPACE` file to your source control every time
you update, and if you have good automated testing, you might even consider
automating this.

One thing we don't recommend is using GitHub's `master.zip` files (for example
Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/symbolize.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ABSL_NAMESPACE_BEGIN
// // Now you can use the symbolizer
// }
void InitializeSymbolizer(const char* argv0);

//
// Symbolize()
//
// Symbolizes a program counter (instruction pointer value) `pc` and, on
Expand Down
7 changes: 1 addition & 6 deletions absl/flags/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ class Flag {
// constexpr initializable.
#if _MSC_VER <= 1900
constexpr Flag(const char* name, const char* filename,
const flags_internal::FlagMarshallingOpFn marshalling_op,
const flags_internal::HelpGenFunc help_gen,
const flags_internal::FlagDfltGenFunc default_value_gen)
: name_(name),
filename_(filename),
marshalling_op_(marshalling_op),
help_gen_(help_gen),
default_value_gen_(default_value_gen),
inited_(false),
Expand All @@ -121,7 +119,7 @@ class Flag {
}

impl_ =
new flags_internal::Flag<T>(name_, filename_, marshalling_op_,
new flags_internal::Flag<T>(name_, filename_,
{flags_internal::FlagHelpMsg(help_gen_),
flags_internal::FlagHelpKind::kGenFunc},
default_value_gen_);
Expand Down Expand Up @@ -161,7 +159,6 @@ class Flag {
// this to be an aggregate type.
const char* name_;
const char* filename_;
const flags_internal::FlagMarshallingOpFn marshalling_op_;
const flags_internal::HelpGenFunc help_gen_;
const flags_internal::FlagDfltGenFunc default_value_gen_;

Expand Down Expand Up @@ -335,7 +332,6 @@ ABSL_NAMESPACE_END
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help); \
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name{ \
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
&absl::flags_internal::FlagMarshallingOps<Type>, \
absl::flags_internal::HelpArg<AbslFlagHelpGenFor##name>(0), \
&AbslFlagsInitFlag##name}; \
extern bool FLAGS_no##name; \
Expand All @@ -349,7 +345,6 @@ ABSL_NAMESPACE_END
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help); \
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name{ \
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
&absl::flags_internal::FlagMarshallingOps<Type>, \
&AbslFlagHelpGenFor##name::NonConst, &AbslFlagsInitFlag##name}; \
extern bool FLAGS_no##name; \
bool FLAGS_no##name = ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
Expand Down
5 changes: 2 additions & 3 deletions absl/flags/flag_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ template <typename T>
bool TestConstructionFor() {
constexpr flags::FlagHelpArg help_arg{flags::FlagHelpMsg("literal help"),
flags::FlagHelpKind::kLiteral};
constexpr flags::Flag<T> f1("f1", "file", &flags::FlagMarshallingOps<T>,
help_arg, &TestMakeDflt<T>);
constexpr flags::Flag<T> f1("f1", "file", help_arg, &TestMakeDflt<T>);
EXPECT_EQ(f1.Name(), "f1");
EXPECT_EQ(f1.Help(), "literal help");
EXPECT_EQ(f1.Filename(), "file");

ABSL_CONST_INIT static flags::Flag<T> f2(
"f2", "file", &flags::FlagMarshallingOps<T>,
"f2", "file",
{flags::FlagHelpMsg(&TestHelpMsg), flags::FlagHelpKind::kGenFunc},
&TestMakeDflt<T>);
flags::FlagRegistrar<T, false>(&f2).OnUpdate(TestCallback);
Expand Down
124 changes: 17 additions & 107 deletions absl/flags/internal/commandlineflag.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace flags_internal {

// Type-specific operations, eg., parsing, copying, etc. are provided
// by function specific to that type with a signature matching FlagOpFn.
enum FlagOp {
kDelete,
kClone,
kCopy,
kCopyConstruct,
kSizeof,
kParse,
kUnparse,
// An alias for flag static type id. Values of type identify the flag value type
// simialarly to typeid(T), but without relying on RTTI being available. In most
// cases this id is enough to uniquely identify the flag's value type. In a few
// cases we'll have to resort to using actual RTTI implementation if it is
// available.
using FlagStaticTypeId = void* (*)();

// Address of this function template is used in current implementation as a flag
// static type id.
template <typename T>
void* FlagStaticTypeIdGen() {
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
kRuntimeTypeId
return const_cast<std::type_info*>(&typeid(T));
#else
return nullptr;
#endif
};
using FlagOpFn = void* (*)(FlagOp, const void*, void*);
using FlagMarshallingOpFn = void* (*)(FlagOp, const void*, void*, void*);
}

// Options that control SetCommandLineOptionWithMode.
enum FlagSettingMode {
Expand All @@ -72,97 +73,6 @@ enum ValueSource {
kProgrammaticChange,
};

// The per-type function
template <typename T>
void* FlagOps(FlagOp op, const void* v1, void* v2) {
switch (op) {
case kDelete:
delete static_cast<const T*>(v1);
return nullptr;
case kClone:
return new T(*static_cast<const T*>(v1));
case kCopy:
*static_cast<T*>(v2) = *static_cast<const T*>(v1);
return nullptr;
case kCopyConstruct:
new (v2) T(*static_cast<const T*>(v1));
return nullptr;
case kSizeof:
return reinterpret_cast<void*>(sizeof(T));
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
case kRuntimeTypeId:
return const_cast<std::type_info*>(&typeid(T));
break;
#endif
default:
return nullptr;
}
}

template <typename T>
void* FlagMarshallingOps(FlagOp op, const void* v1, void* v2, void* v3) {
switch (op) {
case kParse: {
// initialize the temporary instance of type T based on current value in
// destination (which is going to be flag's default value).
T temp(*static_cast<T*>(v2));
if (!absl::ParseFlag<T>(*static_cast<const absl::string_view*>(v1), &temp,
static_cast<std::string*>(v3))) {
return nullptr;
}
*static_cast<T*>(v2) = std::move(temp);
return v2;
}
case kUnparse:
*static_cast<std::string*>(v2) =
absl::UnparseFlag<T>(*static_cast<const T*>(v1));
return nullptr;
default:
return nullptr;
}
}

// Functions that invoke flag-type-specific operations.
inline void Delete(FlagOpFn op, const void* obj) {
op(flags_internal::kDelete, obj, nullptr);
}

inline void* Clone(FlagOpFn op, const void* obj) {
return op(flags_internal::kClone, obj, nullptr);
}

inline void Copy(FlagOpFn op, const void* src, void* dst) {
op(flags_internal::kCopy, src, dst);
}

inline void CopyConstruct(FlagOpFn op, const void* src, void* dst) {
op(flags_internal::kCopyConstruct, src, dst);
}

inline bool Parse(FlagMarshallingOpFn op, absl::string_view text, void* dst,
std::string* error) {
return op(flags_internal::kParse, &text, dst, error) != nullptr;
}

inline std::string Unparse(FlagMarshallingOpFn op, const void* val) {
std::string result;
op(flags_internal::kUnparse, val, &result, nullptr);
return result;
}

inline size_t Sizeof(FlagOpFn op) {
// This sequence of casts reverses the sequence from base::internal::FlagOps()
return static_cast<size_t>(reinterpret_cast<intptr_t>(
op(flags_internal::kSizeof, nullptr, nullptr)));
}

#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
inline const std::type_info& RuntimeTypeId(FlagOpFn op) {
return *static_cast<const std::type_info*>(
op(flags_internal::kRuntimeTypeId, nullptr, nullptr));
}
#endif

// Handle to FlagState objects. Specific flag state objects will restore state
// of a flag produced this flag state from method CommandLineFlag::SaveState().
class FlagStateInterface {
Expand All @@ -187,7 +97,7 @@ class CommandLineFlag {
// Return true iff flag has type T.
template <typename T>
inline bool IsOfType() const {
return TypeId() == &flags_internal::FlagOps<T>;
return TypeId() == &flags_internal::FlagStaticTypeIdGen<T>;
}

// Attempts to retrieve the flag value. Returns value on success,
Expand Down Expand Up @@ -240,7 +150,7 @@ class CommandLineFlag {
// Returns true iff this is a handle to an Abseil Flag.
virtual bool IsAbseilFlag() const { return true; }
// Returns id of the flag's value type.
virtual flags_internal::FlagOpFn TypeId() const = 0;
virtual FlagStaticTypeId TypeId() const = 0;
virtual bool IsModified() const = 0;
virtual bool IsSpecifiedOnCommandLine() const = 0;
virtual std::string DefaultValue() const = 0;
Expand Down

0 comments on commit 3c81410

Please sign in to comment.