Skip to content

Commit 9abb0b5

Browse files
derekmaurocopybara-github
authored andcommitted
Add ABSL_REFACTOR_INLINE to separate the inliner directive from the
deprecated directive so that we can give users a custom deprecation message. PiperOrigin-RevId: 830908658 Change-Id: I07fec685b025ea507ef7dd16f117d4c29e80a2c1
1 parent c70fe97 commit 9abb0b5

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

absl/base/macros.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,65 @@ ABSL_NAMESPACE_END
169169
#define ABSL_INTERNAL_RETHROW do {} while (false)
170170
#endif // ABSL_HAVE_EXCEPTIONS
171171

172-
// ABSL_DEPRECATE_AND_INLINE()
172+
// ABSL_REFACTOR_INLINE
173+
//
174+
// Marks a function or type for automated refactoring by go/cpp-inliner. It can
175+
// be used on inline function definitions or type aliases in header files and
176+
// should be combined with the `[[deprecated]]` attribute.
173177
//
174-
// Marks a function or type alias as deprecated and tags it to be picked up for
175-
// automated refactoring by go/cpp-inliner. It can added to inline function
176-
// definitions or type aliases. It should only be used within a header file. It
177-
// differs from `ABSL_DEPRECATED` in the following ways:
178+
// Using `ABSL_REFACTOR_INLINE` differs from using the `[[deprecated]]` alone in
179+
// the following ways:
178180
//
179181
// 1. New uses of the function or type will be discouraged via Tricorder
180182
// warnings.
181183
// 2. If enabled via `METADATA`, automated changes will be sent out inlining the
182184
// functions's body or replacing the type where it is used.
183185
//
184-
// For example:
186+
// Examples:
185187
//
186-
// ABSL_DEPRECATE_AND_INLINE() inline int OldFunc(int x) {
188+
// [[deprecated("Use NewFunc() instead")]] ABSL_REFACTOR_INLINE
189+
// inline int OldFunc(int x) {
187190
// return NewFunc(x, 0);
188191
// }
189192
//
190-
// will mark `OldFunc` as deprecated, and the go/cpp-inliner service will
191-
// replace calls to `OldFunc(x)` with calls to `NewFunc(x, 0)`. Once all calls
192-
// to `OldFunc` have been replaced, `OldFunc` can be deleted.
193+
// using OldType [[deprecated("Use NewType instead")]] ABSL_REFACTOR_INLINE =
194+
// NewType;
195+
//
196+
// will mark `OldFunc` and `OldType` as deprecated, and the go/cpp-inliner
197+
// service will replace calls to `OldFunc(x)` with calls to `NewFunc(x, 0)` and
198+
// `OldType` with `NewType`. Once all replacements have been completed, the old
199+
// function or type can be deleted.
193200
//
194201
// See go/cpp-inliner for more information.
195202
//
196203
// Note: go/cpp-inliner is Google-internal service for automated refactoring.
197204
// While open-source users do not have access to this service, the macro is
198-
// provided for compatibility, and so that users receive deprecation warnings.
199-
#if ABSL_HAVE_CPP_ATTRIBUTE(deprecated) && \
200-
ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
201-
#define ABSL_DEPRECATE_AND_INLINE() [[deprecated, clang::annotate("inline-me")]]
202-
#elif ABSL_HAVE_CPP_ATTRIBUTE(deprecated)
203-
#define ABSL_DEPRECATE_AND_INLINE() [[deprecated]]
205+
// provided for compatibility.
206+
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
207+
#define ABSL_REFACTOR_INLINE [[clang::annotate("inline-me")]]
204208
#else
205-
#define ABSL_DEPRECATE_AND_INLINE()
209+
#define ABSL_REFACTOR_INLINE
206210
#endif
207211

212+
// ABSL_DEPRECATE_AND_INLINE()
213+
//
214+
// This is the original macro used by go/cpp-inliner that combines
215+
// [[deprecated]] and ABSL_REFACTOR_INLINE.
216+
//
217+
// Examples:
218+
//
219+
// ABSL_DEPRECATE_AND_INLINE() inline int OldFunc(int x) {
220+
// return NewFunc(x, 0);
221+
// }
222+
//
223+
// using OldType ABSL_DEPRECATE_AND_INLINE() = NewType;
224+
//
225+
// The combination of `[[deprecated("Use X instead")]]` and
226+
// `ABSL_REFACTOR_INLINE` is preferred because it provides a more informative
227+
// deprecation message to developers, especially those that do not have access
228+
// to the automated refactoring capabilities of go/cpp-inliner.
229+
#define ABSL_DEPRECATE_AND_INLINE() [[deprecated]] ABSL_REFACTOR_INLINE
230+
208231
// Requires the compiler to prove that the size of the given object is at least
209232
// the expected amount.
210233
#if ABSL_HAVE_ATTRIBUTE(diagnose_if) && ABSL_HAVE_BUILTIN(__builtin_object_size)

0 commit comments

Comments
 (0)