Skip to content

Commit 8828f1a

Browse files
Merge pull request #61699 from aschwaighofer/fix_gen_distributed_opaque_ptr
IRGen: Fix the computation of the number of type metadata pointers for distributed thunks under opaque pointer IR
2 parents 99dcabd + ae77e79 commit 8828f1a

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,14 +681,17 @@ void DistributedAccessor::emit() {
681681
// We need this to determine the expected number of witness tables
682682
// to load from the buffer provided by the caller.
683683
llvm::SmallVector<llvm::Type *, 4> targetGenericArguments;
684-
expandPolymorphicSignature(IGM, targetTy, targetGenericArguments);
684+
auto numDirectGenericArgs =
685+
expandPolymorphicSignature(IGM, targetTy, targetGenericArguments);
685686

686687
// Generic arguments associated with the distributed thunk directly
687688
// e.g. `distributed func echo<T, U>(...)`
688-
auto numDirectGenericArgs =
689-
llvm::count_if(targetGenericArguments, [&](const llvm::Type *type) {
690-
return type == IGM.TypeMetadataPtrTy;
691-
});
689+
assert(
690+
!IGM.getLLVMContext().supportsTypedPointers() ||
691+
numDirectGenericArgs ==
692+
llvm::count_if(targetGenericArguments, [&](const llvm::Type *type) {
693+
return type == IGM.TypeMetadataPtrTy;
694+
}));
692695

693696
auto expectedWitnessTables =
694697
targetGenericArguments.size() - numDirectGenericArgs;

lib/IRGen/GenProto.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,12 +3456,15 @@ void irgen::bindGenericRequirement(IRGenFunction &IGF,
34563456
namespace {
34573457
/// A class for expanding a polymorphic signature.
34583458
class ExpandPolymorphicSignature : public PolymorphicConvention {
3459+
unsigned numTypeMetadataPtrs = 0;
3460+
34593461
public:
34603462
ExpandPolymorphicSignature(IRGenModule &IGM, CanSILFunctionType fn)
34613463
: PolymorphicConvention(IGM, fn) {}
34623464

3463-
void expand(SmallVectorImpl<llvm::Type *> &out,
3464-
SmallVectorImpl<PolymorphicSignatureExpandedTypeSource> *reqs) {
3465+
unsigned
3466+
expand(SmallVectorImpl<llvm::Type *> &out,
3467+
SmallVectorImpl<PolymorphicSignatureExpandedTypeSource> *reqs) {
34653468
auto outStartSize = out.size();
34663469
(void)outStartSize;
34673470
for (auto &source : getSources())
@@ -3472,9 +3475,13 @@ namespace {
34723475
reqs->push_back(reqt);
34733476
out.push_back(reqt.Protocol ? IGM.WitnessTablePtrTy
34743477
: IGM.TypeMetadataPtrTy);
3478+
3479+
if (!reqt.Protocol)
3480+
++numTypeMetadataPtrs;
34753481
});
34763482
assert((!reqs || reqs->size() == (out.size() - outStartSize)) &&
34773483
"missing type source for type");
3484+
return numTypeMetadataPtrs;
34783485
}
34793486

34803487
private:
@@ -3488,6 +3495,7 @@ namespace {
34883495
case MetadataSource::Kind::GenericLValueMetadata:
34893496
if (reqs)
34903497
reqs->push_back(source);
3498+
++numTypeMetadataPtrs;
34913499
return out.push_back(IGM.TypeMetadataPtrTy);
34923500
case MetadataSource::Kind::SelfMetadata:
34933501
case MetadataSource::Kind::SelfWitnessTable:
@@ -3501,11 +3509,11 @@ namespace {
35013509
} // end anonymous namespace
35023510

35033511
/// Given a generic signature, add the argument types required in order to call it.
3504-
void irgen::expandPolymorphicSignature(
3512+
unsigned irgen::expandPolymorphicSignature(
35053513
IRGenModule &IGM, CanSILFunctionType polyFn,
35063514
SmallVectorImpl<llvm::Type *> &out,
35073515
SmallVectorImpl<PolymorphicSignatureExpandedTypeSource> *outReqs) {
3508-
ExpandPolymorphicSignature(IGM, polyFn).expand(out, outReqs);
3516+
return ExpandPolymorphicSignature(IGM, polyFn).expand(out, outReqs);
35093517
}
35103518

35113519
void irgen::expandTrailingWitnessSignature(IRGenModule &IGM,

lib/IRGen/GenProto.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ namespace irgen {
101101

102102
/// Add the witness parameters necessary for calling a function with
103103
/// the given generics clause.
104-
void expandPolymorphicSignature(
104+
/// Returns the number of type metadata pointers added to `types`.
105+
unsigned expandPolymorphicSignature(
105106
IRGenModule &IGM, CanSILFunctionType type,
106107
SmallVectorImpl<llvm::Type *> &types,
107108
SmallVectorImpl<PolymorphicSignatureExpandedTypeSource> *outReqs =

0 commit comments

Comments
 (0)