Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swift 5.8 Support #781

Merged
merged 10 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

##### Enhancements

* None.
* Added new syntax, attribute and declaration kinds introduced in Swift 5.8.
[JP Simard](https://github.com/jpsim)

##### Bug Fixes

Expand Down
16 changes: 16 additions & 0 deletions Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,20 @@ public enum SwiftDeclarationAttributeKind: String, CaseIterable {
case exclusivity = "source.decl.attribute.exclusivity"
case _unsafeInheritExecutor = "source.decl.attribute._unsafeInheritExecutor"
case _compilerInitialized = "source.decl.attribute._compilerInitialized"

// Only available in Swift >= 5.8

case backDeployed = "source.decl.attribute.backDeployed"
case _noEagerMove = "source.decl.attribute._noEagerMove"
case typeWrapperIgnored = "source.decl.attribute.typeWrapperIgnored"
case _spiOnly = "source.decl.attribute._spiOnly"
case _moveOnly = "source.decl.attribute._moveOnly"
case _noMetadata = "source.decl.attribute._noMetadata"
case _alwaysEmitConformanceMetadata = "source.decl.attribute._alwaysEmitConformanceMetadata"
case runtimeMetadata = "source.decl.attribute.runtimeMetadata"
case _objcImplementation = "source.decl.attribute._objcImplementation"
case _eagerMove = "source.decl.attribute._eagerMove"
case typeWrapper = "source.decl.attribute.typeWrapper"
case _expose = "source.decl.attribute._expose"
case _documentation = "source.decl.attribute._documentation"
}
2 changes: 2 additions & 0 deletions Source/SourceKittenFramework/SwiftDeclarationKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ public enum SwiftDeclarationKind: String, CaseIterable {
case varStatic = "source.lang.swift.decl.var.static"
/// `actor`.
case actor = "source.lang.swift.decl.actor"
/// `macro`
case macro = "source.lang.swift.decl.macro"
}
2 changes: 2 additions & 0 deletions Source/SourceKittenFramework/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum SyntaxKind: String, CaseIterable {
case typeidentifier = "source.lang.swift.syntaxtype.typeidentifier"
/// `pounddirective.keyword`.
case poundDirectiveKeyword = "source.lang.swift.syntaxtype.pounddirective.keyword"
/// `operator`
case `operator` = "source.lang.swift.syntaxtype.operator"

/// Returns the valid documentation comment syntax kinds.
internal static func docComments() -> [SyntaxKind] {
Expand Down
8,815 changes: 8,815 additions & 0 deletions Tests/SourceKittenFrameworkTests/Fixtures/Commandant@swift-5.8.json

Large diffs are not rendered by default.

8,815 changes: 8,815 additions & 0 deletions Tests/SourceKittenFrameworkTests/Fixtures/CommandantSPM@swift-5.8.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Tests/SourceKittenFrameworkTests/ModuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class ModuleTests: XCTestCase {
return
}

let pbxprojURL = URL(fileURLWithPath: "\(commandantPath)/Commandant.xcodeproj/project.pbxproj")
let originalPbxproj = try String(contentsOf: pbxprojURL)
let newPbxproj = originalPbxproj.replacingOccurrences(
of: "MACOSX_DEPLOYMENT_TARGET = 10.9",
with: "MACOSX_DEPLOYMENT_TARGET = 10.13"
)
try newPbxproj.data(using: .utf8)?.write(to: pbxprojURL)
let arguments = ["-workspace", "Commandant.xcworkspace", "-scheme", "Commandant"]
let commandantModule = try XCTUnwrap(Module(xcodeBuildArguments: arguments, name: nil, inPath: commandantPath))
compareJSONString(withFixtureNamed: "Commandant", jsonString: commandantModule.docs,
Expand Down
23 changes: 20 additions & 3 deletions Tests/SourceKittenFrameworkTests/SourceKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ class SourceKitTests: XCTestCase {
}

func testSyntaxKinds() {
#if compiler(>=5.8)
let expected = SyntaxKind.allCases
#else
let expected = Set(SyntaxKind.allCases).subtracting([.operator])
#endif

let actual = sourcekitStrings(startingWith: "source.lang.swift.syntaxtype.")
let expectedStrings = Set(expected.map { $0.rawValue })
let expectedStrings = Set(expected.map(\.rawValue))
XCTAssertEqual(
actual,
expectedStrings
Expand All @@ -107,7 +111,10 @@ class SourceKitTests: XCTestCase {
#if !compiler(>=5.1)
expected.remove(.opaqueType)
#endif
let expectedStrings = Set(expected.map { $0.rawValue })
#if compiler(<5.8)
expected.remove(.macro)
#endif
let expectedStrings = Set(expected.map(\.rawValue))
XCTAssertEqual(
actual,
expectedStrings
Expand All @@ -128,6 +135,16 @@ class SourceKitTests: XCTestCase {
let actual = sourcekitStrings(startingWith: "source.decl.attribute.")
.subtracting(attributesFoundInSwift5ButWeIgnore)

#if compiler(>=5.8)
// removed in Swift 5.8
expected.subtract([._typeSequence, ._backDeploy])
#else
// added in Swift 5.8
expected.subtract([.backDeployed, ._noEagerMove, .typeWrapperIgnored, ._spiOnly, ._moveOnly,
._noMetadata, ._alwaysEmitConformanceMetadata, .runtimeMetadata,
._objcImplementation, ._eagerMove, .typeWrapper, ._expose, ._documentation])
#endif

#if compiler(>=5.6)
// removed in Swift 5.6
expected.subtract([.asyncHandler, .actorIndependent, .spawn, ._unsafeMainActor, ._unsafeSendable])
Expand Down Expand Up @@ -257,7 +274,7 @@ class SourceKitTests: XCTestCase {
let actualStructure = Structure(sourceKitResponse: output)
XCTAssertEqual(expectedStructure, actualStructure)
}
#if compiler(<5.9)
#if compiler(<5.8)
func testSyntaxTree() throws {
let file = File(path: "\(fixturesDirectory)Bicycle.swift")!
let request = Request.syntaxTree(file: file, byteTree: false)
Expand Down
16 changes: 8 additions & 8 deletions Tests/SourceKittenFrameworkTests/StructureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class StructureTests: XCTestCase {
"key.offset": 0,
"key.length": 0,
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
"key.substructure": []
"key.substructure": [] as NSArray
]
let structure = try Structure(file: File(contents: ""))
XCTAssertEqual(toNSDictionary(structure.dictionary), expected, "should generate expected structure")
Expand Down Expand Up @@ -57,12 +57,12 @@ class StructureTests: XCTestCase {
"key.length": 5,
"key.nameoffset": 19,
"key.namelength": 5
]
] as [String: Any]
]
]
] as [String: Any]
],
"key.name": "MyEnum"
]
] as [String: Any]
],
"key.offset": 0,
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
Expand Down Expand Up @@ -132,12 +132,12 @@ class StructureTests: XCTestCase {
"key.kind": "source.lang.swift.structure.elem.typeref",
"key.offset": 11,
"key.length": 3
]
] as [String: Any]
],
"key.inheritedtypes": [
["key.name": "Bar"]
]
]
] as [String: Any]
],
"key.offset": 0,
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
Expand Down Expand Up @@ -201,10 +201,10 @@ class StructureTests: XCTestCase {
"key.bodylength": 0,
"key.length": 11,
"key.name": "b()"
]
] as [String: Any]
],
"key.name": "A"
]
] as [String: Any]
],
"key.offset": 0,
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
Expand Down
13 changes: 10 additions & 3 deletions Tests/SourceKittenFrameworkTests/SwiftDocsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private func compareDocs(withFixtureNamed name: String, file: StaticString = #fi

private func versionedExpectedFilename(for name: String) -> String {
#if compiler(>=5.9)
let versions = ["swift-5.9", "swift-5.6", "swift-5.5.2", "swift-5.5", "swift-5.4", "swift-5.3.1", "swift-5.3", "swift-5.2", "swift-5.1", "swift-5.0"]
let versions = ["swift-5.9", "swift-5.8", "swift-5.6", "swift-5.5.2", "swift-5.5", "swift-5.4", "swift-5.3.1", "swift-5.3", "swift-5.2", "swift-5.1",
"swift-5.0"]
#elseif compiler(>=5.8)
let versions = ["swift-5.8", "swift-5.6", "swift-5.5.2", "swift-5.5", "swift-5.4", "swift-5.3.1", "swift-5.3", "swift-5.2", "swift-5.1", "swift-5.0"]
#elseif compiler(>=5.6)
let versions = ["swift-5.6", "swift-5.5.2", "swift-5.5", "swift-5.4", "swift-5.3.1", "swift-5.3", "swift-5.2", "swift-5.1", "swift-5.0"]
#elseif compiler(>=5.5.2)
Expand Down Expand Up @@ -110,7 +113,11 @@ private func diff(original: String, modified: String) -> String {
}

private let buildingSwiftVersion: String = {
#if compiler(>=5.6)
#if compiler(>=5.9)
return "swift-5.9"
#elseif compiler(>=5.8)
return "swift-5.8"
#elseif compiler(>=5.6)
return "swift-5.6"
#elseif compiler(>=5.5.0)
return "swift-5.5"
Expand Down Expand Up @@ -157,7 +164,7 @@ class SwiftDocsTests: XCTestCase {
"key.doc.parameters": [[
"name": "param1",
"discussion": [["Para": "param1_discussion"]]
]],
] as [String: Any]],
"key.doc.result_discussion": [["Para": "result_discussion"]]
]
XCTAssertEqual(toNSDictionary(parsedPreSwift32), expected)
Expand Down