Skip to content

🍒 [6.1] Pass the -dump-ast-format flag down to the frontend. #1799

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

Merged
merged 1 commit into from
Feb 11, 2025
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: 3 additions & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ extension Driver {
try commandLine.appendLast(.lto, from: &parsedOptions)
try commandLine.appendLast(.accessNotesPath, from: &parsedOptions)
try commandLine.appendLast(.enableActorDataRaceChecks, .disableActorDataRaceChecks, from: &parsedOptions)
if isFrontendArgSupported(.dumpAstFormat) {
try commandLine.appendLast(.dumpAstFormat, from: &parsedOptions)
}
try commandLine.appendAll(.D, from: &parsedOptions)
try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions)
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftOptions/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ extension Option {
public static let driverVerifyFineGrainedDependencyGraphAfterEveryImport: Option = Option("-driver-verify-fine-grained-dependency-graph-after-every-import", .flag, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Debug DriverGraph by verifying it after every import", group: .internalDebug)
public static let driverWarnUnusedOptions: Option = Option("-driver-warn-unused-options", .flag, attributes: [.helpHidden], helpText: "Emit warnings for any provided options which are unused by the driver")
public static let dumpApiPath: Option = Option("-dump-api-path", .separate, attributes: [.frontend, .noDriver, .cacheInvariant], helpText: "The path to output swift interface files for the compiled source files")
public static let dumpAstFormat: Option = Option("-dump-ast-format", .separate, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], metaVar: "<format>", helpText: "Desired format for -dump-ast output ('default', 'json', or 'json-zlib'); no format is guaranteed stable across different compiler versions")
public static let dumpAst: Option = Option("-dump-ast", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Parse and type-check input file(s) and dump AST(s)", group: .modes)
public static let dumpAvailabilityScopes: Option = Option("-dump-availability-scopes", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Type-check input file(s) and dump availability scopes", group: .modes)
public static let dumpClangDiagnostics: Option = Option("-dump-clang-diagnostics", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Dump Clang diagnostics to stderr")
Expand Down Expand Up @@ -1197,6 +1198,7 @@ extension Option {
Option.driverVerifyFineGrainedDependencyGraphAfterEveryImport,
Option.driverWarnUnusedOptions,
Option.dumpApiPath,
Option.dumpAstFormat,
Option.dumpAst,
Option.dumpAvailabilityScopes,
Option.dumpClangDiagnostics,
Expand Down
11 changes: 11 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5325,6 +5325,17 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testDumpASTFormat() throws {
var driver = try Driver(args: [
"swiftc", "-dump-ast", "-dump-ast-format", "json", "foo.swift"
])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs[0].kind, .compile)
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast"))
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast-format"))
XCTAssertTrue(plannedJobs[0].commandLine.contains("json"))
}

func testDeriveSwiftDocPath() throws {
var driver = try Driver(args: [
"swiftc", "-emit-module", "/tmp/main.swift", "-emit-module-path", "test-ios-macabi.swiftmodule"
Expand Down