File tree 2 files changed +41
-2
lines changed 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2024 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
13
13
/// A fixed-size array.
14
14
@available ( SwiftStdlib 6 . 2 , * )
15
15
@frozen
16
+ @_addressableForDependencies
16
17
public struct InlineArray < let count: Int , Element: ~ Copyable> : ~ Copyable {
17
18
@usableFromInline
18
19
internal let _storage : Builtin . FixedArray < count , Element >
@@ -395,6 +396,26 @@ extension InlineArray where Element: ~Copyable {
395
396
}
396
397
}
397
398
399
+ //===----------------------------------------------------------------------===//
400
+ // Span
401
+ //===----------------------------------------------------------------------===//
402
+
403
+ @available ( SwiftStdlib 6 . 2 , * )
404
+ extension InlineArray where Element: ~ Copyable {
405
+
406
+ @available ( SwiftStdlib 6 . 2 , * )
407
+ public var span: Span< Element > {
408
+ @lifetime ( borrow self)
409
+ @_addressableSelf
410
+ @_alwaysEmitIntoClient
411
+ borrowing get {
412
+ let pointer = _address
413
+ let span = Span ( _unsafeStart: pointer, count: count)
414
+ return _override Lifetime( span, borrowing : self)
415
+ }
416
+ }
417
+ }
418
+
398
419
//===----------------------------------------------------------------------===//
399
420
// Unsafe APIs
400
421
//===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // RUN: %target-run-stdlib-swift
13
+ // RUN: %target-run-stdlib-swift(-enable-experimental-feature ValueGenerics)
14
14
15
15
// REQUIRES: executable_test
16
+ // REQUIRES: swift_feature_ValueGenerics
16
17
17
18
import StdlibUnittest
18
19
@@ -68,3 +69,20 @@ suite.test("CollectionOfOne.span stride test")
68
69
let bytes = span. bytes
69
70
expectEqual ( bytes. byteCount, MemoryLayout . size ( ofValue: c) )
70
71
}
72
+
73
+ suite. test ( " InlineArray.span property " )
74
+ . skip ( . custom(
75
+ { if #available( SwiftStdlib 6 . 2 , * ) { false } else { true } } ,
76
+ reason: " Requires Swift 6.2's standard library "
77
+ ) )
78
+ . code {
79
+ guard #available( SwiftStdlib 6 . 2 , * ) else { return }
80
+
81
+ var s = InlineArray< 5 , Int> ( repeating : 0 )
82
+ s [ 3 ] = . random( in: 0 ..< 1000 )
83
+ let span = s. span
84
+ expectEqual ( span. count, s. count)
85
+ for i in s. indices {
86
+ expectEqual ( span [ i] , s [ i] )
87
+ }
88
+ }
You can’t perform that action at this time.
0 commit comments