Skip to content

[embedded] Make Unmanaged available in embedded Swift, add a test for various types from the stdlib #68737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions stdlib/public/core/Unmanaged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/// When you use this type, you become partially responsible for
/// keeping the object alive.
@frozen
@_unavailableInEmbedded
public struct Unmanaged<Instance: AnyObject> {
@usableFromInline
internal unowned(unsafe) var _value: Instance
Expand Down Expand Up @@ -244,6 +243,5 @@ public struct Unmanaged<Instance: AnyObject> {
#endif
}

@_unavailableInEmbedded
extension Unmanaged: Sendable where Instance: Sendable { }

42 changes: 42 additions & 0 deletions test/embedded/stdlib-types.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
// 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

// REQUIRES: VENDOR=apple

class MyClass {}

public func test() {
var bool = false
var int = 42
var int8: Int8 = 42
var int32: Int32 = 42
var uint = UInt(42)
var float: Float = 7.77
var double: Double = 7.77
var optional1: Bool? = nil
var optional2: Int? = 42
var optional3: [Int]? = [1, 2, 3]
var staticstring: StaticString = "hello"
var p1 = UnsafeRawPointer(bitPattern: 42)!
var p2 = UnsafeMutableRawPointer(bitPattern: 42)!
var p3 = UnsafePointer<UInt>(bitPattern: 42)!
var p4 = UnsafeMutablePointer<UInt>(bitPattern: 42)!
var p5 = UnsafeBufferPointer<UInt>(start: p3, count: 1)
var array: [Int] = [1, 2, 3]
var array2: ContiguousArray<Int> = ContiguousArray(array)
var subarray: ArraySlice<Int> = array[0..<2]
var enumerated: EnumeratedSequence<ArraySlice<Int>> = subarray.enumerated()
var range1 = 0 ..< 10
var range2 = 0 ... 10
_ = MemoryLayout<Int>.size
_ = MemoryLayout<Int>.stride
_ = MemoryLayout<Int>.alignment
let unmanaged = Unmanaged.passUnretained(MyClass())
let opaque = unmanaged.toOpaque()
let unmanaged2 = Unmanaged<MyClass>.fromOpaque(opaque)
let o = unmanaged2.takeUnretainedValue()
}

test()

// CHECK: define {{.*}}i32 @main(i32 %0, ptr %1)