Skip to content

Commit 3ed62c7

Browse files
committed
Revert "[Swiftify] Don't create safe wrapper for autoreleasing pointers (swiftlang#81568)"
This reverts commit e1eb960.
1 parent c6853cf commit 3ed62c7

File tree

7 files changed

+8
-52
lines changed

7 files changed

+8
-52
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9192,14 +9192,6 @@ static bool SwiftifiableCAT(const clang::CountAttributedType *CAT) {
91929192
return CAT && CountedByExpressionValidator().Visit(CAT->getCountExpr());
91939193
}
91949194

9195-
static bool SwiftifiablePointerType(Type swiftType) {
9196-
// don't try to transform any Swift types that _SwiftifyImport doesn't know how to handle
9197-
Type nonnullType = swiftType->lookThroughSingleOptionalType();
9198-
PointerTypeKind PTK;
9199-
return nonnullType->isOpaquePointer() ||
9200-
(nonnullType->getAnyPointerElementType(PTK) && PTK != PTK_AutoreleasingUnsafeMutablePointer);
9201-
}
9202-
92039195
void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
92049196
if (!SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers))
92059197
return;
@@ -9233,11 +9225,10 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
92339225
return false;
92349226
};
92359227
SwiftifyInfoPrinter printer(getClangASTContext(), SwiftContext, out);
9236-
Type swiftReturnTy = MappedDecl->getResultInterfaceType();
92379228
bool returnIsStdSpan = registerStdSpanTypeMapping(
9238-
swiftReturnTy, ClangDecl->getReturnType());
9229+
MappedDecl->getResultInterfaceType(), ClangDecl->getReturnType());
92399230
auto *CAT = ClangDecl->getReturnType()->getAs<clang::CountAttributedType>();
9240-
if (SwiftifiableCAT(CAT) && SwiftifiablePointerType(swiftReturnTy)) {
9231+
if (SwiftifiableCAT(CAT)) {
92419232
printer.printCountedBy(CAT, SwiftifyInfoPrinter::RETURN_VALUE_INDEX);
92429233
attachMacro = true;
92439234
}
@@ -9251,15 +9242,14 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
92519242
for (auto [index, clangParam] : llvm::enumerate(ClangDecl->parameters())) {
92529243
auto clangParamTy = clangParam->getType();
92539244
auto swiftParam = MappedDecl->getParameters()->get(index);
9254-
Type swiftParamTy = swiftParam->getInterfaceType();
92559245
bool paramHasBoundsInfo = false;
92569246
auto *CAT = clangParamTy->getAs<clang::CountAttributedType>();
9257-
if (SwiftifiableCAT(CAT) && SwiftifiablePointerType(swiftParamTy)) {
9247+
if (SwiftifiableCAT(CAT)) {
92589248
printer.printCountedBy(CAT, index);
92599249
attachMacro = paramHasBoundsInfo = true;
92609250
}
92619251
bool paramIsStdSpan = registerStdSpanTypeMapping(
9262-
swiftParamTy, clangParamTy);
9252+
swiftParam->getInterfaceType(), clangParamTy);
92639253
paramHasBoundsInfo |= paramIsStdSpan;
92649254

92659255
bool paramHasLifetimeInfo = false;
@@ -9270,7 +9260,7 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
92709260
if (clangParam->hasAttr<clang::LifetimeBoundAttr>()) {
92719261
printer.printLifetimeboundReturn(
92729262
index, !paramHasBoundsInfo &&
9273-
swiftParamTy->isEscapable());
9263+
swiftParam->getInterfaceType()->isEscapable());
92749264
paramHasLifetimeInfo = true;
92759265
returnHasLifetimeInfo = true;
92769266
}

test/Interop/C/swiftify-import/Inputs/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ module SizedByNoEscapeClang {
1414
header "sized-by-noescape.h"
1515
export *
1616
}
17+

test/Interop/ObjC/lit.local.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/Interop/ObjC/swiftify-import/Inputs/module.modulemap

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/Interop/ObjC/swiftify-import/counted-by-in-class.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: %target-swift-ide-test -plugin-path %swift-plugin-dir -I %t/Inputs -enable-experimental-feature SafeInteropWrappers -print-module -module-to-print=Method -source-filename=x | %FileCheck %s
66
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/method.swift -dump-macro-expansions -typecheck -verify
77

8+
// REQUIRES: objc_interop
9+
810
// CHECK: class Foo {
911
// CHECK: func bar(_ p: UnsafeMutableBufferPointer<Float>)
1012

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)