Skip to content

Extend internal _mangledTypeName() function to take non-copyable types. #76041

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 3 commits into from
Sep 11, 2024
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
6 changes: 4 additions & 2 deletions stdlib/public/core/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ func _typeName(_ type: Any.Type, qualified: Bool = true) -> String {

@available(SwiftStdlib 5.3, *)
@_silgen_name("swift_getMangledTypeName")
public func _getMangledTypeName(_ type: Any.Type)
@_preInverseGenerics
public func _getMangledTypeName(_ type: any ~Copyable.Type)
-> (UnsafePointer<UInt8>, Int)

/// Returns the mangled name for a given type.
@available(SwiftStdlib 5.3, *)
@_unavailableInEmbedded
@_preInverseGenerics
public // SPI
func _mangledTypeName(_ type: Any.Type) -> String? {
func _mangledTypeName(_ type: any ~Copyable.Type) -> String? {
let (stringPtr, count) = _getMangledTypeName(type)
guard count > 0 else {
return nil
Expand Down
7 changes: 7 additions & 0 deletions test/Runtime/demangleToMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ DemangleToMetadataTests.test("Nested types in same-type-constrained extensions")
// V !: P3 in InnerTEqualsConformsToP1
}

struct NonCopyable: ~Copyable {}

if #available(SwiftStdlib 5.3, *) {
DemangleToMetadataTests.test("Round-trip with _mangledTypeName and _typeByName") {
func roundTrip<T>(_ type: T.Type) {
Expand Down Expand Up @@ -524,6 +526,11 @@ if #available(SwiftStdlib 5.3, *) {
let type: Any.Type = Int.self
expectEqual("Si", _mangledTypeName(type))
}

DemangleToMetadataTests.test("Check _MangledTypeName with any ~Copyable.Type") {
let type: any ~Copyable.Type = NonCopyable.self
expectEqual("4main11NonCopyableV", _mangledTypeName(type))
}
}

if #available(SwiftStdlib 5.1, *) {
Expand Down