Skip to content

Commit bbcb005

Browse files
David Tolnayfacebook-github-bot
David Tolnay
authored andcommitted
Switch to Rust structured annotations in Glean schema
Reviewed By: diliop Differential Revision: D71247871 fbshipit-source-id: b8dea72dbd0dc376431617887292c8eb72e21faa
1 parent bfeff88 commit bbcb005

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

glean/schema/gen/Glean/Schema/Gen/Thrift.hs

+17-13
Original file line numberDiff line numberDiff line change
@@ -336,38 +336,42 @@ thriftTy here t = case t of
336336
HasKey{} -> error "thriftTy: HasKey"
337337
ElementsOf{} -> error "thriftTy: ElementsOf"
338338

339-
mkField :: [Text] -> Text -> Int -> Name -> Text -> Text
340-
mkField annots structOrUnion i p t =
341-
allowReservedIdentifierAnnotation p
342-
<> showt i <> ": " <> t <> " " <> p <> annotText <> ";"
339+
mkField :: [Text] -> [Text] -> Text -> Int -> Name -> Text -> Text
340+
mkField structuredAnnots unstructuredAnnots structOrUnion i p t =
341+
structuredAnnotText <> allowReservedIdentifierAnnotation p
342+
<> showt i <> ": " <> t <> " " <> p <> unstructuredAnnotText <> ";"
343343
where
344+
structuredAnnotText =
345+
Text.concat $ map (\annot -> annot <> newline <> " ") structuredAnnots
346+
344347
-- The java.swift codegen likes to strip underscores from the end of
345348
-- names for some reason.
346-
javaAnnot
349+
javaUnstructuredAnnot
347350
| "_" `Text.isSuffixOf` p = ["java.swift.name = \"" <> p <> "\""]
348351
| otherwise = []
349352

350-
py3Annot
353+
py3UnstructuredAnnot
351354
| p == "from" = ["py3.name = \"from_\""]
352355
| p == "type" && structOrUnion == "union" = ["py3.name = \"type_\""]
353356
| p == "name" && structOrUnion == "union" = ["py3.name = \"name_\""]
354357
| p == "value" && structOrUnion == "union" = ["py3.name = \"value_\""]
355358
| otherwise = []
356359

357-
allAnnots = javaAnnot ++ py3Annot ++ annots
360+
allUnstructuredAnnots =
361+
javaUnstructuredAnnot ++ py3UnstructuredAnnot ++ unstructuredAnnots
358362

359-
annotText
360-
| null allAnnots = ""
361-
| otherwise = " (" <> Text.intercalate ", " allAnnots <> ")"
363+
unstructuredAnnotText
364+
| null allUnstructuredAnnots = ""
365+
| otherwise = " (" <> Text.intercalate ", " allUnstructuredAnnots <> ")"
362366

363367
makeField :: Text -> Int -> Name -> Text -> Text
364-
makeField = mkField []
368+
makeField = mkField [] []
365369

366370
makeRefField :: Text -> Int -> Name -> Text -> Text
367371
makeRefField = mkField
372+
[ "@rust.Box" ]
368373
[ "cpp.ref = \"true\""
369374
, "cpp2.ref = \"true\""
370-
, "rust.box"
371375
, "swift.recursive_reference = \"true\""
372376
]
373377

@@ -442,7 +446,7 @@ genPred here PredicateDef{..} = do
442446
, [ allowReservedIdentifierAnnotation name
443447
<> structOrUnion <> " " <> name <> " {" ]
444448
, indentLines . catMaybes . zipWith (flip ($)) [1..] $
445-
[ \i -> Just $ mkField ["hs.strict"] structOrUnion i "id" type_id
449+
[ \i -> Just $ mkField [] ["hs.strict"] structOrUnion i "id" type_id
446450
, key, val ]
447451
, [ "}" ]
448452
]

0 commit comments

Comments
 (0)