Skip to content

Commit c12b6e2

Browse files
authored
Merge pull request #69970 from NuriAmari/swift-ide-test-updates
[swift-ide-test] Add -enable-upcoming-feature ImportObjcForwardDeclarations support
2 parents b430a02 + 7fb7e42 commit c12b6e2

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This test checks that swift-ide-test output under either -swift-version 6 or
2+
// -enable-upcoming-feature ImportObjCForwardDeclarations the output matches the
3+
// import capabilities of the compiler.
4+
5+
// (1) Print the interface with -enable-upcoming-feature ImportObjCForwardDeclarations
6+
// RUN: %target-swift-ide-test -print-module -module-to-print IncompleteTypeLibrary1 -I %S/Inputs/custom-modules/IncompleteTypes \
7+
// RUN: -enable-objc-interop -enable-upcoming-feature ImportObjcForwardDeclarations -source-filename x | %FileCheck %s
8+
9+
// (2) Print the interface with -swift-version 6
10+
// RUN: %target-swift-ide-test -print-module -module-to-print IncompleteTypeLibrary1 -I %S/Inputs/custom-modules/IncompleteTypes \
11+
// RUN: -enable-objc-interop -swift-version 6 -source-filename x | %FileCheck %s
12+
13+
// REQUIRES: objc_interop
14+
// REQUIRES: asserts
15+
16+
// CHECK: import Foundation
17+
// CHECK: @available(*, unavailable, message: "This Objective-C class has only been forward-declared; import its owning module to use it")
18+
// CHECK: class ForwardDeclaredInterface {
19+
// CHECK: }
20+
// CHECK: @available(*, unavailable, message: "This Objective-C protocol has only been forward-declared; import its owning module to use it")
21+
// CHECK: protocol ForwardDeclaredProtocol {
22+
// CHECK: }
23+
// CHECK: class IncompleteTypeConsumer1 : NSObject {
24+
// CHECK: var propertyUsingAForwardDeclaredProtocol1: (any ForwardDeclaredProtocol)!
25+
// CHECK: var propertyUsingAForwardDeclaredInterface1: ForwardDeclaredInterface!
26+
// CHECK: init!()
27+
// CHECK: func methodReturningForwardDeclaredProtocol1() -> (any ForwardDeclaredProtocol & NSObjectProtocol)!
28+
// CHECK: func methodReturningForwardDeclaredInterface1() -> ForwardDeclaredInterface!
29+
// CHECK: func methodTakingAForwardDeclaredProtocol1(_ param: (any ForwardDeclaredProtocol)!)
30+
// CHECK: func methodTakingAForwardDeclaredInterface1(_ param: ForwardDeclaredInterface!)
31+
// CHECK: }
32+
// CHECK: func CFunctionReturningAForwardDeclaredInterface1() -> ForwardDeclaredInterface!
33+
// CHECK: func CFunctionTakingAForwardDeclaredInterface1(_ param: ForwardDeclaredInterface!)
34+
// CHECK: func CFunctionReturningAForwardDeclaredProtocol1() -> (any ForwardDeclaredProtocol & NSObjectProtocol)!
35+
// CHECK: func CFunctionTakingAForwardDeclaredProtocol1(_ param: (any ForwardDeclaredProtocol)!)

test/ClangImporter/objc_forward_declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -o %t -I %S/Inputs/custom-modules -enable-objc-interop %s
3-
// RUN: %target-swift-ide-test -print-module -module-to-print objc_forward_declarations -I %t -I %S/Inputs/custom-modules -enable-objc-interop -enable-objc-forward-declarations -source-filename x | %FileCheck %s
3+
// RUN: %target-swift-ide-test -print-module -module-to-print objc_forward_declarations -I %t -I %S/Inputs/custom-modules -enable-objc-interop -enable-upcoming-feature ImportObjcForwardDeclarations -source-filename x | %FileCheck %s
44

55
// CHECK: class Innocuous : Confusing {
66

