Skip to content

Commit d0e5372

Browse files
committed
[interop][SwiftToCxx] give explicit error for @alwaysEmitIntoClient exposed functions
1 parent 0368538 commit d0e5372

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@ ERROR(expose_unsupported_async_decl_to_cxx,none,
15481548
"async %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
15491549
ERROR(expose_unsupported_actor_isolated_to_cxx,none,
15501550
"actor-isolated %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1551+
ERROR(expose_unsupported_client_emission_to_cxx,none,
1552+
"%0 %1 can not be exposed to C++ as it requires code to be emitted into client", (DescriptiveDeclKind, ValueDecl *))
15511553

15521554
ERROR(attr_methods_only,none,
15531555
"only methods can be declared %0", (DeclAttribute))

include/swift/AST/SwiftNameTranslation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ enum RepresentationKind { Representable, Unsupported };
6767

6868
enum RepresentationError {
6969
UnrepresentableAsync,
70-
UnrepresentableIsolatedInActor
70+
UnrepresentableIsolatedInActor,
71+
UnrepresentableRequiresClientEmission,
7172
};
7273

7374
struct DeclRepresentation {

lib/AST/SwiftNameTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
172172
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
173173
if (AFD->hasAsync())
174174
return {Unsupported, UnrepresentableAsync};
175+
// Don't expose @_alwaysEmitIntoClient functions as they require their
176+
// bodies to be emitted into client.
177+
if (AFD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
178+
return {Unsupported, UnrepresentableRequiresClientEmission};
175179
}
176180
return {Representable, llvm::None};
177181
}

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,12 +1637,6 @@ class DeclAndTypePrinter::Implementation
16371637

16381638
void visitFuncDecl(FuncDecl *FD) {
16391639
if (outputLang == OutputLanguageMode::Cxx) {
1640-
// Don't expose async functions or @_alwaysEmitIntoClient functions
1641-
// because they're currently unsupported
1642-
if (FD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>()) {
1643-
return;
1644-
}
1645-
16461640
// FIXME: Support static methods.
16471641
if (FD->getDeclContext()->isTypeContext() && FD->isStatic())
16481642
return;

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,11 @@ void AttributeChecker::visitExposeAttr(ExposeAttr *attr) {
19841984
diag::expose_unsupported_actor_isolated_to_cxx,
19851985
VD->getDescriptiveKind(), VD);
19861986
break;
1987+
case UnrepresentableRequiresClientEmission:
1988+
diagnose(attr->getLocation(),
1989+
diag::expose_unsupported_client_emission_to_cxx,
1990+
VD->getDescriptiveKind(), VD);
1991+
break;
19871992
}
19881993
}
19891994

test/Interop/SwiftToCxx/functions/swift-no-expose-unsupported-alwaysEmitInClient-func.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// CHECK: namespace Functions __attribute__((swift_private)) {
1010
// CHECK-EMPTY:
1111
// CHECK-EMPTY:
12-
// CHECK-EMPTY:
13-
// CHECK-EMPTY:
1412
// CHECK-NEXT: } // namespace Functions
1513

1614
// CHECK-NOT: inline bool alwaysEmitIntoClientFunc(bool x) noexcept SWIFT_WARN_UNUSED_RESULT {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -verify -clang-header-expose-decls=has-expose-attr -disable-availability-checking -emit-clang-header-path %t/functions.h
3+
4+
// RUN: cat %s | grep -v _expose > %t/clean.swift
5+
// RUN: %target-swift-frontend %t/clean.swift -typecheck -module-name Functions -clang-header-expose-decls=all-public -disable-availability-checking -emit-clang-header-path %t/header.h
6+
// RUN: %FileCheck %s < %t/header.h
7+
8+
// CHECK-NOT: unsupported
9+
// CHECK: supported
10+
11+
public func supported() {}
12+
13+
@_expose(Cxx) // expected-error {{global function 'unsupportedAEIC()' can not be exposed to C++ as it requires code to be emitted into client}}
14+
@_alwaysEmitIntoClient
15+
public func unsupportedAEIC() {}

0 commit comments

Comments
 (0)