@@ -909,8 +909,9 @@ SwiftASTContext::SwiftASTContext(std::string description, llvm::Triple triple,
909
909
// Set the dependency tracker.
910
910
if (auto g = repro::Reproducer::Instance ().GetGenerator ()) {
911
911
repro::FileProvider &fp = g->GetOrCreate <repro::FileProvider>();
912
- m_dependency_tracker =
913
- std::make_unique<swift::DependencyTracker>(true , fp.GetFileCollector ());
912
+ m_dependency_tracker = std::make_unique<swift::DependencyTracker>(
913
+ swift::IntermoduleDepTrackingMode::IncludeSystem,
914
+ fp.GetFileCollector ());
914
915
}
915
916
// rdar://53971116
916
917
m_compiler_invocation_ap->disableASTScopeLookup ();
@@ -1556,13 +1557,21 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
1556
1557
return dsym;
1557
1558
}
1558
1559
1560
+ // / Detect whether a Swift module was "imported" by DWARFImporter.
1561
+ // / All this *really* means is that it couldn't be loaded through any
1562
+ // / other mechanism.
1563
+ static bool IsDWARFImported (swift::ModuleDecl &module ) {
1564
+ return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1565
+ [](swift::FileUnit *file_unit) {
1566
+ return (file_unit->getKind () ==
1567
+ swift::FileUnitKind::DWARFModule);
1568
+ });
1569
+ }
1570
+
1559
1571
lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1560
1572
Module &module ,
1561
1573
Target *target,
1562
1574
bool fallback) {
1563
- std::vector<std::string> module_search_paths;
1564
- std::vector<std::pair<std::string, bool >> framework_search_paths;
1565
-
1566
1575
if (!SwiftASTContextSupportsLanguage (language))
1567
1576
return lldb::TypeSystemSP ();
1568
1577
@@ -1576,16 +1585,33 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1576
1585
module .GetDescription (ss, eDescriptionLevelBrief);
1577
1586
ss << ' "' << ' )' ;
1578
1587
}
1588
+ std::vector<std::string> module_search_paths;
1589
+ std::vector<std::pair<std::string, bool >> framework_search_paths;
1590
+
1591
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " (Module)" );
1592
+
1593
+ auto logError = [&](const char *message) {
1594
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " Failed to create module context - %s" ,
1595
+ message);
1596
+ };
1579
1597
1580
1598
ArchSpec arch = module .GetArchitecture ();
1599
+ if (!arch.IsValid ()) {
1600
+ logError (" invalid module architecture" );
1601
+ return TypeSystemSP ();
1602
+ }
1581
1603
1582
1604
ObjectFile *objfile = module .GetObjectFile ();
1583
- if (!objfile)
1584
- return {};
1605
+ if (!objfile) {
1606
+ logError (" no object file for module" );
1607
+ return TypeSystemSP ();
1608
+ }
1585
1609
1586
1610
ArchSpec object_arch = objfile->GetArchitecture ();
1587
- if (!object_arch.IsValid ())
1588
- return {};
1611
+ if (!object_arch.IsValid ()) {
1612
+ logError (" invalid objfile architecture" );
1613
+ return TypeSystemSP ();
1614
+ }
1589
1615
1590
1616
lldb::CompUnitSP main_compile_unit_sp = module .GetCompileUnitAtIndex (0 );
1591
1617
@@ -1641,9 +1667,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1641
1667
swift_ast_sp->GetLanguageOptions ().EnableAccessControl = false ;
1642
1668
swift_ast_sp->GetLanguageOptions ().EnableTargetOSChecking = false ;
1643
1669
1644
- if (!arch.IsValid ())
1645
- return TypeSystemSP ();
1646
-
1647
1670
swift_ast_sp->SetTriple (triple, &module );
1648
1671
1649
1672
bool set_triple = false ;
@@ -1654,7 +1677,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1654
1677
std::string target_triple;
1655
1678
1656
1679
if (sym_file) {
1657
- bool got_serialized_options;
1680
+ bool got_serialized_options = false ;
1658
1681
llvm::SmallString<0 > error;
1659
1682
llvm::raw_svector_ostream errs (error);
1660
1683
if (DeserializeAllCompilerFlags (*swift_ast_sp, module , m_description, errs,
@@ -1681,7 +1704,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1681
1704
//
1682
1705
// This step is skipped for modules that don't have any Swift
1683
1706
// debug info. (We assume that a module without a .swift_ast
1684
- // section has not debuggable Swift code). This skips looking
1707
+ // section has no debuggable Swift code). This skips looking
1685
1708
// through all the shared cache dylibs when they don't have debug
1686
1709
// info.
1687
1710
if (found_swift_modules) {
@@ -1784,6 +1807,20 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1784
1807
swift_ast_sp->LogConfiguration ();
1785
1808
}
1786
1809
}
1810
+
1811
+ if (swift_ast_sp->HasFatalErrors ()) {
1812
+ logError (swift_ast_sp->GetFatalErrors ().AsCString ());
1813
+ return {};
1814
+ }
1815
+
1816
+ const bool can_create = true ;
1817
+ swift::ModuleDecl *stdlib =
1818
+ swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
1819
+ if (!stdlib || IsDWARFImported (*stdlib)) {
1820
+ logError (" couldn't load the Swift stdlib" );
1821
+ return {};
1822
+ }
1823
+
1787
1824
return swift_ast_sp;
1788
1825
}
1789
1826
@@ -1840,17 +1877,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1840
1877
return ModuleSP ();
1841
1878
}
1842
1879
1843
- // / Detect whether a Swift module was "imported" by DWARFImporter.
1844
- // / All this *really* means is that it couldn't be loaded through any
1845
- // / other mechanism.
1846
- static bool IsDWARFImported (swift::ModuleDecl &module ) {
1847
- return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1848
- [](swift::FileUnit *file_unit) {
1849
- return (file_unit->getKind () ==
1850
- swift::FileUnitKind::DWARFModule);
1851
- });
1852
- }
1853
-
1854
1880
lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1855
1881
Target &target,
1856
1882
const char *extra_options) {
@@ -2894,9 +2920,6 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2894
2920
class SwiftDWARFImporterDelegate : public swift ::DWARFImporterDelegate {
2895
2921
SwiftASTContext &m_swift_ast_ctx;
2896
2922
using ModuleAndName = std::pair<const char *, const char *>;
2897
- // / Caches successful lookups for the scratch context.
2898
- llvm::DenseMap<ModuleAndName, llvm::SmallVector<clang::QualType, 1 >>
2899
- m_decl_cache;
2900
2923
std::string m_description;
2901
2924
2902
2925
// / Used to filter out types with mismatching kinds.
@@ -3106,27 +3129,32 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3106
3129
auto *swift_ast_ctx = static_cast <SwiftASTContext *>(&*ts);
3107
3130
auto *dwarf_imp = static_cast <SwiftDWARFImporterDelegate *>(
3108
3131
swift_ast_ctx->GetDWARFImporterDelegate ());
3109
- if (!dwarf_imp)
3132
+ if (!dwarf_imp || dwarf_imp == this )
3110
3133
continue ;
3111
- auto it = dwarf_imp->m_decl_cache .find (
3112
- {module_cs.GetCString (), name_cs.GetCString ()});
3113
- if (it == dwarf_imp->m_decl_cache .end ())
3134
+
3135
+ llvm::SmallVector<clang::Decl *, 2 > module_results;
3136
+ dwarf_imp->lookupValue (name, kind, inModule, module_results);
3137
+ if (!module_results.size ())
3114
3138
continue ;
3115
3139
3116
3140
auto *from_clang_importer = swift_ast_ctx->GetClangImporter ();
3117
3141
if (!from_clang_importer)
3118
3142
continue ;
3119
3143
auto &from_ctx = from_clang_importer->getClangASTContext ();
3120
3144
auto &to_ctx = clang_importer->getClangASTContext ();
3121
- for (clang::QualType qual_type : it->second )
3145
+ for (clang::Decl *decl : module_results) {
3146
+ clang::QualType qual_type;
3147
+ if (auto *interface = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
3148
+ qual_type = {interface->getTypeForDecl (), 0 };
3149
+ if (auto *type = llvm::dyn_cast<clang::TypeDecl>(decl))
3150
+ qual_type = {type->getTypeForDecl (), 0 };
3122
3151
importType (qual_type, from_ctx, to_ctx, kind, results);
3152
+ }
3153
+ // Cut the search short after we found the first result.
3154
+ if (results.size ())
3155
+ break ;
3123
3156
}
3124
- LOG_PRINTF (LIBLLDB_LOG_TYPES, " %d types found in cache." , results.size ());
3125
-
3126
- // TODO: Otherwise, the correct thing to do is to invoke
3127
- // search() on all modules. In practice, however, this is
3128
- // prohibitively expensive, so we need to do something
3129
- // more targeted.
3157
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " %d types collected." , results.size ());
3130
3158
return ;
3131
3159
}
3132
3160
@@ -3154,11 +3182,6 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3154
3182
clang::QualType qual_type = ClangUtil::GetQualType (compiler_type);
3155
3183
importType (qual_type, from_ctx, to_ctx, kind, results);
3156
3184
3157
- // If this is a module context, cache the result for the scratch context.
3158
- if (m_swift_ast_ctx.GetModule ())
3159
- m_decl_cache[{module_cs.GetCString (), name_cs.GetCString ()}].push_back (
3160
- qual_type);
3161
-
3162
3185
return true ;
3163
3186
});
3164
3187
0 commit comments