Skip to content

Commit 2be42a6

Browse files
authored
Merge pull request #76 from akyrtzi/no-cpp-exceptions-via-libindexstore
Collect the dependency info and process them outside of the libIndexStore callback
2 parents b99f773 + 20163fa commit 2be42a6

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

lib/Index/IndexDatastore.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,33 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
352352
CanonicalFilePath CanonSysroot = CanonPathCache->getCanonicalPath(Reader.getSysrootPath(), WorkDir);
353353
unitImport.setSysroot(CanonSysroot);
354354

355-
// Collect the newly discovered records and process them outside of the libIndexStore callback.
355+
// Collect the dependency info and process them outside of the libIndexStore callback.
356356
// This is because processing populates the database and C++ exceptions can be thrown; libIndexStore builds with -fno-exceptions so we cannot
357357
// be throwing C++ exceptions from inside its frames.
358-
SmallVector<StoreSymbolRecordRef, 16> newStoreRecords;
359-
358+
struct UnitDependencyInfo {
359+
IndexUnitDependency::DependencyKind Kind;
360+
bool IsSystem;
361+
std::string FilePath;
362+
std::string Name;
363+
std::string ModuleName;
364+
};
365+
SmallVector<UnitDependencyInfo, 16> dependencies;
360366
Reader.foreachDependency([&](IndexUnitDependency Dep)->bool {
361-
switch (Dep.getKind()) {
367+
dependencies.push_back(UnitDependencyInfo{Dep.getKind(), Dep.isSystem(), Dep.getFilePath(), Dep.getName(), Dep.getModuleName()});
368+
return true;
369+
});
370+
371+
for (const UnitDependencyInfo &dep : dependencies) {
372+
switch (dep.Kind) {
362373
case IndexUnitDependency::DependencyKind::Record: {
363-
CanonicalFilePath CanonPath = CanonPathCache->getCanonicalPath(Dep.getFilePath(), WorkDir);
374+
CanonicalFilePath CanonPath = CanonPathCache->getCanonicalPath(dep.FilePath, WorkDir);
364375
if (CanonPath.empty())
365376
break;
366377

367-
if (!Dep.isSystem())
378+
if (!dep.IsSystem)
368379
UserFileDepends.push_back(CanonPath);
369-
StringRef recordName = Dep.getName();
370-
StringRef moduleName = Dep.getModuleName();
380+
StringRef recordName = dep.Name;
381+
StringRef moduleName = dep.ModuleName;
371382
if (moduleName.empty()) {
372383
// Workaround for swift compiler not associating the module name with records of swift files.
373384
// FIXME: Fix this on swift compiler and remove this.
@@ -376,7 +387,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
376387
}
377388
}
378389
bool isNewProvider;
379-
IDCode providerCode = unitImport.addProviderDependency(recordName, CanonPath, moduleName, Dep.isSystem(), &isNewProvider);
390+
IDCode providerCode = unitImport.addProviderDependency(recordName, CanonPath, moduleName, dep.IsSystem, &isNewProvider);
380391
if (!isNewProvider)
381392
break;
382393

@@ -387,32 +398,27 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
387398
break;
388399
}
389400

390-
newStoreRecords.push_back(std::move(Rec));
401+
SymIndex->importSymbols(import, Rec);
391402
break;
392403
}
393404

394405
case IndexUnitDependency::DependencyKind::Unit: {
395-
IDCode unitDepCode = unitImport.addUnitDependency(Dep.getName());
396-
if (!Dep.isSystem())
406+
IDCode unitDepCode = unitImport.addUnitDependency(dep.Name);
407+
if (!dep.IsSystem)
397408
UserUnitDepends.push_back(unitDepCode);
398409
break;
399410
}
400411

401412
case IndexUnitDependency::DependencyKind::File: {
402-
CanonicalFilePath CanonPath = CanonPathCache->getCanonicalPath(Dep.getFilePath(), WorkDir);
413+
CanonicalFilePath CanonPath = CanonPathCache->getCanonicalPath(dep.FilePath, WorkDir);
403414
if (CanonPath.empty())
404415
break;
405416

406-
if (!Dep.isSystem())
417+
if (!dep.IsSystem)
407418
UserFileDepends.push_back(CanonPath);
408419
unitImport.addFileDependency(CanonPath);
409420
}
410421
}
411-
return true;
412-
});
413-
414-
for (const auto &rec : newStoreRecords) {
415-
SymIndex->importSymbols(import, rec);
416422
}
417423

418424
unitImport.commit();

0 commit comments

Comments
 (0)