Skip to content

Commit

Permalink
Annotate generated thrift structs with rust.Ord
Browse files Browse the repository at this point in the history
Summary: We're now generating `set<>` types in thrift. In rust, these are translated to sets which use ordering, so all predicates need to implement the `Ord` trait.

Reviewed By: donsbot

Differential Revision: D65270915

fbshipit-source-id: 6fda2c97a00ba7d0a6d803cca83f84a3a3a79f45
  • Loading branch information
Josef Svenningsson authored and facebook-github-bot committed Nov 4, 2024
1 parent c6e3dae commit d24cbf7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ THRIFT_GLEAN= \
glean/config/client/client_config.thrift \
thrift/annotation/cpp.thrift \
thrift/annotation/hack.thrift \
thrift/annotation/rust.thrift \
thrift/annotation/scope.thrift \
thrift/annotation/thrift.thrift

Expand Down
1 change: 1 addition & 0 deletions glean.cabal.in
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ library thrift-annotation
exposed-modules:
Cpp.Types
Hack.Types
Rust.Types
Scope.Types
Thrift.Types

Expand Down
12 changes: 9 additions & 3 deletions glean/schema/gen/Glean/Schema/Gen/Thrift.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ genTargets slashVn info =
, " thrift_srcs = { \"" <> namespace <> ".thrift\" : [] },"
, " deps = [" <> Text.intercalate ","
( "\"//glean/if:glean\"" : depTargets ) <>
", \"//thrift/annotation:rust\"" <>
", \"//thrift/annotation:thrift\"],"
, " hs2_deps = ["
, " \"//glean/hs:angle\","
Expand Down Expand Up @@ -225,7 +226,8 @@ genNamespace slashVn namespaces version
, "// \x40generated"
, "// @" <> "nolint"
, ""
, "include \"glean/if/glean.thrift\"" ] ++
, "include \"glean/if/glean.thrift\""
, "include \"thrift/annotation/rust.thrift\""] ++
[ "include \"" <> thriftDir slashVn <> "/" <> underscored dep
<> ".thrift\""
| dep <- deps ] ++
Expand Down Expand Up @@ -425,6 +427,7 @@ genPred here PredicateDef{..} = do
, "version=" <> showt (predicateRef_version predicateDefRef) <> ";"
]
, "}"
, "@rust.Ord"
]

-- Predicate types can be recursive so those need to be refs in C++.
Expand Down Expand Up @@ -504,10 +507,13 @@ genType here TypeDef{..} = addExtraDecls $ do
tyName <- withFieldHint nm (thriftTy here ty)
return $ makeField structOrUnion ix nm tyName
let
define | null fields = allowReservedIdentifierAnnotation name
define | null fields =
"@rust.Ord\n" <>
allowReservedIdentifierAnnotation name
<> "struct " <> name <> " {}"
| otherwise = myUnlines $ concat
[ [ allowReservedIdentifierAnnotation name
[ [ "@rust.Ord\n"
<> allowReservedIdentifierAnnotation name
<> structOrUnion <> " " <> name <> " {" ]
, indentLines (fieldTexts ++ extraFields)
, [ "}" ]
Expand Down

0 comments on commit d24cbf7

Please sign in to comment.