Skip to content
Closed
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
4 changes: 3 additions & 1 deletion lib/SIL/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ DifferentiabilityWitnessFunctionInst::DifferentiabilityWitnessFunctionInst(
: getDifferentiabilityWitnessType(
module, witnessKind, witness)),
witnessKind(witnessKind), witness(witness),
hasExplicitFunctionType(FunctionType) {}
hasExplicitFunctionType(FunctionType) {
assert(witness && "Witness must not be null");
}
// SWIFT_ENABLE_TENSORFLOW END

FunctionRefBaseInst::FunctionRefBaseInst(SILInstructionKind Kind,
Expand Down
22 changes: 22 additions & 0 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,28 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
"The function operand must be a '@differentiable(linear)' "
"function");
}

void checkDifferentiabilityWitnessFunctionInst(
DifferentiabilityWitnessFunctionInst *dwfi) {
auto witnessFnTy = dwfi->getType().castTo<SILFunctionType>();
auto *witness = dwfi->getWitness();
// `DifferentiabilityWitnessFunctionInst` constructor asserts that
// `witness` is non-null.
auto witnessKind = dwfi->getWitnessKind();
// Return if not witnessing a derivative function.
auto derivKind = witnessKind.getAsDerivativeFunctionKind();
if (!derivKind)
return;
// Return if witness does not define the referenced derivative.
auto *derivativeFn = witness->getDerivative(*derivKind);
if (!derivativeFn)
return;
auto derivativeFnTy = derivativeFn->getLoweredFunctionType();
requireSameType(SILType::getPrimitiveObjectType(witnessFnTy),
SILType::getPrimitiveObjectType(derivativeFnTy),
"Type of witness instruction does not match actual type of "
"witnessed function");
}
// SWIFT_ENABLE_TENSORFLOW END

void verifyLLVMIntrinsic(BuiltinInst *BI, llvm::Intrinsic::ID ID) {
Expand Down