Skip to content

Commit 5aa1dd5

Browse files
committed
[AST] Make IsNonUserModuleRequest consider SourceFile inputs as well.
We're using a small custom frontend tool to generate indexstore data for `.swiftinterface` files in the SDKs. We do this by treating the `.swiftinterface` file as the input of an interface compilation, but this exits early because it treats it as a `SourceFile` instead of an external `LoadedFile`. This happens even if we call `setIsSystemModule(true)` unless we skip setting the SDK path, but that causes other problems. It seems harmless to check for `SourceFile`s as well, so that a tool processing an SDK interface as a direct input still gets the right state.
1 parent 6236b25 commit 5aa1dd5

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

lib/AST/Module.cpp

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

4042-
auto *LF = dyn_cast_or_null<LoadedFile>(mod->getFiles().front());
4043-
if (!LF)
4044-
return false;
4045-
4046-
StringRef modulePath = LF->getSourceFilename();
4042+
StringRef modulePath;
4043+
auto fileUnit = mod->getFiles().front();
4044+
if (auto *LF = dyn_cast_or_null<LoadedFile>(fileUnit)) {
4045+
modulePath = LF->getSourceFilename();
4046+
} else if (auto *SF = dyn_cast_or_null<SourceFile>(fileUnit)) {
4047+
// Checking for SourceFiles lets custom tools get the correct is-system
4048+
// state for index units when compiling a textual interface directly.
4049+
modulePath = SF->getFilename();
4050+
}
40474051
if (modulePath.empty())
40484052
return false;
40494053

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
//

0 commit comments

Comments
 (0)