Skip to content

Commit d96dbd0

Browse files
author
marcrasi
authored
[AutoDiff] fix TF-961 LoadableByAddress crash (#28623)
1 parent 58a6e7a commit d96dbd0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,22 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
27462746
auto currSILFunctionType = currSILType.castTo<SILFunctionType>();
27472747
GenericEnvironment *genEnv =
27482748
convInstr->getFunction()->getGenericEnvironment();
2749+
// SWIFT_ENABLE_TENSORFLOW
2750+
// Differentiable function conversion instructions can happen while the
2751+
// function is still generic. In that case, we must calculate the new type
2752+
// using the converted function's generic environment rather than the
2753+
// converting function's generic environment.
2754+
//
2755+
// This happens in witness thunks for default implementations of derivative
2756+
// requirements, e.g. `requirement00024` in
2757+
// "test/AutoDiff/compiler_crashers_fixed/tf961".
2758+
if (convInstr->getKind() == SILInstructionKind::DifferentiableFunctionInst ||
2759+
convInstr->getKind() == SILInstructionKind::DifferentiableFunctionExtractInst ||
2760+
convInstr->getKind() == SILInstructionKind::LinearFunctionInst ||
2761+
convInstr->getKind() == SILInstructionKind::LinearFunctionExtractInst)
2762+
if (auto genSig = currSILFunctionType->getSubstGenericSignature())
2763+
genEnv = genSig->getGenericEnvironment();
2764+
// SWIFT_ENABLE_TENSORFLOW_END
27492765
CanSILFunctionType newFnType = MapperCache.getNewSILFunctionType(
27502766
genEnv, currSILFunctionType, *currIRMod);
27512767
SILType newType = SILType::getPrimitiveObjectType(newFnType);

test/AutoDiff/compiler_crashers/tf961-protocol-req-loadable-by-address.swift renamed to test/AutoDiff/compiler_crashers_fixed/tf961-protocol-req-loadable-by-address.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend -emit-ir %s
1+
// RUN: %target-swift-frontend -emit-ir %s
22
// REQUIRES: asserts
33

44
public protocol Protocol00023: Differentiable {

0 commit comments

Comments
 (0)