Skip to content

Commit a0a9739

Browse files
authored
Merge pull request #1880 from swiftlang/print-supported-features-forwarding
[Jobs] Add a job for `-print-supported-features`
2 parents 76069d6 + 55121b9 commit a0a9739

File tree

9 files changed

+87
-10
lines changed

9 files changed

+87
-10
lines changed

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ add_library(SwiftDriver
8888
Jobs/MergeModuleJob.swift
8989
Jobs/ModuleWrapJob.swift
9090
Jobs/Planning.swift
91+
Jobs/PrintSupportedFeaturesJob.swift
9192
Jobs/PrintTargetInfoJob.swift
9293
Jobs/ReplJob.swift
9394
Jobs/SwiftHelpIntroJob.swift

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extension Driver {
9898
.clangModuleMap, .jsonCompilerFeatures, .jsonTargetInfo, .jsonSwiftArtifacts,
9999
.indexUnitOutputPath, .modDepCache, .jsonAPIBaseline, .jsonABIBaseline,
100100
.swiftConstValues, .jsonAPIDescriptor, .moduleSummary, .moduleSemanticInfo,
101-
.cachedDiagnostics, nil:
101+
.cachedDiagnostics, .jsonSupportedFeatures, nil:
102102
return false
103103
}
104104
}
@@ -487,6 +487,8 @@ extension FileType {
487487
return .printTargetInfo
488488
case .jsonCompilerFeatures:
489489
return .emitSupportedFeatures
490+
case .jsonSupportedFeatures:
491+
return .printSupportedFeatures
490492

491493
case .swift, .dSYM, .autolink, .dependencies, .emitModuleDependencies,
492494
.swiftDocumentation, .pcm, .diagnostics, .emitModuleDiagnostics,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension Driver {
104104
.help, .link, .verifyDebugInfo, .scanDependencies,
105105
.emitSupportedFeatures, .moduleWrap,
106106
.generateAPIBaseline, .generateABIBaseline, .compareAPIBaseline,
107-
.compareABIBaseline:
107+
.compareABIBaseline, .printSupportedFeatures:
108108
jobNeedPathRemap = false
109109
}
110110
} else {

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public struct Job: Codable, Equatable, Hashable {
4343
case generateABIBaseline = "generate-abi-baseline"
4444
case compareAPIBaseline = "compare-api-baseline"
4545
case compareABIBaseline = "Check ABI stability"
46+
case printSupportedFeatures = "print-supported-features"
4647
}
4748

4849
public enum ArgTemplate: Equatable, Hashable {
@@ -251,6 +252,9 @@ extension Job : CustomStringConvertible {
251252

252253
case .compareABIBaseline:
253254
return "Comparing ABI of \(moduleName) to baseline"
255+
256+
case .printSupportedFeatures:
257+
return "Print supported upcoming and experimental features"
254258
}
255259
}
256260

@@ -270,7 +274,7 @@ extension Job.Kind {
270274
switch self {
271275
case .backend, .compile, .mergeModule, .emitModule, .compileModuleFromInterface, .generatePCH,
272276
.generatePCM, .dumpPCM, .interpret, .repl, .printTargetInfo,
273-
.versionRequest, .emitSupportedFeatures, .scanDependencies, .verifyModuleInterface:
277+
.versionRequest, .emitSupportedFeatures, .scanDependencies, .verifyModuleInterface, .printSupportedFeatures:
274278
return true
275279

276280
case .autolinkExtract, .generateDSYM, .help, .link, .verifyDebugInfo, .moduleWrap,
@@ -290,7 +294,7 @@ extension Job.Kind {
290294
.help, .link, .verifyDebugInfo, .scanDependencies,
291295
.emitSupportedFeatures, .moduleWrap, .verifyModuleInterface,
292296
.generateAPIBaseline, .generateABIBaseline, .compareAPIBaseline,
293-
.compareABIBaseline:
297+
.compareABIBaseline, .printSupportedFeatures:
294298
return false
295299
}
296300
}
@@ -305,7 +309,7 @@ extension Job.Kind {
305309
.versionRequest, .autolinkExtract, .generateDSYM, .help, .link,
306310
.verifyDebugInfo, .scanDependencies, .emitSupportedFeatures, .moduleWrap,
307311
.generateAPIBaseline, .generateABIBaseline, .compareAPIBaseline,
308-
.compareABIBaseline:
312+
.compareABIBaseline, .printSupportedFeatures:
309313
return false
310314
}
311315
}

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,15 @@ extension Driver {
713713
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs)
714714
}
715715

