Skip to content

Indexing: include index file entry in supplementary output file map #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/CompileJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ extension Driver {
primaryInputs: primaryInputs,
inputsGeneratingCodeCount: inputsGeneratingCodeCount,
inputOutputMap: inputOutputMap,
includeModuleTracePath: emitModuleTrace)
includeModuleTracePath: emitModuleTrace,
indexFilePath: indexFilePath)

// Forward migrator flags.
try commandLine.appendLast(.apiDiffDataFile, from: &parsedOptions)
Expand Down
8 changes: 7 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ extension Driver {
primaryInputs: [TypedVirtualPath],
inputsGeneratingCodeCount: Int,
inputOutputMap: [TypedVirtualPath: TypedVirtualPath],
includeModuleTracePath: Bool) throws -> [TypedVirtualPath] {
includeModuleTracePath: Bool,
indexFilePath: TypedVirtualPath?) throws -> [TypedVirtualPath] {
var flaggedInputOutputPairs: [(flag: String, input: TypedVirtualPath?, output: TypedVirtualPath)] = []

/// Add output of a particular type, if needed.
Expand Down Expand Up @@ -417,6 +418,11 @@ extension Driver {
for flaggedPair in flaggedInputOutputPairs {
addEntry(&entries, input: flaggedPair.input, output: flaggedPair.output)
}
// To match the legacy driver behavior, make sure we add an entry for the
// file under indexing and the primary output file path.
if let indexFilePath = indexFilePath, let idxOutput = inputOutputMap[indexFilePath] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess after 3 input source files we are going to exceed:

if inputsGeneratingCodeCount * FileType.allCases.count > fileListThreshold {

Makes sense to me!

entries[indexFilePath.file] = [.indexData: idxOutput.file]
}
let outputFileMap = OutputFileMap(entries: entries)
let path = RelativePath(createTemporaryFileName(prefix: "supplementaryOutputs"))
commandLine.appendFlag(.supplementaryOutputFileMap)
Expand Down
46 changes: 46 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,52 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(plannedJobs[1].kind, .link)
}


func testIndexFileEntryInSupplementaryFileOutputMap() throws {
var driver1 = try Driver(args: [
"swiftc", "foo1.swift", "foo2.swift", "foo3.swift", "foo4.swift", "foo5.swift",
"-index-file", "-index-file-path", "foo5.swift", "-o", "/tmp/t.o",
"-index-store-path", "/tmp/idx"
])
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
XCTAssertEqual(plannedJobs.count, 1)
let suppleArg = "-supplementary-output-file-map"
// Make sure we are using supplementary file map
XCTAssert(plannedJobs[0].commandLine.contains(.flag(suppleArg)))
let args = plannedJobs[0].commandLine
var fileMapPath: VirtualPath?
for pair in args.enumerated() {
if pair.element == .flag(suppleArg) {
let filemap = args[pair.offset + 1]
switch filemap {
case .path(let p):
fileMapPath = p
default:
break
}
}
}
XCTAssert(fileMapPath != nil)
switch fileMapPath! {
case .fileList(_, let list):
switch list {
case .outputFileMap(let map):
// This is to match the legacy driver behavior
// Make sure the supplementary output map has an entry for the Swift file
// under indexing and its indexData entry is the primary output file
let entry = map.entries[VirtualPath.relative(RelativePath("foo5.swift"))]!
XCTAssert(entry[.indexData]! == .absolute(AbsolutePath("/tmp/t.o")))
return
default:
break
}
break
default:
break
}
XCTAssert(false)
}

func testMultiThreadedWholeModuleOptimizationCompiles() throws {
do {
var driver1 = try Driver(args: [
Expand Down