Skip to content

Commit 8b67b03

Browse files
committed
add language feature SafeInteropWrappers
This replaces the language option -enable-experimental-bounds-safety-interop.
1 parent 7d044bd commit 8b67b03

File tree

7 files changed

+8
-11
lines changed

7 files changed

+8
-11
lines changed

include/swift/Basic/Features.def

+4
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ EXPERIMENTAL_FEATURE(WarnUnsafe, true)
406406
/// Import unsafe C and C++ constructs as @unsafe.
407407
EXPERIMENTAL_FEATURE(SafeInterop, true)
408408

409+
// Import bounds safety and lifetime attributes from interop headers to
410+
// generate Swift wrappers with safe pointer types.
411+
EXPERIMENTAL_FEATURE(SafeInteropWrappers, false)
412+
409413
/// Ignore resilience errors due to C++ types.
410414
EXPERIMENTAL_FEATURE(AssumeResilientCxxTypes, true)
411415

include/swift/Basic/LangOptions.h

-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ namespace swift {
325325
/// disabled because it is not complete.
326326
bool EnableCXXInterop = false;
327327

328-
/// Enable C interop importing bounds safety and lifetime attributes to
329-
/// generate Swift wrappers with safe pointer types (experimental).
330-
bool EnableBoundsSafetyInterop = false;
331-
332328
/// The C++ interoperability source compatibility version. Defaults
333329
/// to the Swift language version.
334330
version::Version cxxInteropCompatVersion;

lib/AST/FeatureSet.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static bool usesFeatureAllowUnsafeAttribute(Decl *decl) {
307307

308308
UNINTERESTING_FEATURE(WarnUnsafe)
309309
UNINTERESTING_FEATURE(SafeInterop)
310+
UNINTERESTING_FEATURE(SafeInteropWrappers)
310311
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
311312
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
312313
UNINTERESTING_FEATURE(CoroutineAccessorsAllocateInCallee)

lib/ClangImporter/ClangImporter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ void importer::getNormalInvocationArguments(
578578
}
579579
}
580580

581-
if (LangOpts.EnableBoundsSafetyInterop)
581+
if (LangOpts.hasFeature(Feature::SafeInteropWrappers))
582582
invocationArgStrs.push_back("-fexperimental-bounds-safety-attributes");
583583

584584
// Set C language options.

lib/ClangImporter/ImportDecl.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -8558,7 +8558,7 @@ class PointerParamInfoPrinter {
85588558

85598559
void ClangImporter::Implementation::importBoundsAttributes(
85608560
FuncDecl *MappedDecl) {
8561-
assert(SwiftContext.LangOpts.EnableBoundsSafetyInterop);
8561+
assert(SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers));
85628562
auto ClangDecl =
85638563
dyn_cast_or_null<clang::FunctionDecl>(MappedDecl->getClangDecl());
85648564
// any function with safe pointer imports should have a clang decl
@@ -8578,7 +8578,6 @@ void ClangImporter::Implementation::importBoundsAttributes(
85788578
}
85798579
}
85808580

8581-
85828581
// Dig out a source file we can use for parsing.
85838582
auto &sourceFile = getClangSwiftAttrSourceFile(
85848583
*MappedDecl->getDeclContext()->getParentModule(), MacroString);

lib/Frontend/CompilerInvocation.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
14491449
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,
14501450
Target.isOSDarwin() && !Opts.hasFeature(Feature::Embedded));
14511451

1452-
Opts.EnableBoundsSafetyInterop =
1453-
Args.hasArg(OPT_enable_experimental_bounds_safety_interop);
1454-
14551452
Opts.CForeignReferenceTypes =
14561453
Args.hasArg(OPT_experimental_c_foreign_reference_types);
14571454

test/Interop/C/pointer-bounds/counted-by.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -disable-availability-checking -plugin-path %swift-plugin-dir -o %t/CountedBy.swiftmodule -I %S/Inputs -enable-experimental-bounds-safety-interop %s
2+
// RUN: %target-swift-frontend -emit-module -disable-availability-checking -plugin-path %swift-plugin-dir -o %t/CountedBy.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s
33

44
// Check that ClangImporter correctly infers and expands @PointerBounds macros for functions with __counted_by parameters.
55

0 commit comments

Comments
 (0)