Skip to content

Commit 5fd9852

Browse files
committed
[Frontend] Support -index-store-path for explicit module interface compilation.
1 parent 2a76cc1 commit 5fd9852

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
@@ -974,6 +974,21 @@ static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
974974
}
975975
}
976976

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

1071-
// FIXME: This predicate matches the status quo, but there's no reason
1072-
// indexing cannot run for actions that do not require stdlib e.g. to better
1073-
// facilitate tests.
1074-
if (FrontendOptions::doesActionRequireSwiftStandardLibrary(action)) {
1086+
if (shouldEmitIndexData(Invocation)) {
10751087
emitIndexData(Instance);
10761088
}
10771089

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)