Skip to content

Commit a305fde

Browse files
authored
Merge pull request #64391 from hyp/eng/no-aeic-var
[interop][SwiftToCxx] do not expose @alwaysEmitIntoClient properties to C++
2 parents fd0dd26 + f405fb0 commit a305fde

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,17 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
205205
if (getActorIsolation(const_cast<ValueDecl *>(VD)).isActorIsolated())
206206
return {Unsupported, UnrepresentableIsolatedInActor};
207207
Optional<CanGenericSignature> genericSignature;
208+
// Don't expose @_alwaysEmitIntoClient decls as they require their
209+
// bodies to be emitted into client.
210+
if (VD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
211+
return {Unsupported, UnrepresentableRequiresClientEmission};
208212
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
209213
if (AFD->hasAsync())
210214
return {Unsupported, UnrepresentableAsync};
211215
if (AFD->hasThrows() &&
212216
!AFD->getASTContext().LangOpts.hasFeature(
213217
Feature::GenerateBindingsForThrowingFunctionsInCXX))
214218
return {Unsupported, UnrepresentableThrows};
215-
// Don't expose @_alwaysEmitIntoClient functions as they require their
216-
// bodies to be emitted into client.
217-
if (AFD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
218-
return {Unsupported, UnrepresentableRequiresClientEmission};
219219
if (AFD->isGeneric())
220220
genericSignature = AFD->getGenericSignature().getCanonicalSignature();
221221
}

test/Interop/SwiftToCxx/stdlib/string/string-in-cxx-execution.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
// RUN: %target-swift-frontend -typecheck %t/print-string.swift -typecheck -module-name Stringer -enable-experimental-cxx-interop -emit-clang-header-path %t/Stringer.h
55

6-
// RUN: %target-interop-build-clangxx -std=gnu++20 -c %t/string-conversions.cpp -I %t -o %t/swift-stdlib-execution.o
6+
// RUN: %target-interop-build-clangxx -std=gnu++20 -c %t/string-conversions.cpp -I %t -o %t/swift-stdlib-execution.o -DDEBUG=1
77
// RUN: %target-build-swift %t/print-string.swift -o %t/swift-stdlib-execution -Xlinker %t/swift-stdlib-execution.o -module-name Stringer -Xfrontend -entry-point-function-name -Xfrontend swiftMain %target-cxx-lib
88
// RUN: %target-codesign %t/swift-stdlib-execution
99
// RUN: %target-run %t/swift-stdlib-execution | %FileCheck %s
1010

11+
// Ensure that this works in optimized mode:
12+
13+
// RUN: %target-interop-build-clangxx -std=gnu++20 -c %t/string-conversions.cpp -I %t -o %t/swift-stdlib-execution-opt.o -O
14+
// RUN: %target-build-swift %t/print-string.swift -o %t/swift-stdlib-execution-opt -Xlinker %t/swift-stdlib-execution-opt.o -module-name Stringer -Xfrontend -entry-point-function-name -Xfrontend swiftMain %target-cxx-lib -O
15+
// RUN: %target-codesign %t/swift-stdlib-execution-opt
16+
// RUN: %target-run %t/swift-stdlib-execution-opt | %FileCheck %s
17+
1118
// REQUIRES: executable_test
1219

1320
//--- print-string.swift

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
// CHECK: SWIFT_INLINE_THUNK void append(const String& other)
7878
// CHECK: SWIFT_INLINE_THUNK UTF8View getUtf8() const SWIFT_SYMBOL({{.*}});
7979
// CHECK-NEXT: SWIFT_INLINE_THUNK void setUtf8(const UTF8View& newValue) SWIFT_SYMBOL({{.*}});
80-
// CHECK: SWIFT_INLINE_THUNK bool isContiguousUTF8() const SWIFT_SYMBOL({{.*}});
8180
// CHECK: #if defined(__OBJC__)
8281
// CHECK-NEXT: SWIFT_INLINE_THUNK operator NSString * _Nonnull () const noexcept {
8382
// CHECK-NEXT: return (__bridge_transfer NSString *)(_impl::$sSS10FoundationE19_bridgeToObjectiveCSo8NSStringCyF(_impl::swift_interop_passDirect_Swift_String(_getOpaquePointer())));

test/Interop/SwiftToCxx/unsupported/unsupported-funcs-in-cxx.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// CHECK-NOT: unsupported
99
// CHECK: HasMethods
1010
// CHECK: supported
11+
// CHECK-NOT: unsupported
1112

1213
public func supported() {}
1314

@@ -36,4 +37,10 @@ public struct HasMethods {
3637
return 42
3738
}
3839
}
40+
41+
@_expose(Cxx) // expected-error {{property 'unsupportedAEICProp' can not be exposed to C++ as it requires code to be emitted into client}}
42+
@_alwaysEmitIntoClient
43+
public var unsupportedAEICProp: Bool {
44+
return false
45+
}
3946
}

0 commit comments

Comments
 (0)