Skip to content

Commit 5ffe328

Browse files
TJ Yinfacebook-github-bot
TJ Yin
authored andcommitted
Add @cpp.AllowLegacyDeprecatedTerseWritesRef to allow using cpp.Ref with deprecated_terse_writes cpp2 option
Summary: We will ban such usages without this annotation. Reviewed By: thedavekwon Differential Revision: D68802575 fbshipit-source-id: 16a60085e3951f0f3ce64e46040d210b9ef93cc9
1 parent 732ff61 commit 5ffe328

File tree

93 files changed

+4271
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4271
-14
lines changed

thrift/annotation/cpp.thrift

+10
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,13 @@ struct AllowLegacyNonOptionalRef {}
403403
*/
404404
@scope.Field
405405
struct DeprecatedTerseWrite {}
406+
407+
/**
408+
* Allows the field to be annotated @cpp.Ref (or cpp[2].ref[_type]) even if it
409+
* is deprecated_terse_writes field.
410+
*
411+
* This annotation is provided for a limited time, to exempt pre-existing fields
412+
* while rolling out a stricter enforcement of the condition above.
413+
*/
414+
@scope.Field
415+
struct AllowLegacyDeprecatedTerseWritesRef {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Autogenerated by Thrift
3+
*
4+
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5+
* @generated
6+
*/
7+
package com.facebook.thrift.annotation.cpp_deprecated;
8+
9+
import java.util.List;
10+
import java.util.ArrayList;
11+
import java.util.Map;
12+
import java.util.HashMap;
13+
import java.util.Set;
14+
import java.util.HashSet;
15+
import java.util.Collections;
16+
import java.util.BitSet;
17+
import java.util.Arrays;
18+
import com.facebook.thrift.*;
19+
import com.facebook.thrift.annotations.*;
20+
import com.facebook.thrift.async.*;
21+
import com.facebook.thrift.meta_data.*;
22+
import com.facebook.thrift.server.*;
23+
import com.facebook.thrift.transport.*;
24+
import com.facebook.thrift.protocol.*;
25+
26+
/**
27+
* Allows the field to be annotated @cpp.Ref (or cpp[2].ref[_type]) even if it
28+
* is deprecated_terse_writes field.
29+
*
30+
* This annotation is provided for a limited time, to exempt pre-existing fields
31+
* while rolling out a stricter enforcement of the condition above.
32+
*/
33+
@SuppressWarnings({ "unused", "serial" })
34+
public class AllowLegacyDeprecatedTerseWritesRef implements TBase, java.io.Serializable, Cloneable {
35+
private static final TStruct STRUCT_DESC = new TStruct("AllowLegacyDeprecatedTerseWritesRef");
36+
37+
38+
public AllowLegacyDeprecatedTerseWritesRef() {
39+
}
40+
41+
/**
42+
* Performs a deep copy on <i>other</i>.
43+
*/
44+
public AllowLegacyDeprecatedTerseWritesRef(AllowLegacyDeprecatedTerseWritesRef other) {
45+
}
46+
47+
public AllowLegacyDeprecatedTerseWritesRef deepCopy() {
48+
return new AllowLegacyDeprecatedTerseWritesRef(this);
49+
}
50+
51+
@Override
52+
public boolean equals(Object _that) {
53+
if (_that == null)
54+
return false;
55+
if (this == _that)
56+
return true;
57+
if (!(_that instanceof AllowLegacyDeprecatedTerseWritesRef))
58+
return false;
59+
AllowLegacyDeprecatedTerseWritesRef that = (AllowLegacyDeprecatedTerseWritesRef)_that;
60+
61+
return true;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Arrays.deepHashCode(new Object[] {});
67+
}
68+
69+
// This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
70+
public void read(TProtocol iprot) throws TException {
71+
throw new TException("unimplemented in android immutable structure");
72+
}
73+
74+
public static AllowLegacyDeprecatedTerseWritesRef deserialize(TProtocol iprot) throws TException {
75+
TField __field;
76+
iprot.readStructBegin();
77+
while (true)
78+
{
79+
__field = iprot.readFieldBegin();
80+
if (__field.type == TType.STOP) {
81+
break;
82+
}
83+
switch (__field.id)
84+
{
85+
default:
86+
TProtocolUtil.skip(iprot, __field.type);
87+
break;
88+
}
89+
iprot.readFieldEnd();
90+
}
91+
iprot.readStructEnd();
92+
93+
AllowLegacyDeprecatedTerseWritesRef _that;
94+
_that = new AllowLegacyDeprecatedTerseWritesRef(
95+
);
96+
_that.validate();
97+
return _that;
98+
}
99+
100+
public void write(TProtocol oprot) throws TException {
101+
validate();
102+
103+
oprot.writeStructBegin(STRUCT_DESC);
104+
oprot.writeFieldStop();
105+
oprot.writeStructEnd();
106+
}
107+
108+
@Override
109+
public String toString() {
110+
return toString(1, true);
111+
}
112+
113+
@Override
114+
public String toString(int indent, boolean prettyPrint) {
115+
return TBaseHelper.toStringHelper(this, indent, prettyPrint);
116+
}
117+
118+
public void validate() throws TException {
119+
// check for required fields
120+
}
121+
122+
}
123+

thrift/compiler/test/fixtures/adapter/out/go/gen-go/thrift/annotation/cpp/codec.go

+27
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ var (
269269
NewFunc: func() thrift.Struct { return NewDeprecatedTerseWrite() },
270270
},
271271

272+
}
273+
}()
274+
premadeCodecTypeSpec_cpp_AllowLegacyDeprecatedTerseWritesRef = func() *thrift.TypeSpec {
275+
return &thrift.TypeSpec{
276+
FullName: "cpp.AllowLegacyDeprecatedTerseWritesRef",
277+
CodecStructSpec: &thrift.CodecStructSpec{
278+
ScopedName: "cpp.AllowLegacyDeprecatedTerseWritesRef",
279+
IsUnion: false,
280+
NewFunc: func() thrift.Struct { return NewAllowLegacyDeprecatedTerseWritesRef() },
281+
},
282+
272283
}
273284
}()
274285
)
@@ -693,6 +704,20 @@ var (
693704
},
694705
FieldSpecNameToIndex: map[string]int{
695706
},
707+
}
708+
}()
709+
premadeStructSpec_AllowLegacyDeprecatedTerseWritesRef = func() *thrift.StructSpec {
710+
return &thrift.StructSpec{
711+
Name: "AllowLegacyDeprecatedTerseWritesRef",
712+
ScopedName: "cpp.AllowLegacyDeprecatedTerseWritesRef",
713+
IsUnion: false,
714+
IsException: false,
715+
FieldSpecs: []thrift.FieldSpec{
716+
},
717+
FieldSpecIDToIndex: map[int16]int{
718+
},
719+
FieldSpecNameToIndex: map[string]int{
720+
},
696721
}
697722
}()
698723
)
@@ -720,6 +745,7 @@ var premadeStructSpecs = func() []*thrift.StructSpec {
720745
fbthriftResults = append(fbthriftResults, premadeStructSpec_GenerateDeprecatedHeaderClientMethods)
721746
fbthriftResults = append(fbthriftResults, premadeStructSpec_AllowLegacyNonOptionalRef)
722747
fbthriftResults = append(fbthriftResults, premadeStructSpec_DeprecatedTerseWrite)
748+
fbthriftResults = append(fbthriftResults, premadeStructSpec_AllowLegacyDeprecatedTerseWritesRef)
723749
return fbthriftResults
724750
}()
725751

