Skip to content

Revert "[CxxInterop] Import C++ references." #31777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2696,10 +2696,10 @@ enum class FunctionTypeRepresentation : uint8_t {
/// A "thin" function that needs no context.
Thin,

/// A C function pointer (or reference), which is thin and also uses the C
/// calling convention.
/// A C function pointer, which is thin and also uses the C calling
/// convention.
CFunctionPointer,

/// The value of the greatest AST function representation.
Last = CFunctionPointer,
};
Expand Down Expand Up @@ -2980,8 +2980,8 @@ class AnyFunctionType : public TypeBase {
// We preserve a full clang::Type *, not a clang::FunctionType * as:
// 1. We need to keep sugar in case we need to present an error to the user.
// 2. The actual type being stored is [ignoring sugar] either a
// clang::PointerType, a clang::BlockPointerType, or a
// clang::ReferenceType which points to a clang::FunctionType.
// clang::PointerType or a clang::BlockPointerType which points to a
// clang::FunctionType.
const clang::Type *ClangFunctionType;

bool empty() const { return !ClangFunctionType; }
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,8 +3376,7 @@ void AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType(
void
AnyFunctionType::ExtInfo::assertIsFunctionType(const clang::Type *type) {
#ifndef NDEBUG
if (!(type->isFunctionPointerType() || type->isBlockPointerType() ||
type->isFunctionReferenceType())) {
if (!(type->isFunctionPointerType() || type->isBlockPointerType())) {
SmallString<256> buf;
llvm::raw_svector_ostream os(buf);
os << "Expected a Clang function type wrapped in a pointer type or "
Expand Down
66 changes: 16 additions & 50 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,6 @@ namespace {
explicit operator bool() const { return (bool) AbstractType; }
};

static ImportResult importFunctionPointerLikeType(const clang::Type &type,
const Type &pointeeType) {
auto funcTy = pointeeType->castTo<FunctionType>();
return {FunctionType::get(
funcTy->getParams(), funcTy->getResult(),
funcTy->getExtInfo()
.withRepresentation(
AnyFunctionType::Representation::CFunctionPointer)
.withClangFunctionType(&type)),
type.isReferenceType() ? ImportHint::None
: ImportHint::CFunctionPointer};
}

static ImportResult importOverAlignedFunctionPointerLikeType(
const clang::Type &type, ClangImporter::Implementation &Impl) {
auto opaquePointer = Impl.SwiftContext.getOpaquePointerDecl();
if (!opaquePointer) {
return Type();
}
return {opaquePointer->getDeclaredType(),
type.isReferenceType() ? ImportHint::None
: ImportHint::OtherPointer};
}

class SwiftTypeConverter :
public clang::TypeVisitor<SwiftTypeConverter, ImportResult>
{
Expand Down Expand Up @@ -430,11 +406,23 @@ namespace {
// alignment is greater than the maximum Swift alignment, import as
// OpaquePointer.
if (!pointeeType || Impl.isOverAligned(pointeeQualType)) {
return importOverAlignedFunctionPointerLikeType(*type, Impl);
auto opaquePointer = Impl.SwiftContext.getOpaquePointerDecl();
if (!opaquePointer)
return Type();
return {opaquePointer->getDeclaredType(),
ImportHint::OtherPointer};
}

if (pointeeQualType->isFunctionType()) {
return importFunctionPointerLikeType(*type, pointeeType);
auto funcTy = pointeeType->castTo<FunctionType>();
return {
FunctionType::get(funcTy->getParams(), funcTy->getResult(),
funcTy->getExtInfo()
.withRepresentation(
AnyFunctionType::Representation::CFunctionPointer)
.withClangFunctionType(type)),
ImportHint::CFunctionPointer
};
}

PointerTypeKind pointerKind;
Expand Down Expand Up @@ -484,29 +472,7 @@ namespace {
}

ImportResult VisitReferenceType(const clang::ReferenceType *type) {
auto pointeeQualType = type->getPointeeType();
auto quals = pointeeQualType.getQualifiers();
Type pointeeType =
Impl.importTypeIgnoreIUO(pointeeQualType, ImportTypeKind::Value,
AllowNSUIntegerAsInt, Bridgeability::None);

if (pointeeQualType->isFunctionType()) {
return importFunctionPointerLikeType(*type, pointeeType);
}

if (Impl.isOverAligned(pointeeQualType)) {
return importOverAlignedFunctionPointerLikeType(*type, Impl);
}

PointerTypeKind pointerKind;
if (quals.hasConst()) {
pointerKind = PTK_UnsafePointer;
} else {
pointerKind = PTK_UnsafeMutablePointer;
}

return {pointeeType->wrapInPointer(pointerKind),
ImportHint::None};
return Type();
}

ImportResult VisitMemberPointer(const clang::MemberPointerType *type) {
Expand Down
7 changes: 3 additions & 4 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ enum class ImportTypeKind {

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

Expand Down
2 changes: 0 additions & 2 deletions lib/SIL/IR/AbstractionPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ getClangFunctionType(const clang::Type *clangType) {
clangType = ptrTy->getPointeeType().getTypePtr();
} else if (auto blockTy = clangType->getAs<clang::BlockPointerType>()) {
clangType = blockTy->getPointeeType().getTypePtr();
} else if (auto refTy = clangType->getAs<clang::ReferenceType>()) {
clangType = refTy->getPointeeType().getTypePtr();
}
return clangType->castAs<clang::FunctionType>();
}
Expand Down
3 changes: 0 additions & 3 deletions test/Interop/Cxx/reference/Inputs/module.modulemap

This file was deleted.

19 changes: 0 additions & 19 deletions test/Interop/Cxx/reference/Inputs/reference.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions test/Interop/Cxx/reference/Inputs/reference.h

This file was deleted.

71 changes: 0 additions & 71 deletions test/Interop/Cxx/reference/reference-irgen.swift

This file was deleted.

14 changes: 0 additions & 14 deletions test/Interop/Cxx/reference/reference-module-interface.swift

This file was deleted.

83 changes: 0 additions & 83 deletions test/Interop/Cxx/reference/reference-silgen.swift

This file was deleted.

Loading