Rename pointer bounds (#78210)

* Make pointer bounds non-experimental

* Rename @PointerBounds to @_SwiftifyImport

* Rename filenames containing PointerBounds

* Add _PointerParam exception to stdlib ABI test

* Add _PointerParam to stdlib API changes

* Rename _PointerParam to _SwiftifyInfo
This commit is contained in:
Henrik G. Olsson
2024-12-20 11:36:01 +01:00
committed by GitHub
parent 57cce71fc2
commit ef9d2b744d
61 changed files with 94 additions and 172 deletions

View File

@@ -747,10 +747,6 @@ option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
"Enable experimental SwiftParser validation by default"
FALSE)
option(SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS
"Enable experimental safe wrappers around external functions"
FALSE)
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
"Build SourceKit" TRUE
"SWIFT_ENABLE_DISPATCH" FALSE)
@@ -1397,7 +1393,6 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
message(STATUS "Observation Support: ${SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION}")
message(STATUS "Synchronization Support: ${SWIFT_ENABLE_SYNCHRONIZATION}")
message(STATUS "Volatile Support: ${SWIFT_ENABLE_VOLATILE}")
message(STATUS "Pointer Bounds Support: ${SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS}")
message(STATUS "")
else()
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

View File

@@ -28,7 +28,6 @@
# Catalyst Support
# -- Will need shadow invocations to generate swiftmodules for Swift parts
# Install *.abi.json, swiftdoc, and swiftsourceinfo
# Pointer bounds (SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
cmake_minimum_required(VERSION 3.26...3.29)

View File

@@ -792,11 +792,6 @@ def enable_experimental_concise_pound_file : Flag<["-"],
Flags<[FrontendOption, ModuleInterfaceOption]>,
HelpText<"Enable experimental concise '#file' identifier">;
def enable_experimental_bounds_safety_interop :
Flag<["-"], "enable-experimental-bounds-safety-interop">,
Flags<[NoDriverOption, FrontendOption, HelpHidden, ModuleInterfaceOption]>,
HelpText<"Enable experimental C bounds safety interop code generation and config directives">;
def enable_experimental_cxx_interop :
Flag<["-"], "enable-experimental-cxx-interop">,
Flags<[NoDriverOption, FrontendOption, HelpHidden]>,

View File

