Skip to content

Commit 7fb7e42

Browse files
committed
[swift-ide-test] Tie ClangImporter fwd-decl option to chosen lang feature
Prviously swift-ide-test enabled importing of ObjC forward declarations with the -enable-objc-forward-declarations option. The compiler enables the same behavior via -enable-upcoming-feature. Now that swift-ide-test also supports upcoming-features, make enabling the ImportObjcForwardDeclarations language feature have the expected effect in swift-ide-test. The old flag is also removed.
1 parent 011b669 commit 7fb7e42

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-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: 6 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"),
@@ -4486,8 +4480,13 @@ int main(int argc, char *argv[]) {
44864480
options::EnableDeserializationSafety;
44874481
InitInvok.getLangOptions().EnableSwift3ObjCInference =
44884482
options::EnableSwift3ObjCInference;
4483+
// The manner in which swift-ide-test constructs its CompilerInvocation does
4484+
// not hit the codepath in arg parsing that would normally construct
4485+
// ClangImporter options based on enabled language features etc. Explicitly
4486+
// enable them here.
44894487
InitInvok.getClangImporterOptions().ImportForwardDeclarations |=
4490-
options::ObjCForwardDeclarations;
4488+
InitInvok.getLangOptions().hasFeature(
4489+
Feature::ImportObjcForwardDeclarations);
44914490
if (!options::ResourceDir.empty()) {
44924491
InitInvok.setRuntimeResourcePath(options::ResourceDir);
44934492
}

0 commit comments

Comments
 (0)