22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
@@ -36,90 +36,98 @@ extension ASTGenVisitor {
3636 func generateTypeAttribute( attribute node: AttributeSyntax ) -> BridgedTypeOrCustomAttr ? {
3737 if let identTy = node. attributeName. as ( IdentifierTypeSyntax . self) {
3838 let attrName = identTy. name. rawText
39- let attrKind = BridgedTypeAttrKind ( from: attrName. bridged)
39+ let attrKind : swift . TypeAttrKind ?
40+ do {
41+ let bridgedOptional = BridgedOptionalTypeAttrKind ( from: attrName. bridged)
42+ attrKind = if bridgedOptional. hasValue {
43+ bridgedOptional. value
44+ } else {
45+ nil
46+ }
47+ }
4048
4149 switch attrKind {
4250 // Simple type attributes.
43- case . autoclosure ,
44- . addressable ,
45- . concurrent ,
46- . escaping ,
47- . noEscape ,
48- . noDerivative ,
49- . async ,
50- . sendable ,
51- . retroactive ,
52- . unchecked ,
53- . unsafe ,
54- . preconcurrency ,
55- . local ,
56- . noMetadata ,
57- . nonisolated ,
58- . packGuaranteed ,
59- . packInout ,
60- . packOut ,
61- . packOwned ,
62- . pseudogeneric ,
63- . yields ,
64- . yieldMany ,
65- . yieldOnce ,
66- . yieldOnce2 ,
67- . thin ,
68- . thick ,
69- . unimplementable :
70- return self . generateSimpleTypeAttr ( attribute: node, kind: attrKind)
51+ case . Autoclosure ,
52+ . Addressable ,
53+ . Concurrent ,
54+ . Escaping ,
55+ . NoEscape ,
56+ . NoDerivative ,
57+ . Async ,
58+ . Sendable ,
59+ . Retroactive ,
60+ . Unchecked ,
61+ . Unsafe ,
62+ . Preconcurrency ,
63+ . Local ,
64+ . NoMetadata ,
65+ . Nonisolated ,
66+ . PackGuaranteed ,
67+ . PackInout ,
68+ . PackOut ,
69+ . PackOwned ,
70+ . Pseudogeneric ,
71+ . Yields ,
72+ . YieldMany ,
73+ . YieldOnce ,
74+ . YieldOnce2 ,
75+ . Thin ,
76+ . Thick ,
77+ . Unimplementable :
78+ return self . generateSimpleTypeAttr ( attribute: node, kind: attrKind! )
7179 . map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
7280
73- case . convention :
81+ case . Convention :
7482 return ( self . generateConventionTypeAttr ( attribute: node) ? . asTypeAttribute)
7583 . map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
76- case . differentiable :
84+ case . Differentiable :
7785 return ( self . generateDifferentiableTypeAttr ( attribute: node) ? . asTypeAttribute)
7886 . map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
79- case . opaqueReturnTypeOf :
87+ case . OpaqueReturnTypeOf :
8088 return ( self . generateOpaqueReturnTypeOfTypeAttr ( attribute: node) ? . asTypeAttribute)
8189 . map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
82- case . isolated :
90+ case . Isolated :
8391 return ( self . generateIsolatedTypeAttr ( attribute: node) ? . asTypeAttribute)
8492 . map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
8593
8694 // SIL type attributes are not supported.
87- case . autoreleased ,
88- . blockStorage ,
89- . box ,
90- . calleeGuaranteed ,
91- . calleeOwned ,
92- . capturesGenerics ,
93- . direct ,
94- . dynamicSelf ,
95- . error ,
96- . errorIndirect ,
97- . errorUnowned ,
98- . guaranteed ,
99- . in ,
100- . inConstant ,
101- . inGuaranteed ,
102- . inCXX ,
103- . inout ,
104- . inoutAliasable ,
105- . moveOnly ,
106- . objCMetatype ,
107- . opened ,
108- . out ,
109- . owned ,
110- . packElement ,
111- . silIsolated ,
112- . silUnmanaged ,
113- . silUnowned ,
114- . silWeak ,
115- . silSending ,
116- . silImplicitLeadingParam ,
117- . unownedInnerPointer :
95+ case . Autoreleased ,
96+ . BlockStorage ,
97+ . Box ,
98+ . CalleeGuaranteed ,
99+ . CalleeOwned ,
100+ . CapturesGenerics ,
101+ . Direct ,
102+ . DynamicSelf ,
103+ . Error ,
104+ . ErrorIndirect ,
105+ . ErrorUnowned ,
106+ . Guaranteed ,
107+ . In ,
108+ . InConstant ,
109+ . InGuaranteed ,
110+ . InCXX ,
111+ . Inout ,
112+ . InoutAliasable ,
113+ . MoveOnly ,
114+ . ObjCMetatype ,
115+ . Opened ,
116+ . Out ,
117+ . Owned ,
118+ . PackElement ,
119+ . SILIsolated ,
120+ . SILUnmanaged ,
121+ . SILUnowned ,
122+ . SILWeak ,
123+ . SILSending ,
124+ . SILImplicitLeadingParam ,
125+ . UnownedInnerPointer :
118126 // TODO: Diagnose or fallback to CustomAttr?
119127 fatalError ( " SIL type attributes are not supported " )
120128 break ;
121129
122- case . none :
130+ case nil :
123131 // Not a builtin type attribute. Fall back to CustomAttr
124132 break ;
125133 }
@@ -131,7 +139,7 @@ extension ASTGenVisitor {
131139 return nil
132140 }
133141
134- func generateSimpleTypeAttr( attribute node: AttributeSyntax , kind: BridgedTypeAttrKind ) -> BridgedTypeAttribute ? {
142+ func generateSimpleTypeAttr( attribute node: AttributeSyntax , kind: swift . TypeAttrKind ) -> BridgedTypeAttribute ? {
135143 // TODO: Diagnose extraneous arguments.
136144 return BridgedTypeAttribute . createSimple (
137145 self . ctx,
0 commit comments