@@ -219,6 +219,9 @@ public struct Driver {
219
219
. appending ( component: filename + " .priors " )
220
220
}
221
221
222
+ /// Whether to consider incremental compilation.
223
+ let shouldAttemptIncrementalCompilation : Bool
224
+
222
225
/// Code & data for incremental compilation. Nil if not running in incremental mode.
223
226
/// Set during planning because needs the jobs to look at outputs.
224
227
@_spi ( Testing) public private( set) var incrementalCompilationState : IncrementalCompilationState ? = nil
@@ -246,6 +249,9 @@ public struct Driver {
246
249
247
250
/// Path to the dependencies file.
248
251
let dependenciesFilePath : VirtualPath ?
252
+
253
+ /// Path to the references dependencies file.
254
+ let referenceDependenciesPath : VirtualPath ?
249
255
250
256
/// Path to the serialized diagnostics file.
251
257
let serializedDiagnosticsFilePath : VirtualPath ?
@@ -376,6 +382,10 @@ public struct Driver {
376
382
377
383
// Determine the compilation mode.
378
384
self . compilerMode = try Self . computeCompilerMode ( & parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
385
+
386
+ self . shouldAttemptIncrementalCompilation = Self . shouldAttemptIncrementalCompilation ( & parsedOptions,
387
+ diagnosticEngine: diagnosticsEngine,
388
+ compilerMode: compilerMode)
379
389
380
390
// Compute the working directory.
381
391
workingDirectory = try parsedOptions. getLastArgument ( . workingDirectory) . map { workingDirectoryArg in
@@ -411,7 +421,7 @@ public struct Driver {
411
421
swiftCompilerPrefixArgs: self . swiftCompilerPrefixArgs)
412
422
413
423
// Classify and collect all of the input files.
414
- let inputFiles = try Self . collectInputFiles ( & self . parsedOptions)
424
+ let inputFiles = try Self . collectInputFiles ( & self . parsedOptions, diagnosticsEngine : diagnosticsEngine )
415
425
self . inputFiles = inputFiles
416
426
self . recordedInputModificationDates = . init( uniqueKeysWithValues:
417
427
Set ( inputFiles) . compactMap {
@@ -533,6 +543,13 @@ public struct Driver {
533
543
compilerMode: compilerMode,
534
544
outputFileMap: self . outputFileMap,
535
545
moduleName: moduleOutputInfo. name)
546
+ self . referenceDependenciesPath = try Self . computeSupplementaryOutputPath (
547
+ & parsedOptions, type: . swiftDeps, isOutputOptions: shouldAttemptIncrementalCompilation ? [ . incremental] : [ ] ,
548
+ outputPath: . emitReferenceDependenciesPath,
549
+ compilerOutputType: compilerOutputType,
550
+ compilerMode: compilerMode,
551
+ outputFileMap: self . outputFileMap,
552
+ moduleName: moduleOutputInfo. name)
536
553
self . serializedDiagnosticsFilePath = try Self . computeSupplementaryOutputPath (
537
554
& parsedOptions, type: . diagnostics, isOutputOptions: [ . serializeDiagnostics] ,
538
555
outputPath: . serializeDiagnosticsPath,
@@ -1314,7 +1331,8 @@ extension Driver {
1314
1331
}
1315
1332
1316
1333
/// Collect all of the input files from the parsed options, translating them into input files.
1317
- private static func collectInputFiles( _ parsedOptions: inout ParsedOptions ) throws -> [ TypedVirtualPath ] {
1334
+ private static func collectInputFiles( _ parsedOptions: inout ParsedOptions , diagnosticsEngine: DiagnosticsEngine ) throws -> [ TypedVirtualPath ] {
1335
+ var swiftFiles = [ String: String] ( ) // [Basename: Path]
1318
1336
return try parsedOptions. allInputs. map { input in
1319
1337
// Standard input is assumed to be Swift code.
1320
1338
if input == " - " {
@@ -1330,6 +1348,17 @@ extension Driver {
1330
1348
// FIXME: The object-file default is carried over from the existing
1331
1349
// driver, but seems odd.
1332
1350
let fileType = FileType ( rawValue: fileExtension) ?? FileType . object
1351
+
1352
+ if fileType == . swift {
1353
+ let basename = file. basename
1354
+ if let originalPath = swiftFiles [ basename] {
1355
+ diagnosticsEngine. emit ( . error_two_files_same_name( basename: basename, firstPath: originalPath, secondPath: input) )
1356
+ diagnosticsEngine. emit ( . note_explain_two_files_same_name)
1357
+ throw Diagnostics . fatalError
1358
+ } else {
1359
+ swiftFiles [ basename] = input
1360
+ }
1361
+ }
1333
1362
1334
1363
return TypedVirtualPath ( file: file, type: fileType)
1335
1364
}
@@ -1453,6 +1482,14 @@ extension Diagnostic.Message {
1453
1482
static var warn_ignore_embed_bitcode_marker : Diagnostic . Message {
1454
1483
. warning( " ignoring -embed-bitcode-marker since no object file is being generated " )
1455
1484
}
1485
+
1486
+ static func error_two_files_same_name( basename: String , firstPath: String , secondPath: String ) -> Diagnostic . Message {
1487
+ . error( " filename \" \( basename) \" used twice: ' \( firstPath) ' and ' \( secondPath) ' " )
1488
+ }
1489
+
1490
+ static var note_explain_two_files_same_name : Diagnostic . Message {
1491
+ . note( " filenames are used to distinguish private declarations with the same name " )
1492
+ }
1456
1493
}
1457
1494
1458
1495
// Multithreading
@@ -2288,8 +2325,7 @@ extension Driver {
2288
2325
compilerOutputType: FileType ? ,
2289
2326
compilerMode: CompilerMode ,
2290
2327
outputFileMap: OutputFileMap ? ,
2291
- moduleName: String ,
2292
- patternOutputFile: VirtualPath ? = nil
2328
+ moduleName: String
2293
2329
) throws -> VirtualPath ? {
2294
2330
// If there is an explicit argument for the output path, use that
2295
2331
if let outputPathArg = parsedOptions. getLastArgument ( outputPath) {
0 commit comments