Skip to content

Commit 648fd43

Browse files
author
Gabor Horvath
committed
[cxx-interop] Remove a feature flag
SafeInterop was guarding whether we import certain foreign types as unsafe. Since these attrbutes are only considered when an opt-in strict language mode is on, this PR removes this feature flag. We still rely on the presence of the AllowUnsafeAttribute flag to add the unsafe attributes to the imported types and functions.
1 parent 2852c59 commit 648fd43

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

include/swift/Basic/Features.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AllowUnsafeAttribute, true)
401401
/// Warn on use of unsafe constructs.
402402
EXPERIMENTAL_FEATURE(WarnUnsafe, true)
403403

404-
/// Import unsafe C and C++ constructs as @unsafe.
405-
EXPERIMENTAL_FEATURE(SafeInterop, true)
406-
407404
// Import bounds safety and lifetime attributes from interop headers to
408405
// generate Swift wrappers with safe pointer types.
409406
EXPERIMENTAL_FEATURE(SafeInteropWrappers, false)

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ static bool usesFeatureABIAttribute(Decl *decl) {
348348
}
349349

350350
UNINTERESTING_FEATURE(WarnUnsafe)
351-
UNINTERESTING_FEATURE(SafeInterop)
352351
UNINTERESTING_FEATURE(SafeInteropWrappers)
353352
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
354353
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,8 +2040,7 @@ namespace {
20402040
if (Impl.SwiftContext.LangOpts.hasFeature(Feature::LifetimeDependence)) {
20412041
fd->getAttrs().add(new (Impl.SwiftContext)
20422042
UnsafeNonEscapableResultAttr(/*Implicit=*/true));
2043-
if (Impl.SwiftContext.LangOpts.hasFeature(Feature::SafeInterop) &&
2044-
Impl.SwiftContext.LangOpts.hasFeature(
2043+
if (Impl.SwiftContext.LangOpts.hasFeature(
20452044
Feature::AllowUnsafeAttribute))
20462045
fd->getAttrs().add(new (Impl.SwiftContext)
20472046
UnsafeAttr(/*Implicit=*/true));
@@ -2203,8 +2202,7 @@ namespace {
22032202

22042203
// We have to do this after populating ImportedDecls to avoid importing
22052204
// the same multiple times.
2206-
if (Impl.SwiftContext.LangOpts.hasFeature(Feature::SafeInterop) &&
2207-
Impl.SwiftContext.LangOpts.hasFeature(
2205+
if (Impl.SwiftContext.LangOpts.hasFeature(
22082206
Feature::AllowUnsafeAttribute)) {
22092207
if (const auto *ctsd =
22102208
dyn_cast<clang::ClassTemplateSpecializationDecl>(decl)) {
@@ -4135,8 +4133,7 @@ namespace {
41354133
LifetimeDependenceInfoRequest{result},
41364134
Impl.SwiftContext.AllocateCopy(lifetimeDependencies));
41374135
}
4138-
if (ASTContext.LangOpts.hasFeature(Feature::AllowUnsafeAttribute) &&
4139-
ASTContext.LangOpts.hasFeature(Feature::SafeInterop)) {
4136+
if (ASTContext.LangOpts.hasFeature(Feature::AllowUnsafeAttribute)) {
41404137
for (auto [idx, param] : llvm::enumerate(decl->parameters())) {
41414138
if (swiftParams->get(idx)->getInterfaceType()->isEscapable())
41424139
continue;
@@ -8500,8 +8497,7 @@ static bool importAsUnsafe(ClangImporter::Implementation &impl,
85008497
const clang::NamedDecl *decl,
85018498
const Decl *MappedDecl) {
85028499
auto &context = impl.SwiftContext;
8503-
if (!context.LangOpts.hasFeature(Feature::SafeInterop) ||
8504-
!context.LangOpts.hasFeature(Feature::AllowUnsafeAttribute))
8500+
if (!context.LangOpts.hasFeature(Feature::AllowUnsafeAttribute))
85058501
return false;
85068502

85078503
if (isa<clang::CXXMethodDecl>(decl) &&

test/Interop/Cxx/class/safe-interop-mode.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22
// RUN: rm -rf %t
33
// RUN: split-file %s %t
4-
// RUN: %target-swift-frontend -typecheck -verify -I %swift_src_root/lib/ClangImporter/SwiftBridging -Xcc -std=c++20 -I %t/Inputs %t/test.swift -enable-experimental-feature AllowUnsafeAttribute -enable-experimental-feature WarnUnsafe -enable-experimental-feature SafeInterop -enable-experimental-feature LifetimeDependence -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1
4+
// RUN: %target-swift-frontend -typecheck -verify -I %swift_src_root/lib/ClangImporter/SwiftBridging -Xcc -std=c++20 -I %t/Inputs %t/test.swift -enable-experimental-feature AllowUnsafeAttribute -enable-experimental-feature WarnUnsafe -enable-experimental-feature LifetimeDependence -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1
55

66
// REQUIRES: objc_interop
77
// REQUIRES: swift_feature_AllowUnsafeAttribute
8-
// REQUIRES: swift_feature_SafeInterop
98
// REQUIRES: swift_feature_WarnUnsafe
109
// REQUIRES: swift_feature_LifetimeDependence
1110

0 commit comments

Comments
 (0)