Skip to content

Commit

Permalink
Enable MinimizePadding for exception
Browse files Browse the repository at this point in the history
Summary: Add exception scope to MinimizePadding annotation.

Reviewed By: createdbysk

Differential Revision: D68016602

fbshipit-source-id: 788fd9a17f8c9bfc24e3897b5f101d5f0576286f
  • Loading branch information
yoney authored and facebook-github-bot committed Jan 10, 2025
1 parent f16fdb5 commit e4f68f0
Show file tree
Hide file tree
Showing 20 changed files with 319 additions and 234 deletions.
1 change: 1 addition & 0 deletions thrift/annotation/cpp.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ struct PackIsset {
which gives the size of 16 bytes compared to 32 bytes if `cpp.MinimizePadding` was not specified.
*/
@scope.Struct
@scope.Exception
struct MinimizePadding {}

@scope.Union
Expand Down
14 changes: 14 additions & 0 deletions thrift/compiler/codemod/structure_annotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def test_cpp(self):
} (cpp.minimize_padding)
struct M {}
exception E {
1: string m;
2: i32 c;
} (message="m", cpp.minimize_padding)
exception EE {}
enum E8 {} (cpp.enum_type="char")
enum E16 {} (cpp.enum_type="int16_t")
enum E32 {} (cpp.enum_type="int")
Expand Down Expand Up @@ -200,6 +206,14 @@ def test_cpp(self):
}
struct M {}
@cpp.MinimizePadding
exception E {
@thrift.ExceptionMessage
1: string m;
2: i32 c;
}
exception EE {}
@cpp.EnumType{type = cpp.EnumUnderlyingType.I8}
enum E8 {}
@cpp.EnumType{type = cpp.EnumUnderlyingType.I16}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,10 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
shape(
)
),
'\facebook\thrift\annotation\Exception' => \facebook\thrift\annotation\Exception::fromShape(
shape(
)
),
],
'fields' => dict[
],
Expand Down
86 changes: 43 additions & 43 deletions thrift/compiler/test/fixtures/adapter/out/json/gen-json/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
},
"EnumUnderlyingType" : {
"lineno" : 274,
"lineno" : 275,
"constants" : {
"I8" : 0,
"U8" : 1,
Expand All @@ -39,11 +39,11 @@
},
"source_range" : {
"begin" : {
"line" : 274,
"line" : 275,
"column" : 1
},
"end" : {
"line" : 285,
"line" : 286,
"column" : 2
}
}
Expand Down Expand Up @@ -350,31 +350,31 @@
"column" : 1
},
"end" : {
"line" : 220,
"line" : 221,
"column" : 26
}
}
},
"ScopedEnumAsUnionType" : {
"lineno" : 222,
"lineno" : 223,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 222,
"line" : 223,
"column" : 1
},
"end" : {
"line" : 223,
"line" : 224,
"column" : 32
}
}
},
"FieldInterceptor" : {
"lineno" : 239,
"lineno" : 240,
"is_exception" : false,
"is_union" : false,
"fields" : {
Expand All @@ -384,11 +384,11 @@
"required" : true,
"source_range" : {
"begin" : {
"line" : 256,
"line" : 257,
"column" : 3
},
"end" : {
"line" : 256,
"line" : 257,
"column" : 18
}
}
Expand All @@ -399,47 +399,47 @@
"required" : true,
"source_range" : {
"begin" : {
"line" : 262,
"line" : 263,
"column" : 3
},
"end" : {
"line" : 262,
"line" : 263,
"column" : 20
}
}
}
},
"source_range" : {
"begin" : {
"line" : 239,
"line" : 240,
"column" : 1
},
"end" : {
"line" : 263,
"line" : 264,
"column" : 2
}
}
},
"UseOpEncode" : {
"lineno" : 265,
"lineno" : 266,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 265,
"line" : 266,
"column" : 1
},
"end" : {
"line" : 267,
"line" : 268,
"column" : 22
}
}
},
"EnumType" : {
"lineno" : 304,
"lineno" : 305,
"is_exception" : false,
"is_union" : false,
"fields" : {
Expand All @@ -449,149 +449,149 @@
"required" : true,
"source_range" : {
"begin" : {
"line" : 306,
"line" : 307,
"column" : 3
},
"end" : {
"line" : 306,
"line" : 307,
"column" : 30
}
}
}
},
"source_range" : {
"begin" : {
"line" : 304,
"line" : 305,
"column" : 1
},
"end" : {
"line" : 307,
"line" : 308,
"column" : 2
}
}
},
"Frozen2Exclude" : {
"lineno" : 312,
"lineno" : 313,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 312,
"line" : 313,
"column" : 1
},
"end" : {
"line" : 313,
"line" : 314,
"column" : 25
}
}
},
"Frozen2RequiresCompleteContainerParams" : {
"lineno" : 319,
"lineno" : 320,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 319,
"line" : 320,
"column" : 1
},
"end" : {
"line" : 320,
"line" : 321,
"column" : 49
}
}
},
"ProcessInEbThreadUnsafe" : {
"lineno" : 333,
"lineno" : 334,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 333,
"line" : 334,
"column" : 1
},
"end" : {
"line" : 335,
"line" : 336,
"column" : 34
}
}
},
"RuntimeAnnotation" : {
"lineno" : 340,
"lineno" : 341,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 340,
"line" : 341,
"column" : 1
},
"end" : {
"line" : 341,
"line" : 342,
"column" : 28
}
}
},
"UseCursorSerialization" : {
"lineno" : 349,
"lineno" : 350,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 349,
"line" : 350,
"column" : 1
},
"end" : {
"line" : 354,
"line" : 355,
"column" : 33
}
}
},
"GenerateDeprecatedHeaderClientMethods" : {
"lineno" : 373,
"lineno" : 374,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 373,
"line" : 374,
"column" : 1
},
"end" : {
"line" : 375,
"line" : 376,
"column" : 48
}
}
},
"AllowLegacyNonOptionalRef" : {
"lineno" : 390,
"lineno" : 391,
"is_exception" : false,
"is_union" : false,
"fields" : {

},
"source_range" : {
"begin" : {
"line" : 390,
"line" : 391,
"column" : 1
},
"end" : {
"line" : 391,
"line" : 392,
"column" : 36
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,10 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
shape(
)
),
'\facebook\thrift\annotation\Exception' => \facebook\thrift\annotation\Exception::fromShape(
shape(
)
),
],
'fields' => dict[
],
Expand Down
Loading

0 comments on commit e4f68f0

Please sign in to comment.