Skip to content

Commit dd4b4b1

Browse files
committed
Fix for missing supplementary outputs. Also removes notion of InputOutputPair
1 parent 4768b9e commit dd4b4b1

File tree

3 files changed

+52
-59
lines changed

3 files changed

+52
-59
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ extension Driver {
7979
/// corresponding primary set of outputs.
8080
mutating func addCompileInputs(primaryInputs: [TypedVirtualPath],
8181
inputs: inout [TypedVirtualPath],
82+
inputOutputMap: inout [TypedVirtualPath: TypedVirtualPath],
8283
outputType: FileType?,
83-
commandLine: inout [Job.ArgTemplate]) -> [InputOutputPair] {
84+
commandLine: inout [Job.ArgTemplate]) -> [TypedVirtualPath] {
8485
// Collect the set of input files that are part of the Swift compilation.
8586
let swiftInputFiles: [TypedVirtualPath] = inputFiles.filter { $0.type.isPartOfSwiftCompilation }
8687

@@ -112,7 +113,7 @@ extension Driver {
112113
let isMultithreaded = numThreads > 0
113114

114115
// Add each of the input files.
115-
var primaryOutputs: [InputOutputPair] = []
116+
var primaryOutputs: [TypedVirtualPath] = []
116117
for input in swiftInputFiles {
117118
inputs.append(input)
118119

@@ -135,7 +136,8 @@ extension Driver {
135136
let output = computePrimaryOutput(for: input,
136137
outputType: outputType,
137138
isTopLevel: isTopLevel)
138-
primaryOutputs.append(InputOutputPair(input: input, output: output))
139+
primaryOutputs.append(output)
140+
inputOutputMap[input] = output
139141
}
140142
}
141143

@@ -146,7 +148,8 @@ extension Driver {
146148
let output = computePrimaryOutput(for: input,
147149
outputType: outputType,
148150
isTopLevel: isTopLevel)
149-
primaryOutputs.append(InputOutputPair(input: input, output: output))
151+
primaryOutputs.append(output)
152+
inputOutputMap[input] = output
150153
}
151154

152155
return primaryOutputs
@@ -158,14 +161,16 @@ extension Driver {
158161
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
159162
var inputs: [TypedVirtualPath] = []
160163
var outputs: [TypedVirtualPath] = []
164+
// Used to map primaryInputs to primaryOutputs
165+
var inputOutputMap = [TypedVirtualPath: TypedVirtualPath]()
161166

162167
commandLine.appendFlag("-frontend")
163168
addCompileModeOption(outputType: outputType, commandLine: &commandLine)
164-
let primaryInputOutputPairs = addCompileInputs(primaryInputs: primaryInputs,
165-
inputs: &inputs,
166-
outputType: outputType,
167-
commandLine: &commandLine)
168-
let primaryOutputs = primaryInputOutputPairs.map { $0.output }
169+
let primaryOutputs = addCompileInputs(primaryInputs: primaryInputs,
170+
inputs: &inputs,
171+
inputOutputMap: &inputOutputMap,
172+
outputType: outputType,
173+
commandLine: &commandLine)
169174
outputs += primaryOutputs
170175

171176
// FIXME: optimization record arguments are added before supplementary outputs
@@ -178,7 +183,8 @@ extension Driver {
178183
try commandLine.appendLast(.saveOptimizationRecordPasses, from: &parsedOptions)
179184

180185
outputs += try addFrontendSupplementaryOutputArguments(commandLine: &commandLine,
181-
primaryInputOutputPairs: primaryInputOutputPairs)
186+
primaryInputs: primaryInputs,
187+
inputOutputMap: inputOutputMap)
182188

183189
// Forward migrator flags.
184190
try commandLine.appendLast(.apiDiffDataFile, from: &parsedOptions)

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ extension Driver {
237237
}
238238

239239
mutating func addFrontendSupplementaryOutputArguments(commandLine: inout [Job.ArgTemplate],
240-
primaryInputOutputPairs: [InputOutputPair]) throws -> [TypedVirtualPath] {
241-
var flaggedInputOutputPairs: [(flag: String, InputOutputPair)] = []
240+
primaryInputs: [TypedVirtualPath],
241+
inputOutputMap: [TypedVirtualPath: TypedVirtualPath]) throws -> [TypedVirtualPath] {
242+
var flaggedInputOutputPairs: [(flag: String, input: TypedVirtualPath?, output: TypedVirtualPath)] = []
242243

243244
/// Add output of a particular type, if needed.
244245
func addOutputOfType(
245246
outputType: FileType, finalOutputPath: VirtualPath?,
246-
primaryPair: InputOutputPair?, flag: String
247+
input: TypedVirtualPath?, flag: String
247248
) {
248249
// If there is no final output, there's nothing to do.
249250
guard let finalOutputPath = finalOutputPath else { return }
@@ -255,125 +256,127 @@ extension Driver {
255256
// Compute the output path based on the input path (if there is one), or
256257
// use the final output.
257258
let outputPath: VirtualPath
258-
if let pair = primaryPair, let input = pair.input {
259+
if let input = input {
259260
if let outputFileMapPath = outputFileMap?.existingOutput(inputFile: input.file, outputType: outputType) {
260261
outputPath = outputFileMapPath
261-
} else if compilerOutputType != nil {
262+
} else if let output = inputOutputMap[input], compilerOutputType != nil {
262263
// Alongside primary output
263-
outputPath = pair.output.file.replacingExtension(with: outputType)
264+
outputPath = output.file.replacingExtension(with: outputType)
264265
} else {
265266
outputPath = .temporary(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(outputType)))
266267
}
267268
} else {
268269
outputPath = finalOutputPath
269270
}
270271

271-
flaggedInputOutputPairs.append((flag: flag, InputOutputPair(input: primaryPair?.input, output: TypedVirtualPath(file: outputPath, type: outputType))))
272+
flaggedInputOutputPairs.append((flag: flag, input: input, output: TypedVirtualPath(file: outputPath, type: outputType)))
272273
}
273274

274275
/// Add all of the outputs needed for a given input.
275-
func addAllOutputsFor(primaryPair: InputOutputPair?) {
276+
func addAllOutputsFor(input: TypedVirtualPath?) {
276277
if !forceEmitModuleInSingleInvocation {
277278
addOutputOfType(
278279
outputType: .swiftModule,
279280
finalOutputPath: moduleOutputInfo.output?.outputPath,
280-
primaryPair: primaryPair,
281+
input: input,
281282
flag: "-emit-module-path")
282283
addOutputOfType(
283284
outputType: .swiftDocumentation,
284285
finalOutputPath: moduleDocOutputPath,
285-
primaryPair: primaryPair,
286+
input: input,
286287
flag: "-emit-module-doc-path")
287288
addOutputOfType(
288289
outputType: .swiftSourceInfoFile,
289290
finalOutputPath: moduleSourceInfoPath,
290-
primaryPair: primaryPair,
291+
input: input,
291292
flag: "-emit-module-source-info-path")
292293
addOutputOfType(
293294
outputType: .dependencies,
294295
finalOutputPath: dependenciesFilePath,
295-
primaryPair: primaryPair,
296+
input: input,
296297
flag: "-emit-dependencies-path")
297298
}
298299

299300
addOutputOfType(
300301
outputType: .yamlOptimizationRecord,
301302
finalOutputPath: optimizationRecordPath,
302-
primaryPair: primaryPair,
303+
input: input,
303304
flag: "-save-optimization-record-path")
304305

305306
addOutputOfType(
306307
outputType: .diagnostics,
307308
finalOutputPath: serializedDiagnosticsFilePath,
308-
primaryPair: primaryPair,
309+
input: input,
309310
flag: "-serialize-diagnostics-path")
310311

311312
#if false
312313
// FIXME: handle -update-code
313-
addOutputOfType(outputType: .remap, input: input.file, flag: "-emit-remap-file-path")
314+
addOutputOfType(outputType: .remap, input: input, flag: "-emit-remap-file-path")
314315
#endif
315316
}
316317

317318
if compilerMode.usesPrimaryFileInputs {
318-
for pair in primaryInputOutputPairs {
319-
addAllOutputsFor(primaryPair: pair)
319+
for input in primaryInputs {
320+
addAllOutputsFor(input: input)
320321
}
321322
} else {
322-
addAllOutputsFor(primaryPair: nil)
323+
addAllOutputsFor(input: nil)
323324

324325
// Outputs that only make sense when the whole module is processed
325326
// together.
326327
addOutputOfType(
327328
outputType: .objcHeader,
328329
finalOutputPath: objcGeneratedHeaderPath,
329-
primaryPair: nil,
330+
input: nil,
330331
flag: "-emit-objc-header-path")
331332

332333
addOutputOfType(
333334
outputType: .swiftInterface,
334335
finalOutputPath: swiftInterfacePath,
335-
primaryPair: nil,
336+
input: nil,
336337
flag: "-emit-module-interface-path")
337338

338339
addOutputOfType(
339340
outputType: .tbd,
340341
finalOutputPath: tbdPath,
341-
primaryPair: nil,
342+
input: nil,
342343
flag: "-emit-tbd-path")
343344
}
344345

345346
// Question: outputs.count > fileListThreshold makes sense, but c++ does the following:
346-
if primaryInputOutputPairs.count * FileType.allCases.count > fileListThreshold {
347+
if primaryInputs.count * FileType.allCases.count > fileListThreshold {
347348
var entries = [VirtualPath: [FileType: VirtualPath]]()
348-
for pair in primaryInputOutputPairs {
349-
addEntry(&entries, for: pair)
349+
for input in primaryInputs {
350+
if let output = inputOutputMap[input] {
351+
addEntry(&entries, input: input, output: output)
352+
}
350353
}
351-
for output in flaggedInputOutputPairs {
352-
addEntry(&entries, for: output.1)
354+
for flaggedPair in flaggedInputOutputPairs {
355+
addEntry(&entries, input: flaggedPair.input, output: flaggedPair.output)
353356
}
354357
let outputFileMap = OutputFileMap(entries: entries)
355358
let path = RelativePath(createTemporaryFileName(prefix: "supplementaryOutputs"))
356359
commandLine.appendFlag(.supplementaryOutputFileMap)
357360
commandLine.appendPath(.fileList(path, .outputFileMap(outputFileMap)))
358361
} else {
359-
for output in flaggedInputOutputPairs {
362+
for flaggedPair in flaggedInputOutputPairs {
360363
// Add the appropriate flag.
361-
commandLine.appendFlag(output.flag)
362-
commandLine.appendPath(output.1.output.file)
364+
commandLine.appendFlag(flaggedPair.flag)
365+
commandLine.appendPath(flaggedPair.output.file)
363366
}
364367
}
365368

366-
return flaggedInputOutputPairs.map { $0.1.output }
369+
return flaggedInputOutputPairs.map { $0.output }
367370
}
368371

369-
func addEntry(_ entries: inout [VirtualPath: [FileType: VirtualPath]], for pair: InputOutputPair) {
372+
func addEntry(_ entries: inout [VirtualPath: [FileType: VirtualPath]], input: TypedVirtualPath?, output: TypedVirtualPath) {
370373
let entryInput: VirtualPath
371-
if let input = pair.input?.file, input != OutputFileMap.singleInputKey {
374+
if let input = input?.file, input != OutputFileMap.singleInputKey {
372375
entryInput = input
373376
} else {
374377
entryInput = inputFiles[0].file
375378
}
376-
entries[entryInput, default: [:]][pair.output.type] = pair.output.file
379+
entries[entryInput, default: [:]][output.type] = output.file
377380
}
378381

379382
/// Adds all dependencies required for an explicit module build

Sources/SwiftDriver/Utilities/InputOuputPair.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)