Skip to content

Commit 1cd423d

Browse files
authored
Merge pull request #68737 from kubamracek/embedded-unmanaged
[embedded] Make Unmanaged available in embedded Swift, add a test for various types from the stdlib
2 parents 8f4f222 + 0f1dff4 commit 1cd423d

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

stdlib/public/core/Unmanaged.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
/// When you use this type, you become partially responsible for
1616
/// keeping the object alive.
1717
@frozen
18-
@_unavailableInEmbedded
1918
public struct Unmanaged<Instance: AnyObject> {
2019
@usableFromInline
2120
internal unowned(unsafe) var _value: Instance
@@ -244,6 +243,5 @@ public struct Unmanaged<Instance: AnyObject> {
244243
#endif
245244
}
246245

247-
@_unavailableInEmbedded
248246
extension Unmanaged: Sendable where Instance: Sendable { }
249247

test/embedded/stdlib-types.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
3+
4+
// REQUIRES: VENDOR=apple
5+
6+
class MyClass {}
7+
8+
public func test() {
9+
var bool = false
10+
var int = 42
11+
var int8: Int8 = 42
12+
var int32: Int32 = 42
13+
var uint = UInt(42)
14+
var float: Float = 7.77
15+
var double: Double = 7.77
16+
var optional1: Bool? = nil
17+
var optional2: Int? = 42
18+
var optional3: [Int]? = [1, 2, 3]
19+
var staticstring: StaticString = "hello"
20+
var p1 = UnsafeRawPointer(bitPattern: 42)!
21+
var p2 = UnsafeMutableRawPointer(bitPattern: 42)!
22+
var p3 = UnsafePointer<UInt>(bitPattern: 42)!
23+
var p4 = UnsafeMutablePointer<UInt>(bitPattern: 42)!
24+
var p5 = UnsafeBufferPointer<UInt>(start: p3, count: 1)
25+
var array: [Int] = [1, 2, 3]
26+
var array2: ContiguousArray<Int> = ContiguousArray(array)
27+
var subarray: ArraySlice<Int> = array[0..<2]
28+
var enumerated: EnumeratedSequence<ArraySlice<Int>> = subarray.enumerated()
29+
var range1 = 0 ..< 10
30+
var range2 = 0 ... 10
31+
_ = MemoryLayout<Int>.size
32+
_ = MemoryLayout<Int>.stride
33+
_ = MemoryLayout<Int>.alignment
34+
let unmanaged = Unmanaged.passUnretained(MyClass())
35+
let opaque = unmanaged.toOpaque()
36+
let unmanaged2 = Unmanaged<MyClass>.fromOpaque(opaque)
37+
let o = unmanaged2.takeUnretainedValue()
38+
}
39+
40+
test()
41+
42+
// CHECK: define {{.*}}i32 @main(i32 %0, ptr %1)

0 commit comments

Comments
 (0)