@@ -8673,16 +8673,16 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
}
namespace {
class PointerParamInfoPrinter {
class SwiftifyInfoPrinter {
public:
clang::ASTContext &ctx;
llvm::raw_ostream &out;
bool firstParam = true;
PointerParamInfoPrinter(clang::ASTContext &ctx, llvm::raw_ostream &out)
SwiftifyInfoPrinter(clang::ASTContext &ctx, llvm::raw_ostream &out)
: ctx(ctx), out(out) {
out << "@PointerBounds(";
out << "@_SwiftifyImport(";
}
~PointerParamInfoPrinter() { out << ")"; }
~SwiftifyInfoPrinter() { out << ")"; }
void printCountedBy(const clang::CountAttributedType *CAT,
size_t pointerIndex) {
@@ -8725,7 +8725,7 @@ void ClangImporter::Implementation::importBoundsAttributes(
{
llvm::raw_svector_ostream out(MacroString);
PointerParamInfoPrinter printer(getClangASTContext(), out);
SwiftifyInfoPrinter printer(getClangASTContext(), out);
for (auto [index, param] : llvm::enumerate(ClangDecl->parameters())) {
if (auto CAT = param->getType()->getAs<clang::CountAttributedType>()) {
printer.printCountedBy(CAT, index);

View File

@@ -16,7 +16,7 @@ add_swift_macro_library(SwiftMacros
DistributedResolvableMacro.swift
SyntaxExtensions.swift
TaskLocalMacro.swift
PointerBoundsMacro.swift
SwiftifyImportMacro.swift
SWIFT_DEPENDENCIES
SwiftDiagnostics
SwiftSyntax

View File

@@ -461,12 +461,12 @@ func getParameterIndexForDeclRef(
/// Intended to map to C attributes like __counted_by, __ended_by and __no_escape,
/// for automatic application by ClangImporter when the C declaration is annotated
/// appropriately.
public struct PointerBoundsMacro: PeerMacro {
public struct SwiftifyImportMacro: PeerMacro {
static func parseEnumName(_ enumConstructorExpr: FunctionCallExprSyntax) throws -> String {
guard let calledExpr = enumConstructorExpr.calledExpression.as(MemberAccessExprSyntax.self)
else {
throw DiagnosticError(
"expected PointerParam enum literal as argument, got '\(enumConstructorExpr)'",
"expected _SwiftifyInfo enum literal as argument, got '\(enumConstructorExpr)'",
node: enumConstructorExpr)
}
return calledExpr.declName.baseName.text
@@ -564,7 +564,7 @@ public struct PointerBoundsMacro: PeerMacro {
let paramExpr = paramAST.expression
guard let enumConstructorExpr = paramExpr.as(FunctionCallExprSyntax.self) else {
throw DiagnosticError(
"expected PointerParam enum literal as argument, got '\(paramExpr)'", node: paramExpr)
"expected _SwiftifyInfo enum literal as argument, got '\(paramExpr)'", node: paramExpr)
}
let enumName = try parseEnumName(enumConstructorExpr)
switch enumName {
@@ -627,7 +627,7 @@ public struct PointerBoundsMacro: PeerMacro {
}
if argByIndex[i] != nil {
throw DiagnosticError(
"multiple PointerParams referring to parameter with index "
"multiple _SwiftifyInfos referring to parameter with index "
+ "\(i): \(pointerArg) and \(argByIndex[i]!)", node: pointerArg.original)
}
argByIndex[i] = pointerArg
@@ -647,7 +647,7 @@ public struct PointerBoundsMacro: PeerMacro {
) throws -> [DeclSyntax] {
do {
guard let funcDecl = declaration.as(FunctionDeclSyntax.self) else {
throw DiagnosticError("@PointerBounds only works on functions", node: declaration)
throw DiagnosticError("@_SwiftifyImport only works on functions", node: declaration)
}
let argumentList = node.arguments!.as(LabeledExprListSyntax.self)!
@@ -692,7 +692,7 @@ public struct PointerBoundsMacro: PeerMacro {
case .attribute(let attr):
// don't apply this macro recursively, and avoid dupe _alwaysEmitIntoClient
let name = attr.attributeName.as(IdentifierTypeSyntax.self)?.name.text
return name == nil || (name != "PointerBounds" && name != "_alwaysEmitIntoClient")
return name == nil || (name != "_SwiftifyImport" && name != "_alwaysEmitIntoClient")
default: return true
}
} + [

View File

@@ -326,10 +326,6 @@ function(_add_target_variant_swift_compile_flags
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION")
endif()
if(SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS")
endif()
if(SWIFT_ENABLE_SYNCHRONIZATION)
list(APPEND result "-D" "SWIFT_ENABLE_SYNCHRONIZATION")
endif()

View File

@@ -230,6 +230,7 @@ split_embedded_sources(
EMBEDDED Int128.swift
EMBEDDED Mirror.swift
NORMAL PlaygroundDisplay.swift
EMBEDDED SwiftifyImport.swift
NORMAL CommandLine.swift
EMBEDDED SliceBuffer.swift
EMBEDDED StaticBigInt.swift
@@ -263,11 +264,6 @@ if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
list(APPEND SWIFTLIB_EMBEDDED_GYB_SOURCES SIMDConcreteOperations.swift.gyb SIMDVectorTypes.swift.gyb)
endif()
if (SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
list(APPEND SWIFTLIB_SOURCES PointerBounds.swift)
list(APPEND SWIFTLIB_EMBEDDED_SOURCES PointerBounds.swift)
endif()
# Freestanding and Linux/Android builds both have failures to resolve.
if(NOT BOOTSTRAPPING_MODE STREQUAL "OFF" AND NOT SWIFT_FREESTANDING_FLAVOR AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
list(APPEND SWIFTLIB_SOURCES ObjectIdentifier+DebugDescription.swift)

View File

@@ -190,7 +190,7 @@
],
"Pointer": [
"Pointer.swift",
"PointerBounds.swift",
"SwiftifyImport.swift",
"TemporaryAllocation.swift",
"UnsafePointer.swift",
"UnsafeRawPointer.swift",

View File

@@ -1,9 +1,13 @@
/// Different ways to annotate pointer parameters using the `@PointerBounds` macro.
/// Different ways to annotate pointer parameters using the `@_SwiftifyImport` macro.
/// All indices into parameter lists start at 1. Indices __must__ be integer literals, and strings
/// __must__ be string literals, because their contents are parsed by the `@PointerBounds` macro.
/// __must__ be string literals, because their contents are parsed by the `@_SwiftifyImport` macro.
/// Only 1 instance of `countedBy`, `sizedBy` or `endedBy` can refer to each pointer index, however
/// `nonescaping` is orthogonal to the rest and can (and should) overlap with other annotations.
public enum PointerParam {
///
/// This is not marked @available, because _SwiftifyImport is available for any target. Instances
/// of _SwiftifyInfo should ONLY be passed as arguments directly to _SwiftifyImport, so they should
/// not affect linkage since there are never any instances at runtime.
public enum _SwiftifyInfo {
/// Corresponds to the C `__counted_by(count)` attribute.
/// Parameter pointer: index of pointer in function parameter list. Must be of type
/// `Unsafe[Mutable]Pointer<T>[?]`, i.e. not an `UnsafeRawPointer`.
@@ -40,5 +44,5 @@ public enum PointerParam {
/// Parameter paramInfo: information about how the function uses the pointer passed to it. The
/// safety of the generated wrapper function depends on this info being extensive and accurate.
@attached(peer, names: overloaded)
public macro PointerBounds(_ paramInfo: PointerParam...) =
#externalMacro(module: "SwiftMacros", type: "PointerBoundsMacro")
public macro _SwiftifyImport(_ paramInfo: _SwiftifyInfo...) =
#externalMacro(module: "SwiftMacros", type: "SwiftifyImportMacro")

View File

@@ -457,10 +457,6 @@ foreach(SDK ${SWIFT_SDKS})
list(APPEND LIT_ARGS "--param" "string_processing")
endif()
if(SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
list(APPEND LIT_ARGS "--param" "pointer_bounds")
endif()
if(SWIFT_ENABLE_BACKTRACING)
list(APPEND LIT_ARGS "--param" "backtracing")
endif()

View File

@@ -4,7 +4,8 @@
void simple(int len, int * __counted_by(len) p);
void swiftAttr(int len, int * p) __attribute__((swift_attr("@PointerBounds(.countedBy(pointer: 2, count: \"len\"))")));
void swiftAttr(int len, int *p) __attribute__((
swift_attr("@_SwiftifyImport(.countedBy(pointer: 2, count: \"len\"))")));
void shared(int len, int * __counted_by(len) p1, int * __counted_by(len) p2);

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_feature_SafeInteropWrappers
// REQUIRES: pointer_bounds
// RUN: %empty-directory(%t)
// 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
// Check that ClangImporter correctly infers and expands @PointerBounds macros for functions with __counted_by parameters.
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __counted_by parameters.
import CountedByClang

View File

@@ -1,9 +0,0 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir
// expected-error@+1{{multiple PointerParams referring to parameter with index 1: .countedBy(pointer: 1, count: "dummy", nonescaping: false) and .countedBy(pointer: 1, count: "len", nonescaping: false)}}
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 1, count: "dummy"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt, _ dummy: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "size * count"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "size * count"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 3, count: "len2"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 3, count: "len2"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt, _ ptr2: UnsafePointer<CInt>, _ len2: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafeMutablePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,11 +1,10 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: not %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span > %t.log 2>&1
// RUN: %FileCheck --match-full-lines %s < %t.log
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafeMutablePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>?, _ len: CInt) {
}

View File

@@ -1,13 +1,12 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func foo(_ ptr: Swift.UnsafePointer<Swift.Int>, _ len: Swift.Int) -> Swift.Void {
}
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func bar(_ ptr: Swift.UnsafePointer<Swift.CInt>, _ len: Swift.Int) -> () {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) -> CInt {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 2, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 2, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ ptr2: UnsafePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) -> CInt {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>!, _ len: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
// expected-error@+1{{expected pointer type, got [CInt] with kind arrayType}}
func myFunc(_ ptr: [CInt], _ len: String) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
let countString = "len"
// expected-error@+1{{expected string literal for 'count' parameter, got countString}}
@PointerBounds(.countedBy(pointer: 1, count: countString))
@_SwiftifyImport(.countedBy(pointer: 1, count: countString))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
let countedBy = PointerParam.countedBy(pointer: 1, count: "len")
// expected-error@+1{{expected PointerParam enum literal as argument, got 'countedBy'}}
@PointerBounds(countedBy)
let countedBy = _SwiftifyInfo.countedBy(pointer: 1, count: "len")
// expected-error@+1{{expected _SwiftifyInfo enum literal as argument, got 'countedBy'}}
@_SwiftifyImport(countedBy)
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
let pointerIndex = 1
// expected-error@+1{{expected integer literal, got 'pointerIndex'}}
@PointerBounds(.countedBy(pointer: pointerIndex, count: "len"))
@_SwiftifyImport(.countedBy(pointer: pointerIndex, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
// expected-error@+1{{no parameter with name 'foo' in '_ ptr: UnsafePointer<CInt>, _ len: CInt'}}
@PointerBounds(.countedBy(pointer: 1, count: "foo"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "foo"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}

View File

@@ -1,20 +1,19 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
// expected-error@+1{{pointer index out of bounds}}
@PointerBounds(.countedBy(pointer: 3, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 3, count: "len"))
// expected-note@+1{{function myFunc has parameter indices 1..2}}
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}
// expected-error@+1{{pointer index out of bounds}}
@PointerBounds(.countedBy(pointer: 0, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 0, count: "len"))
// expected-note@+1{{function myFunc2 has parameter indices 1..2}}
func myFunc2(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}
// expected-error@+1{{pointer index out of bounds}}
@PointerBounds(.countedBy(pointer: 0, count: "1"))
@_SwiftifyImport(.countedBy(pointer: 0, count: "1"))
// expected-note@+1{{function myFunc3 has no parameters}}
func myFunc3() {
}

View File

@@ -0,0 +1,8 @@
// REQUIRES: swift_swift_parser
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir
// expected-error@+1{{multiple _SwiftifyInfos referring to parameter with index 1: .countedBy(pointer: 1, count: "dummy", nonescaping: false) and .countedBy(pointer: 1, count: "len", nonescaping: false)}}
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 1, count: "dummy"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt, _ dummy: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
// expected-error@+1{{cannot convert value of type 'Int' to expected argument type 'String'}}
@PointerBounds(.countedBy(pointer: 1, count: 2))
@_SwiftifyImport(.countedBy(pointer: 1, count: 2))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
}

View File

@@ -1,12 +1,11 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// XFAIL: *
// RUN: not %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
}
@@ -15,4 +14,4 @@ func myFunc(_ ptr: UnsafePointer<CInt>, _ len: String) {
// CHECK-NEXT: myFunc(ptr.baseAddress!, String(exactly: ptr.count)!)
// CHECK-NEXT: }
// expected-error@PointerBounds:2{{no exact matches in call to initializer}}
// expected-error@_SwiftifyImport:2{{no exact matches in call to initializer}}

View File

@@ -1,13 +1,12 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-typecheck-verify-swift -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
// expected-error@+2{{expected Unsafe[Mutable][Raw]Pointer type for type CInt - first type token is 'CInt'}}
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc(_ ptr: CInt, _ len: CInt) {
}
// expected-error@+2{{expected Unsafe[Mutable][Raw]Pointer type for type UnsafeBufferPointer<CInt> - first type token is 'UnsafeBufferPointer'}}
@PointerBounds(.countedBy(pointer: 1, count: "len"))
@_SwiftifyImport(.countedBy(pointer: 1, count: "len"))
func myFunc2(_ ptr: UnsafeBufferPointer<CInt>, _ len: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .sizedBy(pointer: 3, size: "size2"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"), .sizedBy(pointer: 3, size: "size2"))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt, _ ptr2: UnsafeRawPointer, _ size2: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"))
func myFunc(_ ptr: UnsafeMutableRawPointer, _ size: CInt) {
}

View File

@@ -1,11 +1,10 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: not %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span > %t.log 2>&1
// RUN: %FileCheck --match-full-lines %s < %t.log
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafeMutableRawPointer, _ size: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"))
func myFunc(_ ptr: UnsafeRawPointer?, _ size: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt) -> CInt {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .sizedBy(pointer: 2, size: "size"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"), .sizedBy(pointer: 2, size: "size"))
func myFunc(_ ptr: UnsafeRawPointer, _ ptr2: UnsafeRawPointer, _ size: CInt) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt) {
}

View File

@@ -1,10 +1,9 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// REQUIRES: swift_feature_Span
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"), .nonescaping(pointer: 1))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt) -> CInt {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size"))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "size * count"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "size * count"))
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt, _ count: CInt) {
}

View File

@@ -1,9 +1,8 @@
// REQUIRES: swift_swift_parser
// REQUIRES: pointer_bounds
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
@PointerBounds(.sizedBy(pointer: 1, size: "len"))
@_SwiftifyImport(.sizedBy(pointer: 1, size: "len"))
func myFunc(_ ptr: UnsafeRawPointer!, _ len: CInt) {
}

View File

@@ -797,3 +797,13 @@ Added: _$ss7RawSpanV9byteCountSivpMV
Added: _$ss7RawSpanVMa
Added: _$ss7RawSpanVMn
Added: _$ss7RawSpanVN
// _SwiftifyInfo enum for _SwiftifyImports macro
Added: _$ss13_SwiftifyInfoO11nonescapingyABSi_tcABmFWC
Added: _$ss13_SwiftifyInfoO7endedByyABSi_SitcABmFWC
Added: _$ss13_SwiftifyInfoO7sizedByyABSi_SStcABmFWC
Added: _$ss13_SwiftifyInfoO9countedByyABSi_SStcABmFWC
Added: _$ss13_SwiftifyInfoOMa
Added: _$ss13_SwiftifyInfoOMn
Added: _$ss13_SwiftifyInfoON

View File

@@ -798,3 +798,13 @@ Added: _$ss7RawSpanV9byteCountSivpMV
Added: _$ss7RawSpanVMa
Added: _$ss7RawSpanVMn
Added: _$ss7RawSpanVN
// _SwiftifyInfo enum for _SwiftifyImports macro
Added: _$ss13_SwiftifyInfoO11nonescapingyABSi_tcABmFWC
Added: _$ss13_SwiftifyInfoO7endedByyABSi_SitcABmFWC
Added: _$ss13_SwiftifyInfoO7sizedByyABSi_SStcABmFWC
Added: _$ss13_SwiftifyInfoO9countedByyABSi_SStcABmFWC
Added: _$ss13_SwiftifyInfoOMa
Added: _$ss13_SwiftifyInfoOMn
Added: _$ss13_SwiftifyInfoON

View File

@@ -822,4 +822,5 @@ Func _SliceBuffer.withUnsafeMutableBufferPointer(_:) has mangled name changing f
Struct String.Index has added a conformance to an existing protocol CustomDebugStringConvertible
Enum _SwiftifyInfo is a new API without @available attribute
// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment above.)

View File

@@ -156,8 +156,6 @@ if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
config.available_features.add('string_processing')
if "@SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION@" == "TRUE":
config.available_features.add('observation')
if "@SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS@" == "TRUE":
config.available_features.add('pointer_bounds')
if "@SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE@" == "TRUE":
config.available_features.add('swift_stdlib_debug_preconditions_in_release')
if "@SWIFT_ENABLE_VOLATILE@" == "TRUE":

View File

@@ -2092,13 +2092,6 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi
if [[ "${SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS}" ]] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL=$(true_false "${SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS}")
)
fi
# SWIFT_THREADING_PACKAGE can be:
#
# - Empty

View File

@@ -1524,7 +1524,6 @@ function Build-Compilers() {
SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED = "YES";
SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES";
SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES";
SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS = "YES";
SWIFT_ENABLE_SYNCHRONIZATION = "YES";
SWIFT_ENABLE_VOLATILE = "YES";
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
@@ -1835,7 +1834,6 @@ function Build-Runtime([Platform]$Platform, $Arch) {
SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED = "YES";
SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES";
SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES";
SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS = "YES";
SWIFT_ENABLE_SYNCHRONIZATION = "YES";
SWIFT_ENABLE_VOLATILE = "YES";
SWIFT_NATIVE_SWIFT_TOOLS_PATH = (Join-Path -Path $CompilersBinaryCache -ChildPath "bin");

View File

@@ -1493,10 +1493,6 @@ def create_argument_parser():
default=True,
help='Enable experimental Swift Parser validation by default.')
option('--enable-experimental-pointer-bounds', toggle_true,
default=False,
help='Enable experimental bounds safe C interop.')
# -------------------------------------------------------------------------
in_group('Unsupported options')

View File

@@ -184,7 +184,6 @@ EXPECTED_DEFAULTS = {
'enable_experimental_string_processing': True,
'enable_experimental_observation': True,
'enable_experimental_parser_validation': True,
'enable_experimental_pointer_bounds': False,
'swift_enable_backtracing': True,
'enable_synchronization': True,
'enable_volatile': True,
@@ -628,7 +627,6 @@ EXPECTED_OPTIONS = [
EnableOption('--enable-experimental-string-processing'),
EnableOption('--enable-experimental-observation'),
EnableOption('--enable-experimental-parser-validation'),
EnableOption('--enable-experimental-pointer-bounds'),
EnableOption('--enable-lsan'),
EnableOption('--enable-sanitize-coverage'),
EnableOption('--enable-tsan'),

View File

@@ -104,8 +104,6 @@ class MinimalStdlib(cmake_product.CMakeProduct):
'SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL', 'FALSE')
self.cmake_options.define(
'SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL', 'FALSE')
self.cmake_options.define(
'SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL', 'FALSE')
self.cmake_options.define('SWIFT_ENABLE_REFLECTION:BOOL', 'FALSE')
self.cmake_options.define(
'SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS:BOOL', 'FALSE')

View File

@@ -57,9 +57,6 @@ class Swift(product.Product):
self.cmake_options.extend(self._enable_experimental_cxx_interop)
self.cmake_options.extend(self._enable_cxx_interop_swift_bridging_header)
# Add experimental c interop flag.
self.cmake_options.extend(self._enable_experimental_pointer_bounds)
# Add experimental distributed flag.
self.cmake_options.extend(self._enable_experimental_distributed)
@@ -218,11 +215,6 @@ updated without updating swift.py?")
return [('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL',
self.args.enable_experimental_observation)]
@property
def _enable_experimental_pointer_bounds(self):
return [('SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL',
self.args.enable_experimental_pointer_bounds)]
@property
def _enable_synchronization(self):
return [('SWIFT_ENABLE_SYNCHRONIZATION:BOOL',

View File

@@ -164,8 +164,6 @@ class WasmStdlib(cmake_product.CMakeProduct):
self.cmake_options.define('SWIFT_ENABLE_SYNCHRONIZATION:BOOL', 'TRUE')
self.cmake_options.define('SWIFT_ENABLE_VOLATILE:BOOL', 'TRUE')
self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL', 'TRUE')
self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL',
'TRUE')
self.add_extra_cmake_options()

View File

@@ -60,7 +60,6 @@ class SwiftTestCase(unittest.TestCase):
enable_experimental_distributed=False,
enable_experimental_observation=False,
enable_experimental_parser_validation=False,
enable_experimental_pointer_bounds=False,
swift_enable_backtracing=False,
enable_synchronization=False,
enable_volatile=False,
@@ -110,7 +109,6 @@ class SwiftTestCase(unittest.TestCase):
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
'-DSWIFT_ENABLE_VOLATILE:BOOL=FALSE',
@@ -145,7 +143,6 @@ class SwiftTestCase(unittest.TestCase):
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
'-DSWIFT_ENABLE_VOLATILE:BOOL=FALSE',
@@ -434,19 +431,6 @@ class SwiftTestCase(unittest.TestCase):
[x for x in swift.cmake_options
if 'DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION' in x])
def test_experimental_pointer_bounds_flags(self):
self.args.enable_experimental_pointer_bounds = True
swift = Swift(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
self.assertEqual(
['-DSWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS:BOOL='
'TRUE'],
[x for x in swift.cmake_options
if 'DSWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS' in x])
def test_backtracing_flags(self):
self.args.swift_enable_backtracing = True
swift = Swift(

View File

@@ -133,8 +133,6 @@ if "@SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED@" == "TRUE":
config.available_features.add('distributed')
if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
config.available_features.add('string_processing')
if "@SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS@" == "TRUE":
config.available_features.add('pointer_bounds')
if "@SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE@" == "TRUE":
config.available_features.add('swift_stdlib_debug_preconditions_in_release')