Skip to content

[AST] Make IsNonUserModuleRequest consider SourceFile inputs as well. #76456

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
Sep 18, 2024
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
14 changes: 9 additions & 5 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4039,11 +4039,15 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
if (!mod->hasName() || mod->getFiles().empty())
return false;

auto *LF = dyn_cast_or_null<LoadedFile>(mod->getFiles().front());
if (!LF)
return false;

StringRef modulePath = LF->getSourceFilename();
StringRef modulePath;
auto fileUnit = mod->getFiles().front();
if (auto *LF = dyn_cast_or_null<LoadedFile>(fileUnit)) {
modulePath = LF->getSourceFilename();
} else if (auto *SF = dyn_cast_or_null<SourceFile>(fileUnit)) {
// Checking for SourceFiles lets custom tools get the correct is-system
// state for index units when compiling a textual interface directly.
modulePath = SF->getFilename();
}
if (modulePath.empty())
return false;

Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_cgfloat_double.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func foo(_ x: Double) {}

// Make sure we suggest completions for both CGFloat and Double.
foo(.#^FOO^#)
// FOO-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init()[#CGFloat#]; name=init()
// FOO-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init()[#CGFloat#]; name=init()
// FOO-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init()[#Double#]; name=init()
2 changes: 1 addition & 1 deletion test/IDE/complete_exception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func test014() {
}
// NSERROR_DOT-DAG: Decl[InstanceVar]/CurrNominal/IsSystem: domain[#String#]; name=domain
// NSERROR_DOT-DAG: Decl[InstanceVar]/CurrNominal/IsSystem: code[#Int#]; name=code
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super: hashValue[#Int#]; name=hashValue
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super/IsSystem: hashValue[#Int#]; name=hashValue
// NSERROR_DOT-DAG: Decl[InstanceMethod]/Super/IsSystem: myClass()[#AnyClass!#]; name=myClass()
// NSERROR_DOT-DAG: Decl[InstanceMethod]/Super/IsSystem: isEqual({#(other): NSObject!#})[#Bool#]; name=isEqual(:)
// NSERROR_DOT-DAG: Decl[InstanceVar]/Super/IsSystem: hash[#Int#]; name=hash
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_pound_keypath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func completeInKeyPath6() {
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop1[#String#]; name=prop1
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop2[#ObjCClass?#]; name=prop2
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop3[#[ObjCClass]?#]; name=prop3
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super: hashValue[#Int#]; name=hashValue
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super/IsSystem: hashValue[#Int#]; name=hashValue

// Make sure we unwrap optionals (members of Optional itself are invalid in this context)
//
Expand Down
21 changes: 21 additions & 0 deletions test/Index/Store/unit-system-source-file.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/SDK)
// RUN: cp %s %t/SDK/FakeSystemModule.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use split-file here instead, but... doesn't really matter I suppose.


// When the source file is in the SDK, consider it a system module.
//
// RUN: %target-swift-frontend -c -o %t/FakeSystemModule.o -index-store-path %t/idx -sdk %t/SDK %t/SDK/FakeSystemModule.swift
// RUN: c-index-test core -print-unit %t/idx | %FileCheck %s
//
// CHECK: FakeSystemModule.o-{{[A-Z0-9]*}}
// CHECK: --------
// CHECK: is-system: 1

// RUN: %target-swift-frontend -c -o %t/FakeSystemModule.o -index-store-path %t/idx %t/SDK/FakeSystemModule.swift
// RUN: c-index-test core -print-unit %t/idx | %FileCheck %s -check-prefix NO-SDK
//
// NO-SDK: FakeSystemModule.o-{{[A-Z0-9]*}}
// NO-SDK: --------
// NO-SDK: is-system: 0

func someFunc() {}