Skip to content

Commit 2472f90

Browse files
authored
Merge pull request swiftlang#79545 from allevato/6.1-index-swiftinterface
[6.1 🍒 ] [Frontend] Support `-index-store-path` for explicit module interface compilation.
2 parents 5134191 + 4379be6 commit 2472f90

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

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

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

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)