Skip to content

Commit 3582987

Browse files
committed
Make sure the builtin use is inlined so it can statically see what's going on
1 parent 47545bf commit 3582987

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
274274
realMinimumCapacity._builtinWordValue, Element.self)
275275

276276
let storageAddr = UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(_storage))
277-
if let allocSize = _mallocSize(ofAllocation: storageAddr) {
277+
if let allocSize = _mallocSizeIfHeap(ofAllocation: storageAddr) {
278278
let endAddr = storageAddr + allocSize
279279
let realCapacity = endAddr.assumingMemoryBound(to: Element.self) - firstElementAddress
280280
_initStorageHeader(

stdlib/public/core/Shims.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ internal let _fastEnumerationStorageMutationsPtr =
3737
UnsafeMutablePointer<CUnsignedLong>(Builtin.addressof(&_fastEnumerationStorageMutationsTarget))
3838
#endif
3939

40+
41+
42+
4043
@usableFromInline @_alwaysEmitIntoClient @_effects(readonly)
4144
internal func _mallocSize(ofAllocation ptr: UnsafeRawPointer) -> Int? {
42-
return !Builtin.isOnStack(ptr) && _swift_stdlib_has_malloc_size() ?
43-
_swift_stdlib_malloc_size(ptr) :
44-
nil
45+
return _swift_stdlib_has_malloc_size() ? _swift_stdlib_malloc_size(ptr) : nil
4546
}
47+
48+
@inline(__always) @inlinable @_effects(readonly)
49+
internal func _mallocSizeIfHeap(ofAllocation ptr: UnsafeRawPointer) -> Int? {
50+
if !Builtin.isOnStack(ptr) { return nil }
51+
return _mallocSize(ofAllocation: ptr)
52+
}
53+

stdlib/public/core/StringStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fileprivate func _allocate<T: AnyObject>(
206206
let totalTailBytes = total - numHeaderBytes
207207

208208
let object = tailAllocator(totalTailBytes)
209-
if let allocSize = _mallocSize(ofAllocation:
209+
if let allocSize = _mallocSizeIfHeap(ofAllocation:
210210
UnsafeRawPointer(Builtin.bridgeToRawPointer(object))) {
211211
_internalInvariant(allocSize % MemoryLayout<Int>.stride == 0)
212212

0 commit comments

Comments
 (0)