Skip to content

Commit 716267d

Browse files
authored
Replace deprecated uses of <<< with send (#1444)
`<<<` operator has been deprecated in TSC, as it mostly duplicates string interpolation, and the latter should be used instead in most cases where `<<<` was used previously. Additionally, `<<<` can't be introduced to scope with a qualified import (which is the case for any operator).
1 parent 61304dd commit 716267d

19 files changed

+418
-434
lines changed

Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
3434
"state": {
3535
"branch": "main",
36-
"revision": "7c8bcf3eab7286855a2eb0cd0df103ea2761e259",
36+
"revision": "ee4cb5e1c2ba6b033a964c77c96bc057be2e2e2a",
3737
"version": null
3838
}
3939
},

Sources/SwiftDriver/Driver/Driver.swift

+30-30
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import SwiftOptions
1313

1414
import class Dispatch.DispatchQueue
15-
16-
import TSCBasic // <<<
1715
import class TSCBasic.DiagnosticsEngine
16+
import class TSCBasic.UnknownLocation
1817
import enum TSCBasic.ProcessEnv
18+
import func TSCBasic.withTemporaryDirectory
1919
import protocol TSCBasic.DiagnosticData
2020
import protocol TSCBasic.FileSystem
2121
import protocol TSCBasic.OutputByteStream
2222
import struct TSCBasic.AbsolutePath
23+
import struct TSCBasic.ByteString
2324
import struct TSCBasic.Diagnostic
2425
import struct TSCBasic.FileInfo
2526
import struct TSCBasic.RelativePath
@@ -475,23 +476,23 @@ public struct Driver {
475476
stdErrQueue.sync {
476477
let stream = stderrStream
477478
if !(diagnostic.location is UnknownLocation) {
478-
stream <<< diagnostic.location.description <<< ": "
479+
stream.send("\(diagnostic.location.description): ")
479480
}
480481

481482
switch diagnostic.message.behavior {
482483
case .error:
483-
stream <<< "error: "
484+
stream.send("error: ")
484485
case .warning:
485-
stream <<< "warning: "
486+
stream.send("warning: ")
486487
case .note:
487-
stream <<< "note: "
488+
stream.send("note: ")
488489
case .remark:
489-
stream <<< "remark: "
490+
stream.send("remark: ")
490491
case .ignored:
491492
break
492493
}
493494

494-
stream <<< diagnostic.localizedDescription <<< "\n"
495+
stream.send("\(diagnostic.localizedDescription)\n")
495496
stream.flush()
496497
}
497498
}
@@ -1430,7 +1431,7 @@ extension Driver {
14301431

14311432
if parsedOptions.contains(.driverPrintOutputFileMap) {
14321433
if let outputFileMap = self.outputFileMap {
1433-
stderrStream <<< outputFileMap.description
1434+
stderrStream.send(outputFileMap.description)
14341435
stderrStream.flush()
14351436
} else {
14361437
diagnosticEngine.emit(.error_no_output_file_map_specified)
@@ -1507,17 +1508,17 @@ extension Driver {
15071508
// Print the driver source version first before we print the compiler
15081509
// versions.
15091510
if inPlaceJob.kind == .versionRequest && !Driver.driverSourceVersion.isEmpty {
1510-
stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " "
1511+
stderrStream.send("swift-driver version: \(Driver.driverSourceVersion) ")
15111512
if let blocklistVersion = try Driver.findCompilerClientsConfigVersion(RelativeTo: try toolchain.executableDir) {
1512-
stderrStream <<< blocklistVersion <<< " "
1513+
stderrStream.send("\(blocklistVersion) ")
15131514
}
15141515
stderrStream.flush()
15151516
}
15161517
// In verbose mode, print out the job
15171518
if parsedOptions.contains(.v) {
15181519
let arguments: [String] = try executor.resolver.resolveArgumentList(for: inPlaceJob,
15191520
useResponseFiles: forceResponseFiles ? .forced : .heuristic)
1520-
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
1521+
stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n")
15211522
stdoutStream.flush()
15221523
}
15231524
try executor.execute(job: inPlaceJob,
@@ -1640,17 +1641,16 @@ extension Driver {
16401641
}
16411642

16421643
private func printBindings(_ job: Job) {
1643-
stdoutStream <<< #"# ""# <<< targetTriple.triple
1644-
stdoutStream <<< #"" - ""# <<< job.tool.basename
1645-
stdoutStream <<< #"", inputs: ["#
1646-
stdoutStream <<< job.displayInputs.map { "\"" + $0.file.name + "\"" }.joined(separator: ", ")
1644+
stdoutStream.send(#"# ""#).send(targetTriple.triple)
1645+
stdoutStream.send(#"" - ""#).send(job.tool.basename)
1646+
stdoutStream.send(#"", inputs: ["#)
1647+
stdoutStream.send(job.displayInputs.map { "\"" + $0.file.name + "\"" }.joined(separator: ", "))
16471648

1648-
stdoutStream <<< "], output: {"
1649+
stdoutStream.send("], output: {")
16491650

1650-
stdoutStream <<< job.outputs.map { $0.type.name + ": \"" + $0.file.name + "\"" }.joined(separator: ", ")
1651+
stdoutStream.send(job.outputs.map { $0.type.name + ": \"" + $0.file.name + "\"" }.joined(separator: ", "))
16511652

1652-
stdoutStream <<< "}"
1653-
stdoutStream <<< "\n"
1653+
stdoutStream.send("}\n")
16541654
stdoutStream.flush()
16551655
}
16561656

@@ -1721,36 +1721,36 @@ extension Driver {
17211721
}
17221722

17231723
// Print current Job
1724-
stdoutStream <<< nextId <<< ": " <<< job.kind.rawValue <<< ", {"
1724+
stdoutStream.send("\(nextId): ").send(job.kind.rawValue).send(", {")
17251725
switch job.kind {
17261726
// Don't sort for compile jobs. Puts pch last
17271727
case .compile:
1728-
stdoutStream <<< inputIds.map(\.description).joined(separator: ", ")
1728+
stdoutStream.send(inputIds.map(\.description).joined(separator: ", "))
17291729
default:
1730-
stdoutStream <<< inputIds.sorted().map(\.description).joined(separator: ", ")
1730+
stdoutStream.send(inputIds.sorted().map(\.description).joined(separator: ", "))
17311731
}
17321732
var typeName = job.outputs.first?.type.name
17331733
if typeName == nil {
17341734
typeName = "none"
17351735
}
1736-
stdoutStream <<< "}, " <<< typeName! <<< "\n"
1736+
stdoutStream.send("}, \(typeName!)\n")
17371737
jobIdMap[job] = nextId
17381738
nextId += 1
17391739
}
17401740
}
17411741

17421742
private static func printInputIfNew(_ input: TypedVirtualPath, inputIdMap: inout [TypedVirtualPath: UInt], nextId: inout UInt) {
17431743
if inputIdMap[input] == nil {
1744-
stdoutStream <<< nextId <<< ": " <<< "input, "
1745-
stdoutStream <<< "\"" <<< input.file <<< "\", " <<< input.type <<< "\n"
1744+
stdoutStream.send("\(nextId): input, ")
1745+
stdoutStream.send("\"\(input.file)\", \(input.type)\n")
17461746
inputIdMap[input] = nextId
17471747
nextId += 1
17481748
}
17491749
}
17501750

17511751
private func printVersion<S: OutputByteStream>(outputStream: inout S) throws {
1752-
outputStream <<< frontendTargetInfo.compilerVersion <<< "\n"
1753-
outputStream <<< "Target: \(frontendTargetInfo.target.triple.triple)\n"
1752+
outputStream.send("\(frontendTargetInfo.compilerVersion)\n")
1753+
outputStream.send("Target: \(frontendTargetInfo.target.triple.triple)\n")
17541754
outputStream.flush()
17551755
}
17561756
}
@@ -2007,9 +2007,9 @@ extension Driver {
20072007
let filePath = VirtualPath.absolute(absPath.appending(component: "main.swift"))
20082008

20092009
try fileSystem.writeFileContents(filePath) { file in
2010-
file <<< ###"#sourceLocation(file: "-e", line: 1)\###n"###
2010+
file.send(###"#sourceLocation(file: "-e", line: 1)\###n"###)
20112011
for option in parsedOptions.arguments(for: .e) {
2012-
file <<< option.argument.asSingle <<< "\n"
2012+
file.send("\(option.argument.asSingle)\n")
20132013
}
20142014
}
20152015

Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Musl
2323
#error("Missing libc or equivalent")
2424
#endif
2525

26-
import TSCBasic // <<<
2726
import class TSCBasic.DiagnosticsEngine
2827
import struct TSCBasic.Diagnostic
2928
import struct TSCBasic.ProcessResult
@@ -79,7 +78,7 @@ import var TSCBasic.stdoutStream
7978
case .regular, .silent:
8079
break
8180
case .verbose:
82-
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
81+
stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n")
8382
stdoutStream.flush()
8483
case .parsableOutput:
8584
let messages = constructJobBeganMessages(job: job, arguments: arguments, pid: pid)
@@ -114,7 +113,7 @@ import var TSCBasic.stdoutStream
114113
let output = (try? result.utf8Output() + result.utf8stderrOutput()) ?? ""
115114
if !output.isEmpty {
116115
Driver.stdErrQueue.sync {
117-
stderrStream <<< output
116+
stderrStream.send(output)
118117
stderrStream.flush()
119118
}
120119
}
@@ -169,8 +168,13 @@ import var TSCBasic.stdoutStream
169168
// FIXME: Do we need to do error handling here? Can this even fail?
170169
guard let json = try? message.toJSON() else { return }
171170
Driver.stdErrQueue.sync {
172-
stderrStream <<< json.count <<< "\n"
173-
stderrStream <<< String(data: json, encoding: .utf8)! <<< "\n"
171+
stderrStream.send(
172+
"""
173+
\(json.count)
174+
\(String(data: json, encoding: .utf8)!)
175+
176+
"""
177+
)
174178
stderrStream.flush()
175179
}
176180
}

Sources/SwiftDriver/Execution/ArgsResolver.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import class Foundation.NSLock
1414

15-
import TSCBasic // <<<
1615
import func TSCBasic.withTemporaryDirectory
1716
import protocol TSCBasic.FileSystem
1817
import struct TSCBasic.AbsolutePath
@@ -50,7 +49,7 @@ public final class ArgsResolver {
5049
// FIXME: withTemporaryDirectory uses FileManager.default, need to create a FileSystem.temporaryDirectory api.
5150
let tmpDir: AbsolutePath = try withTemporaryDirectory(removeTreeOnDeinit: false) { path in
5251
// FIXME: TSC removes empty directories even when removeTreeOnDeinit is false. This seems like a bug.
53-
try fileSystem.writeFileContents(path.appending(component: ".keep-directory")) { $0 <<< "" }
52+
try fileSystem.writeFileContents(path.appending(component: ".keep-directory")) { $0.send("") }
5453
return path
5554
}
5655
self.temporaryDirectory = .absolute(tmpDir)
@@ -152,7 +151,7 @@ public final class ArgsResolver {
152151
if let absPath = path.absolutePath {
153152
try fileSystem.writeFileContents(absPath) { out in
154153
for path in contents {
155-
try! out <<< unsafeResolve(path: path) <<< "\n"
154+
try! out.send("\(unsafeResolve(path: path))\n")
156155
}
157156
}
158157
}
@@ -167,13 +166,13 @@ public final class ArgsResolver {
167166
// and the frontend (llvm) only seems to support implicit block format.
168167
try fileSystem.writeFileContents(absPath) { out in
169168
for (input, map) in outputFileMap.entries {
170-
out <<< quoteAndEscape(path: VirtualPath.lookup(input)) <<< ":"
169+
out.send("\(quoteAndEscape(path: VirtualPath.lookup(input))):")
171170
if map.isEmpty {
172-
out <<< " {}\n"
171+
out.send(" {}\n")
173172
} else {
174-
out <<< "\n"
173+
out.send("\n")
175174
for (type, output) in map {
176-
out <<< " " <<< type.name <<< ": " <<< quoteAndEscape(path: VirtualPath.lookup(output)) <<< "\n"
175+
out.send(" \(type.name): \(quoteAndEscape(path: VirtualPath.lookup(output)))\n")
177176
}
178177
}
179178
}
@@ -213,7 +212,7 @@ public final class ArgsResolver {
213212
// Wrap all arguments in double quotes to ensure that both Unix and
214213
// Windows tools understand the response file.
215214
try fileSystem.writeFileContents(absPath) {
216-
$0 <<< resolvedArguments[1...].map { quote($0) }.joined(separator: "\n")
215+
$0.send(resolvedArguments[1...].map { quote($0) }.joined(separator: "\n"))
217216
}
218217
resolvedArguments = [resolvedArguments[0], "@\(absPath.pathString)"]
219218
}

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import TSCBasic // <<<
1413
import protocol TSCBasic.FileSystem
1514
import struct TSCBasic.AbsolutePath
1615
import struct TSCBasic.Diagnostic
@@ -49,7 +48,7 @@ extension Diagnostic.Message {
4948
var dependencyGraph = try performDependencyScan()
5049

5150
if parsedOptions.hasArgument(.printPreprocessedExplicitDependencyGraph) {
52-
try stdoutStream <<< dependencyGraph.toJSONString()
51+
try stdoutStream.send(dependencyGraph.toJSONString())
5352
stdoutStream.flush()
5453
}
5554

@@ -68,7 +67,7 @@ extension Diagnostic.Message {
6867
if parsedOptions.hasArgument(.printExplicitDependencyGraph) {
6968
let outputFormat = parsedOptions.getLastArgument(.explicitDependencyGraphFormat)?.asSingle
7069
if outputFormat == nil || outputFormat == "json" {
71-
try stdoutStream <<< dependencyGraph.toJSONString()
70+
try stdoutStream.send(dependencyGraph.toJSONString())
7271
} else if outputFormat == "dot" {
7372
DOTModuleDependencyGraphSerializer(dependencyGraph).writeDOT(to: &stdoutStream)
7473
}
@@ -224,7 +223,7 @@ public extension Driver {
224223
if parsedOptions.contains(.v) {
225224
let arguments: [String] = try executor.resolver.resolveArgumentList(for: scannerJob,
226225
useResponseFiles: .disabled)
227-
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
226+
stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n")
228227
stdoutStream.flush()
229228
}
230229

Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import TSCBasic // <<<
1413
import protocol TSCBasic.WritableByteStream
1514

1615
// MARK: - Asking to write dot files / interface
@@ -126,7 +125,7 @@ extension ModuleDependencyGraph.Node: ExportableNode {
126125

127126
extension ExportableNode {
128127
fileprivate func emit(id: Int, to out: inout WritableByteStream, _ t: InternedStringTable) {
129-
out <<< DotFileNode(id: id, node: self, in: t).description <<< "\n"
128+
out.send("\(DotFileNode(id: id, node: self, in: t).description)\n")
130129
}
131130

132131
fileprivate func label(in t: InternedStringTable) -> String {
@@ -225,11 +224,11 @@ fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph>: Interne
225224
}
226225

227226
private func emitPrelude() {
228-
out <<< "digraph " <<< graphID.quoted <<< " {\n"
227+
out.send("digraph \(graphID.quoted) {\n")
229228
}
230229
private mutating func emitLegend() {
231230
for dummy in DependencyKey.Designator.oneOfEachKind {
232-
out <<< DotFileNode(forLegend: dummy).description <<< "\n"
231+
out.send("\(DotFileNode(forLegend: dummy).description)\n")
233232
}
234233
}
235234
private mutating func emitNodes() {
@@ -250,12 +249,12 @@ fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph>: Interne
250249
private func emitArcs() {
251250
graph.forEachExportableArc { (def: Graph.Node, use: Graph.Node) in
252251
if include(def: def, use: use) {
253-
out <<< DotFileArc(defID: nodeIDs[def]!, useID: nodeIDs[use]!).description <<< "\n"
252+
out.send("\(DotFileArc(defID: nodeIDs[def]!, useID: nodeIDs[use]!).description)\n")
254253
}
255254
}
256255
}
257256
private func emitPostlude() {
258-
out <<< "\n}\n"
257+
out.send("\n}\n")
259258
}
260259

261260
func include(_ n: Graph.Node) -> Bool {

Sources/SwiftDriver/Jobs/Planning.swift

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import SwiftOptions
1414
import class Foundation.JSONDecoder
1515

16-
import TSCBasic // <<<
1716
import protocol TSCBasic.DiagnosticData
1817
import struct TSCBasic.AbsolutePath
1918
import struct TSCBasic.Diagnostic

0 commit comments

Comments
 (0)