@@ -2899,24 +2899,30 @@ KeyPathInst::create(SILDebugLocation Loc,
28992899 assert (Args.size () == Pattern->getNumOperands ()
29002900 && " number of key path args doesn't match pattern" );
29012901
2902- auto totalSize = totalSizeToAlloc<Operand>(Args.size ());
2902+ SmallVector<SILValue, 8 > allOperands (Args.begin (), Args.end ());
2903+ collectTypeDependentOperands (allOperands, F, Ty);
2904+
2905+ auto totalSize = totalSizeToAlloc<Operand>(allOperands.size ());
29032906 void *mem = F.getModule ().allocateInst (totalSize, alignof (KeyPathInst));
2904- return ::new (mem) KeyPathInst (Loc, Pattern, Subs, Args, Ty);
2907+ return ::new (mem) KeyPathInst (Loc, Pattern, Subs, allOperands, Args. size () , Ty);
29052908}
29062909
29072910KeyPathInst::KeyPathInst (SILDebugLocation Loc,
29082911 KeyPathPattern *Pattern,
29092912 SubstitutionMap Subs,
2910- ArrayRef<SILValue> Args,
2913+ ArrayRef<SILValue> allOperands,
2914+ unsigned numPatternOperands,
29112915 SILType Ty)
29122916 : InstructionBase(Loc, Ty),
29132917 Pattern(Pattern),
2914- NumOperands(Pattern->getNumOperands ()),
2918+ numPatternOperands(numPatternOperands),
2919+ numTypeDependentOperands(allOperands.size() - numPatternOperands),
29152920 Substitutions(Subs)
29162921{
2922+ assert (allOperands.size () >= numPatternOperands);
29172923 auto *operandsBuf = getTrailingObjects<Operand>();
2918- for (unsigned i = 0 ; i < Args .size (); ++i) {
2919- ::new ((void *)&operandsBuf[i]) Operand (this , Args [i]);
2924+ for (unsigned i = 0 ; i < allOperands .size (); ++i) {
2925+ ::new ((void *)&operandsBuf[i]) Operand (this , allOperands [i]);
29202926 }
29212927
29222928 // Increment the use of any functions referenced from the keypath pattern.
@@ -2927,7 +2933,7 @@ KeyPathInst::KeyPathInst(SILDebugLocation Loc,
29272933
29282934MutableArrayRef<Operand>
29292935KeyPathInst::getAllOperands () {
2930- return {getTrailingObjects<Operand>(), NumOperands };
2936+ return {getTrailingObjects<Operand>(), numPatternOperands + numTypeDependentOperands };
29312937}
29322938
29332939KeyPathInst::~KeyPathInst () {
0 commit comments