From fbf4bb738db00b2b6c72874bc61170fbc603c2c6 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 14 Dec 2018 17:00:17 -0800 Subject: [PATCH] [SIMD] Add CustomDebugStringConvertible conformance for SIMD types. The old SIMD types had a conformance to CustomDebugStringConvertible, but the new ones do not, causing a source compatibility regression. Add back a CustomDebugStringConvertible conformance. Fixes rdar://problem/46746829. --- stdlib/public/core/SIMDVectorTypes.swift.gyb | 8 ++++++++ test/stdlib/simd.swift.gyb | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/stdlib/public/core/SIMDVectorTypes.swift.gyb b/stdlib/public/core/SIMDVectorTypes.swift.gyb index b5d91cecf7852..d079d77494fa7 100644 --- a/stdlib/public/core/SIMDVectorTypes.swift.gyb +++ b/stdlib/public/core/SIMDVectorTypes.swift.gyb @@ -109,6 +109,14 @@ public extension SIMD${n} where Scalar : FixedWidthInteger { } } +extension SIMD${n} : CustomDebugStringConvertible { + /// Debug string representation + 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 diff --git a/test/stdlib/simd.swift.gyb b/test/stdlib/simd.swift.gyb index afadc168a5286..84bedf3570631 100644 --- a/test/stdlib/simd.swift.gyb +++ b/test/stdlib/simd.swift.gyb @@ -313,5 +313,10 @@ simdTestSuite.test("matrix elements") { % end # for type } +simdTestSuite.test("debug description") { + expectEqual("SIMD2(1.0, 2.5)", + SIMD2(1.0, 2.5).debugDescription) +} + runAllTests()