Skip to content

Commit bed8956

Browse files
authored
Disable calling _swift_stdlib_dyld_is_objc_constant_string, it's unnecessary currently (swiftlang#77064)
1 parent 1a07030 commit bed8956

File tree

1 file changed

+1
-112
lines changed

1 file changed

+1
-112
lines changed

stdlib/public/core/StringBridge.swift

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,11 @@ private func _NSStringLen(_ str: _StringSelectorHolder) -> Int {
102102
internal func _stdlib_binary_CFStringGetLength(
103103
_ source: _CocoaString
104104
) -> Int {
105-
if let len = getConstantTaggedCocoaContents(source)?.utf16Length {
106-
return len
107-
}
108105
return _NSStringLen(_objc(source))
109106
}
110107

111108
@_effects(readonly)
112109
internal func _isNSString(_ str:AnyObject) -> Bool {
113-
if getConstantTaggedCocoaContents(str) != nil {
114-
return true
115-
}
116110
return _swift_stdlib_isNSString(str) != 0
117111
}
118112

@@ -316,24 +310,13 @@ internal enum _KnownCocoaString {
316310
#if _pointerBitWidth(_64)
317311
case tagged
318312
#endif
319-
#if arch(arm64)
320-
case constantTagged
321-
#endif
322313

323314
@inline(__always)
324315
init(_ str: _CocoaString) {
325316

326317
#if _pointerBitWidth(_64)
327318
if _isObjCTaggedPointer(str) {
328-
#if arch(arm64)
329-
if let _ = getConstantTaggedCocoaContents(str) {
330-
self = .constantTagged
331-
} else {
332-
self = .tagged
333-
}
334-
#else
335319
self = .tagged
336-
#endif
337320
return
338321
}
339322
#endif
@@ -404,9 +387,6 @@ private func _withCocoaASCIIPointer<R>(
404387
) -> R? {
405388
#if _pointerBitWidth(_64)
406389
if _isObjCTaggedPointer(str) {
407-
if let ptr = getConstantTaggedCocoaContents(str)?.asciiContentsPointer {
408-
return work(ptr)
409-
}
410390
if requireStableAddress {
411391
return nil // tagged pointer strings don't support _fastCStringContents
412392
}
@@ -432,9 +412,6 @@ private func _withCocoaUTF8Pointer<R>(
432412
) -> R? {
433413
#if _pointerBitWidth(_64)
434414
if _isObjCTaggedPointer(str) {
435-
if let ptr = getConstantTaggedCocoaContents(str)?.asciiContentsPointer {
436-
return work(ptr)
437-
}
438415
if requireStableAddress {
439416
return nil // tagged pointer strings don't support _fastCStringContents
440417
}
@@ -499,83 +476,6 @@ private func _getCocoaStringPointer(
499476
return .none
500477
}
501478

502-
#if arch(arm64)
503-
//11000000..payload..111
504-
private var constantTagMask:UInt {
505-
0b1111_1111_1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0111
506-
}
507-
private var expectedConstantTagValue:UInt {
508-
0b1100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0111
509-
}
510-
#endif
511-
512-
@inline(__always)
513-
private func formConstantTaggedCocoaString(
514-
untaggedCocoa: _CocoaString
515-
) -> AnyObject? {
516-
#if !arch(arm64)
517-
return nil
518-
#else
519-
520-
let constantPtr:UnsafeRawPointer = Builtin.reinterpretCast(untaggedCocoa)
521-
522-
// Check if what we're pointing to is actually a valid tagged constant
523-
guard _swift_stdlib_dyld_is_objc_constant_string(constantPtr) == 1 else {
524-
return nil
525-
}
526-
527-
let retaggedPointer = UInt(bitPattern: constantPtr) | expectedConstantTagValue
528-
529-
return unsafeBitCast(retaggedPointer, to: AnyObject.self)
530-
#endif
531-
}
532-
533-
@inline(__always)
534-
private func getConstantTaggedCocoaContents(_ cocoaString: _CocoaString) ->
535-
(utf16Length: Int,
536-
asciiContentsPointer: UnsafePointer<UInt8>,
537-
untaggedCocoa: _CocoaString)? {
538-
#if !arch(arm64)
539-
return nil
540-
#else
541-
542-
guard _isObjCTaggedPointer(cocoaString) else {
543-
return nil
544-
}
545-
546-
let taggedValue = unsafeBitCast(cocoaString, to: UInt.self)
547-
548-
549-
550-
guard taggedValue & constantTagMask == expectedConstantTagValue else {
551-
return nil
552-
}
553-
554-
let payloadMask = ~constantTagMask
555-
let payload = taggedValue & payloadMask
556-
let ivarPointer = UnsafePointer<_swift_shims_builtin_CFString>(
557-
bitPattern: payload
558-
)!
559-
560-
guard _swift_stdlib_dyld_is_objc_constant_string(
561-
UnsafeRawPointer(ivarPointer)
562-
) == 1 else {
563-
return nil
564-
}
565-
566-
let length = ivarPointer.pointee.length
567-
let isUTF16Mask:UInt = 0x0000_0000_0000_0004 //CFStringFlags bit 4: isUnicode
568-
let isASCII = ivarPointer.pointee.flags & isUTF16Mask == 0
569-
_precondition(isASCII) // we don't currently support non-ASCII here
570-
let contentsPtr = ivarPointer.pointee.str
571-
return (
572-
utf16Length: Int(length),
573-
asciiContentsPointer: contentsPtr,
574-
untaggedCocoa: Builtin.reinterpretCast(ivarPointer)
575-
)
576-
#endif
577-
}
578-
579479
#if !$Embedded
580480
@usableFromInline
581481
@_effects(releasenone) // @opaque
@@ -594,16 +494,6 @@ internal func _bridgeCocoaString(_ cocoaString: _CocoaString) -> _StringGuts {
594494
// which will never have tagged pointer strings that aren't small, hence
595495
// the force unwrap here.
596496
return _StringGuts(_SmallString(taggedCocoa: cocoaString)!)
597-
#if arch(arm64)
598-
case .constantTagged:
599-
let taggedContents = getConstantTaggedCocoaContents(cocoaString)!
600-
return _StringGuts(
601-
cocoa: taggedContents.untaggedCocoa,
602-
providesFastUTF8: false, //TODO: if contentsPtr is UTF8 compatible, use it
603-
isASCII: true,
604-
length: taggedContents.utf16Length
605-
)
606-
#endif
607497
#endif
608498
case .cocoa:
609499
// "Copy" it into a value to be sure nobody will modify behind
@@ -743,8 +633,7 @@ extension String {
743633

744634
_internalInvariant(_guts._object.hasObjCBridgeableObject,
745635
"Unknown non-bridgeable object case")
746-
let result = _guts._object.objCBridgeableObject
747-
return formConstantTaggedCocoaString(untaggedCocoa: result) ?? result
636+
return _guts._object.objCBridgeableObject
748637
}
749638
}
750639

0 commit comments

Comments
 (0)