@@ -693,7 +693,7 @@ void DistributedAccessor::emit() {
693
693
}
694
694
695
695
// Add all of the substitutions to the explosion
696
- if (auto *genericEnvironment = Target->getGenericEnvironment ()) {
696
+ if (Target->getGenericEnvironment ()) {
697
697
// swift.type **
698
698
llvm::Value *substitutionBuffer =
699
699
IGF.Builder .CreateBitCast (substitutions, IGM.TypeMetadataPtrPtrTy );
@@ -817,7 +817,9 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
817
817
// is passed indirectly. This is good for structs and enums because
818
818
// `decodeNextArgument` is a mutating method, but not for classes because
819
819
// 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)) {
821
823
auto selfTy = methodTy->getSelfParameter ().getSILStorageType (
822
824
IGM.getSILModule (), methodTy, expansionContext);
823
825
@@ -836,15 +838,35 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
836
838
instance);
837
839
838
840
decoder = instance.claimNext ();
839
- }
840
841
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
+ }
844
852
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
+ }
848
870
849
871
return {decoder, decoderTy, witnessTable, methodPtr, methodTy};
850
872
}
0 commit comments