Skip to content

Commit 80b1d92

Browse files
committed
Move @PointerBounds to stdlib core, support Implicitly Unwrapped types
1 parent ef164a8 commit 80b1d92

40 files changed

+37
-89
lines changed

lib/Macros/Sources/SwiftMacros/PointerBoundsMacro.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func transformType(_ prev: TypeSyntax, _ variant: Variant, _ isSizedBy: Bool) th
9797
if let optType = prev.as(OptionalTypeSyntax.self) {
9898
return TypeSyntax(optType.with(\.wrappedType, try transformType(optType.wrappedType, variant, isSizedBy)))
9999
}
100+
if let impOptType = prev.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) {
101+
return try transformType(impOptType.wrappedType, variant, isSizedBy)
102+
}
100103
guard let idType = prev.as(IdentifierTypeSyntax.self) else {
101104
throw DiagnosticError("expected pointer type, got \(prev) with kind \(prev.kind)", node: prev)
102105
}

stdlib/private/StdlibUnittest/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ endif()
3232
if (SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
3333
list(APPEND swift_stdlib_unittest_modules "_StringProcessing")
3434
endif()
35-
if (SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
36-
list(APPEND swift_stdlib_unittest_modules "_PointerBounds")
37-
endif()
3835

3936
add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
4037
# This file should be listed the first. Module name is inferred from the

stdlib/public/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ if(SWIFT_BUILD_STDLIB)
279279
add_subdirectory(StringProcessing)
280280
add_subdirectory(RegexBuilder)
281281
endif()
282-
283-
if(SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
284-
add_subdirectory(PointerBounds)
285-
endif()
286282
endif()
287283

288284
if(SWIFT_BUILD_STDLIB AND NOT SWIFT_STDLIB_BUILD_ONLY_CORE_MODULES)

stdlib/public/PointerBounds/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

stdlib/public/core/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
261261
list(APPEND SWIFTLIB_EMBEDDED_GYB_SOURCES SIMDConcreteOperations.swift.gyb SIMDVectorTypes.swift.gyb)
262262
endif()
263263

264+
if (SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS)
265+
list(APPEND SWIFTLIB_SOURCES PointerBounds.swift)
266+
list(APPEND SWIFTLIB_EMBEDDED_SOURCES PointerBounds.swift)
267+
endif()
268+
264269
# Freestanding and Linux/Android builds both have failures to resolve.
265270
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")
266271
list(APPEND SWIFTLIB_SOURCES ObjectIdentifier+DebugDescription.swift)

stdlib/public/core/GroupInfo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
],
191191
"Pointer": [
192192
"Pointer.swift",
193+
"PointerBounds.swift",
193194
"TemporaryAllocation.swift",
194195
"UnsafePointer.swift",
195196
"UnsafeRawPointer.swift",

stdlib/public/PointerBounds/PointerBounds.swift renamed to stdlib/public/core/PointerBounds.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Swift
2-
31
/// Different ways to annotate pointer parameters using the `@PointerBounds` macro.
42
/// All indices into parameter lists start at 1. Indices __must__ be integer literals, and strings
53
/// __must__ be string literals, because their contents are parsed by the `@PointerBounds` macro.

test/Macros/PointerBounds/CountedBy/CountExpr.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// 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 %s
55

6-
import _PointerBounds
7-
86
@PointerBounds(.countedBy(pointer: 1, count: "size * count"))
97
func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
108
}

test/Macros/PointerBounds/CountedBy/MultipleParams.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// 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 %s
55

6-
import _PointerBounds
7-
86
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 3, count: "len2"))
97
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt, _ ptr2: UnsafePointer<CInt>, _ len2: CInt) {
108
}

test/Macros/PointerBounds/CountedBy/Mutable.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// 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 %s
55

6-
import _PointerBounds
7-
86
@PointerBounds(.countedBy(pointer: 1, count: "len"))
97
func myFunc(_ ptr: UnsafeMutablePointer<CInt>, _ len: CInt) {
108
}

0 commit comments

Comments
 (0)