Skip to content

Commit 3c81410

Browse files
Abseil Teammbxx
authored andcommitted
Export of internal Abseil changes
-- 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
1 parent c44657f commit 3c81410

27 files changed

Lines changed: 5348 additions & 336 deletions

FAQ.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ instructions](https://github.com/abseil/abseil-cpp/blob/master/CMake/README.md)
3333
for more information.
3434

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

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

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

120-
We recommend you update to the latest release of Abseil as often as
121+
We recommend you update to the [latest commit in the `master` branch of
122+
Abseil](https://github.com/abseil/abseil-cpp/commits/master) as often as
121123
possible. Not only will you pick up bug fixes more quickly, but if you have good
122124
automated testing, you will catch and be able to fix any [Hyrum's
123125
Law](https://www.hyrumslaw.com/) dependency problems on an incremental basis
@@ -130,9 +132,27 @@ feature, updating the
130132
[`http_archive`](https://docs.bazel.build/versions/master/repo/http.html#http_archive)
131133
rule in your
132134
[`WORKSPACE`](https://docs.bazel.build/versions/master/be/workspace.html) for
133-
`com_google_abseil` to point to the latest release is all you need to do. You
134-
can commit the updated `WORKSPACE` file to your source control every time you
135-
update, and if you have good automated testing, you might even consider
135+
`com_google_abseil` to point to the [latest commit in the `master` branch of
136+
Abseil](https://github.com/abseil/abseil-cpp/commits/master) is all you need to
137+
do. For example, on February 11, 2020, the latest commit to the master branch
138+
was `98eb410c93ad059f9bba1bf43f5bb916fc92a5ea`. To update to this commit, you
139+
would add the following snippet to your `WORKSPACE` file:
140+
141+
```
142+
http_archive(
143+
name = "com_google_absl",
144+
urls = ["https://github.com/abseil/abseil-cpp/archive/98eb410c93ad059f9bba1bf43f5bb916fc92a5ea.zip"], # 2020-02-11T18:50:53Z
145+
strip_prefix = "abseil-cpp-98eb410c93ad059f9bba1bf43f5bb916fc92a5ea",
146+
sha256 = "aabf6c57e3834f8dc3873a927f37eaf69975d4b28117fc7427dfb1c661542a87",
147+
)
148+
```
149+
150+
To get the `sha256` of this URL, run `curl -sL --output -
151+
https://github.com/abseil/abseil-cpp/archive/98eb410c93ad059f9bba1bf43f5bb916fc92a5ea.zip
152+
| sha256sum -`.
153+
154+
You can commit the updated `WORKSPACE` file to your source control every time
155+
you update, and if you have good automated testing, you might even consider
136156
automating this.
137157

138158
One thing we don't recommend is using GitHub's `master.zip` files (for example

absl/debugging/symbolize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ABSL_NAMESPACE_BEGIN
7171
// // Now you can use the symbolizer
7272
// }
7373
void InitializeSymbolizer(const char* argv0);
74-
74+
//
7575
// Symbolize()
7676
//
7777
// Symbolizes a program counter (instruction pointer value) `pc` and, on

absl/flags/flag.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,10 @@ class Flag {
100100
// constexpr initializable.
101101
#if _MSC_VER <= 1900
102102
constexpr Flag(const char* name, const char* filename,
103-
const flags_internal::FlagMarshallingOpFn marshalling_op,
104103
const flags_internal::HelpGenFunc help_gen,
105104
const flags_internal::FlagDfltGenFunc default_value_gen)
106105
: name_(name),
107106
filename_(filename),
108-
marshalling_op_(marshalling_op),
109107
help_gen_(help_gen),
110108
default_value_gen_(default_value_gen),
111109
inited_(false),
@@ -121,7 +119,7 @@ class Flag {
121119
}
122120

123121
impl_ =
124-
new flags_internal::Flag<T>(name_, filename_, marshalling_op_,
122+
new flags_internal::Flag<T>(name_, filename_,
125123
{flags_internal::FlagHelpMsg(help_gen_),
126124
flags_internal::FlagHelpKind::kGenFunc},
127125
default_value_gen_);
@@ -161,7 +159,6 @@ class Flag {
161159
// this to be an aggregate type.
162160
const char* name_;
163161
const char* filename_;
164-
const flags_internal::FlagMarshallingOpFn marshalling_op_;
165162
const flags_internal::HelpGenFunc help_gen_;
166163
const flags_internal::FlagDfltGenFunc default_value_gen_;
167164

@@ -335,7 +332,6 @@ ABSL_NAMESPACE_END
335332
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help); \
336333
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name{ \
337334
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
338-
&absl::flags_internal::FlagMarshallingOps<Type>, \
339335
absl::flags_internal::HelpArg<AbslFlagHelpGenFor##name>(0), \
340336
&AbslFlagsInitFlag##name}; \
341337
extern bool FLAGS_no##name; \
@@ -349,7 +345,6 @@ ABSL_NAMESPACE_END
349345
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help); \
350346
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name{ \
351347
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
352-
&absl::flags_internal::FlagMarshallingOps<Type>, \
353348
&AbslFlagHelpGenFor##name::NonConst, &AbslFlagsInitFlag##name}; \
354349
extern bool FLAGS_no##name; \
355350
bool FLAGS_no##name = ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)

absl/flags/flag_test.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ template <typename T>
5353
bool TestConstructionFor() {
5454
constexpr flags::FlagHelpArg help_arg{flags::FlagHelpMsg("literal help"),
5555
flags::FlagHelpKind::kLiteral};
56-
constexpr flags::Flag<T> f1("f1", "file", &flags::FlagMarshallingOps<T>,
57-
help_arg, &TestMakeDflt<T>);
56+
constexpr flags::Flag<T> f1("f1", "file", help_arg, &TestMakeDflt<T>);
5857
EXPECT_EQ(f1.Name(), "f1");
5958
EXPECT_EQ(f1.Help(), "literal help");
6059
EXPECT_EQ(f1.Filename(), "file");
6160

6261
ABSL_CONST_INIT static flags::Flag<T> f2(
63-
"f2", "file", &flags::FlagMarshallingOps<T>,
62+
"f2", "file",
6463
{flags::FlagHelpMsg(&TestHelpMsg), flags::FlagHelpKind::kGenFunc},
6564
&TestMakeDflt<T>);
6665
flags::FlagRegistrar<T, false>(&f2).OnUpdate(TestCallback);

absl/flags/internal/commandlineflag.h

Lines changed: 17 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,23 @@ namespace absl {
3434
ABSL_NAMESPACE_BEGIN
3535
namespace flags_internal {
3636

37-
// Type-specific operations, eg., parsing, copying, etc. are provided
38-
// by function specific to that type with a signature matching FlagOpFn.
39-
enum FlagOp {
40-
kDelete,
41-
kClone,
42-
kCopy,
43-
kCopyConstruct,
44-
kSizeof,
45-
kParse,
46-
kUnparse,
37+
// An alias for flag static type id. Values of type identify the flag value type
38+
// simialarly to typeid(T), but without relying on RTTI being available. In most
39+
// cases this id is enough to uniquely identify the flag's value type. In a few
40+
// cases we'll have to resort to using actual RTTI implementation if it is
41+
// available.
42+
using FlagStaticTypeId = void* (*)();
43+
44+
// Address of this function template is used in current implementation as a flag
45+
// static type id.
46+
template <typename T>
47+
void* FlagStaticTypeIdGen() {
4748
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
48-
kRuntimeTypeId
49+
return const_cast<std::type_info*>(&typeid(T));
50+
#else
51+
return nullptr;
4952
#endif
50-
};
51-
using FlagOpFn = void* (*)(FlagOp, const void*, void*);
52-
using FlagMarshallingOpFn = void* (*)(FlagOp, const void*, void*, void*);
53+
}
5354

5455
// Options that control SetCommandLineOptionWithMode.
5556
enum FlagSettingMode {
@@ -72,97 +73,6 @@ enum ValueSource {
7273
kProgrammaticChange,
7374
};
7475

75-
// The per-type function
76-
template <typename T>
77-
void* FlagOps(FlagOp op, const void* v1, void* v2) {
78-
switch (op) {
79-
case kDelete:
80-
delete static_cast<const T*>(v1);
81-
return nullptr;
82-
case kClone:
83-
return new T(*static_cast<const T*>(v1));
84-
case kCopy:
85-
*static_cast<T*>(v2) = *static_cast<const T*>(v1);
86-
return nullptr;
87-
case kCopyConstruct:
88-
new (v2) T(*static_cast<const T*>(v1));
89-
return nullptr;
90-
case kSizeof:
91-
return reinterpret_cast<void*>(sizeof(T));
92-
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
93-
case kRuntimeTypeId:
94-
return const_cast<std::type_info*>(&typeid(T));
95-
break;
96-
#endif
97-
default:
98-
return nullptr;
99-
}
100-
}
101-
102-
template <typename T>
103-
void* FlagMarshallingOps(FlagOp op, const void* v1, void* v2, void* v3) {
104-
switch (op) {
105-
case kParse: {
106-
// initialize the temporary instance of type T based on current value in
107-
// destination (which is going to be flag's default value).
108-
T temp(*static_cast<T*>(v2));
109-
if (!absl::ParseFlag<T>(*static_cast<const absl::string_view*>(v1), &temp,
110-
static_cast<std::string*>(v3))) {
111-
return nullptr;
112-
}
113-
*static_cast<T*>(v2) = std::move(temp);
114-
return v2;
115-
}
116-
case kUnparse:
117-
*static_cast<std::string*>(v2) =
118-
absl::UnparseFlag<T>(*static_cast<const T*>(v1));
119-
return nullptr;
120-
default:
121-
return nullptr;
122-
}
123-
}
124-
125-
// Functions that invoke flag-type-specific operations.
126-
inline void Delete(FlagOpFn op, const void* obj) {
127-
op(flags_internal::kDelete, obj, nullptr);
128-
}
129-
130-
inline void* Clone(FlagOpFn op, const void* obj) {
131-
return op(flags_internal::kClone, obj, nullptr);
132-
}
133-
134-
inline void Copy(FlagOpFn op, const void* src, void* dst) {
135-
op(flags_internal::kCopy, src, dst);
136-
}
137-
138-
inline void CopyConstruct(FlagOpFn op, const void* src, void* dst) {
139-
op(flags_internal::kCopyConstruct, src, dst);
140-
}
141-
142-
inline bool Parse(FlagMarshallingOpFn op, absl::string_view text, void* dst,
143-
std::string* error) {
144-
return op(flags_internal::kParse, &text, dst, error) != nullptr;
145-
}
146-
147-
inline std::string Unparse(FlagMarshallingOpFn op, const void* val) {
148-
std::string result;
149-
op(flags_internal::kUnparse, val, &result, nullptr);
150-
return result;
151-
}
152-
153-
inline size_t Sizeof(FlagOpFn op) {
154-
// This sequence of casts reverses the sequence from base::internal::FlagOps()
155-
return static_cast<size_t>(reinterpret_cast<intptr_t>(
156-
op(flags_internal::kSizeof, nullptr, nullptr)));
157-
}
158-
159-
#if defined(ABSL_FLAGS_INTERNAL_HAS_RTTI)
160-
inline const std::type_info& RuntimeTypeId(FlagOpFn op) {
161-
return *static_cast<const std::type_info*>(
162-
op(flags_internal::kRuntimeTypeId, nullptr, nullptr));
163-
}
164-
#endif
165-
16676
// Handle to FlagState objects. Specific flag state objects will restore state
16777
// of a flag produced this flag state from method CommandLineFlag::SaveState().
16878
class FlagStateInterface {
@@ -187,7 +97,7 @@ class CommandLineFlag {
18797
// Return true iff flag has type T.
18898
template <typename T>
18999
inline bool IsOfType() const {
190-
return TypeId() == &flags_internal::FlagOps<T>;
100+
return TypeId() == &flags_internal::FlagStaticTypeIdGen<T>;
191101
}
192102

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

0 commit comments

Comments
 (0)