Skip to content

Commit ad89497

Browse files
committed
Revert "[AutoDiff] Fix custom derivative thunk for Optional (#71721)"
This reverts commit aa5dddb.
1 parent abc9490 commit ad89497

File tree

3 files changed

+14
-49
lines changed

3 files changed

+14
-49
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6347,13 +6347,10 @@ SILFunction *SILGenModule::getOrCreateCustomDerivativeThunk(
63476347
arguments.push_back(indErrorRes.getLValueAddress());
63486348
forwardFunctionArguments(thunkSGF, loc, fnRefType, params, arguments);
63496349

6350-
SubstitutionMap subs = thunk->getForwardingSubstitutionMap();
6351-
SILType substFnType = fnRef->getType().substGenericArgs(
6352-
M, subs, thunk->getTypeExpansionContext());
6353-
63546350
// Apply function argument.
6355-
auto apply =
6356-
thunkSGF.emitApplyWithRethrow(loc, fnRef, substFnType, subs, arguments);
6351+
auto apply = thunkSGF.emitApplyWithRethrow(
6352+
loc, fnRef, /*substFnType*/ fnRef->getType(),
6353+
thunk->getForwardingSubstitutionMap(), arguments);
63576354

63586355
// Self reordering thunk is necessary if wrt at least two parameters,
63596356
// including self.

lib/SILOptimizer/Mandatory/Differentiation.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -906,15 +906,6 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
906906
traceMessage.c_str(), witness->getOriginalFunction());
907907

908908
assert(witness->isDefinition());
909-
SILFunction *orig = witness->getOriginalFunction();
910-
911-
// We can generate empty JVP / VJP for functions available externally. These
912-
// functions have the same linkage as the original ones sans `external`
913-
// flag. Important exception here hidden_external functions as they are
914-
// serializable but corresponding hidden ones would be not and the SIL
915-
// verifier will fail. Patch `serializeFunctions` for this case.
916-
if (orig->getLinkage() == SILLinkage::HiddenExternal)
917-
serializeFunctions = IsNotSerialized;
918909

919910
// If the JVP doesn't exist, need to synthesize it.
920911
if (!witness->getJVP()) {
@@ -923,8 +914,9 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
923914
// - Functions with unsupported control flow.
924915
if (context.getASTContext()
925916
.LangOpts.hasFeature(Feature::ForwardModeDifferentiation) &&
926-
(diagnoseNoReturn(context, orig, invoker) ||
927-
diagnoseUnsupportedControlFlow(context, orig, invoker)))
917+
(diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) ||
918+
diagnoseUnsupportedControlFlow(
919+
context, witness->getOriginalFunction(), invoker)))
928920
return true;
929921

930922
// Create empty JVP.
@@ -941,10 +933,10 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
941933
!witness->getVJP()) {
942934
// JVP and differential generation do not currently support functions with
943935
// multiple basic blocks.
944-
if (orig->size() > 1) {
945-
context.emitNondifferentiabilityError(orig->getLocation().getSourceLoc(),
946-
invoker,
947-
diag::autodiff_jvp_control_flow_not_supported);
936+
if (witness->getOriginalFunction()->size() > 1) {
937+
context.emitNondifferentiabilityError(
938+
witness->getOriginalFunction()->getLocation().getSourceLoc(),
939+
invoker, diag::autodiff_jvp_control_flow_not_supported);
948940
return true;
949941
}
950942
// Emit JVP function.
@@ -958,7 +950,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
958950
"_fatalErrorForwardModeDifferentiationDisabled");
959951
LLVM_DEBUG(getADDebugStream()
960952
<< "Generated empty JVP for "
961-
<< orig->getName() << ":\n"
953+
<< witness->getOriginalFunction()->getName() << ":\n"
962954
<< *jvp);
963955
}
964956
}
@@ -968,8 +960,9 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
968960
// Diagnose:
969961
// - Functions with no return.
970962
// - Functions with unsupported control flow.
971-
if (diagnoseNoReturn(context, orig, invoker) ||
972-
diagnoseUnsupportedControlFlow(context, orig, invoker))
963+
if (diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) ||
964+
diagnoseUnsupportedControlFlow(
965+
context, witness->getOriginalFunction(), invoker))
973966
return true;
974967

975968
// Create empty VJP.

test/AutoDiff/SILGen/nil_coalescing.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)