@@ -749,6 +775,7 @@ var premadeCodecSpecsMap = func() map[string]*thrift.TypeSpec {
749775
fbthriftTypeSpecsMap[premadeCodecTypeSpec_cpp_GenerateDeprecatedHeaderClientMethods.FullName] = premadeCodecTypeSpec_cpp_GenerateDeprecatedHeaderClientMethods
750776
fbthriftTypeSpecsMap[premadeCodecTypeSpec_cpp_AllowLegacyNonOptionalRef.FullName] = premadeCodecTypeSpec_cpp_AllowLegacyNonOptionalRef
751777
fbthriftTypeSpecsMap[premadeCodecTypeSpec_cpp_DeprecatedTerseWrite.FullName] = premadeCodecTypeSpec_cpp_DeprecatedTerseWrite
778+
fbthriftTypeSpecsMap[premadeCodecTypeSpec_cpp_AllowLegacyDeprecatedTerseWritesRef.FullName] = premadeCodecTypeSpec_cpp_AllowLegacyDeprecatedTerseWritesRef
752779
return fbthriftTypeSpecsMap
753780
}()
754781

thrift/compiler/test/fixtures/adapter/out/go/gen-go/thrift/annotation/cpp/metadata.go

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ var (
161161
SetName("cpp.DeprecatedTerseWrite"),
162162
)
163163
}()
164+
premadeThriftType_cpp_AllowLegacyDeprecatedTerseWritesRef = func() *metadata.ThriftType {
165+
return metadata.NewThriftType().SetTStruct(
166+
metadata.NewThriftStructType().
167+
SetName("cpp.AllowLegacyDeprecatedTerseWritesRef"),
168+
)
169+
}()
164170
)
165171

