Skip to content

Commit 2511e25

Browse files
authored
Add _BridgeObject and _TrivialStride layouts (#2390)
* Add _BridgeObject and _TrivialStride layouts Both layout kinds are useful for pre-specializations of commonly emitted generic function specializations. * Add tests * Code formatting
1 parent ab49772 commit 2511e25

File tree

9 files changed

+58
-4
lines changed

9 files changed

+58
-4
lines changed

CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public let GENERIC_NODES: [Node] = [
205205
.keyword(._NativeRefCountedObject),
206206
.keyword(._Class),
207207
.keyword(._NativeClass),
208+
.keyword(._BridgeObject),
209+
.keyword(._TrivialStride),
208210
])
209211
),
210212
Child(

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public enum Keyword: CaseIterable {
8282
case _backDeploy
8383
case _borrow
8484
case _borrowing
85+
case _BridgeObject
8586
case _cdecl
8687
case _Class
8788
case _compilerInitialized
@@ -119,6 +120,7 @@ public enum Keyword: CaseIterable {
119120
case _swift_native_objc_runtime_base
120121
case _Trivial
121122
case _TrivialAtMost
123+
case _TrivialStride
122124
case _typeEraser
123125
case _unavailableFromAsync
124126
case _underlyingVersion
@@ -302,6 +304,8 @@ public enum Keyword: CaseIterable {
302304
return KeywordSpec("_backDeploy")
303305
case ._borrow:
304306
return KeywordSpec("_borrow")
307+
case ._BridgeObject:
308+
return KeywordSpec("_BridgeObject")
305309
case ._cdecl:
306310
return KeywordSpec("_cdecl")
307311
case ._Class:
@@ -372,6 +376,8 @@ public enum Keyword: CaseIterable {
372376
return KeywordSpec("_Trivial")
373377
case ._TrivialAtMost:
374378
return KeywordSpec("_TrivialAtMost")
379+
case ._TrivialStride:
380+
return KeywordSpec("_TrivialStride")
375381
case ._typeEraser:
376382
return KeywordSpec("_typeEraser")
377383
case ._unavailableFromAsync:

Sources/SwiftParser/Declarations.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,16 @@ extension Parser {
579579
var hasArguments: Bool {
580580
switch layoutSpecifier {
581581
case ._Trivial,
582-
._TrivialAtMost:
582+
._TrivialAtMost,
583+
._TrivialStride:
583584
return true
584585

585586
case ._UnknownLayout,
586587
._RefCountedObject,
587588
._NativeRefCountedObject,
588589
._Class,
589-
._NativeClass:
590+
._NativeClass,
591+
._BridgeObject:
590592
return false
591593
}
592594
}

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ enum TokenPrecedence: Comparable {
288288
case // Treat all other keywords as expression keywords in the absence of any better information.
289289
.__owned,
290290
.__shared,
291+
._BridgeObject,
291292
._Class,
292293
._compilerInitialized,
293294
._const,
@@ -300,6 +301,7 @@ enum TokenPrecedence: Comparable {
300301
._RefCountedObject,
301302
._Trivial,
302303
._TrivialAtMost,
304+
._TrivialStride,
303305
._underlyingVersion,
304306
._UnknownLayout,
305307
._version,

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,8 @@ extension LayoutRequirementSyntax {
19871987
case _NativeRefCountedObject
19881988
case _Class
19891989
case _NativeClass
1990+
case _BridgeObject
1991+
case _TrivialStride
19901992

19911993
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
19921994
switch PrepareForKeywordMatch(lexeme) {
@@ -2004,6 +2006,10 @@ extension LayoutRequirementSyntax {
20042006
self = ._Class
20052007
case TokenSpec(._NativeClass):
20062008
self = ._NativeClass
2009+
case TokenSpec(._BridgeObject):
2010+
self = ._BridgeObject
2011+
case TokenSpec(._TrivialStride):
2012+
self = ._TrivialStride
20072013
default:
20082014
return nil
20092015
}
@@ -2025,6 +2031,10 @@ extension LayoutRequirementSyntax {
20252031
return .keyword(._Class)
20262032
case ._NativeClass:
20272033
return .keyword(._NativeClass)
2034+
case ._BridgeObject:
2035+
return .keyword(._BridgeObject)
2036+
case ._TrivialStride:
2037+
return .keyword(._TrivialStride)
20282038
}
20292039
}
20302040

@@ -2048,6 +2058,10 @@ extension LayoutRequirementSyntax {
20482058
return .keyword(._Class)
20492059
case ._NativeClass:
20502060
return .keyword(._NativeClass)
2061+
case ._BridgeObject:
2062+
return .keyword(._BridgeObject)
2063+
case ._TrivialStride:
2064+
return .keyword(._TrivialStride)
20512065
}
20522066
}
20532067
}

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public enum Keyword: UInt8, Hashable {
2222
case _borrow
2323
@_spi(ExperimentalLanguageFeatures)
2424
case _borrowing
25+
case _BridgeObject
2526
case _cdecl
2627
case _Class
2728
case _compilerInitialized
@@ -61,6 +62,7 @@ public enum Keyword: UInt8, Hashable {
6162
case _swift_native_objc_runtime_base
6263
case _Trivial
6364
case _TrivialAtMost
65+
case _TrivialStride
6466
case _typeEraser
6567
case _unavailableFromAsync
6668
case _underlyingVersion
@@ -649,6 +651,8 @@ public enum Keyword: UInt8, Hashable {
649651
}
650652
case 13:
651653
switch text {
654+
case "_BridgeObject":
655+
self = ._BridgeObject
652656
case "associativity":
653657
self = .associativity
654658
case "unsafeAddress":
@@ -664,6 +668,8 @@ public enum Keyword: UInt8, Hashable {
664668
self = ._spi_available
665669
case "_TrivialAtMost":
666670
self = ._TrivialAtMost
671+
case "_TrivialStride":
672+
self = ._TrivialStride
667673
case "_UnknownLayout":
668674
self = ._UnknownLayout
669675
case "associatedtype":
@@ -793,6 +799,7 @@ public enum Keyword: UInt8, Hashable {
793799
"_backDeploy",
794800
"_borrow",
795801
"_borrowing",
802+
"_BridgeObject",
796803
"_cdecl",
797804
"_Class",
798805
"_compilerInitialized",
@@ -830,6 +837,7 @@ public enum Keyword: UInt8, Hashable {
830837
"_swift_native_objc_runtime_base",
831838
"_Trivial",
832839
"_TrivialAtMost",
840+
"_TrivialStride",
833841
"_typeEraser",
834842
"_unavailableFromAsync",
835843
"_underlyingVersion",

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,9 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
17001700
.keyword("_RefCountedObject"),
17011701
.keyword("_NativeRefCountedObject"),
17021702
.keyword("_Class"),
1703-
.keyword("_NativeClass")
1703+
.keyword("_NativeClass"),
1704+
.keyword("_BridgeObject"),
1705+
.keyword("_TrivialStride")
17041706
]))
17051707
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
17061708
assertNoError(kind, 7, verify(layout[7], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.leftParen)]))

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ public struct LabeledStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSy
13501350
///
13511351
/// - `type`: ``TypeSyntax``
13521352
/// - `colon`: `:`
1353-
/// - `layoutSpecifier`: (`_Trivial` | `_TrivialAtMost` | `_UnknownLayout` | `_RefCountedObject` | `_NativeRefCountedObject` | `_Class` | `_NativeClass`)
1353+
/// - `layoutSpecifier`: (`_Trivial` | `_TrivialAtMost` | `_UnknownLayout` | `_RefCountedObject` | `_NativeRefCountedObject` | `_Class` | `_NativeClass` | `_BridgeObject` | `_TrivialStride`)
13541354
/// - `leftParen`: `(`?
13551355
/// - `size`: `<integerLiteral>`?
13561356
/// - `comma`: `,`?
@@ -1505,6 +1505,8 @@ public struct LayoutRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt
15051505
/// - `_NativeRefCountedObject`
15061506
/// - `_Class`
15071507
/// - `_NativeClass`
1508+
/// - `_BridgeObject`
1509+
/// - `_TrivialStride`
15081510
public var layoutSpecifier: TokenSyntax {
15091511
get {
15101512
return Syntax(self).child(at: 5)!.cast(TokenSyntax.self)

Tests/SwiftParserTest/AttributeTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ final class AttributeTests: ParserTestCase {
7070
)
7171
}
7272

73+
func testSpecializeAttribute() {
74+
assertParse(
75+
"""
76+
@_specialize(where @_noMetdata T : _BridgeObject)
77+
func foo(_ t: T) {}
78+
"""
79+
)
80+
81+
assertParse(
82+
"""
83+
@_specialize(where @_noMetdata T : _TrivialStride(64))
84+
func foo(_ t: T) {}
85+
"""
86+
)
87+
}
88+
7389
func testMissingClosingParenToAttribute() {
7490
assertParse(
7591
"""

0 commit comments

Comments
 (0)