mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SILGen] Remove SubstitutionList from most of key-path SIL generation.
This commit is contained in:
@@ -1264,9 +1264,9 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubstitutionList subs = {};
|
SubstitutionMap subs = {};
|
||||||
if (genericEnv)
|
if (genericEnv)
|
||||||
subs = genericEnv->getForwardingSubstitutions();
|
subs = genericEnv->getForwardingSubstitutionMap();
|
||||||
|
|
||||||
if (auto sub = dyn_cast<SubscriptDecl>(decl)) {
|
if (auto sub = dyn_cast<SubscriptDecl>(decl)) {
|
||||||
for (auto *index : *sub->getIndices()) {
|
for (auto *index : *sub->getIndices()) {
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ public:
|
|||||||
GenericEnvironment *genericEnv,
|
GenericEnvironment *genericEnv,
|
||||||
unsigned &baseOperand,
|
unsigned &baseOperand,
|
||||||
bool &needsGenericContext,
|
bool &needsGenericContext,
|
||||||
SubstitutionList subs,
|
SubstitutionMap subs,
|
||||||
AbstractStorageDecl *storage,
|
AbstractStorageDecl *storage,
|
||||||
ArrayRef<ProtocolConformanceRef> indexHashables,
|
ArrayRef<ProtocolConformanceRef> indexHashables,
|
||||||
CanType baseTy,
|
CanType baseTy,
|
||||||
|
|||||||
@@ -2999,8 +2999,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
|
|||||||
SILLocation loc,
|
SILLocation loc,
|
||||||
SILValue paramArg,
|
SILValue paramArg,
|
||||||
CanType &baseType,
|
CanType &baseType,
|
||||||
SubstitutionList &subs,
|
SubstitutionMap subs) {
|
||||||
SmallVectorImpl<Substitution> &subsBuf) {
|
|
||||||
// If the storage is at global scope, then the base value () is a formality.
|
// If the storage is at global scope, then the base value () is a formality.
|
||||||
// There no real argument to pass to the underlying accessors.
|
// There no real argument to pass to the underlying accessors.
|
||||||
if (!storage->getDeclContext()->isTypeContext())
|
if (!storage->getDeclContext()->isTypeContext())
|
||||||
@@ -3026,7 +3025,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
|
|||||||
if (storage->getDeclContext()->getAsClassOrClassExtensionContext()) {
|
if (storage->getDeclContext()->getAsClassOrClassExtensionContext()) {
|
||||||
opened = ArchetypeType::getOpened(baseType);
|
opened = ArchetypeType::getOpened(baseType);
|
||||||
} else {
|
} else {
|
||||||
opened = subs[0].getReplacement()->castTo<ArchetypeType>();
|
opened = subs.getReplacementTypes()[0]->castTo<ArchetypeType>();
|
||||||
}
|
}
|
||||||
assert(opened->isOpenedExistential());
|
assert(opened->isOpenedExistential());
|
||||||
|
|
||||||
@@ -3104,7 +3103,7 @@ static RValue loadIndexValuesForKeyPathComponent(SILGenFunction &SGF,
|
|||||||
static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
||||||
SILLocation loc,
|
SILLocation loc,
|
||||||
AbstractStorageDecl *property,
|
AbstractStorageDecl *property,
|
||||||
SubstitutionList subs,
|
SubstitutionMap subs,
|
||||||
AccessStrategy strategy,
|
AccessStrategy strategy,
|
||||||
GenericEnvironment *genericEnv,
|
GenericEnvironment *genericEnv,
|
||||||
ArrayRef<IndexTypePair> indexes,
|
ArrayRef<IndexTypePair> indexes,
|
||||||
@@ -3152,10 +3151,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
|||||||
|
|
||||||
// Find the function and see if we already created it.
|
// Find the function and see if we already created it.
|
||||||
SmallVector<CanType, 2> interfaceSubs;
|
SmallVector<CanType, 2> interfaceSubs;
|
||||||
for (auto &sub : subs) {
|
for (auto replacement : subs.getReplacementTypes()) {
|
||||||
interfaceSubs.push_back(
|
interfaceSubs.push_back(
|
||||||
sub.getReplacement()->mapTypeOutOfContext()
|
replacement->mapTypeOutOfContext()->getCanonicalType());
|
||||||
->getCanonicalType());
|
|
||||||
}
|
}
|
||||||
auto name = Mangle::ASTMangler()
|
auto name = Mangle::ASTMangler()
|
||||||
.mangleKeyPathGetterThunkHelper(property, genericSig, baseType,
|
.mangleKeyPathGetterThunkHelper(property, genericSig, baseType,
|
||||||
@@ -3193,11 +3191,9 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
|||||||
|
|
||||||
Scope scope(subSGF, loc);
|
Scope scope(subSGF, loc);
|
||||||
|
|
||||||
SmallVector<Substitution, 2> subsBuf;
|
|
||||||
|
|
||||||
auto baseSubstValue = emitKeyPathRValueBase(subSGF, property,
|
auto baseSubstValue = emitKeyPathRValueBase(subSGF, property,
|
||||||
loc, baseArg,
|
loc, baseArg,
|
||||||
baseType, subs, subsBuf);
|
baseType, subs);
|
||||||
|
|
||||||
RValue indexValue = loadIndexValuesForKeyPathComponent(subSGF, loc,
|
RValue indexValue = loadIndexValuesForKeyPathComponent(subSGF, loc,
|
||||||
indexes,
|
indexes,
|
||||||
@@ -3206,7 +3202,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
|||||||
auto resultSubst = subSGF.emitRValueForStorageLoad(loc, baseSubstValue,
|
auto resultSubst = subSGF.emitRValueForStorageLoad(loc, baseSubstValue,
|
||||||
baseType, /*super*/false,
|
baseType, /*super*/false,
|
||||||
property, std::move(indexValue),
|
property, std::move(indexValue),
|
||||||
subs, AccessSemantics::Ordinary,
|
subs.toList(), AccessSemantics::Ordinary,
|
||||||
propertyType, SGFContext())
|
propertyType, SGFContext())
|
||||||
.getAsSingleValue(subSGF, loc);
|
.getAsSingleValue(subSGF, loc);
|
||||||
if (resultSubst.getType().getAddressType() != resultArg->getType())
|
if (resultSubst.getType().getAddressType() != resultArg->getType())
|
||||||
@@ -3225,7 +3221,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
|
|||||||
SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
||||||
SILLocation loc,
|
SILLocation loc,
|
||||||
AbstractStorageDecl *property,
|
AbstractStorageDecl *property,
|
||||||
SubstitutionList subs,
|
SubstitutionMap subs,
|
||||||
AccessStrategy strategy,
|
AccessStrategy strategy,
|
||||||
GenericEnvironment *genericEnv,
|
GenericEnvironment *genericEnv,
|
||||||
ArrayRef<IndexTypePair> indexes,
|
ArrayRef<IndexTypePair> indexes,
|
||||||
@@ -3280,10 +3276,9 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
|||||||
SmallString<64> nameBuf;
|
SmallString<64> nameBuf;
|
||||||
|
|
||||||
SmallVector<CanType, 2> interfaceSubs;
|
SmallVector<CanType, 2> interfaceSubs;
|
||||||
for (auto &sub : subs) {
|
for (Type replacement : subs.getReplacementTypes()) {
|
||||||
interfaceSubs.push_back(
|
interfaceSubs.push_back(
|
||||||
sub.getReplacement()->mapTypeOutOfContext()
|
replacement->mapTypeOutOfContext()->getCanonicalType());
|
||||||
->getCanonicalType());
|
|
||||||
}
|
}
|
||||||
auto name = Mangle::ASTMangler().mangleKeyPathSetterThunkHelper(property,
|
auto name = Mangle::ASTMangler().mangleKeyPathSetterThunkHelper(property,
|
||||||
genericSig,
|
genericSig,
|
||||||
@@ -3338,12 +3333,11 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
|||||||
propertyType);
|
propertyType);
|
||||||
|
|
||||||
LValue lv;
|
LValue lv;
|
||||||
SmallVector<Substitution, 2> subsBuf;
|
|
||||||
|
|
||||||
if (!property->isSetterMutating()) {
|
if (!property->isSetterMutating()) {
|
||||||
auto baseSubst = emitKeyPathRValueBase(subSGF, property,
|
auto baseSubst = emitKeyPathRValueBase(subSGF, property,
|
||||||
loc, baseArg,
|
loc, baseArg,
|
||||||
baseType, subs, subsBuf);
|
baseType, subs);
|
||||||
|
|
||||||
lv = LValue::forValue(baseSubst, baseType);
|
lv = LValue::forValue(baseSubst, baseType);
|
||||||
} else {
|
} else {
|
||||||
@@ -3354,7 +3348,7 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
|||||||
|
|
||||||
// Open an existential lvalue, if necessary.
|
// Open an existential lvalue, if necessary.
|
||||||
if (baseType->isAnyExistentialType()) {
|
if (baseType->isAnyExistentialType()) {
|
||||||
auto opened = subs[0].getReplacement()->castTo<ArchetypeType>();
|
auto opened = subs.getReplacementTypes()[0]->castTo<ArchetypeType>();
|
||||||
assert(opened->isOpenedExistential());
|
assert(opened->isOpenedExistential());
|
||||||
baseType = opened->getCanonicalType();
|
baseType = opened->getCanonicalType();
|
||||||
lv = subSGF.emitOpenExistentialLValue(loc, std::move(lv),
|
lv = subSGF.emitOpenExistentialLValue(loc, std::move(lv),
|
||||||
@@ -3366,12 +3360,12 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
|
|||||||
|
|
||||||
LValueOptions lvOptions;
|
LValueOptions lvOptions;
|
||||||
if (auto var = dyn_cast<VarDecl>(property)) {
|
if (auto var = dyn_cast<VarDecl>(property)) {
|
||||||
lv.addMemberVarComponent(subSGF, loc, var, subs, lvOptions,
|
lv.addMemberVarComponent(subSGF, loc, var, subs.toList(), lvOptions,
|
||||||
/*super*/ false, AccessKind::Write,
|
/*super*/ false, AccessKind::Write,
|
||||||
AccessSemantics::Ordinary, strategy, propertyType);
|
AccessSemantics::Ordinary, strategy, propertyType);
|
||||||
} else {
|
} else {
|
||||||
auto sub = cast<SubscriptDecl>(property);
|
auto sub = cast<SubscriptDecl>(property);
|
||||||
lv.addMemberSubscriptComponent(subSGF, loc, sub, subs, lvOptions,
|
lv.addMemberSubscriptComponent(subSGF, loc, sub, subs.toList(), lvOptions,
|
||||||
/*super*/ false, AccessKind::Write,
|
/*super*/ false, AccessKind::Write,
|
||||||
AccessSemantics::Ordinary, strategy, propertyType,
|
AccessSemantics::Ordinary, strategy, propertyType,
|
||||||
std::move(indexValue));
|
std::move(indexValue));
|
||||||
@@ -3741,7 +3735,7 @@ lowerKeyPathSubscriptIndexTypes(
|
|||||||
SILGenModule &SGM,
|
SILGenModule &SGM,
|
||||||
SmallVectorImpl<IndexTypePair> &indexPatterns,
|
SmallVectorImpl<IndexTypePair> &indexPatterns,
|
||||||
SubscriptDecl *subscript,
|
SubscriptDecl *subscript,
|
||||||
SubstitutionList subscriptSubs,
|
SubstitutionMap subscriptSubs,
|
||||||
bool &needsGenericContext) {
|
bool &needsGenericContext) {
|
||||||
// Capturing an index value dependent on the generic context means we
|
// Capturing an index value dependent on the generic context means we
|
||||||
// need the generic context captured in the key path.
|
// need the generic context captured in the key path.
|
||||||
@@ -3749,15 +3743,14 @@ lowerKeyPathSubscriptIndexTypes(
|
|||||||
SubstitutionMap subMap;
|
SubstitutionMap subMap;
|
||||||
auto sig = subscript->getGenericSignature();
|
auto sig = subscript->getGenericSignature();
|
||||||
if (sig) {
|
if (sig) {
|
||||||
subMap = sig->getSubstitutionMap(subscriptSubs);
|
subscriptSubstTy = subscriptSubstTy.subst(subscriptSubs);
|
||||||
subscriptSubstTy = subscriptSubstTy.subst(subMap);
|
|
||||||
}
|
}
|
||||||
needsGenericContext |= subscriptSubstTy->hasArchetype();
|
needsGenericContext |= subscriptSubstTy->hasArchetype();
|
||||||
|
|
||||||
for (auto *index : *subscript->getIndices()) {
|
for (auto *index : *subscript->getIndices()) {
|
||||||
auto indexTy = index->getInterfaceType();
|
auto indexTy = index->getInterfaceType();
|
||||||
if (sig) {
|
if (sig) {
|
||||||
indexTy = indexTy.subst(subMap);
|
indexTy = indexTy.subst(subscriptSubs);
|
||||||
}
|
}
|
||||||
auto indexLoweredTy = SGM.Types.getLoweredType(
|
auto indexLoweredTy = SGM.Types.getLoweredType(
|
||||||
AbstractionPattern::getOpaque(),
|
AbstractionPattern::getOpaque(),
|
||||||
@@ -3796,7 +3789,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
|
|||||||
GenericEnvironment *genericEnv,
|
GenericEnvironment *genericEnv,
|
||||||
unsigned &baseOperand,
|
unsigned &baseOperand,
|
||||||
bool &needsGenericContext,
|
bool &needsGenericContext,
|
||||||
SubstitutionList subs,
|
SubstitutionMap subs,
|
||||||
AbstractStorageDecl *storage,
|
AbstractStorageDecl *storage,
|
||||||
ArrayRef<ProtocolConformanceRef> indexHashables,
|
ArrayRef<ProtocolConformanceRef> indexHashables,
|
||||||
CanType baseTy,
|
CanType baseTy,
|
||||||
@@ -3823,8 +3816,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
|
|||||||
auto componentObjTy = componentTy->getWithoutSpecifierType();
|
auto componentObjTy = componentTy->getWithoutSpecifierType();
|
||||||
if (genericEnv)
|
if (genericEnv)
|
||||||
componentObjTy = genericEnv->mapTypeIntoContext(componentObjTy);
|
componentObjTy = genericEnv->mapTypeIntoContext(componentObjTy);
|
||||||
auto storageTy = Types.getSubstitutedStorageType(var,
|
auto storageTy = Types.getSubstitutedStorageType(var, componentObjTy);
|
||||||
componentObjTy);
|
|
||||||
auto opaqueTy = Types
|
auto opaqueTy = Types
|
||||||
.getLoweredType(AbstractionPattern::getOpaque(), componentObjTy);
|
.getLoweredType(AbstractionPattern::getOpaque(), componentObjTy);
|
||||||
|
|
||||||
@@ -4008,7 +4000,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
|
|||||||
auto sub = cast<SubscriptDecl>(component.getDeclRef().getDecl());
|
auto sub = cast<SubscriptDecl>(component.getDeclRef().getDecl());
|
||||||
lowerKeyPathSubscriptIndexTypes(
|
lowerKeyPathSubscriptIndexTypes(
|
||||||
SGF.SGM, indexTypes, sub,
|
SGF.SGM, indexTypes, sub,
|
||||||
component.getDeclRef().getSubstitutions().toList(),
|
component.getDeclRef().getSubstitutions(),
|
||||||
needsGenericContext);
|
needsGenericContext);
|
||||||
lowerKeyPathSubscriptIndexPatterns(indices, indexTypes,
|
lowerKeyPathSubscriptIndexPatterns(indices, indexTypes,
|
||||||
component.getSubscriptIndexHashableConformances(),
|
component.getSubscriptIndexHashableConformances(),
|
||||||
@@ -4044,7 +4036,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
|
|||||||
SGF.F.getGenericEnvironment(),
|
SGF.F.getGenericEnvironment(),
|
||||||
numOperands,
|
numOperands,
|
||||||
needsGenericContext,
|
needsGenericContext,
|
||||||
component.getDeclRef().getSubstitutions().toList(),
|
component.getDeclRef().getSubstitutions(),
|
||||||
decl,
|
decl,
|
||||||
component.getSubscriptIndexHashableConformances(),
|
component.getSubscriptIndexHashableConformances(),
|
||||||
baseTy,
|
baseTy,
|
||||||
|
|||||||
Reference in New Issue
Block a user