716+
if parsedOptions.hasArgument(.printSupportedFeatures) {
717+
try verifyFrontendSupportsOptionIfNecessary(.printSupportedFeatures)
718+
719+
return try toolchain.printSupportedFeaturesJob(
720+
requiresInPlaceExecution: true,
721+
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs
722+
)
723+
}
724+
716725
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
717726
return Job(
718727
moduleName: moduleOutputInfo.name,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===------- PrintSupportedFeaturesJob.swift - Swift Target Info Job ------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
extension Toolchain {
14+
@_spi(Testing) public func printSupportedFeaturesJob(
15+
requiresInPlaceExecution: Bool = false,
16+
swiftCompilerPrefixArgs: [String]
17+
) throws -> Job {
18+
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
19+
commandLine.append(contentsOf: [
20+
.flag("-frontend"),
21+
.flag("-print-supported-features"),
22+
])
23+
24+
return Job(
25+
moduleName: "",
26+
kind: .printSupportedFeatures,
27+
tool: try resolvedTool(.swiftCompiler),
28+
commandLine: commandLine,
29+
displayInputs: [],
30+
inputs: [],
31+
primaryInputs: [],
32+
outputs: [.init(file: .standardOutput, type: .jsonSupportedFeatures)],
33+
requiresInPlaceExecution: requiresInPlaceExecution
34+
)
35+
}
36+
}

Sources/SwiftDriver/Utilities/FileType.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public enum FileType: String, Hashable, CaseIterable, Codable {
117117
/// JSON-based -emit-supported-features output
118118
case jsonCompilerFeatures = "compilerFeatures.json"
119119

120+
/// JSON-based -print-supported-features output
121+
case jsonSupportedFeatures = "supportedFeatures.json"
122+
120123
/// JSON-based binary Swift module artifact description
121124
case jsonSwiftArtifacts = "artifacts.json"
122125

@@ -271,6 +274,9 @@ extension FileType: CustomStringConvertible {
271274

272275
case .cachedDiagnostics:
273276
return "cached-diagnostics"
277+
278+
case .jsonSupportedFeatures:
279+
return "json-supported-swift-features"
274280
}
275281
}
276282
}
@@ -291,7 +297,8 @@ extension FileType {
291297
.jsonDependencies, .clangModuleMap, .jsonTargetInfo, .jsonCompilerFeatures,
292298
.jsonSwiftArtifacts, .indexUnitOutputPath, .modDepCache, .jsonAPIBaseline,
293299
.jsonABIBaseline, .swiftConstValues, .jsonAPIDescriptor,
294-
.moduleSummary, .moduleSemanticInfo, .cachedDiagnostics, .raw_llvmIr:
300+
.moduleSummary, .moduleSemanticInfo, .cachedDiagnostics, .raw_llvmIr,
301+
.jsonSupportedFeatures:
295302
return false
296303
}
297304
}
@@ -408,6 +415,8 @@ extension FileType {
408415
return "module-semantic-info"
409416
case .cachedDiagnostics:
410417
return "cached-diagnostics"
418+
case .jsonSupportedFeatures:
419+
return "json-supported-swift-features"
411420
}
412421
}
413422
}
@@ -421,7 +430,7 @@ extension FileType {
421430
.jsonDependencies, .clangModuleMap, .jsonCompilerFeatures, .jsonTargetInfo,
422431
.jsonSwiftArtifacts, .jsonAPIBaseline, .jsonABIBaseline, .swiftConstValues,
423432
.jsonAPIDescriptor, .moduleSummary, .moduleSemanticInfo, .cachedDiagnostics,
424-
.raw_llvmIr:
433+
.raw_llvmIr, .jsonSupportedFeatures:
425434
return true
426435
case .image, .object, .dSYM, .pch, .sib, .raw_sib, .swiftModule,
427436
.swiftDocumentation, .swiftSourceInfoFile, .llvmBitcode, .diagnostics,
@@ -446,15 +455,15 @@ extension FileType {
446455
.clangModuleMap, .jsonCompilerFeatures, .jsonTargetInfo, .jsonSwiftArtifacts,
447456
.indexUnitOutputPath, .jsonAPIBaseline, .jsonABIBaseline, .swiftConstValues,
448457
.jsonAPIDescriptor, .moduleSummary, .moduleSemanticInfo, .cachedDiagnostics,
449-
.raw_llvmIr:
458+
.raw_llvmIr, .jsonSupportedFeatures:
450459
return false
451460
}
452461
}
453462

