2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -36,90 +36,98 @@ extension ASTGenVisitor {
36
36
func generateTypeAttribute( attribute node: AttributeSyntax ) -> BridgedTypeOrCustomAttr ? {
37
37
if let identTy = node. attributeName. as ( IdentifierTypeSyntax . self) {
38
38
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
+ }
40
48
41
49
switch attrKind {
42
50
// 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! )
71
79
. map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
72
80
73
- case . convention :
81
+ case . Convention :
74
82
return ( self . generateConventionTypeAttr ( attribute: node) ? . asTypeAttribute)
75
83
. map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
76
- case . differentiable :
84
+ case . Differentiable :
77
85
return ( self . generateDifferentiableTypeAttr ( attribute: node) ? . asTypeAttribute)
78
86
. map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
79
- case . opaqueReturnTypeOf :
87
+ case . OpaqueReturnTypeOf :
80
88
return ( self . generateOpaqueReturnTypeOfTypeAttr ( attribute: node) ? . asTypeAttribute)
81
89
. map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
82
- case . isolated :
90
+ case . Isolated :
83
91
return ( self . generateIsolatedTypeAttr ( attribute: node) ? . asTypeAttribute)
84
92
. map ( BridgedTypeOrCustomAttr . typeAttr ( _: ) )
85
93
86
94
// 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 :
118
126
// TODO: Diagnose or fallback to CustomAttr?
119
127
fatalError ( " SIL type attributes are not supported " )
120
128
break ;
121
129
122
- case . none :
130
+ case nil :
123
131
// Not a builtin type attribute. Fall back to CustomAttr
124
132
break ;
125
133
}
@@ -131,7 +139,7 @@ extension ASTGenVisitor {
131
139
return nil
132
140
}
133
141
134
- func generateSimpleTypeAttr( attribute node: AttributeSyntax , kind: BridgedTypeAttrKind ) -> BridgedTypeAttribute ? {
142
+ func generateSimpleTypeAttr( attribute node: AttributeSyntax , kind: swift . TypeAttrKind ) -> BridgedTypeAttribute ? {
135
143
// TODO: Diagnose extraneous arguments.
136
144
return BridgedTypeAttribute . createSimple (
137
145
self . ctx,
0 commit comments