Skip to content

Commit 28c0468

Browse files
authored
[Frontend] Avoid doing whole-module work under primary-file typecheck (#27159)
...a situation we get into with indexing. The way Xcode generates indexing invocations is to take a build command and add additional flags to it; in order for the Driver to produce a single frontend command from /that/, it currently plans as if it's going to do a whole-module -typecheck and then turns around and uses -primary-file anyway. This is questionable practice, to be sure... ...but meanwhile, let's not crash by trying to access declarations that haven't been type-checked yet. rdar://problem/53117124 (cherry picked from commit 9e6d4db)
1 parent 01bb621 commit 28c0468

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,12 @@ static bool performCompile(CompilerInstance &Instance,
10581058
if (Action == FrontendOptions::ActionType::Typecheck) {
10591059
if (emitIndexData(Invocation, Instance))
10601060
return true;
1061-
if (emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance,
1062-
Invocation,
1063-
moduleIsPublic)) {
1064-
return true;
1061+
if (opts.InputsAndOutputs.isWholeModule()) {
1062+
if (emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance,
1063+
Invocation,
1064+
moduleIsPublic)) {
1065+
return true;
1066+
}
10651067
}
10661068
return false;
10671069
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// This test is very deliberately *not* indexing the current file; we need to
4+
// make sure the frontend job doesn't try to emit the auxiliary outputs based
5+
// on the non-indexed files. (This is how Xcode currently constructs -index-file
6+
// invocations: take a normal build command and add extra arguments to it.)
7+
// RUN: %target-build-swift -index-file -index-file-path %S/Inputs/SwiftModuleA.swift %S/Inputs/SwiftModuleA.swift %s -index-store-path %t/idx -module-name driver_index -emit-objc-header-path %t/out.h -emit-module-interface-path %t/out.swiftinterface
8+
9+
// RUN: test ! -f %t/out.h
10+
// RUN: test ! -f %t/out.swiftinterface
11+
// RUN: c-index-test core -print-unit %t/idx | %FileCheck %s
12+
13+
// CHECK-LABEL: module-name: driver_index
14+
// CHECK: DEPEND START
15+
// CHECK-NOT: Record |
16+
// CHECK: Record | user | {{.+}}SwiftModuleA.swift
17+
// CHECK-NOT: Record |
18+
// CHECK: DEPEND END
19+
20+
#if _runtime(_ObjC)
21+
22+
// Do a stronger test here involving checking @objc
23+
import ObjectiveC
24+
25+
public class PossiblyObjC: NSObject {
26+
@objc public init(x: Int) {}
27+
}
28+
29+
#else // _runtime(_ObjC)
30+
31+
public class Boring {
32+
init()
33+
}
34+
35+
#endif // _runtime(_ObjC)

0 commit comments

Comments
 (0)