Skip to content

Commit 7c258f2

Browse files
authored
Merge pull request #79485 from allevato/index-swiftinterface
[Frontend] Support `-index-store-path` for explicit module interface compilation.
2 parents a3d6992 + 5fd9852 commit 7c258f2

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,21 @@ static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
978978
}
979979
}
980980

981+
static bool shouldEmitIndexData(const CompilerInvocation &Invocation) {
982+
const auto &opts = Invocation.getFrontendOptions();
983+
auto action = opts.RequestedAction;
984+
985+
if (action == FrontendOptions::ActionType::CompileModuleFromInterface &&
986+
opts.ExplicitInterfaceBuild) {
987+
return true;
988+
}
989+
990+
// FIXME: This predicate matches the status quo, but there's no reason
991+
// indexing cannot run for actions that do not require stdlib e.g. to better
992+
// facilitate tests.
993+
return FrontendOptions::doesActionRequireSwiftStandardLibrary(action);
994+
}
995+
981996
/// Perform any actions that must have access to the ASTContext, and need to be
982997
/// delayed until the Swift compile pipeline has finished. This may be called
983998
/// before or after LLVM depending on when the ASTContext gets freed.
@@ -1072,10 +1087,7 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
10721087
}
10731088
}
10741089

1075-
// FIXME: This predicate matches the status quo, but there's no reason
1076-
// indexing cannot run for actions that do not require stdlib e.g. to better
1077-
// facilitate tests.
1078-
if (FrontendOptions::doesActionRequireSwiftStandardLibrary(action)) {
1090+
if (shouldEmitIndexData(Invocation)) {
10791091
emitIndexData(Instance);
10801092
}
10811093

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name IndexWhileBuilding
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %empty-directory(%t/idx)
6+
// RUN: %target-swift-frontend -compile-module-from-interface -explicit-interface-module-build -module-name IndexWhileBuilding -index-store-path %/t/idx -index-include-locals -o %/t/IndexWhileBuilding.swiftmodule %s
7+
// RUN: c-index-test core -print-record %t/idx | %FileCheck %s
8+
9+
import Swift
10+
// CHECK: [[@LINE-1]]:8 | module/Swift | c:@M@Swift | Ref | rel: 0
11+
12+
public struct MyStruct {
13+
// CHECK: [[@LINE-1]]:15 | struct/Swift | s:18IndexWhileBuilding8MyStructV | Def
14+
public init()
15+
// CHECK: [[@LINE-1]]:10 | constructor/Swift | s:18IndexWhileBuilding8MyStructVACycfc | Def,RelChild
16+
// CHECK-NEXT: RelChild | s:18IndexWhileBuilding8MyStructV
17+
}
18+
19+
@inlinable public func myFunc() {
20+
// CHECK: [[@LINE-1]]:24 | function/Swift | s:18IndexWhileBuilding6myFuncyyF | Def
21+
let s = MyStruct()
22+
// CHECK: [[@LINE-1]]:7 | function/acc-get(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvg | Def,Impl,RelChild,RelAcc
23+
// CHECK-NEXT: RelChild,RelAcc | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
24+
// CHECK: [[@LINE-3]]:7 | function/acc-set(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvs | Def,Impl,RelChild,RelAcc
25+
// CHECK-NEXT: RelChild,RelAcc | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
26+
// CHECK: [[@LINE-5]]:7 | variable(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp | Def,RelChild
27+
// CHECK-NEXT: RelChild | s:18IndexWhileBuilding6myFuncyyF
28+
// CHECK: [[@LINE-7]]:11 | struct/Swift | s:18IndexWhileBuilding8MyStructV | Ref,RelCont
29+
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
30+
// CHECK: [[@LINE-9]]:11 | constructor/Swift | s:18IndexWhileBuilding8MyStructVACycfc | Ref,Call,RelCall,RelCont
31+
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
32+
// CHECK-NEXT: RelCall | s:18IndexWhileBuilding6myFuncyyF
33+
_ = s
34+
// CHECK: [[@LINE-1]]:7 | function/acc-get(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvg | Ref,Call,Impl,RelCall,RelCont | rel: 1
35+
// CHECK-NEXT: RelCall,RelCont | s:18IndexWhileBuilding6myFuncyyF
36+
// CHECK: [[@LINE-3]]:7 | variable(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp | Ref,Read,RelCont | rel: 1
37+
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF
38+
}

0 commit comments

Comments
 (0)