diff --git a/README.md b/README.md index dd40471feaae3..72ff037c9af10 100644 --- a/README.md +++ b/README.md @@ -167,3 +167,4 @@ view of the available documentation. In particular, the documents titled [Debugging the Swift Compiler](docs/DebuggingTheCompiler.md) and [Continuous Integration for Swift](docs/ContinuousIntegration.md) are very helpful to understand before submitting your first PR. + diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 176b50f8df41f..09d95256b66fe 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -6347,13 +6347,10 @@ SILFunction *SILGenModule::getOrCreateCustomDerivativeThunk( arguments.push_back(indErrorRes.getLValueAddress()); forwardFunctionArguments(thunkSGF, loc, fnRefType, params, arguments); - SubstitutionMap subs = thunk->getForwardingSubstitutionMap(); - SILType substFnType = fnRef->getType().substGenericArgs( - M, subs, thunk->getTypeExpansionContext()); - // Apply function argument. - auto apply = - thunkSGF.emitApplyWithRethrow(loc, fnRef, substFnType, subs, arguments); + auto apply = thunkSGF.emitApplyWithRethrow( + loc, fnRef, /*substFnType*/ fnRef->getType(), + thunk->getForwardingSubstitutionMap(), arguments); // Self reordering thunk is necessary if wrt at least two parameters, // including self. diff --git a/lib/SILOptimizer/Mandatory/Differentiation.cpp b/lib/SILOptimizer/Mandatory/Differentiation.cpp index 3584fba568a3c..b8251eccfdd09 100644 --- a/lib/SILOptimizer/Mandatory/Differentiation.cpp +++ b/lib/SILOptimizer/Mandatory/Differentiation.cpp @@ -906,15 +906,6 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness( traceMessage.c_str(), witness->getOriginalFunction()); assert(witness->isDefinition()); - SILFunction *orig = witness->getOriginalFunction(); - - // We can generate empty JVP / VJP for functions available externally. These - // functions have the same linkage as the original ones sans `external` - // flag. Important exception here hidden_external functions as they are - // serializable but corresponding hidden ones would be not and the SIL - // verifier will fail. Patch `serializeFunctions` for this case. - if (orig->getLinkage() == SILLinkage::HiddenExternal) - serializeFunctions = IsNotSerialized; // If the JVP doesn't exist, need to synthesize it. if (!witness->getJVP()) { @@ -923,8 +914,9 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness( // - Functions with unsupported control flow. if (context.getASTContext() .LangOpts.hasFeature(Feature::ForwardModeDifferentiation) && - (diagnoseNoReturn(context, orig, invoker) || - diagnoseUnsupportedControlFlow(context, orig, invoker))) + (diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) || + diagnoseUnsupportedControlFlow( + context, witness->getOriginalFunction(), invoker))) return true; // Create empty JVP. @@ -941,10 +933,10 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness( !witness->getVJP()) { // JVP and differential generation do not currently support functions with // multiple basic blocks. - if (orig->size() > 1) { - context.emitNondifferentiabilityError(orig->getLocation().getSourceLoc(), - invoker, - diag::autodiff_jvp_control_flow_not_supported); + if (witness->getOriginalFunction()->size() > 1) { + context.emitNondifferentiabilityError( + witness->getOriginalFunction()->getLocation().getSourceLoc(), + invoker, diag::autodiff_jvp_control_flow_not_supported); return true; } // Emit JVP function. @@ -958,7 +950,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness( "_fatalErrorForwardModeDifferentiationDisabled"); LLVM_DEBUG(getADDebugStream() << "Generated empty JVP for " - << orig->getName() << ":\n" + << witness->getOriginalFunction()->getName() << ":\n" << *jvp); } } @@ -968,8 +960,9 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness( // Diagnose: // - Functions with no return. // - Functions with unsupported control flow. - if (diagnoseNoReturn(context, orig, invoker) || - diagnoseUnsupportedControlFlow(context, orig, invoker)) + if (diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) || + diagnoseUnsupportedControlFlow( + context, witness->getOriginalFunction(), invoker)) return true; // Create empty VJP. diff --git a/test/AutoDiff/SILGen/nil_coalescing.swift b/test/AutoDiff/SILGen/nil_coalescing.swift deleted file mode 100644 index 994fbeed691fa..0000000000000 --- a/test/AutoDiff/SILGen/nil_coalescing.swift +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s - -import _Differentiation - -// CHECK: sil @test_nil_coalescing -// CHECK: bb0(%{{.*}} : $*T, %[[ARG_OPT:.*]] : $*Optional, %[[ARG_PB:.*]] : -// CHECK: $@noescape @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for ): -// CHECK: %[[ALLOC_OPT:.*]] = alloc_stack [lexical] $Optional -// CHECK: copy_addr %[[ARG_OPT]] to [init] %[[ALLOC_OPT]] : $*Optional -// CHECK: switch_enum_addr %[[ALLOC_OPT]] : $*Optional, case #Optional.some!enumelt: {{.*}}, case #Optional.none!enumelt: {{.*}} -// CHECK: try_apply %[[ARG_PB]](%{{.*}}) : $@noescape @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for , normal {{.*}}, error {{.*}} -// -@_silgen_name("test_nil_coalescing") -@derivative(of: ??) -@usableFromInline -func nilCoalescing(optional: T?, defaultValue: @autoclosure () throws -> T) - rethrows -> (value: T, pullback: (T.TangentVector) -> Optional.TangentVector) -{ - let hasValue = optional != nil - let value = try optional ?? defaultValue() - func pullback(_ v: T.TangentVector) -> Optional.TangentVector { - return hasValue ? .init(v) : .zero - } - return (value, pullback) -}