Skip to content

Commit 1402020

Browse files
committed
Revert "[interop] do not import functions whose return type is not imported"
This reverts commit 8e0c17b.
1 parent 227c6a8 commit 1402020

File tree

6 files changed

+14
-97
lines changed

6 files changed

+14
-97
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ NOTE(record_field_not_imported, none, "field %0 unavailable (cannot import)", (c
256256
NOTE(invoked_func_not_imported, none, "function %0 unavailable (cannot import)", (const clang::NamedDecl*))
257257
NOTE(record_method_not_imported, none, "method %0 unavailable (cannot import)", (const clang::NamedDecl*))
258258
NOTE(objc_property_not_imported, none, "property %0 unavailable (cannot import)", (const clang::NamedDecl*))
259-
NOTE(unsupported_return_type, none, "C++ function %0 is unavailable: return type is unavailable in Swift", (const clang::NamedDecl*))
260259

261260
NOTE(placeholder_for_forward_declared_interface_member_access_failure, none,
262261
"class '%0' will be imported as an opaque placeholder class and may be "

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5711,7 +5711,13 @@ importName(const clang::NamedDecl *D,
57115711

57125712
Type ClangImporter::importFunctionReturnType(
57135713
const clang::FunctionDecl *clangDecl, DeclContext *dc) {
5714-
if (auto imported = Impl.importFunctionReturnType(clangDecl, dc).getType())
5714+
bool isInSystemModule =
5715+
cast<ClangModuleUnit>(dc->getModuleScopeContext())->isSystemModule();
5716+
bool allowNSUIntegerAsInt =
5717+
Impl.shouldAllowNSUIntegerAsInt(isInSystemModule, clangDecl);
5718+
if (auto imported =
5719+
Impl.importFunctionReturnType(dc, clangDecl, allowNSUIntegerAsInt)
5720+
.getType())
57155721
return imported;
57165722
return dc->getASTContext().getNeverType();
57175723
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,16 +3137,13 @@ namespace {
31373137

31383138
if (auto recordType = dyn_cast<clang::RecordType>(
31393139
decl->getReturnType().getCanonicalType())) {
3140-
if (recordHasReferenceSemantics(recordType->getDecl())) {
3141-
Impl.addImportDiagnostic(
3142-
decl,
3143-
Diagnostic(diag::reference_passed_by_value,
3144-
Impl.SwiftContext.AllocateCopy(
3145-
recordType->getDecl()->getNameAsString()),
3146-
"the return"),
3147-
decl->getLocation());
3148-
return true;
3149-
}
3140+
Impl.addImportDiagnostic(
3141+
decl, Diagnostic(diag::reference_passed_by_value,
3142+
Impl.SwiftContext.AllocateCopy(
3143+
recordType->getDecl()->getNameAsString()),
3144+
"the return"),
3145+
decl->getLocation());
3146+
return recordHasReferenceSemantics(recordType->getDecl());
31503147
}
31513148

31523149
return false;
@@ -3532,14 +3529,6 @@ namespace {
35323529
func->setAccess(AccessLevel::Public);
35333530
}
35343531

3535-
if (!isa<clang::CXXConstructorDecl>(decl) && !importedType) {
3536-
if (!Impl.importFunctionReturnType(decl, result->getDeclContext())) {
3537-
Impl.addImportDiagnostic(
3538-
decl, Diagnostic(diag::unsupported_return_type, decl),
3539-
decl->getSourceRange().getBegin());
3540-
return nullptr;
3541-
}
3542-
}
35433532
result->setIsObjC(false);
35443533
result->setIsDynamic(false);
35453534

lib/ClangImporter/ImportType.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,15 +2075,6 @@ applyImportTypeAttrs(ImportTypeAttrs attrs, Type type,
20752075
return type;
20762076
}
20772077

2078-
ImportedType ClangImporter::Implementation::importFunctionReturnType(
2079-
const clang::FunctionDecl *clangDecl, DeclContext *dc) {
2080-
bool isInSystemModule =
2081-
cast<ClangModuleUnit>(dc->getModuleScopeContext())->isSystemModule();
2082-
bool allowNSUIntegerAsInt =
2083-
shouldAllowNSUIntegerAsInt(isInSystemModule, clangDecl);
2084-
return importFunctionReturnType(dc, clangDecl, allowNSUIntegerAsInt);
2085-
}
2086-
20872078
ImportedType ClangImporter::Implementation::importFunctionReturnType(
20882079
DeclContext *dc, const clang::FunctionDecl *clangDecl,
20892080
bool allowNSUIntegerAsInt) {

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
13721372
const clang::FunctionDecl *clangDecl,
13731373
bool allowNSUIntegerAsInt);
13741374

1375-
ImportedType importFunctionReturnType(const clang::FunctionDecl *clangDecl,
1376-
DeclContext *dc);
1377-
13781375
/// Import the parameter list for a function
13791376
///
13801377
/// \param clangDecl The underlying declaration, if any; should only be

test/Interop/Cxx/class/returns-unavailable-class.swift

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

0 commit comments

Comments
 (0)