Skip to content

[6.1 🍒 ] [Frontend] Support -index-store-path for explicit module interface compilation. #79545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,21 @@ static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
}
}

static bool shouldEmitIndexData(const CompilerInvocation &Invocation) {
const auto &opts = Invocation.getFrontendOptions();
auto action = opts.RequestedAction;

if (action == FrontendOptions::ActionType::CompileModuleFromInterface &&
opts.ExplicitInterfaceBuild) {
return true;
}

// FIXME: This predicate matches the status quo, but there's no reason
// indexing cannot run for actions that do not require stdlib e.g. to better
// facilitate tests.
return FrontendOptions::doesActionRequireSwiftStandardLibrary(action);
}

/// Perform any actions that must have access to the ASTContext, and need to be
/// delayed until the Swift compile pipeline has finished. This may be called
/// before or after LLVM depending on when the ASTContext gets freed.
Expand Down Expand Up @@ -1070,10 +1085,7 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
}
}

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

Expand Down
38 changes: 38 additions & 0 deletions test/ModuleInterface/IndexWhileBuilding.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name IndexWhileBuilding

// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/idx)
// 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
// RUN: c-index-test core -print-record %t/idx | %FileCheck %s

import Swift
// CHECK: [[@LINE-1]]:8 | module/Swift | c:@M@Swift | Ref | rel: 0

public struct MyStruct {
// CHECK: [[@LINE-1]]:15 | struct/Swift | s:18IndexWhileBuilding8MyStructV | Def
public init()
// CHECK: [[@LINE-1]]:10 | constructor/Swift | s:18IndexWhileBuilding8MyStructVACycfc | Def,RelChild
// CHECK-NEXT: RelChild | s:18IndexWhileBuilding8MyStructV
}

@inlinable public func myFunc() {
// CHECK: [[@LINE-1]]:24 | function/Swift | s:18IndexWhileBuilding6myFuncyyF | Def
let s = MyStruct()
// CHECK: [[@LINE-1]]:7 | function/acc-get(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvg | Def,Impl,RelChild,RelAcc
// CHECK-NEXT: RelChild,RelAcc | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
// CHECK: [[@LINE-3]]:7 | function/acc-set(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvs | Def,Impl,RelChild,RelAcc
// CHECK-NEXT: RelChild,RelAcc | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
// CHECK: [[@LINE-5]]:7 | variable(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp | Def,RelChild
// CHECK-NEXT: RelChild | s:18IndexWhileBuilding6myFuncyyF
// CHECK: [[@LINE-7]]:11 | struct/Swift | s:18IndexWhileBuilding8MyStructV | Ref,RelCont
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
// CHECK: [[@LINE-9]]:11 | constructor/Swift | s:18IndexWhileBuilding8MyStructVACycfc | Ref,Call,RelCall,RelCont
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp
// CHECK-NEXT: RelCall | s:18IndexWhileBuilding6myFuncyyF
_ = s
// CHECK: [[@LINE-1]]:7 | function/acc-get(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvg | Ref,Call,Impl,RelCall,RelCont | rel: 1
// CHECK-NEXT: RelCall,RelCont | s:18IndexWhileBuilding6myFuncyyF
// CHECK: [[@LINE-3]]:7 | variable(local)/Swift | s:18IndexWhileBuilding6myFuncyyF1sL_AA8MyStructVvp | Ref,Read,RelCont | rel: 1
// CHECK-NEXT: RelCont | s:18IndexWhileBuilding6myFuncyyF
}