Skip to content

Commit f270e36

Browse files
author
Gabor Horvath
committed
[cxx-interop] Move addressable parameters in interop behind a flag
This unblocks the CI while we figure out some SILGen issues. We cannot reuse AddressableParameters because that is already used in some projects and consuming modules where the AddressableParameters flag was not propagated to results in deserialization errors.
1 parent aa16ff5 commit f270e36

File tree

7 files changed

+27
-5
lines changed

7 files changed

+27
-5
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ EXPERIMENTAL_FEATURE(CoroutineAccessorsUnwindOnCallerError, false)
502502

503503
EXPERIMENTAL_FEATURE(AddressableParameters, true)
504504
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
505+
EXPERIMENTAL_FEATURE(AddressableInterop, true)
505506

506507
/// Allow custom availability domains to be defined and referenced.
507508
EXPERIMENTAL_FEATURE(CustomAvailability, true)

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ static bool usesFeatureAddressableTypes(Decl *d) {
409409
return false;
410410
}
411411

412+
UNINTERESTING_FEATURE(AddressableInterop)
412413
UNINTERESTING_FEATURE(IsolatedAny2)
413414
UNINTERESTING_FEATURE(GlobalActorIsolatedTypesUsability)
414415
UNINTERESTING_FEATURE(ObjCImplementation)

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4038,7 +4038,9 @@ namespace {
40384038
func->setSelfIndex(selfIdx.value());
40394039
// FIXME: Make this work when SIL Opaque Values are enabled.
40404040
// Currently, addressable parameters and opaque values are at odds.
4041-
if (!dc->getDeclaredInterfaceType()->hasReferenceSemantics() &&
4041+
if (Impl.SwiftContext.LangOpts.hasFeature(
4042+
Feature::AddressableInterop) &&
4043+
!dc->getDeclaredInterfaceType()->hasReferenceSemantics() &&
40424044
!importedName.importAsMember() &&
40434045
!Impl.SwiftContext.SILOpts.EnableSILOpaqueValues)
40444046
func->getAttrs().add(new (Impl.SwiftContext)

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,8 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
27252725
// subobject of the referenced storage. In those cases we need to prevent the
27262726
// Swift compiler to pass in a temporary copy to prevent dangling.
27272727
auto paramContext = param->getDeclContext();
2728-
if (!param->getType().isNull() && param->getType()->isLValueReferenceType() &&
2728+
if (impl->SwiftContext.LangOpts.hasFeature(Feature::AddressableInterop) &&
2729+
!param->getType().isNull() && param->getType()->isLValueReferenceType() &&
27292730
!swiftParamTy->isForeignReferenceType() &&
27302731
!(isa<clang::FunctionDecl>(paramContext) &&
27312732
cast<clang::FunctionDecl>(paramContext)->isOverloadedOperator()) &&

test/ClangImporter/cxx_interop_ir.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-swiftxx-frontend -module-name cxx_ir -I %S/Inputs/custom-modules -emit-ir -o - -primary-file %s -Xcc -fignore-exceptions | %FileCheck %s
1+
// RUN: %target-swiftxx-frontend -module-name cxx_ir -I %S/Inputs/custom-modules -emit-ir -o - -primary-file %s -Xcc -fignore-exceptions -enable-experimental-feature AddressableInterop | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_AddressableInterop
24

35
import CXXInterop
46

test/Interop/Cxx/class/nonescapable-lifetimebound.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// RUN: rm -rf %t
22
// RUN: split-file %s %t
3-
// RUN: %target-swift-frontend -I %swift_src_root/lib/ClangImporter/SwiftBridging -I %t/Inputs -emit-sil %t/test.swift -enable-experimental-feature LifetimeDependence -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s
4-
// RUN: %target-swift-frontend -I %swift_src_root/lib/ClangImporter/SwiftBridging -I %t/Inputs -emit-sil %t/test.swift -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s
3+
// RUN: %target-swift-frontend -I %swift_src_root/lib/ClangImporter/SwiftBridging -I %t/Inputs -emit-sil %t/test.swift -enable-experimental-feature AddressableInterop -enable-experimental-feature LifetimeDependence -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend -I %swift_src_root/lib/ClangImporter/SwiftBridging -I %t/Inputs -emit-sil %t/test.swift -enable-experimental-feature AddressableInterop -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s
55

66
// REQUIRES: swift_feature_LifetimeDependence
7+
// REQUIRES: swift_feature_AddressableInterop
78

89
//--- Inputs/module.modulemap
910
module Test {

test/Interop/Cxx/stdlib/use-std-function.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77

88
// REQUIRES: executable_test
99

10+
// libstdc++11 declares a templated constructor of std::function with an rvalue-reference parameter,
11+
// which aren't yet supported in Swift. Therefore initializing a std::function from Swift closures
12+
// will not work on the platforms that are shipped with this version of libstdc++ (rdar://125816354).
13+
// XFAIL: LinuxDistribution=ubuntu-24.04
14+
// XFAIL: LinuxDistribution=ubuntu-22.04
15+
// XFAIL: LinuxDistribution=rhel-9.3
16+
// XFAIL: LinuxDistribution=rhel-9.4
17+
// XFAIL: LinuxDistribution=rhel-9.5
18+
// XFAIL: LinuxDistribution=rhel-9.6
19+
// XFAIL: LinuxDistribution=fedora-39
20+
// XFAIL: LinuxDistribution=fedora-41
21+
// XFAIL: LinuxDistribution=debian-12
22+
// XFAIL: LinuxDistribution=amzn-2023
23+
1024
import StdlibUnittest
1125
import StdFunction
1226
import CxxStdlib

0 commit comments

Comments
 (0)