166172
// Helper type to allow us to store Thrift types in a slice at compile time,
@@ -197,6 +203,7 @@ var premadeThriftTypesMap = func() map[string]*metadata.ThriftType {
197203
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "cpp.GenerateDeprecatedHeaderClientMethods", premadeThriftType_cpp_GenerateDeprecatedHeaderClientMethods })
198204
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "cpp.AllowLegacyNonOptionalRef", premadeThriftType_cpp_AllowLegacyNonOptionalRef })
199205
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "cpp.DeprecatedTerseWrite", premadeThriftType_cpp_DeprecatedTerseWrite })
206+
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "cpp.AllowLegacyDeprecatedTerseWritesRef", premadeThriftType_cpp_AllowLegacyDeprecatedTerseWritesRef })
200207

201208
fbthriftThriftTypesMap := make(map[string]*metadata.ThriftType, len(thriftTypesWithFullName))
202209
for _, value := range thriftTypesWithFullName {

thrift/compiler/test/fixtures/adapter/out/go/gen-go/thrift/annotation/cpp/types.go

+73
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,78 @@ func (x *DeprecatedTerseWrite) setDefaults() *DeprecatedTerseWrite {
22092209
return x
22102210
}
22112211

2212+
type AllowLegacyDeprecatedTerseWritesRef struct {
2213+
}
2214+
// Compile time interface enforcer
2215+
var _ thrift.Struct = (*AllowLegacyDeprecatedTerseWritesRef)(nil)
2216+
2217+
func NewAllowLegacyDeprecatedTerseWritesRef() *AllowLegacyDeprecatedTerseWritesRef {
2218+
return (&AllowLegacyDeprecatedTerseWritesRef{}).setDefaults()
2219+
}
2220+
2221+
2222+
2223+
func (x *AllowLegacyDeprecatedTerseWritesRef) Write(p thrift.Encoder) error {
2224+
if err := p.WriteStructBegin("AllowLegacyDeprecatedTerseWritesRef"); err != nil {
2225+
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
2226+
}
2227+
2228+
2229+
if err := p.WriteFieldStop(); err != nil {
2230+
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
2231+
}
2232+
2233+
if err := p.WriteStructEnd(); err != nil {
2234+
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
2235+
}
2236+
return nil
2237+
}
2238+
2239+
func (x *AllowLegacyDeprecatedTerseWritesRef) Read(p thrift.Decoder) error {
2240+
if _, err := p.ReadStructBegin(); err != nil {
2241+
return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
2242+
}
2243+
2244+
for {
2245+
fieldName, wireType, id, err := p.ReadFieldBegin()
2246+
if err != nil {
2247+
return thrift.PrependError(fmt.Sprintf("%T field %d ('%s') read error: ", x, id, fieldName), err)
2248+
}
2249+
2250+
if wireType == thrift.STOP {
2251+
break;
2252+
}
2253+
2254+
var fieldReadErr error
2255+
switch {
2256+
default:
2257+
fieldReadErr = p.Skip(wireType)
2258+
}
2259+
2260+
if fieldReadErr != nil {
2261+
return fieldReadErr
2262+
}
2263+
2264+
if err := p.ReadFieldEnd(); err != nil {
2265+
return err
2266+
}
2267+
}
2268+
2269+
if err := p.ReadStructEnd(); err != nil {
2270+
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
2271+
}
2272+
2273+
return nil
2274+
}
2275+
2276+
func (x *AllowLegacyDeprecatedTerseWritesRef) String() string {
2277+
return thrift.StructToString(reflect.ValueOf(x))
2278+
}
2279+
2280+
func (x *AllowLegacyDeprecatedTerseWritesRef) setDefaults() *AllowLegacyDeprecatedTerseWritesRef {
2281+
return x
2282+
}
2283+
22122284

22132285

22142286
// RegisterTypes registers types found in this file that have a thrift_uri with the passed in registry.
@@ -2235,6 +2307,7 @@ func RegisterTypes(registry interface {
22352307
registry.RegisterType("facebook.com/thrift/annotation/cpp/GenerateDeprecatedHeaderClientMethods", func() any { return NewGenerateDeprecatedHeaderClientMethods() })
22362308
registry.RegisterType("facebook.com/thrift/annotation/cpp/AllowLegacyNonOptionalRef", func() any { return NewAllowLegacyNonOptionalRef() })
22372309
registry.RegisterType("facebook.com/thrift/annotation/cpp/DeprecatedTerseWrite", func() any { return NewDeprecatedTerseWrite() })
2310+
registry.RegisterType("facebook.com/thrift/annotation/cpp/AllowLegacyDeprecatedTerseWritesRef", func() any { return NewAllowLegacyDeprecatedTerseWritesRef() })
22382311

22392312
registry.RegisterType("facebook.com/thrift/annotation/cpp/RefType", func() any { return RefType(0) })
22402313
registry.RegisterType("facebook.com/thrift/annotation/cpp/EnumUnderlyingType", func() any { return EnumUnderlyingType(0) })

thrift/compiler/test/fixtures/adapter/out/hack/gen-hack/cpp_types.php

+88
Original file line numberDiff line numberDiff line change
@@ -2485,3 +2485,91 @@ public function readFromJson(string $jsonText): void {
24852485

24862486
}
24872487

2488+
/**
2489+
* Allows the field to be annotated @cpp.Ref (or cpp[2].ref[_type]) even if it
2490+
* is deprecated_terse_writes field.
2491+
*
2492+
* This annotation is provided for a limited time, to exempt pre-existing fields
2493+
* while rolling out a stricter enforcement of the condition above.
2494+
*
2495+
* Original thrift struct:-
2496+
* AllowLegacyDeprecatedTerseWritesRef
2497+
*/
2498+
<<\ThriftTypeInfo(shape('uri' => 'facebook.com/thrift/annotation/cpp/AllowLegacyDeprecatedTerseWritesRef'))>>
2499+
class AllowLegacyDeprecatedTerseWritesRef implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftShapishSyncStruct {
2500+
use \ThriftSerializationTrait;
2501+
2502+
const \ThriftStructTypes::TSpec SPEC = dict[
2503+
];
2504+
const dict<string, int> FIELDMAP = dict[
2505+
];
2506+
2507+
const type TConstructorShape = shape(
2508+
);
2509+
2510+
const type TShape = shape(
2511+
);
2512+
const int STRUCTURAL_ID = 957977401221134810;
2513+
2514+
public function __construct()[] {
2515+
}
2516+
2517+
public static function withDefaultValues()[]: this {
2518+
return new static();
2519+
}
2520+
2521+
public static function fromShape(self::TConstructorShape $shape)[]: this {
2522+
return new static(
2523+
);
2524+
}
2525+
2526+
public function getName()[]: string {
2527+
return 'AllowLegacyDeprecatedTerseWritesRef';
2528+
}
2529+
2530+
public static function getStructMetadata()[]: \tmeta_ThriftStruct {
2531+
return \tmeta_ThriftStruct::fromShape(
2532+
shape(
2533+
"name" => "cpp.AllowLegacyDeprecatedTerseWritesRef",
2534+
"is_union" => false,
2535+
)
2536+
);
2537+
}
2538+
2539+
public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
2540+
return shape(
2541+
'struct' => dict[
2542+
'\facebook\thrift\annotation\Field' => \facebook\thrift\annotation\Field::fromShape(
2543+
shape(
2544+
)
2545+
),
2546+
],
2547+
'fields' => dict[
2548+
],
2549+
);
2550+
}
2551+
2552+
public static function __fromShape(self::TShape $shape)[]: this {
2553+
return new static(
2554+
);
2555+
}
2556+
2557+
public function __toShape()[]: self::TShape {
2558+
return shape(
2559+
);
2560+
}
2561+
public function getInstanceKey()[write_props]: string {
2562+
return \TCompactSerializer::serialize($this);
2563+
}
2564+
2565+
public function readFromJson(string $jsonText): void {
2566+
$parsed = json_decode($jsonText, true);
2567+
2568+
if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
2569+
throw new \TProtocolException("Cannot parse the given json string.");
2570+
}
2571+
2572+
}
2573+
2574+
}
2575+

0 commit comments

Comments
 (0)