Skip to content

Commit 4edc241

Browse files
committed
Fix Lock and mark a few tests unsupported
1 parent 38e9af4 commit 4edc241

File tree

11 files changed

+35
-31
lines changed

11 files changed

+35
-31
lines changed

stdlib/public/Reflection/Sources/_Runtime/Utils/Lock.swift

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,29 @@ func _lockLock(_: UnsafeRawPointer)
2323
@_silgen_name("_swift_reflection_lock_unlock")
2424
func _lockUnlock(_: UnsafeRawPointer)
2525

26-
class Lock<T> {
27-
var value: T
26+
struct Lock<T> {
27+
var storage: ManagedBuffer<T, UInt8>
2828

29-
var mutex: UnsafeRawPointer {
30-
UnsafeRawPointer(
31-
Builtin.projectTailElems(self, UnsafeRawPointer.self)
32-
)
33-
}
34-
35-
init(_ x: T) {
36-
value = x
37-
}
38-
39-
static func create(with initialValue: T) -> Lock<T> {
40-
let lock = Builtin.allocWithTailElems_1(
41-
Lock<T>.self,
42-
_lockSize()._builtinWordValue,
43-
UnsafeRawPointer.self
44-
)
45-
46-
lock.value = initialValue
29+
init(initialValue: T) {
30+
storage = .create(minimumCapacity: _lockSize()) {
31+
$0.withUnsafeMutablePointerToElements {
32+
_lockInit(UnsafeRawPointer($0))
33+
}
4734

48-
_lockInit(lock.mutex)
49-
50-
return lock
35+
return initialValue
36+
}
5137
}
5238

5339
func withLock<U>(_ body: @Sendable (inout T) throws -> U) rethrows -> U {
54-
_lockLock(mutex)
40+
try storage.withUnsafeMutablePointers { header, elements in
41+
_lockLock(UnsafeRawPointer(elements))
5542

56-
defer {
57-
_lockUnlock(mutex)
58-
}
43+
defer {
44+
_lockUnlock(UnsafeRawPointer(elements))
45+
}
5946

60-
return try body(&value)
47+
return try body(&header.pointee)
48+
}
6149
}
6250
}
6351

stdlib/public/Reflection/Sources/_Runtime/Utils/PointerStuff.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import Swift
1313

1414
@_alwaysEmitIntoClient
15-
func unsafeBitCast<T, U>(_ x: T, to type: U.Type = U.self) -> U {
15+
func unsafeBitCast<T, U>(_ x: T, toDefault type: U.Type = U.self) -> U {
1616
Swift.unsafeBitCast(x, to: type)
1717
}
1818

stdlib/public/Reflection/Sources/_Runtime/Utils/TypeCache.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct TypeCache {
1717

1818
@available(SwiftStdlib 5.9, *)
1919
init() {
20-
cache = Lock.create(with: [:])
20+
cache = Lock<[Key: Any.Type?]>(initialValue: [:])
2121
}
2222
}
2323

@@ -192,7 +192,7 @@ var typeCache: TypeCache = {
192192
var result = TypeCache()
193193

194194
result.cache.withLock {
195-
$0.reserveCapacity(50)
195+
$0.reserveCapacity(25)
196196
}
197197

198198
return result

test/stdlib/_Runtime/ContextDescriptor/StructDescriptor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/FunctionMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/Metadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/MetatypeMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/StructMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/TupleMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/TypeMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

test/stdlib/_Runtime/Metadata/ValueWitnessTable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
// UNSUPPORTED: freestanding
5+
46
import StdlibUnittest
57
import _Runtime
68

0 commit comments

Comments
 (0)