@@ -693,7 +693,7 @@ void DistributedAccessor::emit() {
693693 }
694694
695695 // Add all of the substitutions to the explosion
696- if (auto *genericEnvironment = Target->getGenericEnvironment ()) {
696+ if (Target->getGenericEnvironment ()) {
697697 // swift.type **
698698 llvm::Value *substitutionBuffer =
699699 IGF.Builder .CreateBitCast (substitutions, IGM.TypeMetadataPtrPtrTy );
@@ -817,7 +817,9 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
817817 // is passed indirectly. This is good for structs and enums because
818818 // `decodeNextArgument` is a mutating method, but not for classes because
819819 // in that case heap object is mutated directly.
820- if (isa<ClassDecl>(decoderDecl)) {
820+ llvm::Function *fnPtr = nullptr ;
821+ bool usesDispatchThunk = false ;
822+ if (auto classDecl = dyn_cast<ClassDecl>(decoderDecl)) {
821823 auto selfTy = methodTy->getSelfParameter ().getSILStorageType (
822824 IGM.getSILModule (), methodTy, expansionContext);
823825
@@ -836,15 +838,35 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
836838 instance);
837839
838840 decoder = instance.claimNext ();
839- }
840841
841- auto *decodeSIL = IGM.getSILModule ().lookUpFunction (SILDeclRef (decodeFn));
842- auto *fnPtr = IGM.getAddrOfSILFunction (decodeSIL, NotForDefinition,
843- /* isDynamicallyReplaceable=*/ false );
842+ // / When using library evolution functions have another "dispatch thunk"
843+ // / so we must use this instead of the decodeFn directly.
844+ if (classDecl->hasResilientMetadata ()) {
845+ if (getMethodDispatch (decodeFn) == swift::MethodDispatch::Class) {
846+ SILDeclRef (decodeFn).getOverriddenVTableEntry ().getDecl ()->getDeclContext ()->dumpContext ();
847+ fnPtr = IGM.getAddrOfDispatchThunk (SILDeclRef (decodeFn), NotForDefinition);
848+ usesDispatchThunk = true ;
849+ }
850+ }
851+ }
844852
845- auto methodPtr = FunctionPointer::forDirect (
846- classifyFunctionPointerKind (decodeSIL), fnPtr,
847- /* secondaryValue=*/ nullptr , signature);
853+ if (!fnPtr) {
854+ auto *decodeSIL = IGM.getSILModule ().lookUpFunction (SILDeclRef (decodeFn));
855+ fnPtr = IGM.getAddrOfSILFunction (decodeSIL, NotForDefinition,
856+ /* isDynamicallyReplaceable=*/ false );
857+ }
858+ assert (fnPtr);
859+
860+ FunctionPointer methodPtr;
861+ if (usesDispatchThunk) {
862+ methodPtr = FunctionPointer::createUnsigned (
863+ methodTy, fnPtr, signature, /* useSignature=*/ true );
864+ } else {
865+ auto *decodeSIL = IGM.getSILModule ().lookUpFunction (SILDeclRef (decodeFn));
866+ methodPtr = FunctionPointer::forDirect (
867+ classifyFunctionPointerKind (decodeSIL), fnPtr,
868+ /* secondaryValue=*/ nullptr , signature);
869+ }
848870
849871 return {decoder, decoderTy, witnessTable, methodPtr, methodTy};
850872}
0 commit comments