45
45
#include " swift/Frontend/FrontendOptions.h"
46
46
#include " swift/Frontend/ModuleInterfaceLoader.h"
47
47
#include " swift/Strings.h"
48
- #include " clang/Basic/Module .h"
48
+ #include " clang/CAS/IncludeTree .h"
49
49
#include " llvm/ADT/STLExtras.h"
50
50
#include " llvm/ADT/SetOperations.h"
51
51
#include " llvm/ADT/SetVector.h"
69
69
#include < sstream>
70
70
#include < stack>
71
71
#include < string>
72
- #include < algorithm>
73
72
74
73
using namespace swift ;
75
74
using namespace swift ::dependencies;
@@ -101,9 +100,6 @@ class ExplicitModuleDependencyResolver {
101
100
if (resolvingDepInfo.isFinalized ())
102
101
return false ;
103
102
104
- if (auto ID = resolvingDepInfo.getClangIncludeTree ())
105
- includeTrees.push_back (*ID);
106
-
107
103
for (const auto &depModuleID : dependencies) {
108
104
const auto &depInfo = cache.findKnownDependency (depModuleID);
109
105
switch (depModuleID.Kind ) {
@@ -322,8 +318,10 @@ class ExplicitModuleDependencyResolver {
322
318
// Collect CAS deppendencies from clang modules.
323
319
if (!clangDepDetails.CASFileSystemRootID .empty ())
324
320
rootIDs.push_back (clangDepDetails.CASFileSystemRootID );
325
- if (!clangDepDetails.CASClangIncludeTreeRootID .empty ())
326
- includeTrees.push_back (clangDepDetails.CASClangIncludeTreeRootID );
321
+ if (!clangDepDetails.CASClangIncludeTreeRootID .empty ()) {
322
+ if (addIncludeTree (clangDepDetails.CASClangIncludeTreeRootID ))
323
+ return true ;
324
+ }
327
325
328
326
collectUsedVFSOverlay (clangDepDetails);
329
327
@@ -358,12 +356,14 @@ class ExplicitModuleDependencyResolver {
358
356
auto bridgeRoot = tracker->createTreeFromDependencies ();
359
357
if (!bridgeRoot)
360
358
return diagnoseCASFSCreationError (bridgeRoot.takeError ());
361
- fileListIDs.push_back (bridgeRoot->getID ().toString ());
359
+
360
+ fileListRefs.push_back (bridgeRoot->getRef ());
362
361
}
363
362
}
364
- } else
365
- includeTrees.push_back (sourceDepDetails.textualModuleDetails
366
- .CASBridgingHeaderIncludeTreeRootID );
363
+ } else if (addIncludeTree (sourceDepDetails.textualModuleDetails
364
+ .CASBridgingHeaderIncludeTreeRootID ))
365
+ return true ;
366
+
367
367
return false ;
368
368
};
369
369
@@ -499,9 +499,7 @@ class ExplicitModuleDependencyResolver {
499
499
auto root = tracker->createTreeFromDependencies ();
500
500
if (!root)
501
501
return diagnoseCASFSCreationError (root.takeError ());
502
- auto rootID = root->getID ().toString ();
503
- dependencyInfoCopy.updateCASFileSystemRootID (rootID);
504
- fileListIDs.push_back (rootID);
502
+ fileListRefs.push_back (root->getRef ());
505
503
} else if (auto *textualDep =
506
504
resolvingDepInfo.getAsSwiftInterfaceModule ()) {
507
505
tracker->startTracking ();
@@ -516,9 +514,7 @@ class ExplicitModuleDependencyResolver {
516
514
auto root = tracker->createTreeFromDependencies ();
517
515
if (!root)
518
516
return diagnoseCASFSCreationError (root.takeError ());
519
- auto rootID = root->getID ().toString ();
520
- dependencyInfoCopy.updateCASFileSystemRootID (rootID);
521
- fileListIDs.push_back (rootID);
517
+ fileListRefs.push_back (root->getRef ());
522
518
}
523
519
524
520
// Update build command line.
@@ -530,15 +526,8 @@ class ExplicitModuleDependencyResolver {
530
526
commandline.push_back (rootID);
531
527
}
532
528
533
- for (auto tree : includeTrees) {
534
- commandline.push_back (" -clang-include-tree-root" );
535
- commandline.push_back (tree);
536
- }
537
-
538
- for (auto list : fileListIDs) {
539
- commandline.push_back (" -clang-include-tree-filelist" );
540
- commandline.push_back (list);
541
- }
529
+ if (computeCASFileSystem (dependencyInfoCopy))
530
+ return true ;
542
531
}
543
532
544
533
// Compute and update module cache key.
@@ -636,6 +625,53 @@ class ExplicitModuleDependencyResolver {
636
625
cmd.push_back (" -cache-disable-replay" );
637
626
}
638
627
628
+ bool addIncludeTree (StringRef includeTree) {
629
+ auto &db = cache.getScanService ().getCAS ();
630
+ auto casID = db.parseID (includeTree);
631
+ if (!casID) {
632
+ instance.getDiags ().diagnose (SourceLoc (), diag::error_invalid_cas_id,
633
+ includeTree, toString (casID.takeError ()));
634
+ return true ;
635
+ }
636
+ auto ref = db.getReference (*casID);
637
+ if (!ref) {
638
+ instance.getDiags ().diagnose (SourceLoc (), diag::error_load_input_from_cas,
639
+ includeTree);
640
+ return true ;
641
+ }
642
+
643
+ auto root = clang::cas::IncludeTreeRoot::get (db, *ref);
644
+ if (!root) {
645
+ instance.getDiags ().diagnose (SourceLoc (), diag::error_cas_malformed_input,
646
+ includeTree, toString (root.takeError ()));
647
+ return true ;
648
+ }
649
+
650
+ fileListRefs.push_back (root->getFileListRef ());
651
+ return false ;
652
+ }
653
+
654
+ bool computeCASFileSystem (ModuleDependencyInfo &dependencyInfoCopy) {
655
+ if (fileListRefs.empty ())
656
+ return false ;
657
+
658
+ auto &db = cache.getScanService ().getCAS ();
659
+ auto casFS =
660
+ clang::cas::IncludeTree::FileList::create (db, {}, fileListRefs);
661
+ if (!casFS) {
662
+ instance.getDiags ().diagnose (SourceLoc (), diag::error_cas,
663
+ " CAS IncludeTree FileList creation" ,
664
+ toString (casFS.takeError ()));
665
+ return true ;
666
+ }
667
+
668
+ auto casID = casFS->getID ().toString ();
669
+ dependencyInfoCopy.updateCASFileSystemRootID (casID);
670
+ commandline.push_back (" -clang-include-tree-filelist" );
671
+ commandline.push_back (casID);
672
+ return false ;
673
+ }
674
+
639
675
private:
640
676
const ModuleDependencyID &moduleID;
641
677
ModuleDependenciesCache &cache;
@@ -644,8 +680,7 @@ class ExplicitModuleDependencyResolver {
644
680
645
681
std::optional<SwiftDependencyTracker> tracker;
646
682
std::vector<std::string> rootIDs;
647
- std::vector<std::string> includeTrees;
648
- std::vector<std::string> fileListIDs;
683
+ std::vector<llvm::cas::ObjectRef> fileListRefs;
649
684
std::vector<std::string> commandline;
650
685
std::vector<std::string> bridgingHeaderBuildCmd;
651
686
llvm::StringMap<MacroPluginDependency> macros;
0 commit comments