Skip to content

Commit 31d5c20

Browse files
authored
Merge pull request #86075 from swiftlang/skip-mismatching-paramlist
[Swiftify] don't swiftify functions with sugared parameter lists
2 parents 73cb75a + 38827c8 commit 31d5c20

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

lib/ClangImporter/SwiftifyDecl.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,24 @@ static bool swiftifyImpl(ClangImporter::Implementation &Self,
414414
}
415415

416416
bool isClangInstanceMethod =
417-
isa<clang::CXXMethodDecl>(ClangDecl) &&
418-
!isa<clang::CXXConstructorDecl>(ClangDecl) &&
419-
cast<clang::CXXMethodDecl>(ClangDecl)->isInstance();
420-
size_t swiftNumParams = MappedDecl->getParameters()->size() -
421-
(ClangDecl->isVariadic() ? 1 : 0);
422-
ASSERT((MappedDecl->isImportAsInstanceMember() == isClangInstanceMethod) ==
423-
(getNumParams(ClangDecl) == swiftNumParams));
417+
(isa<clang::CXXMethodDecl>(ClangDecl) &&
418+
!isa<clang::CXXConstructorDecl>(ClangDecl) &&
419+
cast<clang::CXXMethodDecl>(ClangDecl)->isInstance()) ||
420+
(isa<clang::ObjCMethodDecl>(ClangDecl) &&
421+
cast<clang::ObjCMethodDecl>(ClangDecl)->isInstanceMethod());
422+
423+
size_t swiftNumParams = MappedDecl->getParameters()->size();
424+
if (MappedDecl->isInstanceMember() && !isClangInstanceMethod) {
425+
ASSERT(MappedDecl->isImportAsInstanceMember());
426+
swiftNumParams += 1;
427+
}
428+
if (getNumParams(ClangDecl) != swiftNumParams) {
429+
DLOG("mismatching parameter lists");
430+
assert(ClangDecl->isVariadic() ||
431+
MappedDecl->getForeignErrorConvention().has_value() ||
432+
MappedDecl->getForeignAsyncConvention().has_value());
433+
return false;
434+
}
424435

425436
size_t selfParamIndex = MappedDecl->isImportAsInstanceMember()
426437
? MappedDecl->getSelfIndex()
@@ -531,6 +542,9 @@ class SwiftifyProtocolInfoPrinter : public SwiftifyInfoPrinter {
531542
void printMethodSignature(const FuncDecl *Method) {
532543
auto options =
533544
PrintOptions::printForDiagnostics(AccessLevel::Private, true);
545+
for (const auto *attr : Method->getAttrs()) {
546+
options.ExcludeAttrList.push_back(attr->getKind());
547+
}
534548
StreamPrinter printer(out);
535549
Method->print(printer, options);
536550
}

test/Interop/C/swiftify-import/Inputs/counted-by.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ void hexLiteral(int * __counted_by(0xfa) p);
6262
void binaryLiteral(int * __counted_by(0b10) p);
6363

6464
void octalLiteral(int * __counted_by(0777) p);
65+
66+
void variadic(int len, int * __counted_by(len) p, ...);

test/Interop/C/swiftify-import/counted-by-no-swiftify.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} longLiteral
1717
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} sizeofType
1818
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} sizeofParam
19+
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} variadic

test/Interop/ObjC/swiftify-import/Inputs/objc-no-swiftify.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@
77
void autoreleaseParam(SomeClass * __autoreleasing * __counted_by(len) p, int len); // expected-note{{declared here}}
88

99
SomeClass * __autoreleasing * __counted_by(len) autoreleaseReturn(int len);
10+
11+
@interface NSError
12+
@end
13+
14+
@interface NSData
15+
@end
16+
17+
@protocol Foo
18+
- (void)errorAsTry:(int) len : (int * __counted_by(len)) p error:(NSError * *) error;
19+
- (void)completionHandlerAsAsync:(int) len : (int * __counted_by(len)) p completionHandler:(void (^)(NSData * data, NSError *)) completionHandler;
20+
@end

test/Interop/ObjC/swiftify-import/objc-no-swiftify.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import NoSwiftifyClang
99

10-
// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload public func callAutoreleaseParam
11-
// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload public func callAutoreleaseReturn
10+
// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload
1211

1312
public func callAutoreleaseParam(_ p: UnsafeMutableBufferPointer<SomeClass>) {
1413
// expected-error@+2{{missing argument for parameter #2 in call}}
@@ -19,4 +18,14 @@ public func callAutoreleaseParam(_ p: UnsafeMutableBufferPointer<SomeClass>) {
1918
public func callAutoreleaseReturn() {
2019
// expected-error@+1{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<SomeClass?>?' to specified type 'UnsafeMutableBufferPointer<SomeClass>'}}
2120
let p: UnsafeMutableBufferPointer<SomeClass> = autoreleaseReturn(10)
22-
}
21+
}
22+
23+
public func callErrorAsTry(_ x: Foo, _ p: UnsafeMutablePointer<CInt>, _ error: AutoreleasingUnsafeMutablePointer<NSError?>) {
24+
x.error(asTry: 10, p, error: error)
25+
}
26+
27+
public func callCompletionHandlerAsAsync(_ x: Foo, _ p: UnsafeMutablePointer<CInt>) {
28+
x.completionHandler(asAsync: 10, p, completionHandler: { (a: NSData?, b: NSError?) in
29+
print("asdf")
30+
})
31+
}

0 commit comments

Comments
 (0)