@@ -181,8 +181,10 @@ struct AccessorTarget {
181
181
// / Witness metadata is computed lazily upon the first request.
182
182
WitnessMetadata *getWitnessMetadata (llvm::Value *actorSelf);
183
183
184
- public :
184
+ private :
185
185
FunctionPointer getPointerToTarget (llvm::Value *actorSelf);
186
+
187
+ llvm::Value *emitMetadataRef (llvm::Value *actorSelf) const ;
186
188
};
187
189
188
190
class DistributedAccessor {
@@ -596,7 +598,7 @@ static llvm::Value *lookupWitnessTable(IRGenFunction &IGF, llvm::Value *witness,
596
598
witnessTable, llvm::ConstantPointerNull::get (IGM.WitnessTablePtrTy ));
597
599
IGF.Builder .CreateCondBr (isNull, failBB, contBB);
598
600
599
- // This operation shouldn't fail because the compuler should have
601
+ // This operation shouldn't fail because the compiler should have
600
602
// checked that the given witness conforms to the protocol. If it
601
603
// does fail then accessor should trap.
602
604
{
@@ -870,6 +872,19 @@ FunctionPointer AccessorTarget::getPointerToTarget(llvm::Value *actorSelf) {
870
872
/* secondaryValue=*/ nullptr , sig, true );
871
873
}
872
874
875
+ llvm::Value *AccessorTarget::emitMetadataRef (llvm::Value *actorSelf) const {
876
+ auto &IGM = IGF.IGM ;
877
+
878
+ if (!IGM.ObjCInterop ) {
879
+ llvm::Value *slot =
880
+ IGF.Builder .CreateBitCast (actorSelf, IGM.TypeMetadataPtrPtrTy );
881
+ return IGF.Builder .CreateLoad (
882
+ Address (slot, IGM.TypeMetadataPtrTy , IGM.getPointerAlignment ()));
883
+ }
884
+
885
+ return emitHeapMetadataRefForUnknownHeapObject (IGF, actorSelf);
886
+ }
887
+
873
888
Callee AccessorTarget::getCallee (llvm::Value *actorSelf) {
874
889
CalleeInfo info{Type, Type, SubstitutionMap ()};
875
890
return {std::move (info), getPointerToTarget (actorSelf), actorSelf};
@@ -887,8 +902,8 @@ WitnessMetadata *AccessorTarget::getWitnessMetadata(llvm::Value *actorSelf) {
887
902
assert (protocol);
888
903
889
904
witness.SelfMetadata = actorSelf;
890
- witness.SelfWitnessTable = lookupWitnessTable (
891
- IGF, emitHeapMetadataRefForUnknownHeapObject (IGF, actorSelf), protocol);
905
+ witness.SelfWitnessTable =
906
+ lookupWitnessTable (IGF, emitMetadataRef ( actorSelf), protocol);
892
907
893
908
Witness = witness;
894
909
}
0 commit comments