Skip to content

Commit 15acfbb

Browse files
committed
stdlib: improve debug performance of UnsafePointer.pointer(to:)
Making those functions transparent enables to completely remove the creation of keypaths, even with -Onone. rdar://127793797
1 parent fb036e9 commit 15acfbb

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ extension UnsafePointer {
444444
/// - Returns: A pointer to the stored property represented
445445
/// by the key path, or `nil`.
446446
@_alwaysEmitIntoClient
447-
#if $Embedded
448447
@_transparent
449-
#endif
450448
public func pointer<Property>(
451449
to property: KeyPath<Pointee, Property>
452450
) -> UnsafePointer<Property>? {
@@ -1332,9 +1330,7 @@ extension UnsafeMutablePointer {
13321330
/// - Returns: A pointer to the stored property represented
13331331
/// by the key path, or `nil`.
13341332
@_alwaysEmitIntoClient
1335-
#if $Embedded
13361333
@_transparent
1337-
#endif
13381334
public func pointer<Property>(
13391335
to property: KeyPath<Pointee, Property>
13401336
) -> UnsafePointer<Property>? {
@@ -1356,9 +1352,7 @@ extension UnsafeMutablePointer {
13561352
/// - Returns: A mutable pointer to the stored property represented
13571353
/// by the key path, or `nil`.
13581354
@_alwaysEmitIntoClient
1359-
#if $Embedded
13601355
@_transparent
1361-
#endif
13621356
public func pointer<Property>(
13631357
to property: WritableKeyPath<Pointee, Property>
13641358
) -> UnsafeMutablePointer<Property>? {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend %s -module-name=test -parse-as-library -emit-sil | %FileCheck %s
2+
3+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
4+
5+
public struct S {
6+
var a: Int
7+
var b: Int
8+
}
9+
10+
// Check that even with -Onone, no keypath is created.
11+
12+
// CHECK-LABEL: sil @$s4test6testitySPySiGSgSPyAA1SVGF :
13+
// CHECK-NOT: keypath
14+
// CHECK: } // end sil function '$s4test6testitySPySiGSgSPyAA1SVGF'
15+
public func testit(_ p: UnsafePointer<S>) -> UnsafePointer<Int>? {
16+
return p.pointer(to: \.b)
17+
}

0 commit comments

Comments
 (0)