Skip to content

Commit e5f9ffc

Browse files
authored
Merge pull request #84024 from tbkka/tbkka-missing-embedded-allocators
Fill in two missing functions for Embedded Swift
2 parents 8eb31a8 + 4368722 commit e5f9ffc

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ func alignedAlloc(size: Int, alignment: Int) -> UnsafeMutableRawPointer? {
149149
return unsafe r
150150
}
151151

152+
@_cdecl("swift_coroFrameAlloc")
153+
public func swift_coroFrameAlloc(_ size: Int, _ type: UInt) -> UnsafeMutableRawPointer? {
154+
return unsafe alignedAlloc(
155+
size: size,
156+
alignment: _swift_MinAllocationAlignment)
157+
}
158+
152159
@_cdecl("swift_slowAlloc")
153160
public func swift_slowAlloc(_ size: Int, _ alignMask: Int) -> UnsafeMutableRawPointer? {
154161
let alignment: Int
@@ -178,6 +185,14 @@ func swift_allocObject(metadata: UnsafeMutablePointer<ClassMetadata>, requiredSi
178185
return unsafe object
179186
}
180187

188+
@_cdecl("swift_deallocUninitializedObject")
189+
public func swift_deallocUninitializedObject(object: Builtin.RawPointer, allocatedSize: Int, allocatedAlignMask: Int) {
190+
unsafe swift_deallocObject(
191+
object: UnsafeMutablePointer<HeapObject>(object),
192+
allocatedSize: allocatedSize,
193+
allocatedAlignMask: allocatedAlignMask)
194+
}
195+
181196
@_cdecl("swift_deallocObject")
182197
public func swift_deallocObject(object: Builtin.RawPointer, allocatedSize: Int, allocatedAlignMask: Int) {
183198
unsafe swift_deallocObject(object: UnsafeMutablePointer<HeapObject>(object), allocatedSize: allocatedSize, allocatedAlignMask: allocatedAlignMask)

test/embedded/accessors.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -Onone -parse-as-library -enable-experimental-feature Embedded -c -o %t/main.o
3+
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: executable_test
8+
// REQUIRES: optimized_stdlib
9+
// REQUIRES: swift_feature_Embedded
10+
11+
public class C {
12+
public var x: Int {
13+
_read {
14+
yield(y)
15+
}
16+
_modify {
17+
yield(&y)
18+
}
19+
}
20+
21+
var y: Int = 27
22+
}
23+
24+
@main
25+
struct Main {
26+
static func main() {
27+
print("1") // CHECK: 1
28+
let c = C() // CHECK: 27
29+
print(c.y)
30+
c.y = 28
31+
print(c.y) // CHECK: 28
32+
print("")
33+
34+
print("2") // CHECK: 2
35+
print("")
36+
}
37+
}

test/embedded/closures-heap.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// REQUIRES: optimized_stdlib
99
// REQUIRES: swift_feature_Embedded
1010

11+
12+
13+
func f() -> Bool? { return nil }
14+
1115
public class MyClass {
1216
var handler: (()->())? = nil
1317
func foo() {
@@ -32,5 +36,12 @@ struct Main {
3236
o!.foo() // CHECK: capture local
3337
print(local == 43 ? "43" : "???") // CHECK: 43
3438
o = nil // CHECK: deinit
39+
40+
let closure = {
41+
guard var b = f() else { print("success"); return }
42+
let c = { b = true }
43+
_ = (b, c)
44+
}
45+
closure() // CHECK: success
3546
}
3647
}

0 commit comments

Comments
 (0)