Skip to content

Commit 4bb9a58

Browse files
authored
Merge pull request #76456 from allevato/system-module-check
[AST] Make `IsNonUserModuleRequest` consider `SourceFile` inputs as well.
2 parents 628d7cb + 67d9eec commit 4bb9a58

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

lib/AST/Module.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,11 +3948,15 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
39483948
if (!mod->hasName() || mod->getFiles().empty())
39493949
return false;
39503950

3951-
auto *LF = dyn_cast_or_null<LoadedFile>(mod->getFiles().front());
3952-
if (!LF)
3953-
return false;
3954-
3955-
StringRef modulePath = LF->getSourceFilename();
3951+
StringRef modulePath;
3952+
auto fileUnit = mod->getFiles().front();
3953+
if (auto *LF = dyn_cast_or_null<LoadedFile>(fileUnit)) {
3954+
modulePath = LF->getSourceFilename();
3955+
} else if (auto *SF = dyn_cast_or_null<SourceFile>(fileUnit)) {
3956+
// Checking for SourceFiles lets custom tools get the correct is-system
3957+
// state for index units when compiling a textual interface directly.
3958+
modulePath = SF->getFilename();
3959+
}
39563960
if (modulePath.empty())
39573961
return false;
39583962

test/IDE/complete_cgfloat_double.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ func foo(_ x: Double) {}
1010

1111
// Make sure we suggest completions for both CGFloat and Double.
1212
foo(.#^FOO^#)
13-
// FOO-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init()[#CGFloat#]; name=init()
13+
// FOO-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init()[#CGFloat#]; name=init()
1414
// FOO-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init()[#Double#]; name=init()

test/IDE/complete_exception.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func test014() {
156156
}
157157
// NSERROR_DOT-DAG: Decl[InstanceVar]/CurrNominal/IsSystem: domain[#String#]; name=domain
158158
// NSERROR_DOT-DAG: Decl[InstanceVar]/CurrNominal/IsSystem: code[#Int#]; name=code
159-
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super: hashValue[#Int#]; name=hashValue
159+
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super/IsSystem: hashValue[#Int#]; name=hashValue
160160
// NSERROR_DOT-DAG: Decl[InstanceMethod]/Super/IsSystem: myClass()[#AnyClass!#]; name=myClass()
161161
// NSERROR_DOT-DAG: Decl[InstanceMethod]/Super/IsSystem: isEqual({#(other): NSObject!#})[#Bool#]; name=isEqual(:)
162162
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super/IsSystem: hash[#Int#]; name=hash

test/IDE/complete_pound_keypath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func completeInKeyPath6() {
7272
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop1[#String#]; name=prop1
7373
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop2[#ObjCClass?#]; name=prop2
7474
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop3[#[ObjCClass]?#]; name=prop3
75-
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super: hashValue[#Int#]; name=hashValue
75+
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super/IsSystem: hashValue[#Int#]; name=hashValue
7676

7777
// Make sure we unwrap optionals (members of Optional itself are invalid in this context)
7878
//
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/SDK)
3+
// RUN: cp %s %t/SDK/FakeSystemModule.swift
4+
5+
// When the source file is in the SDK, consider it a system module.
6+
//
7+
// RUN: %target-swift-frontend -c -o %t/FakeSystemModule.o -index-store-path %t/idx -sdk %t/SDK %t/SDK/FakeSystemModule.swift
8+
// RUN: c-index-test core -print-unit %t/idx | %FileCheck %s
9+
//
10+
// CHECK: FakeSystemModule.o-{{[A-Z0-9]*}}
11+
// CHECK: --------
12+
// CHECK: is-system: 1
13+
14+
// RUN: %target-swift-frontend -c -o %t/FakeSystemModule.o -index-store-path %t/idx %t/SDK/FakeSystemModule.swift
15+
// RUN: c-index-test core -print-unit %t/idx | %FileCheck %s -check-prefix NO-SDK
16+
//
17+
// NO-SDK: FakeSystemModule.o-{{[A-Z0-9]*}}
18+
// NO-SDK: --------
19+
// NO-SDK: is-system: 0
20+
21+
func someFunc() {}

0 commit comments

Comments
 (0)