Skip to content

Commit 6bf7593

Browse files
authored
Revert "[CxxInterop] Import C++ references." (#31777)
1 parent 63167fa commit 6bf7593

File tree

12 files changed

+25
-364
lines changed

12 files changed

+25
-364
lines changed

include/swift/AST/Types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,10 +2696,10 @@ enum class FunctionTypeRepresentation : uint8_t {
26962696
/// A "thin" function that needs no context.
26972697
Thin,
26982698

2699-
/// A C function pointer (or reference), which is thin and also uses the C
2700-
/// calling convention.
2699+
/// A C function pointer, which is thin and also uses the C calling
2700+
/// convention.
27012701
CFunctionPointer,
2702-
2702+
27032703
/// The value of the greatest AST function representation.
27042704
Last = CFunctionPointer,
27052705
};
@@ -2980,8 +2980,8 @@ class AnyFunctionType : public TypeBase {
29802980
// We preserve a full clang::Type *, not a clang::FunctionType * as:
29812981
// 1. We need to keep sugar in case we need to present an error to the user.
29822982
// 2. The actual type being stored is [ignoring sugar] either a
2983-
// clang::PointerType, a clang::BlockPointerType, or a
2984-
// clang::ReferenceType which points to a clang::FunctionType.
2983+
// clang::PointerType or a clang::BlockPointerType which points to a
2984+
// clang::FunctionType.
29852985
const clang::Type *ClangFunctionType;
29862986

29872987
bool empty() const { return !ClangFunctionType; }

lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,8 +3376,7 @@ void AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType(
33763376
void
33773377
AnyFunctionType::ExtInfo::assertIsFunctionType(const clang::Type *type) {
33783378
#ifndef NDEBUG
3379-
if (!(type->isFunctionPointerType() || type->isBlockPointerType() ||
3380-
type->isFunctionReferenceType())) {
3379+
if (!(type->isFunctionPointerType() || type->isBlockPointerType())) {
33813380
SmallString<256> buf;
33823381
llvm::raw_svector_ostream os(buf);
33833382
os << "Expected a Clang function type wrapped in a pointer type or "

lib/ClangImporter/ImportType.cpp

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,6 @@ namespace {
159159
explicit operator bool() const { return (bool) AbstractType; }
160160
};
161161

162-
static ImportResult importFunctionPointerLikeType(const clang::Type &type,
163-
const Type &pointeeType) {
164-
auto funcTy = pointeeType->castTo<FunctionType>();
165-
return {FunctionType::get(
166-
funcTy->getParams(), funcTy->getResult(),
167-
funcTy->getExtInfo()
168-
.withRepresentation(
169-
AnyFunctionType::Representation::CFunctionPointer)
170-
.withClangFunctionType(&type)),
171-
type.isReferenceType() ? ImportHint::None
172-
: ImportHint::CFunctionPointer};
173-
}
174-
175-
static ImportResult importOverAlignedFunctionPointerLikeType(
176-
const clang::Type &type, ClangImporter::Implementation &Impl) {
177-
auto opaquePointer = Impl.SwiftContext.getOpaquePointerDecl();
178-
if (!opaquePointer) {
179-
return Type();
180-
}
181-
return {opaquePointer->getDeclaredType(),
182-
type.isReferenceType() ? ImportHint::None
183-
: ImportHint::OtherPointer};
184-
}
185-
186162
class SwiftTypeConverter :
187163
public clang::TypeVisitor<SwiftTypeConverter, ImportResult>
188164
{
@@ -430,11 +406,23 @@ namespace {
430406
// alignment is greater than the maximum Swift alignment, import as
431407
// OpaquePointer.
432408
if (!pointeeType || Impl.isOverAligned(pointeeQualType)) {
433-
return importOverAlignedFunctionPointerLikeType(*type, Impl);
409+
auto opaquePointer = Impl.SwiftContext.getOpaquePointerDecl();
410+
if (!opaquePointer)
411+
return Type();
412+
return {opaquePointer->getDeclaredType(),
413+
ImportHint::OtherPointer};
434414
}
435-
415+
436416
if (pointeeQualType->isFunctionType()) {
437-
return importFunctionPointerLikeType(*type, pointeeType);
417+
auto funcTy = pointeeType->castTo<FunctionType>();
418+
return {
419+
FunctionType::get(funcTy->getParams(), funcTy->getResult(),
420+
funcTy->getExtInfo()
421+
.withRepresentation(
422+
AnyFunctionType::Representation::CFunctionPointer)
423+
.withClangFunctionType(type)),
424+
ImportHint::CFunctionPointer
425+
};
438426
}
439427

440428
PointerTypeKind pointerKind;
@@ -484,29 +472,7 @@ namespace {
484472
}
485473

486474
ImportResult VisitReferenceType(const clang::ReferenceType *type) {
487-
auto pointeeQualType = type->getPointeeType();
488-
auto quals = pointeeQualType.getQualifiers();
489-
Type pointeeType =
490-
Impl.importTypeIgnoreIUO(pointeeQualType, ImportTypeKind::Value,
491-
AllowNSUIntegerAsInt, Bridgeability::None);
492-
493-
if (pointeeQualType->isFunctionType()) {
494-
return importFunctionPointerLikeType(*type, pointeeType);
495-
}
496-
497-
if (Impl.isOverAligned(pointeeQualType)) {
498-
return importOverAlignedFunctionPointerLikeType(*type, Impl);
499-
}
500-
501-
PointerTypeKind pointerKind;
502-
if (quals.hasConst()) {
503-
pointerKind = PTK_UnsafePointer;
504-
} else {
505-
pointerKind = PTK_UnsafeMutablePointer;
506-
}
507-
508-
return {pointeeType->wrapInPointer(pointerKind),
509-
ImportHint::None};
475+
return Type();
510476
}
511477

512478
ImportResult VisitMemberPointer(const clang::MemberPointerType *type) {

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ enum class ImportTypeKind {
135135

136136
/// Import the type of a function parameter.
137137
///
138-
/// Special handling:
139-
/// * C and C++ pointers become `UnsafePointer?` or `UnsafeMutablePointer?`
140-
/// * C++ references become `UnsafePointer` or `UnsafeMutablePointer`
141-
/// * Bridging that requires type conversions is allowed.
138+
/// This provides special treatment for C++ references (which become
139+
/// [inout] parameters) and C pointers (which become magic [inout]-able types),
140+
/// among other things, and enables the conversion of bridged types.
142141
/// Parameters are always considered CF-audited.
143142
Parameter,
144143

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ getClangFunctionType(const clang::Type *clangType) {
319319
clangType = ptrTy->getPointeeType().getTypePtr();
320320
} else if (auto blockTy = clangType->getAs<clang::BlockPointerType>()) {
321321
clangType = blockTy->getPointeeType().getTypePtr();
322-
} else if (auto refTy = clangType->getAs<clang::ReferenceType>()) {
323-
clangType = refTy->getPointeeType().getTypePtr();
324322
}
325323
return clangType->castAs<clang::FunctionType>();
326324
}

test/Interop/Cxx/reference/Inputs/module.modulemap

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

test/Interop/Cxx/reference/Inputs/reference.cpp

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

test/Interop/Cxx/reference/Inputs/reference.h

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

test/Interop/Cxx/reference/reference-irgen.swift

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

test/Interop/Cxx/reference/reference-module-interface.swift

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

test/Interop/Cxx/reference/reference-silgen.swift

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

0 commit comments

Comments
 (0)