Skip to content

Commit c00c692

Browse files
committed
[IRGen] Distributed: Fix distributed actor metadata referencing when ObjC interop is disabled
1 parent a4c0d84 commit c00c692

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ struct AccessorTarget {
181181
/// Witness metadata is computed lazily upon the first request.
182182
WitnessMetadata *getWitnessMetadata(llvm::Value *actorSelf);
183183

184-
public:
184+
private:
185185
FunctionPointer getPointerToTarget(llvm::Value *actorSelf);
186+
187+
llvm::Value *emitMetadataRef(llvm::Value *actorSelf) const;
186188
};
187189

188190
class DistributedAccessor {
@@ -596,7 +598,7 @@ static llvm::Value *lookupWitnessTable(IRGenFunction &IGF, llvm::Value *witness,
596598
witnessTable, llvm::ConstantPointerNull::get(IGM.WitnessTablePtrTy));
597599
IGF.Builder.CreateCondBr(isNull, failBB, contBB);
598600

599-
// This operation shouldn't fail because the compuler should have
601+
// This operation shouldn't fail because the compiler should have
600602
// checked that the given witness conforms to the protocol. If it
601603
// does fail then accessor should trap.
602604
{
@@ -870,6 +872,19 @@ FunctionPointer AccessorTarget::getPointerToTarget(llvm::Value *actorSelf) {
870872
/*secondaryValue=*/nullptr, sig, true);
871873
}
872874

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+
873888
Callee AccessorTarget::getCallee(llvm::Value *actorSelf) {
874889
CalleeInfo info{Type, Type, SubstitutionMap()};
875890
return {std::move(info), getPointerToTarget(actorSelf), actorSelf};
@@ -887,8 +902,8 @@ WitnessMetadata *AccessorTarget::getWitnessMetadata(llvm::Value *actorSelf) {
887902
assert(protocol);
888903

889904
witness.SelfMetadata = actorSelf;
890-
witness.SelfWitnessTable = lookupWitnessTable(
891-
IGF, emitHeapMetadataRefForUnknownHeapObject(IGF, actorSelf), protocol);
905+
witness.SelfWitnessTable =
906+
lookupWitnessTable(IGF, emitMetadataRef(actorSelf), protocol);
892907

893908
Witness = witness;
894909
}

0 commit comments

Comments
 (0)