diff --git a/lib/SIL/IR/Linker.cpp b/lib/SIL/IR/Linker.cpp index 6ff6c2bd8536f..c391114e05ee7 100644 --- a/lib/SIL/IR/Linker.cpp +++ b/lib/SIL/IR/Linker.cpp @@ -141,6 +141,20 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist( // are also set to IsSerialized. Worklist.push_back(F); } + + if (F->markedAsAlwaysEmitIntoClient()) { + // For @_alwaysEmitIntoClient functions, we need to lookup its + // differentiability witness and, if present, ask SILLoader to obtain its + // definition. Otherwise, a linker error would occur due to undefined + // reference to these symbols. + for (SILDifferentiabilityWitness *witness : + F->getModule().lookUpDifferentiabilityWitnessesForFunction( + F->getName())) { + F->getModule().getSILLoader()->lookupDifferentiabilityWitness( + witness->getKey()); + } + } + return; } diff --git a/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb b/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb index 904768cfd2588..e1da73241ab91 100644 --- a/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb +++ b/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb @@ -455,3 +455,27 @@ where return (Self(repeating: value), { v in Self(repeating: v) }) } } + +%for (Scalar, bits) in [('Float',32), ('Double',64)]: +% for n in vectorscalarCounts: +extension SIMD${n} where Scalar == ${Scalar} { + @inlinable + @_alwaysEmitIntoClient + @derivative(of: init(repeating:)) + static func _vjpInit(repeating value: Scalar) + -> (value: Self, pullback: (TangentVector) -> Scalar.TangentVector) + { + return (Self(repeating: value), { v in v.sum() }) + } + + @inlinable + @_alwaysEmitIntoClient + @derivative(of: init(repeating:)) + static func _jvpInit(repeating value: Scalar) + -> (value: Self, differential: (Scalar.TangentVector) -> TangentVector) + { + return (Self(repeating: value), { v in Self(repeating: v) }) + } +} +% end +%end diff --git a/stdlib/public/core/SIMDFloatConcreteOperations.swift.gyb b/stdlib/public/core/SIMDFloatConcreteOperations.swift.gyb index 8c30a42b4fedf..71d2e91ba08ec 100644 --- a/stdlib/public/core/SIMDFloatConcreteOperations.swift.gyb +++ b/stdlib/public/core/SIMDFloatConcreteOperations.swift.gyb @@ -34,8 +34,6 @@ extension SIMD${n} where Scalar == ${Scalar} { _storage = ${Scalar}.SIMD${storageN}Storage(_builtin) } - /* Breaks differentiation testing, commented out while we figure out - what to do about that. @_alwaysEmitIntoClient @_transparent public init(repeating scalar: ${Scalar}) { let asVector = Builtin.insertelement_${Builtin}_FPIEEE${bits}_Int32( @@ -52,7 +50,6 @@ extension SIMD${n} where Scalar == ${Scalar} { )) %end } - */ % if n >= 4: @_alwaysEmitIntoClient @_transparent diff --git a/test/stdlib/SIMDFloatInitializers.swift.gyb b/test/stdlib/SIMDFloatInitializers.swift.gyb index f728764d596d9..c535d57bf1de8 100644 --- a/test/stdlib/SIMDFloatInitializers.swift.gyb +++ b/test/stdlib/SIMDFloatInitializers.swift.gyb @@ -14,10 +14,6 @@ // RUN: %target-swift-frontend -primary-file %t/SIMDFloatInitializers.swift -S | %FileCheck %t/SIMDFloatInitializers.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKOnone-%target-cpu // RUN: %target-swift-frontend -primary-file %t/SIMDFloatInitializers.swift -S -O | %FileCheck %t/SIMDFloatInitializers.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKO-%target-cpu -// Disable this test for now because aEIC/transparent functions still are not -// correctly differentiable, and so these inits are suppressed in the stdlib. -// REQUIRES: differentiable-aEIC-transparent - import Swift %for bits in [16,32,64]: