Skip to content

Commit c19f3ce

Browse files
committed
Remove silgen changes and use getParameterType in CSApply
1 parent 0f6ff75 commit c19f3ce

File tree

3 files changed

+26
-70
lines changed

3 files changed

+26
-70
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,8 +2560,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
25602560
return paramSubstValue;
25612561
}
25622562

2563-
/// formal, lowered, isVariadic
2564-
using IndexTypeTuple = std::tuple<CanType, SILType, bool>;
2563+
using IndexTypePair = std::pair<CanType, SILType>;
25652564

25662565
/// Helper function to load the captured indexes out of a key path component
25672566
/// in order to invoke the accessors on that key path. A component with captured
@@ -2571,7 +2570,7 @@ using IndexTypeTuple = std::tuple<CanType, SILType, bool>;
25712570
static PreparedArguments
25722571
loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
25732572
AbstractStorageDecl *storage,
2574-
ArrayRef<IndexTypeTuple> indexes,
2573+
ArrayRef<IndexTypePair> indexes,
25752574
SILValue pointer) {
25762575
// If not a subscript, do nothing.
25772576
if (!isa<SubscriptDecl>(storage))
@@ -2580,7 +2579,7 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
25802579
SmallVector<AnyFunctionType::Param, 8> indexParams;
25812580
for (auto &elt : indexes) {
25822581
// FIXME: Varargs?
2583-
indexParams.emplace_back(SGF.F.mapTypeIntoContext(std::get<0>(elt)));
2582+
indexParams.emplace_back(SGF.F.mapTypeIntoContext(elt.first));
25842583
}
25852584

25862585
PreparedArguments indexValues(indexParams);
@@ -2603,12 +2602,12 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
26032602
if (indexes.size() > 1) {
26042603
eltAddr = SGF.B.createTupleElementAddr(loc, eltAddr, i);
26052604
}
2606-
auto ty = SGF.F.mapTypeIntoContext(std::get<1>(indexes[i]));
2605+
auto ty = SGF.F.mapTypeIntoContext(indexes[i].second);
26072606
auto value = SGF.emitLoad(loc, eltAddr,
26082607
SGF.getTypeLowering(ty),
26092608
SGFContext(), IsNotTake);
26102609
auto substType =
2611-
SGF.F.mapTypeIntoContext(std::get<0>(indexes[i]))->getCanonicalType();
2610+
SGF.F.mapTypeIntoContext(indexes[i].first)->getCanonicalType();
26122611
indexValues.add(loc, RValue(SGF, loc, substType, value));
26132612
}
26142613

@@ -2630,7 +2629,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
26302629
SubstitutionMap subs,
26312630
GenericEnvironment *genericEnv,
26322631
ResilienceExpansion expansion,
2633-
ArrayRef<IndexTypeTuple> indexes,
2632+
ArrayRef<IndexTypePair> indexes,
26342633
CanType baseType,
26352634
CanType propertyType) {
26362635
// If the storage declaration is from a protocol, chase the override chain
@@ -2768,7 +2767,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
27682767
SubstitutionMap subs,
27692768
GenericEnvironment *genericEnv,
27702769
ResilienceExpansion expansion,
2771-
ArrayRef<IndexTypeTuple> indexes,
2770+
ArrayRef<IndexTypePair> indexes,
27722771
CanType baseType,
27732772
CanType propertyType) {
27742773
// If the storage declaration is from a protocol, chase the override chain
@@ -3311,7 +3310,7 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
33113310
static void
33123311
lowerKeyPathSubscriptIndexTypes(
33133312
SILGenModule &SGM,
3314-
SmallVectorImpl<IndexTypeTuple> &indexPatterns,
3313+
SmallVectorImpl<IndexTypePair> &indexPatterns,
33153314
SubscriptDecl *subscript,
33163315
SubstitutionMap subscriptSubs,
33173316
ResilienceExpansion expansion,
@@ -3338,67 +3337,28 @@ lowerKeyPathSubscriptIndexTypes(
33383337
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext();
33393338
indexPatterns.push_back({indexTy->mapTypeOutOfContext()
33403339
->getCanonicalType(),
3341-
indexLoweredTy, index->isVariadic()});
3340+
indexLoweredTy});
33423341
}
33433342
};
33443343

3345-
static void lowerKeyPathSubscriptEqualsIndexPatterns(
3346-
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3347-
ArrayRef<IndexTypeTuple> indexTypes,
3348-
ArrayRef<ProtocolConformanceRef> indexHashables, unsigned baseOperand,
3349-
SILGenModule &SGM, ResilienceExpansion expansion) {
3344+
static void
3345+
lowerKeyPathSubscriptIndexPatterns(
3346+
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3347+
ArrayRef<IndexTypePair> indexTypes,
3348+
ArrayRef<ProtocolConformanceRef> indexHashables,
3349+
unsigned &baseOperand) {
33503350
for (unsigned i : indices(indexTypes)) {
33513351
CanType formalTy;
33523352
SILType loweredTy;
3353-
bool isVariadic;
3354-
std::tie(formalTy, loweredTy, isVariadic) = indexTypes[i];
3353+
std::tie(formalTy, loweredTy) = indexTypes[i];
33553354
auto hashable = indexHashables[i].mapConformanceOutOfContext();
3356-
// We have an array of variadic parameters...
3357-
if (isVariadic) {
3358-
// Use the element type instead of the array type for hash/equals.
3359-
auto arrayTy = cast<BoundGenericStructType>(formalTy.getPointer());
3360-
auto elementTy = arrayTy->getGenericArgs()[0];
3361-
3362-
// Make sure that we aren't leaving out any hashables.
3363-
assert(indexTypes.size() == indexHashables.size());
3364-
3365-
// Make sure the element type matches the hashable.
3366-
assert(hashable.getConcrete()->getType()->isEqual(elementTy));
3367-
auto newLoweredTy = SGM.Types.getLoweredType(
3368-
AbstractionPattern::getOpaque(), elementTy,
3369-
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(expansion));
3370-
newLoweredTy = newLoweredTy.mapTypeOutOfContext();
3371-
auto newFormalTy = elementTy->mapTypeOutOfContext()->getCanonicalType();
3372-
3373-
indexPatterns.push_back(
3374-
{baseOperand++, newFormalTy, newLoweredTy, hashable});
3375-
3376-
// We're done because variadics must come last.
3377-
break;
3378-
}
3379-
33803355
assert(hashable.isAbstract() ||
33813356
hashable.getConcrete()->getType()->isEqual(formalTy));
33823357

33833358
indexPatterns.push_back({baseOperand++, formalTy, loweredTy, hashable});
33843359
}
33853360
};
33863361

3387-
static void lowerKeyPathSubscriptIndexPatterns(
3388-
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
3389-
ArrayRef<IndexTypeTuple> indexTypes,
3390-
ArrayRef<ProtocolConformanceRef> indexHashables, unsigned &baseOperand) {
3391-
for (unsigned i : indices(indexTypes)) {
3392-
CanType formalTy;
3393-
SILType loweredTy;
3394-
bool isVariadic;
3395-
std::tie(formalTy, loweredTy, isVariadic) = indexTypes[i];
3396-
auto hashable = indexHashables[i].mapConformanceOutOfContext();
3397-
3398-
indexPatterns.push_back({baseOperand++, formalTy, loweredTy, hashable});
3399-
}
3400-
};
3401-
34023362
KeyPathPatternComponent
34033363
SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
34043364
GenericEnvironment *genericEnv,
@@ -3534,29 +3494,25 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
35343494
baseSubscriptTy->mapTypeOutOfContext()->getCanonicalType());
35353495
auto componentTy = baseSubscriptInterfaceTy.getResult();
35363496

3537-
SmallVector<IndexTypeTuple, 4> indexTypes;
3497+
SmallVector<IndexTypePair, 4> indexTypes;
35383498
lowerKeyPathSubscriptIndexTypes(*this, indexTypes,
35393499
decl, subs,
35403500
expansion,
35413501
needsGenericContext);
3542-
3543-
SmallVector<KeyPathPatternComponent::Index, 4> equalsIndexPatterns;
3502+
35443503
SmallVector<KeyPathPatternComponent::Index, 4> indexPatterns;
35453504
SILFunction *indexEquals = nullptr, *indexHash = nullptr;
35463505
// Property descriptors get their index information from the client.
35473506
if (!forPropertyDescriptor) {
3548-
// Gather the index patters that we will use for the component.
3549-
lowerKeyPathSubscriptEqualsIndexPatterns(equalsIndexPatterns, indexTypes,
3550-
indexHashables, baseOperand,
3551-
*this, expansion);
3552-
// Gather the index patterns that we will use for equals and hash.
35533507
lowerKeyPathSubscriptIndexPatterns(indexPatterns,
35543508
indexTypes, indexHashables,
35553509
baseOperand);
3556-
3557-
getOrCreateKeyPathEqualsAndHash(
3558-
*this, loc, needsGenericContext ? genericEnv : nullptr, expansion,
3559-
equalsIndexPatterns, indexEquals, indexHash);
3510+
3511+
getOrCreateKeyPathEqualsAndHash(*this, loc,
3512+
needsGenericContext ? genericEnv : nullptr,
3513+
expansion,
3514+
indexPatterns,
3515+
indexEquals, indexHash);
35603516
}
35613517

35623518
auto id = getIdForKeyPathComponentComputedProperty(*this, decl, strategy);

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4591,7 +4591,7 @@ namespace {
45914591
for (auto &param : fnType->getParams()) {
45924592
newLabels.push_back(param.getLabel());
45934593

4594-
auto indexType = simplifyType(param.getPlainType());
4594+
auto indexType = simplifyType(param.getParameterType());
45954595
// Index type conformance to Hashable protocol has been
45964596
// verified by the solver, we just need to get it again
45974597
// with all of the generic parameters resolved.

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
22502250
// Hashable, because it would be used as a component inside key path.
22512251
for (auto index : indices(subscriptTy->getParams())) {
22522252
const auto &param = subscriptTy->getParams()[index];
2253-
verifyThatArgumentIsHashable(index, param.getPlainType(), locator);
2253+
verifyThatArgumentIsHashable(index, param.getParameterType(), locator);
22542254
}
22552255
}
22562256
}

0 commit comments

Comments
 (0)