Skip to content

Commit 1cf2fd0

Browse files
committed
Stop launching REPL when there aren't inputs
Now that there is a more user-friendly help intro that shows by default, stop launching the REPL when there are no input files. Launch the REPL explicitly with the `repl` subcommand.
1 parent a287667 commit 1cf2fd0

File tree

5 files changed

+5
-51
lines changed

5 files changed

+5
-51
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,13 +1471,7 @@ extension Driver {
14711471
switch outputOption.option {
14721472
case .emitImportedModules:
14731473
return .singleCompile
1474-
1475-
case .repl:
1476-
if driverKind == .interactive, !parsedOptions.hasAnyInput {
1477-
diagnosticsEngine.emit(.warning_unnecessary_repl_mode(option: outputOption.option, kind: driverKind))
1478-
}
1479-
fallthrough
1480-
case .lldbRepl:
1474+
case .repl, .lldbRepl:
14811475
return .repl
14821476

14831477
case .deprecatedIntegratedRepl:
@@ -1553,10 +1547,6 @@ extension Driver {
15531547
}
15541548

15551549
extension Diagnostic.Message {
1556-
static func warning_unnecessary_repl_mode(option: Option, kind: DriverKind) -> Diagnostic.Message {
1557-
.warning("unnecessary option '\(option.spelling)'; this is the default for '\(kind.rawValue)' with no input files")
1558-
}
1559-
15601550
static func warn_ignoring_batch_mode(_ option: Option) -> Diagnostic.Message {
15611551
.warning("ignoring '-enable-batch-mode' because '\(option.spelling)' was also specified")
15621552
}

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -740,19 +740,7 @@ extension Driver {
740740
}
741741
return ([try generateDumpPCMJob(input: inputFiles.first!)], nil)
742742
case .intro:
743-
// TODO: Remove this check once the REPL no longer launches
744-
// by default.
745-
if !inputFiles.isEmpty {
746-
throw PlanningError.replReceivedInput
747-
}
748-
// end TODO.
749-
750-
var introJobs = try helpIntroJobs()
751-
752-
// TODO: Remove this to stop launching the REPL by default.
753-
introJobs.append(try replJob())
754-
755-
return (introJobs, nil)
743+
return (try helpIntroJobs(), nil)
756744
}
757745
}
758746
}

Sources/SwiftDriver/Jobs/SwiftHelpIntroJob.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ import SwiftOptions
1414
extension Driver {
1515
mutating func helpIntroJobs() throws -> [Job] {
1616
return [
17-
Job(
18-
moduleName: moduleOutputInfo.name,
19-
kind: .versionRequest,
20-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
21-
commandLine: [.flag("--version")],
22-
inputs: [],
23-
primaryInputs: [],
24-
outputs: [],
25-
requiresInPlaceExecution: false),
2617
Job(
2718
moduleName: moduleOutputInfo.name,
2819
kind: .help,

Sources/swift-help/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct SwiftHelp: ParsableCommand {
110110
// `repl` not included in `Subcommand`, also print it here.
111111
do {
112112
let padding = String(repeating: " ", count: maxSubcommandNameLength - "repl".count)
113-
print(" \(plainBold)swift repl\(plain)\(padding) Experiment with Swift code interactively (default)")
113+
print(" \(plainBold)swift repl\(plain)\(padding) Experiment with Swift code interactively")
114114
}
115115

116116
print("\n Use \(plainBold)`swift --help`\(plain) for descriptions of available options and flags.")

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,6 @@ final class SwiftDriverTests: XCTestCase {
517517
XCTAssertEqual(driver.moduleOutputInfo.name, "main")
518518
}
519519

520-
try assertDriverDiagnostics(args: "swift", "-repl") { driver, verifier in
521-
verifier.expect(.warning("unnecessary option '-repl'; this is the default for 'swift' with no input files"))
522-
XCTAssertNil(driver.moduleOutputInfo.output)
523-
XCTAssertEqual(driver.moduleOutputInfo.name, "REPL")
524-
}
525-
526520
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "bar.swift", "-emit-library", "-o", "libWibble.so") { driver in
527521
XCTAssertEqual(driver.moduleOutputInfo.name, "Wibble")
528522
}
@@ -2584,20 +2578,11 @@ final class SwiftDriverTests: XCTestCase {
25842578
do {
25852579
var driver = try Driver(args: ["swift"], env: envWithFakeSwiftHelp)
25862580
let plannedJobs = try driver.planBuild()
2587-
XCTAssertEqual(plannedJobs.count, 3)
2588-
2589-
let versionJob = plannedJobs[0]
2590-
XCTAssertTrue(versionJob.tool.name.contains("swift"))
2591-
XCTAssertTrue(versionJob.commandLine.contains(.flag("--version")))
2581+
XCTAssertEqual(plannedJobs.count, 1)
25922582

2593-
let helpJob = plannedJobs[1]
2583+
let helpJob = plannedJobs[0]
25942584
XCTAssertTrue(helpJob.tool.name.contains("swift-help"))
25952585
XCTAssertTrue(helpJob.commandLine.contains(.flag("intro")))
2596-
2597-
let replJob = plannedJobs[2]
2598-
XCTAssertTrue(replJob.tool.name.contains("lldb"))
2599-
XCTAssertTrue(replJob.requiresInPlaceExecution)
2600-
XCTAssert(replJob.commandLine.contains(where: { isExpectedLLDBREPLFlag($0) }))
26012586
}
26022587

26032588
do {

0 commit comments

Comments
 (0)