Skip to content

Commit 9c834d0

Browse files
committed
Revert "[Index] Add APIs to provide the recorded #includes of a unit file"
Potentially the reason for this bot failure: <rdar://problem/62609786> Swift CI: 0. OSS - Swift Incremental RA - OS X (master); IndexStoreDBTests.IndexTests testWaitUntilDoneInitializing; Assertion failed: (hasVal) This reverts commit 713db93.
1 parent e20848a commit 9c834d0

File tree

12 files changed

+30
-184
lines changed

12 files changed

+30
-184
lines changed

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public final class IndexStoreDB {
195195
@discardableResult
196196
public func forEachMainFileContainingFile(path: String, crossLanguage: Bool, body: @escaping (String) -> Bool) -> Bool {
197197
let fromSwift = path.hasSuffix(".swift")
198-
return indexstoredb_index_units_containing_file(impl, path) { unit in
199-
let mainFileStr = String(cString: indexstoredb_unit_info_main_file_path(unit))
198+
return indexstoredb_index_main_files_containing_file(impl, path) { mainFile in
199+
let mainFileStr = String(cString: mainFile)
200200
let toSwift = mainFileStr.hasSuffix(".swift")
201201
if !crossLanguage && fromSwift != toSwift {
202202
return true // continue
@@ -214,59 +214,6 @@ public final class IndexStoreDB {
214214
return result
215215
}
216216

217-
@discardableResult
218-
public func forEachUnitNameContainingFile(path: String, body: @escaping (String) -> Bool) -> Bool {
219-
return indexstoredb_index_units_containing_file(impl, path) { unit in
220-
let unitName = String(cString: indexstoredb_unit_info_unit_name(unit))
221-
return body(unitName)
222-
}
223-
}
224-
225-
public func unitNamesContainingFile(path: String) -> [String] {
226-
var result: [String] = []
227-
forEachUnitNameContainingFile(path: path) { unitName in
228-
result.append(unitName)
229-
return true
230-
}
231-
return result
232-
}
233-
234-
/// A recorded header `#include` from a unit file.
235-
public struct UnitIncludeEntry: Equatable {
236-
/// The path where the `#include` was added.
237-
public let sourcePath: String
238-
/// The path that the `#include` resolved to.
239-
public let targetPath: String
240-
/// the line where the `#include` was added.
241-
public let line: Int
242-
243-
public init(sourcePath: String, targetPath: String, line: Int) {
244-
self.sourcePath = sourcePath
245-
self.targetPath = targetPath
246-
self.line = line
247-
}
248-
}
249-
250-
/// Iterates over recorded `#include`s of a unit.
251-
@discardableResult
252-
public func forEachIncludeOfUnit(unitName: String, body: @escaping (UnitIncludeEntry) -> Bool) -> Bool {
253-
return indexstoredb_index_includes_of_unit(impl, unitName) { sourcePath, targetPath, line in
254-
let sourcePathStr = String(cString: sourcePath)
255-
let targetPathStr = String(cString: targetPath)
256-
return body(UnitIncludeEntry(sourcePath: sourcePathStr, targetPath: targetPathStr, line: line))
257-
}
258-
}
259-
260-
/// Returns the recorded `#include`s of a unit.
261-
public func includesOfUnit(unitName: String) -> [UnitIncludeEntry] {
262-
var result: [UnitIncludeEntry] = []
263-
forEachIncludeOfUnit(unitName: unitName) { entry in
264-
result.append(entry)
265-
return true
266-
}
267-
return result
268-
}
269-
270217
/// Iterates over the name of every symbol in the index.
271218
///
272219
/// - Parameter body: A closure to be called for each symbol. The closure should return true to

Tests/INPUTS/MainFiles/main1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "shared.h" /*include_main1_shared*/
2-
#include "uniq1.h" /*include_main1_uniq1*/
1+
#include "shared.h"
2+
#include "uniq1.h"
33

44
void main1(void) {
55
/*main1*/

Tests/IndexStoreDBTests/IndexTests.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,6 @@ final class IndexTests: XCTestCase {
280280
XCTAssertEqual(mainFiles(unknown, false), [])
281281
}
282282

283-
func testUnitIncludes() throws {
284-
guard let ws = try staticTibsTestWorkspace(name: "MainFiles") else { return }
285-
try ws.buildAndIndex()
286-
let index = ws.index
287-
288-
let main1 = ws.testLoc("main1").url.path
289-
let uniq1 = ws.testLoc("uniq1").url.path
290-
let shared = ws.testLoc("shared").url.path
291-
292-
let units = index.unitNamesContainingFile(path: main1)
293-
XCTAssertEqual(units.count, 1)
294-
let main1Unit = try XCTUnwrap(units.first)
295-
296-
let includes = index.includesOfUnit(unitName: main1Unit)
297-
XCTAssertEqual(includes, [
298-
IndexStoreDB.UnitIncludeEntry(sourcePath: main1, targetPath: shared, line: ws.testLoc("include_main1_shared").line),
299-
IndexStoreDB.UnitIncludeEntry(sourcePath: main1, targetPath: uniq1, line: ws.testLoc("include_main1_uniq1").line),
300-
])
301-
}
302-
303283
func testAllSymbolNames() throws {
304284
guard let ws = try staticTibsTestWorkspace(name: "proj1") else { return }
305285
try ws.buildAndIndex()

Tests/IndexStoreDBTests/XCTestManifests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ extension IndexTests {
2424
("testMainFilesContainingFile", testMainFilesContainingFile),
2525
("testMixedLangTarget", testMixedLangTarget),
2626
("testSwiftModules", testSwiftModules),
27-
("testUnitIncludes", testUnitIncludes),
2827
("testWaitUntilDoneInitializing", testWaitUntilDoneInitializing),
2928
]
3029
}

include/CIndexStoreDB/CIndexStoreDB.h

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ typedef void *indexstoredb_symbol_occurrence_t;
5757
typedef void *indexstoredb_error_t;
5858
typedef void *indexstoredb_symbol_location_t;
5959
typedef void *indexstoredb_symbol_relation_t;
60-
typedef void *indexstoredb_unit_info_t;
6160

6261
typedef enum {
6362
INDEXSTOREDB_SYMBOL_ROLE_DECLARATION = 1 << 0,
@@ -136,10 +135,7 @@ typedef bool(^indexstoredb_symbol_name_receiver)(const char *_Nonnull);
136135
typedef void(^indexstoredb_delegate_event_receiver_t)(_Nonnull indexstoredb_delegate_event_t);
137136

138137
/// Returns true to continue.
139-
typedef bool(^indexstoredb_unit_info_receiver)(_Nonnull indexstoredb_unit_info_t);
140-
141-
/// Returns true to continue.
142-
typedef bool(^indexstoredb_unit_includes_receiver)(const char *_Nonnull sourcePath, const char *_Nonnull targetPath, size_t line);
138+
typedef bool(^indexstoredb_path_receiver)(const char *_Nonnull);
143139

144140
/// Creates an index for the given raw index data in \p storePath.
145141
///
@@ -356,41 +352,20 @@ indexstoredb_symbol_occurrence_relations(_Nonnull indexstoredb_symbol_occurrence
356352
INDEXSTOREDB_PUBLIC indexstoredb_symbol_kind_t
357353
indexstoredb_symbol_kind(_Nonnull indexstoredb_symbol_t);
358354

359-
/// Returns the main file path of a unit info object.
360-
///
361-
/// The main file is typically the one that e.g. a build system would have explicit knowledge of.
362-
INDEXSTOREDB_PUBLIC const char *_Nonnull
363-
indexstoredb_unit_info_main_file_path(_Nonnull indexstoredb_unit_info_t);
364-
365-
/// Returns the unit name of a unit info object.
366-
INDEXSTOREDB_PUBLIC const char *_Nonnull
367-
indexstoredb_unit_info_unit_name(_Nonnull indexstoredb_unit_info_t);
368-
369-
/// Iterates over the compilation units that contain \p path and return their units.
355+
/// Iterates over the compilation units that contain \p path and return their main file.
370356
///
371-
/// This can be used to find information for units that include a given header.
357+
/// This can be used to find the main files that include a given header. The main file is typically
358+
/// the one that e.g. a build system would have explicit knowledge of.
372359
///
373360
/// \param index An IndexStoreDB object which contains the symbols.
374361
/// \param path The source file to search for.
375-
/// \param receiver A function to be called for each unit. The pointer is only valid for
362+
/// \param receiver A function to be called for each main file path. The string pointer is only valid for
376363
/// the duration of the call. The function should return a true to continue iterating.
377364
INDEXSTOREDB_PUBLIC bool
378-
indexstoredb_index_units_containing_file(
365+
indexstoredb_index_main_files_containing_file(
379366
_Nonnull indexstoredb_index_t index,
380367
const char *_Nonnull path,
381-
_Nonnull indexstoredb_unit_info_receiver receiver);
382-
383-
/// Iterates over recorded `#include`s of a unit.
384-
///
385-
/// \param index An IndexStoreDB object which contains the symbols.
386-
/// \param unitName The unit name to search for.
387-
/// \param receiver A function to be called for each include entry. The pointers are only valid for
388-
/// the duration of the call. The function should return a true to continue iterating.
389-
INDEXSTOREDB_PUBLIC bool
390-
indexstoredb_index_includes_of_unit(
391-
_Nonnull indexstoredb_index_t index,
392-
const char *_Nonnull unitName,
393-
_Nonnull indexstoredb_unit_includes_receiver receiver);
368+
_Nonnull indexstoredb_path_receiver receiver);
394369

395370
INDEXSTOREDB_END_DECLS
396371

include/IndexStoreDB/Index/FilePathIndex.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ class FilePathIndex {
7272
bool foreachFileIncludedByFile(CanonicalFilePathRef sourcePath,
7373
function_ref<bool(CanonicalFilePathRef TargetPath, unsigned Line)> Receiver);
7474

75-
bool foreachIncludeOfUnit(StringRef unitName,
76-
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
77-
7875
private:
7976
void *Impl; // A FileIndexImpl.
8077
};

include/IndexStoreDB/Index/IndexSystem.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ class INDEXSTOREDB_EXPORT IndexSystem {
139139
bool foreachFileIncludedByFile(StringRef SourcePath,
140140
function_ref<bool(CanonicalFilePathRef TargetPath, unsigned Line)> Receiver);
141141

142-
bool foreachIncludeOfUnit(StringRef unitName,
143-
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
144-
145142
/// Returns unit test class/method occurrences that are referenced from units associated with the provided output file paths.
146143
/// \returns `false` if the receiver returned `false` to stop receiving symbols, `true` otherwise.
147144
bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths,

include/IndexStoreDB/Support/Path.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ namespace IndexStoreDB {
2222
class CanonicalFilePathRef;
2323

2424
class CanonicalFilePath {
25-
std::string Path;
25+
SmallString<128> Path;
2626

2727
public:
2828
CanonicalFilePath() = default;
2929
inline CanonicalFilePath(CanonicalFilePathRef CanonPath);
3030

31-
const std::string &getPath() const { return Path; }
31+
StringRef getPath() const { return Path; }
3232
bool empty() const { return Path.empty(); }
3333

3434
friend bool operator==(CanonicalFilePath LHS, CanonicalFilePath RHS) {

lib/CIndexStoreDB/CIndexStoreDB.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -422,38 +422,14 @@ static indexstoredb_symbol_kind_t toCSymbolKind(SymbolKind K) {
422422
}
423423
}
424424

425-
const char *
426-
indexstoredb_unit_info_main_file_path(indexstoredb_unit_info_t info) {
427-
auto obj = (const StoreUnitInfo *)info;
428-
return obj->MainFilePath.getPath().c_str();
429-
}
430-
431-
const char *
432-
indexstoredb_unit_info_unit_name(indexstoredb_unit_info_t info) {
433-
auto obj = (const StoreUnitInfo *)info;
434-
return obj->UnitName.c_str();
435-
}
436-
437425
bool
438-
indexstoredb_index_units_containing_file(
426+
indexstoredb_index_main_files_containing_file(
439427
indexstoredb_index_t index,
440428
const char *path,
441-
indexstoredb_unit_info_receiver receiver)
429+
indexstoredb_path_receiver receiver)
442430
{
443431
auto obj = (IndexStoreDBObject<std::shared_ptr<IndexSystem>> *)index;
444432
return obj->value->foreachMainUnitContainingFile(path, [&](const StoreUnitInfo &unitInfo) -> bool {
445-
return receiver((indexstoredb_unit_info_receiver)&unitInfo);
446-
});
447-
}
448-
449-
bool
450-
indexstoredb_index_includes_of_unit(
451-
indexstoredb_index_t index,
452-
const char *unitName,
453-
indexstoredb_unit_includes_receiver receiver)
454-
{
455-
auto obj = (IndexStoreDBObject<std::shared_ptr<IndexSystem>> *)index;
456-
return obj->value->foreachIncludeOfUnit(unitName, [&](CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)->bool {
457-
return receiver(sourcePath.getPath().str().c_str(), targetPath.getPath().str().c_str(), line);
433+
return receiver(unitInfo.MainFilePath.getPath().str().c_str());
458434
});
459435
}

lib/Index/FilePathIndex.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class FileIndexImpl {
7676
bool foreachFileIncludedByFile(CanonicalFilePathRef sourcePath,
7777
function_ref<bool(CanonicalFilePathRef targetPath, unsigned line)> Receiver);
7878

79-
bool foreachIncludeOfUnit(StringRef unitName,
80-
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
81-
8279
bool foreachIncludeOfStoreUnitContainingFile(CanonicalFilePathRef filePath,
8380
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
8481
};
@@ -226,23 +223,6 @@ bool FileIndexImpl::foreachFileIncludedByFile(CanonicalFilePathRef inputSourcePa
226223
});
227224
}
228225

229-
bool FileIndexImpl::foreachIncludeOfUnit(StringRef unitName,
230-
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
231-
std::string error;
232-
IndexUnitReader storeUnit(*IdxStore, unitName, error);
233-
if (!storeUnit.isValid())
234-
return true;
235-
StringRef workDir = storeUnit.getWorkingDirectory();
236-
return storeUnit.foreachInclude([&](IndexUnitInclude inc) -> bool {
237-
StringRef sourcePath = inc.getSourcePath();
238-
StringRef targetPath = inc.getTargetPath();
239-
unsigned line = inc.getSourceLine();
240-
CanonicalFilePath fullSourcePath = getCanonicalPath(sourcePath, workDir);
241-
CanonicalFilePath fullTargetPath = getCanonicalPath(targetPath, workDir);
242-
return receiver(fullSourcePath, fullTargetPath, line);
243-
});
244-
}
245-
246226
bool FileIndexImpl::foreachIncludeOfStoreUnitContainingFile(CanonicalFilePathRef filePath,
247227
function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
248228
SmallVector<std::string, 32> allUnitNames;
@@ -261,7 +241,19 @@ bool FileIndexImpl::foreachIncludeOfStoreUnitContainingFile(CanonicalFilePathRef
261241
}
262242

263243
for (auto &unitName: allUnitNames) {
264-
bool cont = foreachIncludeOfUnit(unitName, receiver);
244+
std::string error;
245+
IndexUnitReader storeUnit(*IdxStore, unitName, error);
246+
if (!storeUnit.isValid())
247+
continue;
248+
StringRef workDir = storeUnit.getWorkingDirectory();
249+
bool cont = storeUnit.foreachInclude([&](IndexUnitInclude inc) -> bool {
250+
StringRef sourcePath = inc.getSourcePath();
251+
StringRef targetPath = inc.getTargetPath();
252+
unsigned line = inc.getSourceLine();
253+
CanonicalFilePath fullSourcePath = getCanonicalPath(sourcePath, workDir);
254+
CanonicalFilePath fullTargetPath = getCanonicalPath(targetPath, workDir);
255+
return receiver(fullSourcePath, fullTargetPath, line);
256+
});
265257
if (!cont)
266258
return false;
267259
}
@@ -322,7 +314,3 @@ bool FilePathIndex::foreachFileIncludingFile(CanonicalFilePathRef TargetPath, fu
322314
bool FilePathIndex::foreachFileIncludedByFile(CanonicalFilePathRef SourcePath, function_ref<bool (CanonicalFilePathRef, unsigned int)> Receiver) {
323315
return IMPL->foreachFileIncludedByFile(SourcePath, Receiver);
324316
}
325-
326-
bool FilePathIndex::foreachIncludeOfUnit(StringRef unitName, function_ref<bool(CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
327-
return IMPL->foreachIncludeOfUnit(unitName, receiver);
328-
}

0 commit comments

Comments
 (0)