Skip to content

Commit 9e6d4db

Browse files
authored
[Frontend] Avoid doing whole-module work under primary-file typecheck (#27153)
...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
1 parent 0434d58 commit 9e6d4db

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
@@ -1122,10 +1122,12 @@ static bool performCompile(CompilerInstance &Instance,
11221122
if (Action == FrontendOptions::ActionType::Typecheck) {
11231123
if (emitIndexData(Invocation, Instance))
11241124
return true;
1125-
if (emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance,
1126-
Invocation,
1127-
moduleIsPublic)) {
1128-
return true;
1125+
if (opts.InputsAndOutputs.isWholeModule()) {
1126+
if (emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance,
1127+
Invocation,
1128+
moduleIsPublic)) {
1129+
return true;
1130+
}
11291131
}
11301132
return false;
11311133
}
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)