test/IDE/print_clang_ObjectiveC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %FileCheck -input-file %t/ObjectiveC.NSObject.printed.txt %s
55
// RUN: %FileCheck -input-file %t/ObjectiveC.NSObject.printed.txt -check-prefix=NEGATIVE -check-prefix=NEGATIVE-WITHOUT-FORWARD-DECLS %s
66

7-
// RUN: %target-swift-ide-test -print-module -source-filename %s -module-to-print=ObjectiveC.NSObject -function-definitions=false -enable-objc-forward-declarations > %t/ObjectiveC.NSObject.forward-decls.txt
7+
// RUN: %target-swift-ide-test -print-module -source-filename %s -module-to-print=ObjectiveC.NSObject -function-definitions=false -enable-upcoming-feature ImportObjcForwardDeclarations > %t/ObjectiveC.NSObject.forward-decls.txt
88
// RUN: %FileCheck -input-file %t/ObjectiveC.NSObject.forward-decls.txt -check-prefix=CHECK -check-prefix=CHECK-WITH-FORWARD-DECLS %s
99
// RUN: %FileCheck -input-file %t/ObjectiveC.NSObject.forward-decls.txt -check-prefix=NEGATIVE %s
1010

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,6 @@ static llvm::cl::opt<bool> CodeCompleteCallPatternHeuristics(
413413
"Use heuristics to guess whether we want call pattern completions"),
414414
llvm::cl::cat(Category));
415415

416-
static llvm::cl::opt<bool>
417-
ObjCForwardDeclarations("enable-objc-forward-declarations",
418-
llvm::cl::desc("Import Objective-C forward declarations when possible"),
419-
llvm::cl::cat(Category),
420-
llvm::cl::init(false));
421-
422416
static llvm::cl::opt<bool>
423417
EnableSwift3ObjCInference("enable-swift3-objc-inference",
424418
llvm::cl::desc("Enable Swift 3's @objc inference rules"),
@@ -870,6 +864,11 @@ static llvm::cl::list<std::string>
870864
llvm::cl::desc("Enable an experimental feature"),
871865
llvm::cl::cat(Category));
872866

867+
static llvm::cl::list<std::string>
868+
EnableUpcomingFeatures("enable-upcoming-feature",
869+
llvm::cl::desc("Enable a feature that will be introduced in an upcoming language version"),
870+
llvm::cl::cat(Category));
871+
873872
static llvm::cl::list<std::string>
874873
AccessNotesPath("access-notes-path", llvm::cl::desc("Path to access notes file"),
875874
llvm::cl::cat(Category));
@@ -4435,6 +4434,12 @@ int main(int argc, char *argv[]) {
44354434
}
44364435
}
44374436

4437+
for (const auto &featureArg : options::EnableUpcomingFeatures) {
4438+
if (auto feature = getUpcomingFeature(featureArg)) {
4439+
InitInvok.getLangOptions().Features.insert(*feature);
4440+
}
4441+
}
4442+
44384443
if (!options::Triple.empty())
44394444
InitInvok.setTargetTriple(options::Triple);
44404445
if (!options::SwiftVersion.empty()) {
@@ -4489,8 +4494,13 @@ int main(int argc, char *argv[]) {
44894494
options::EnableDeserializationSafety;
44904495
InitInvok.getLangOptions().EnableSwift3ObjCInference =
44914496
options::EnableSwift3ObjCInference;
4497+
// The manner in which swift-ide-test constructs its CompilerInvocation does
4498+
// not hit the codepath in arg parsing that would normally construct
4499+
// ClangImporter options based on enabled language features etc. Explicitly
4500+
// enable them here.
44924501
InitInvok.getClangImporterOptions().ImportForwardDeclarations |=
4493-
options::ObjCForwardDeclarations;
4502+
InitInvok.getLangOptions().hasFeature(
4503+
Feature::ImportObjcForwardDeclarations);
44944504
if (!options::ResourceDir.empty()) {
44954505
InitInvok.setRuntimeResourcePath(options::ResourceDir);
44964506
}

0 commit comments

Comments
 (0)