Skip to content

Commit 6132321

Browse files
committed
Fix for missing supplementary outputs. Also removes notion of InputOutputPair
1 parent 597fc22 commit 6132321

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
@@ -249,13 +249,14 @@ extension Driver {
249249
}
250250

251251
mutating func addFrontendSupplementaryOutputArguments(commandLine: inout [Job.ArgTemplate],
252-
primaryInputOutputPairs: [InputOutputPair]) throws -> [TypedVirtualPath] {
253-
var flaggedInputOutputPairs: [(flag: String, InputOutputPair)] = []
252+
primaryInputs: [TypedVirtualPath],
253+
inputOutputMap: [TypedVirtualPath: TypedVirtualPath]) throws -> [TypedVirtualPath] {
254+
var flaggedInputOutputPairs: [(flag: String, input: TypedVirtualPath?, output: TypedVirtualPath)] = []
254255

255256
/// Add output of a particular type, if needed.
256257
func addOutputOfType(
257258
outputType: FileType, finalOutputPath: VirtualPath?,
258-
primaryPair: InputOutputPair?, flag: String
259+
input: TypedVirtualPath?, flag: String
259260
) {
260261
// If there is no final output, there's nothing to do.
261262
guard let finalOutputPath = finalOutputPath else { return }
@@ -267,125 +268,127 @@ extension Driver {
267268
// Compute the output path based on the input path (if there is one), or
268269
// use the final output.
269270
let outputPath: VirtualPath
270-
if let pair = primaryPair, let input = pair.input {
271+
if let input = input {
271272
if let outputFileMapPath = outputFileMap?.existingOutput(inputFile: input.file, outputType: outputType) {
272273
outputPath = outputFileMapPath
273-
} else if compilerOutputType != nil {
274+
} else if let output = inputOutputMap[input], compilerOutputType != nil {
274275
// Alongside primary output
275-
outputPath = pair.output.file.replacingExtension(with: outputType)
276+
outputPath = output.file.replacingExtension(with: outputType)
276277
} else {
277278
outputPath = .temporary(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(outputType)))
278279
}
279280
} else {
280281
outputPath = finalOutputPath
281282
}
282283

283-
flaggedInputOutputPairs.append((flag: flag, InputOutputPair(input: primaryPair?.input, output: TypedVirtualPath(file: outputPath, type: outputType))))
284+
flaggedInputOutputPairs.append((flag: flag, input: input, output: TypedVirtualPath(file: outputPath, type: outputType)))
284285
}
285286

286287
/// Add all of the outputs needed for a given input.
287-
func addAllOutputsFor(primaryPair: InputOutputPair?) {
288+
func addAllOutputsFor(input: TypedVirtualPath?) {
288289
if !forceEmitModuleInSingleInvocation {
289290
addOutputOfType(
290291
outputType: .swiftModule,
291292
finalOutputPath: moduleOutputInfo.output?.outputPath,
292-
primaryPair: primaryPair,
293+
input: input,
293294
flag: "-emit-module-path")
294295
addOutputOfType(
295296
outputType: .swiftDocumentation,
296297
finalOutputPath: moduleDocOutputPath,
297-
primaryPair: primaryPair,
298+
input: input,
298299
flag: "-emit-module-doc-path")
299300
addOutputOfType(
300301
outputType: .swiftSourceInfoFile,
301302
finalOutputPath: moduleSourceInfoPath,
302-
primaryPair: primaryPair,
303+
input: input,
303304
flag: "-emit-module-source-info-path")
304305
addOutputOfType(
305306
outputType: .dependencies,
306307
finalOutputPath: dependenciesFilePath,
307-
primaryPair: primaryPair,
308+
input: input,
308309
flag: "-emit-dependencies-path")
309310
}
310311

311312
addOutputOfType(
312313
outputType: .yamlOptimizationRecord,
313314
finalOutputPath: optimizationRecordPath,
314-
primaryPair: primaryPair,
315+
input: input,
315316
flag: "-save-optimization-record-path")
316317

317318
addOutputOfType(
318319
outputType: .diagnostics,
319320
finalOutputPath: serializedDiagnosticsFilePath,
320-
primaryPair: primaryPair,
321+
input: input,
321322
flag: "-serialize-diagnostics-path")
322323

323324
#if false
324325
// FIXME: handle -update-code
325-
addOutputOfType(outputType: .remap, input: input.file, flag: "-emit-remap-file-path")
326+
addOutputOfType(outputType: .remap, input: input, flag: "-emit-remap-file-path")
326327
#endif
327328
}
328329

329330
if compilerMode.usesPrimaryFileInputs {
330-
for pair in primaryInputOutputPairs {
331-
addAllOutputsFor(primaryPair: pair)
331+
for input in primaryInputs {
332+
addAllOutputsFor(input: input)
332333
}
333334
} else {
334-
addAllOutputsFor(primaryPair: nil)
335+
addAllOutputsFor(input: nil)
335336

336337
// Outputs that only make sense when the whole module is processed
337338
// together.
338339
addOutputOfType(
339340
outputType: .objcHeader,
340341
finalOutputPath: objcGeneratedHeaderPath,
341-
primaryPair: nil,
342+
input: nil,
342343
flag: "-emit-objc-header-path")
343344

344345
addOutputOfType(
345346
outputType: .swiftInterface,
346347
finalOutputPath: swiftInterfacePath,
347-
primaryPair: nil,
348+
input: nil,
348349
flag: "-emit-module-interface-path")
349350

350351
addOutputOfType(
351352
outputType: .tbd,
352353
finalOutputPath: tbdPath,
353-
primaryPair: nil,
354+
input: nil,
354355
flag: "-emit-tbd-path")
355356
}
356357

357358
// Question: outputs.count > fileListThreshold makes sense, but c++ does the following:
358-
if primaryInputOutputPairs.count * FileType.allCases.count > fileListThreshold {
359+
if primaryInputs.count * FileType.allCases.count > fileListThreshold {
359360
var entries = [VirtualPath: [FileType: VirtualPath]]()
360-
for pair in primaryInputOutputPairs {
361-
addEntry(&entries, for: pair)
361+
for input in primaryInputs {
362+
if let output = inputOutputMap[input] {
363+
addEntry(&entries, input: input, output: output)
364+
}
362365
}
363-
for output in flaggedInputOutputPairs {
364-
addEntry(&entries, for: output.1)
366+
for flaggedPair in flaggedInputOutputPairs {
367+
addEntry(&entries, input: flaggedPair.input, output: flaggedPair.output)
365368
}
366369
let outputFileMap = OutputFileMap(entries: entries)
367370
let path = RelativePath(createTemporaryFileName(prefix: "supplementaryOutputs"))
368371
commandLine.appendFlag(.supplementaryOutputFileMap)
369372
commandLine.appendPath(.fileList(path, .outputFileMap(outputFileMap)))
370373
} else {
371-
for output in flaggedInputOutputPairs {
374+
for flaggedPair in flaggedInputOutputPairs {
372375
// Add the appropriate flag.
373-
commandLine.appendFlag(output.flag)
374-
commandLine.appendPath(output.1.output.file)
376+
commandLine.appendFlag(flaggedPair.flag)
377+
commandLine.appendPath(flaggedPair.output.file)
375378
}
376379
}
377380

378-
return flaggedInputOutputPairs.map { $0.1.output }
381+
return flaggedInputOutputPairs.map { $0.output }
379382
}
380383

381-
func addEntry(_ entries: inout [VirtualPath: [FileType: VirtualPath]], for pair: InputOutputPair) {
384+
func addEntry(_ entries: inout [VirtualPath: [FileType: VirtualPath]], input: TypedVirtualPath?, output: TypedVirtualPath) {
382385
let entryInput: VirtualPath
383-
if let input = pair.input?.file, input != OutputFileMap.singleInputKey {
386+
if let input = input?.file, input != OutputFileMap.singleInputKey {
384387
entryInput = input
385388
} else {
386389
entryInput = inputFiles[0].file
387390
}
388-
entries[entryInput, default: [:]][pair.output.type] = pair.output.file
391+
entries[entryInput, default: [:]][output.type] = output.file
389392
}
390393

391394
/// 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)