@@ -430,11 +430,6 @@ private func adjustSwiftCompilerArgumentsForIndexStoreUpdate(
430430 . option( " output-file-map " , [ . singleDash] , [ . separatedBySpace, . separatedByEqualSign] ) ,
431431 ]
432432
433- let removeFrontendFlags = [
434- " -experimental-skip-non-inlinable-function-bodies " ,
435- " -experimental-skip-all-function-bodies " ,
436- ]
437-
438433 var result : [ String ] = [ ]
439434 result. reserveCapacity ( compilerArguments. count)
440435 var iterator = compilerArguments. makeIterator ( )
@@ -448,18 +443,14 @@ private func adjustSwiftCompilerArgumentsForIndexStoreUpdate(
448443 case nil :
449444 break
450445 }
451- if argument == " -Xfrontend " {
452- if let nextArgument = iterator. next ( ) {
453- if removeFrontendFlags. contains ( nextArgument) {
454- continue
455- }
456- result += [ argument, nextArgument]
457- continue
458- }
459- }
460446 result. append ( argument)
461447 }
448+ result += supplementalClangIndexingArgs. flatMap { [ " -Xcc " , $0] }
462449 result += [
450+ // Preparation produces modules with errors. We should allow reading them.
451+ " -Xfrontend " , " -experimental-allow-module-with-compiler-errors " ,
452+ // Avoid emitting the ABI descriptor, we don't need it
453+ " -Xfrontend " , " -empty-abi-descriptor " ,
463454 " -index-file " ,
464455 " -index-file-path " , fileToIndex. pseudoPath,
465456 // batch mode is not compatible with -index-file
@@ -520,12 +511,40 @@ private func adjustClangCompilerArgumentsForIndexStoreUpdate(
520511 }
521512 result. append ( argument)
522513 }
514+ result += supplementalClangIndexingArgs
523515 result. append (
524516 " -fsyntax-only "
525517 )
526518 return result
527519}
528520
521+ #if compiler(>=6.1)
522+ #warning(
523+ " Remove -fmodules-validate-system-headers from supplementalClangIndexingArgs once all supported Swift compilers have https://github.com/apple/swift/pull/74063 "
524+ )
525+ #endif
526+
527+ fileprivate let supplementalClangIndexingArgs : [ String ] = [
528+ // Retain extra information for indexing
529+ " -fretain-comments-from-system-headers " ,
530+ // Pick up macro definitions during indexing
531+ " -Xclang " , " -detailed-preprocessing-record " ,
532+
533+ // libclang uses 'raw' module-format. Match it so we can reuse the module cache and PCHs that libclang uses.
534+ " -Xclang " , " -fmodule-format=raw " ,
535+
536+ // Be less strict - we want to continue and typecheck/index as much as possible
537+ " -Xclang " , " -fallow-pch-with-compiler-errors " ,
538+ " -Xclang " , " -fallow-pcm-with-compiler-errors " ,
539+ " -Wno-non-modular-include-in-framework-module " ,
540+ " -Wno-incomplete-umbrella " ,
541+
542+ // sourcekitd adds `-fno-modules-validate-system-headers` before https://github.com/apple/swift/pull/74063.
543+ // This completely disables system module validation and never re-builds pcm for system modules. The intended behavior
544+ // is to only re-build those PCMs once per sourcekitd session.
545+ " -fmodules-validate-system-headers " ,
546+ ]
547+
529548fileprivate extension Sequence {
530549 /// Returns `true` if this sequence contains an element that is equal to an element in `otherSequence` when
531550 /// considering two elements as equal if they satisfy `predicate`.
0 commit comments