Skip to content

[AutoDiff] fix TF-961 LoadableByAddress crash #28623

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 1 commit into from
Dec 10, 2019
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
16 changes: 16 additions & 0 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2746,6 +2746,22 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
auto currSILFunctionType = currSILType.castTo<SILFunctionType>();
GenericEnvironment *genEnv =
convInstr->getFunction()->getGenericEnvironment();
// SWIFT_ENABLE_TENSORFLOW
// Differentiable function conversion instructions can happen while the
// function is still generic. In that case, we must calculate the new type
// using the converted function's generic environment rather than the
// converting function's generic environment.
//
// This happens in witness thunks for default implementations of derivative
// requirements, e.g. `requirement00024` in
// "test/AutoDiff/compiler_crashers_fixed/tf961".
if (convInstr->getKind() == SILInstructionKind::DifferentiableFunctionInst ||
convInstr->getKind() == SILInstructionKind::DifferentiableFunctionExtractInst ||
convInstr->getKind() == SILInstructionKind::LinearFunctionInst ||
convInstr->getKind() == SILInstructionKind::LinearFunctionExtractInst)
if (auto genSig = currSILFunctionType->getSubstGenericSignature())
genEnv = genSig->getGenericEnvironment();
// SWIFT_ENABLE_TENSORFLOW_END
CanSILFunctionType newFnType = MapperCache.getNewSILFunctionType(
genEnv, currSILFunctionType, *currIRMod);
SILType newType = SILType::getPrimitiveObjectType(newFnType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not --crash %target-swift-frontend -emit-ir %s
// RUN: %target-swift-frontend -emit-ir %s
// REQUIRES: asserts

public protocol Protocol00023: Differentiable {
Expand Down