@@ -257,3 +257,54 @@ struct AllowReservedFilename {}
257257 */
258258@scope.Struct
259259struct RuntimeAnnotation {}
260+
261+ /**
262+ * Allows the Thrift compiler to add a URI to the target typedef.
263+ *
264+ * Use of this annotation is strongly DISCOURAGED, and is provided for
265+ * backwards-compatibility purposes only.
266+ *
267+ * Indeed, Thrift IDL [typedefs](https://github.com/facebook/fbthrift/blob/main/thrift/doc/idl/index.md#typedefs)
268+ * do not correspond to the set of user-defined types that can have unique URIs
269+ * per the [Thrift Object Model](https://github.com/facebook/fbthrift/blob/main/thrift/doc/object-model/index.md#thrift-uri)
270+ * While it may seem like typedefs correspond to
271+ * [Opaque Alias Types](https://github.com/facebook/fbthrift/blob/main/thrift/doc/object-model/index.md#opaque-alias-types),
272+ * that is actually incorrect, as the "aliased" type that a typedef introduces
273+ * is considered identical - at the Object Model level - to the original type.
274+ *
275+ * This annotation is introduced to allow "grandfathering in" existing typedef
276+ * URIs in preparation for the thrift compiler to reject such cases in the
277+ * future (unless this annotation is specified).
278+ *
279+ * This annoation MUST NOT be applied to a typedef for which no URI is
280+ * specified (either explicitly via @thrift.Uri, or implicitly through a
281+ * non-empty
282+ * [package declaration](https://github.com/facebook/fbthrift/blob/main/thrift/doc/idl/index.md#package-declaration)).
283+ */
284+ @scope.Typedef
285+ struct AllowLegacyTypedefUri {}
286+
287+ /**
288+ * Allows the target field of a structured user-defined type (i.e., struct,
289+ * union or exception), whose qualifier is `optional`, to have a custom default
290+ * value specified in IDL.
291+ *
292+ * Use of this annotation is strongly DISCOURAGED, as custom default values for
293+ * optional fields are both non-sensical and dangerous:
294+ * - non-sensical because, by definition, the "default" state of an optional
295+ * field is to have no value (i.e., be "absent") - as explicitly specified
296+ * in the [Thrift Object Model](https://github.com/facebook/fbthrift/blob/main/thrift/doc/object-model/index.md#structured-types).
297+ * - dangerous because in practice, the runtime behavior of the generated code
298+ * for optional fields with custom default values is inconsistent (sometimes
299+ * even for the same programming language!).
300+ *
301+ * This annotation is merely introduced to allow existing use cases to be
302+ * grandfathered into the new compiler validation logic, which will reject
303+ * optional fields with custom default values unless this annotation is
304+ * specified.
305+ *
306+ * This annotation MUST NOT be applied to a field whose qualifier is not
307+ * optional, or that doesn't have a custom default value.
308+ */
309+ @scope.Field
310+ struct AllowUnsafeOptionalCustomDefaultValue {}
0 commit comments