454463
/// Returns true if producing the file type requires running SILGen.
455464
var requiresSILGen: Bool {
456465
switch self {
457-
case .swift, .ast, .indexData, .indexUnitOutputPath, .jsonCompilerFeatures, .jsonTargetInfo:
466+
case .swift, .ast, .indexData, .indexUnitOutputPath, .jsonCompilerFeatures, .jsonTargetInfo, .jsonSupportedFeatures:
458467
return false
459468
case .sil, .sib, .image, .object, .dSYM, .dependencies, .autolink, .swiftModule, .swiftDocumentation, .swiftInterface, .privateSwiftInterface, .packageSwiftInterface, .swiftSourceInfoFile, .swiftConstValues, .assembly, .raw_sil, .raw_sib, .llvmIR, .llvmBitcode, .diagnostics, .emitModuleDiagnostics, .emitModuleDependencies, .objcHeader, .swiftDeps, .modDepCache, .remap, .importedModules, .tbd, .jsonDependencies, .jsonSwiftArtifacts, .moduleTrace, .yamlOptimizationRecord, .bitstreamOptimizationRecord, .pcm, .pch, .clangModuleMap, .jsonAPIBaseline, .jsonABIBaseline, .jsonAPIDescriptor, .moduleSummary, .moduleSemanticInfo, .cachedDiagnostics, .raw_llvmIr:
460469
return true
@@ -469,7 +478,7 @@ extension FileType {
469478
.jsonSwiftArtifacts, .remap, .indexUnitOutputPath, .modDepCache,
470479
// the remaining should not be an output from a caching swift job.
471480
.swift, .image, .dSYM, .importedModules, .clangModuleMap,
472-
.jsonCompilerFeatures, .jsonTargetInfo, .autolink:
481+
.jsonCompilerFeatures, .jsonTargetInfo, .autolink, .jsonSupportedFeatures:
473482
return false
474483
case .assembly, .llvmIR, .llvmBitcode, .object, .sil, .sib, .ast,
475484
.dependencies, .emitModuleDependencies, .swiftModule,

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ extension Option {
763763
public static let printModule_: Option = Option("--print-module", .flag, alias: Option.printModule, attributes: [.noDriver], helpText: "Print module names in diagnostics")
764764
public static let printPreprocessedExplicitDependencyGraph: Option = Option("-print-preprocessed-explicit-dependency-graph", .flag, attributes: [.helpHidden], helpText: "Print the result of module dependency scanning to output")
765765
public static let printStats: Option = Option("-print-stats", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Print various statistics")
766+
public static let printSupportedFeatures: Option = Option("-print-supported-features", .flag, attributes: [.frontend], metaVar: "<features>", helpText: "Print information about features supported by the compiler")
766767
public static let printTargetInfo: Option = Option("-print-target-info", .flag, attributes: [.frontend], metaVar: "<triple>", helpText: "Print target information for the given target <triple>, such as x86_64-apple-macos10.9")
767768
public static let printZeroStats: Option = Option("-print-zero-stats", .flag, attributes: [.helpHidden, .frontend], helpText: "Prints all stats even if they are zero")
768769
public static let profileCoverageMapping: Option = Option("-profile-coverage-mapping", .flag, attributes: [.frontend, .noInteractive], helpText: "Generate coverage data for use with profiled execution counts")
@@ -1720,6 +1721,7 @@ extension Option {
17201721
Option.printModule_,
17211722
Option.printPreprocessedExplicitDependencyGraph,
17221723
Option.printStats,
1724+
Option.printSupportedFeatures,
17231725
Option.printTargetInfo,
17241726
Option.printZeroStats,
17251727
Option.profileCoverageMapping,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5899,6 +5899,20 @@ final class SwiftDriverTests: XCTestCase {
58995899
}
59005900
}
59015901

5902+
func testFrontendSupportedFeatures() throws {
5903+
var driver = try Driver(args: ["swift", "-print-supported-features"])
5904+
5905+
guard driver.isFrontendArgSupported(.printSupportedFeatures) else {
5906+
throw XCTSkip("Skipping: compiler does not support '-print-supported-features'")
5907+
}
5908+
5909+
let plannedJobs = try driver.planBuild()
5910+
XCTAssertEqual(plannedJobs.count, 1)
5911+
let job = plannedJobs[0]
5912+
XCTAssertEqual(job.kind, .printSupportedFeatures)
5913+
XCTAssertJobInvocationMatches(job, .flag("-print-supported-features"))
5914+
}
5915+
59025916
func testPrintOutputFileMap() throws {
59035917
try withTemporaryDirectory { path in
59045918
// Replace the error stream with one we capture here.

0 commit comments

Comments
 (0)