From c19f3cefeca46fca0443ff90a4f73c8d45b1b8fe Mon Sep 17 00:00:00 2001 From: zoecarver Date: Tue, 26 Nov 2019 00:07:31 -0800 Subject: [PATCH] Remove silgen changes and use getParameterType in CSApply --- lib/SILGen/SILGenExpr.cpp | 92 +++++++++-------------------------- lib/Sema/CSApply.cpp | 2 +- lib/Sema/ConstraintSystem.cpp | 2 +- 3 files changed, 26 insertions(+), 70 deletions(-) diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index ce5db8dce26..5323894fcb2 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -2560,8 +2560,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF, return paramSubstValue; } -/// formal, lowered, isVariadic -using IndexTypeTuple = std::tuple; +using IndexTypePair = std::pair; /// Helper function to load the captured indexes out of a key path component /// in order to invoke the accessors on that key path. A component with captured @@ -2571,7 +2570,7 @@ using IndexTypeTuple = std::tuple; static PreparedArguments loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc, AbstractStorageDecl *storage, - ArrayRef indexes, + ArrayRef indexes, SILValue pointer) { // If not a subscript, do nothing. if (!isa(storage)) @@ -2580,7 +2579,7 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc, SmallVector indexParams; for (auto &elt : indexes) { // FIXME: Varargs? - indexParams.emplace_back(SGF.F.mapTypeIntoContext(std::get<0>(elt))); + indexParams.emplace_back(SGF.F.mapTypeIntoContext(elt.first)); } PreparedArguments indexValues(indexParams); @@ -2603,12 +2602,12 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc, if (indexes.size() > 1) { eltAddr = SGF.B.createTupleElementAddr(loc, eltAddr, i); } - auto ty = SGF.F.mapTypeIntoContext(std::get<1>(indexes[i])); + auto ty = SGF.F.mapTypeIntoContext(indexes[i].second); auto value = SGF.emitLoad(loc, eltAddr, SGF.getTypeLowering(ty), SGFContext(), IsNotTake); auto substType = - SGF.F.mapTypeIntoContext(std::get<0>(indexes[i]))->getCanonicalType(); + SGF.F.mapTypeIntoContext(indexes[i].first)->getCanonicalType(); indexValues.add(loc, RValue(SGF, loc, substType, value)); } @@ -2630,7 +2629,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM, SubstitutionMap subs, GenericEnvironment *genericEnv, ResilienceExpansion expansion, - ArrayRef indexes, + ArrayRef indexes, CanType baseType, CanType propertyType) { // If the storage declaration is from a protocol, chase the override chain @@ -2768,7 +2767,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM, SubstitutionMap subs, GenericEnvironment *genericEnv, ResilienceExpansion expansion, - ArrayRef indexes, + ArrayRef indexes, CanType baseType, CanType propertyType) { // If the storage declaration is from a protocol, chase the override chain @@ -3311,7 +3310,7 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM, static void lowerKeyPathSubscriptIndexTypes( SILGenModule &SGM, - SmallVectorImpl &indexPatterns, + SmallVectorImpl &indexPatterns, SubscriptDecl *subscript, SubstitutionMap subscriptSubs, ResilienceExpansion expansion, @@ -3338,45 +3337,21 @@ lowerKeyPathSubscriptIndexTypes( indexLoweredTy = indexLoweredTy.mapTypeOutOfContext(); indexPatterns.push_back({indexTy->mapTypeOutOfContext() ->getCanonicalType(), - indexLoweredTy, index->isVariadic()}); + indexLoweredTy}); } }; -static void lowerKeyPathSubscriptEqualsIndexPatterns( - SmallVectorImpl &indexPatterns, - ArrayRef indexTypes, - ArrayRef indexHashables, unsigned baseOperand, - SILGenModule &SGM, ResilienceExpansion expansion) { +static void +lowerKeyPathSubscriptIndexPatterns( + SmallVectorImpl &indexPatterns, + ArrayRef indexTypes, + ArrayRef indexHashables, + unsigned &baseOperand) { for (unsigned i : indices(indexTypes)) { CanType formalTy; SILType loweredTy; - bool isVariadic; - std::tie(formalTy, loweredTy, isVariadic) = indexTypes[i]; + std::tie(formalTy, loweredTy) = indexTypes[i]; auto hashable = indexHashables[i].mapConformanceOutOfContext(); - // We have an array of variadic parameters... - if (isVariadic) { - // Use the element type instead of the array type for hash/equals. - auto arrayTy = cast(formalTy.getPointer()); - auto elementTy = arrayTy->getGenericArgs()[0]; - - // Make sure that we aren't leaving out any hashables. - assert(indexTypes.size() == indexHashables.size()); - - // Make sure the element type matches the hashable. - assert(hashable.getConcrete()->getType()->isEqual(elementTy)); - auto newLoweredTy = SGM.Types.getLoweredType( - AbstractionPattern::getOpaque(), elementTy, - TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(expansion)); - newLoweredTy = newLoweredTy.mapTypeOutOfContext(); - auto newFormalTy = elementTy->mapTypeOutOfContext()->getCanonicalType(); - - indexPatterns.push_back( - {baseOperand++, newFormalTy, newLoweredTy, hashable}); - - // We're done because variadics must come last. - break; - } - assert(hashable.isAbstract() || hashable.getConcrete()->getType()->isEqual(formalTy)); @@ -3384,21 +3359,6 @@ static void lowerKeyPathSubscriptEqualsIndexPatterns( } }; -static void lowerKeyPathSubscriptIndexPatterns( - SmallVectorImpl &indexPatterns, - ArrayRef indexTypes, - ArrayRef indexHashables, unsigned &baseOperand) { - for (unsigned i : indices(indexTypes)) { - CanType formalTy; - SILType loweredTy; - bool isVariadic; - std::tie(formalTy, loweredTy, isVariadic) = indexTypes[i]; - auto hashable = indexHashables[i].mapConformanceOutOfContext(); - - indexPatterns.push_back({baseOperand++, formalTy, loweredTy, hashable}); - } -}; - KeyPathPatternComponent SILGenModule::emitKeyPathComponentForDecl(SILLocation loc, GenericEnvironment *genericEnv, @@ -3534,29 +3494,25 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc, baseSubscriptTy->mapTypeOutOfContext()->getCanonicalType()); auto componentTy = baseSubscriptInterfaceTy.getResult(); - SmallVector indexTypes; + SmallVector indexTypes; lowerKeyPathSubscriptIndexTypes(*this, indexTypes, decl, subs, expansion, needsGenericContext); - - SmallVector equalsIndexPatterns; + SmallVector indexPatterns; SILFunction *indexEquals = nullptr, *indexHash = nullptr; // Property descriptors get their index information from the client. if (!forPropertyDescriptor) { - // Gather the index patters that we will use for the component. - lowerKeyPathSubscriptEqualsIndexPatterns(equalsIndexPatterns, indexTypes, - indexHashables, baseOperand, - *this, expansion); - // Gather the index patterns that we will use for equals and hash. lowerKeyPathSubscriptIndexPatterns(indexPatterns, indexTypes, indexHashables, baseOperand); - - getOrCreateKeyPathEqualsAndHash( - *this, loc, needsGenericContext ? genericEnv : nullptr, expansion, - equalsIndexPatterns, indexEquals, indexHash); + + getOrCreateKeyPathEqualsAndHash(*this, loc, + needsGenericContext ? genericEnv : nullptr, + expansion, + indexPatterns, + indexEquals, indexHash); } auto id = getIdForKeyPathComponentComputedProperty(*this, decl, strategy); diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index a2c5c62e120..86673cd92ab 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -4591,7 +4591,7 @@ namespace { for (auto ¶m : fnType->getParams()) { newLabels.push_back(param.getLabel()); - auto indexType = simplifyType(param.getPlainType()); + auto indexType = simplifyType(param.getParameterType()); // Index type conformance to Hashable protocol has been // verified by the solver, we just need to get it again // with all of the generic parameters resolved. diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 4cfa49a352a..5a121dba2e6 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -2250,7 +2250,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator, // Hashable, because it would be used as a component inside key path. for (auto index : indices(subscriptTy->getParams())) { const auto ¶m = subscriptTy->getParams()[index]; - verifyThatArgumentIsHashable(index, param.getPlainType(), locator); + verifyThatArgumentIsHashable(index, param.getParameterType(), locator); } } }