Skip to content

[SIMD] Add CustomDebugStringConvertible conformance for SIMD types. #21339

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
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
8 changes: 8 additions & 0 deletions stdlib/public/core/SIMDVectorTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ public extension SIMD${n} where Scalar : FixedWidthInteger {
}
}

extension SIMD${n} : CustomDebugStringConvertible {
/// Debug string representation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overrides the default documentation for debugDescription. Was that intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it, but we can clean it up in another PR. =)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled the fix into #21379

public var debugDescription: String {
return "SIMD${n}<\(Scalar.self)>(${', '.join(map(lambda c:
'\\(self['+ str(c) + '])',
xrange(n)))})"
}
}

public extension SIMD${n} where Scalar : BinaryFloatingPoint {
@inlinable
Expand Down
5 changes: 5 additions & 0 deletions test/stdlib/simd.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,10 @@ simdTestSuite.test("matrix elements") {
% end # for type
}

simdTestSuite.test("debug description") {
expectEqual("SIMD2<Float>(1.0, 2.5)",
SIMD2<Float>(1.0, 2.5).debugDescription)
}

runAllTests()