Skip to content

[interop][SwiftToCxx] give explicit error for @alwaysEmitIntoClient e… #62421

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
Dec 7, 2022
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
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,8 @@ ERROR(expose_unsupported_async_decl_to_cxx,none,
"async %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
ERROR(expose_unsupported_actor_isolated_to_cxx,none,
"actor-isolated %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
ERROR(expose_unsupported_client_emission_to_cxx,none,
"%0 %1 can not be exposed to C++ as it requires code to be emitted into client", (DescriptiveDeclKind, ValueDecl *))

ERROR(attr_methods_only,none,
"only methods can be declared %0", (DeclAttribute))
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/SwiftNameTranslation.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ enum RepresentationKind { Representable, Unsupported };

enum RepresentationError {
UnrepresentableAsync,
UnrepresentableIsolatedInActor
UnrepresentableIsolatedInActor,
UnrepresentableRequiresClientEmission,
};

struct DeclRepresentation {
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
if (AFD->hasAsync())
return {Unsupported, UnrepresentableAsync};
// Don't expose @_alwaysEmitIntoClient functions as they require their
// bodies to be emitted into client.
if (AFD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
return {Unsupported, UnrepresentableRequiresClientEmission};
}
return {Representable, llvm::None};
}
Expand Down
6 changes: 0 additions & 6 deletions lib/PrintAsClang/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,6 @@ class DeclAndTypePrinter::Implementation

void visitFuncDecl(FuncDecl *FD) {
if (outputLang == OutputLanguageMode::Cxx) {
// Don't expose async functions or @_alwaysEmitIntoClient functions
// because they're currently unsupported
if (FD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>()) {
return;
}

// FIXME: Support static methods.
if (FD->getDeclContext()->isTypeContext() && FD->isStatic())
return;
Expand Down
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,11 @@ void AttributeChecker::visitExposeAttr(ExposeAttr *attr) {
diag::expose_unsupported_actor_isolated_to_cxx,
VD->getDescriptiveKind(), VD);
break;
case UnrepresentableRequiresClientEmission:
diagnose(attr->getLocation(),
diag::expose_unsupported_client_emission_to_cxx,
VD->getDescriptiveKind(), VD);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// CHECK: namespace Functions __attribute__((swift_private)) {
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: } // namespace Functions

// CHECK-NOT: inline bool alwaysEmitIntoClientFunc(bool x) noexcept SWIFT_WARN_UNUSED_RESULT {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// 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

// RUN: cat %s | grep -v _expose > %t/clean.swift
// 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
// RUN: %FileCheck %s < %t/header.h

// CHECK-NOT: unsupported
// CHECK: supported

public func supported() {}

@_expose(Cxx) // expected-error {{global function 'unsupportedAEIC()' can not be exposed to C++ as it requires code to be emitted into client}}
@_alwaysEmitIntoClient
public func unsupportedAEIC() {}