mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AST] Remove GenericSignature params from GenericEnvironment methods.
The GenericEnvironment stores a signature internally.
This commit is contained in:
@@ -83,18 +83,16 @@ public:
|
|||||||
/// with contextual types instead of interface types.
|
/// with contextual types instead of interface types.
|
||||||
SubstitutionMap
|
SubstitutionMap
|
||||||
getSubstitutionMap(ModuleDecl *mod,
|
getSubstitutionMap(ModuleDecl *mod,
|
||||||
GenericSignature *sig,
|
|
||||||
ArrayRef<Substitution> subs) const;
|
ArrayRef<Substitution> subs) const;
|
||||||
|
|
||||||
/// Same as above, but updates an existing map.
|
/// Same as above, but updates an existing map.
|
||||||
void
|
void
|
||||||
getSubstitutionMap(ModuleDecl *mod,
|
getSubstitutionMap(ModuleDecl *mod,
|
||||||
GenericSignature *sig,
|
|
||||||
ArrayRef<Substitution> subs,
|
ArrayRef<Substitution> subs,
|
||||||
SubstitutionMap &subMap) const;
|
SubstitutionMap &subMap) const;
|
||||||
|
|
||||||
ArrayRef<Substitution>
|
ArrayRef<Substitution>
|
||||||
getForwardingSubstitutions(ModuleDecl *M, GenericSignature *sig) const;
|
getForwardingSubstitutions(ModuleDecl *M) const;
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
|
|||||||
|
|
||||||
void computeSubsMap() {
|
void computeSubsMap() {
|
||||||
if (auto *env = Original.getGenericEnvironment()) {
|
if (auto *env = Original.getGenericEnvironment()) {
|
||||||
auto sig = Original.getLoweredFunctionType()->getGenericSignature();
|
SubsMap = env->getSubstitutionMap(SwiftMod, ApplySubs);
|
||||||
SubsMap = env->getSubstitutionMap(SwiftMod, sig, ApplySubs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ GenericTypeParamType *GenericEnvironment::getSugaredType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef<Substitution>
|
ArrayRef<Substitution>
|
||||||
GenericEnvironment::getForwardingSubstitutions(
|
GenericEnvironment::getForwardingSubstitutions(ModuleDecl *M) const {
|
||||||
ModuleDecl *M, GenericSignature *sig) const {
|
|
||||||
auto lookupConformanceFn =
|
auto lookupConformanceFn =
|
||||||
[&](CanType original, Type replacement, ProtocolType *protoType)
|
[&](CanType original, Type replacement, ProtocolType *protoType)
|
||||||
-> ProtocolConformanceRef {
|
-> ProtocolConformanceRef {
|
||||||
@@ -105,16 +104,14 @@ GenericEnvironment::getForwardingSubstitutions(
|
|||||||
|
|
||||||
SubstitutionMap GenericEnvironment::
|
SubstitutionMap GenericEnvironment::
|
||||||
getSubstitutionMap(ModuleDecl *mod,
|
getSubstitutionMap(ModuleDecl *mod,
|
||||||
GenericSignature *sig,
|
|
||||||
ArrayRef<Substitution> subs) const {
|
ArrayRef<Substitution> subs) const {
|
||||||
SubstitutionMap result;
|
SubstitutionMap result;
|
||||||
getSubstitutionMap(mod, getGenericSignature(), subs, result);
|
getSubstitutionMap(mod, subs, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericEnvironment::
|
void GenericEnvironment::
|
||||||
getSubstitutionMap(ModuleDecl *mod,
|
getSubstitutionMap(ModuleDecl *mod,
|
||||||
GenericSignature *sig,
|
|
||||||
ArrayRef<Substitution> subs,
|
ArrayRef<Substitution> subs,
|
||||||
SubstitutionMap &result) const {
|
SubstitutionMap &result) const {
|
||||||
for (auto depTy : getGenericSignature()->getAllDependentTypes()) {
|
for (auto depTy : getGenericSignature()->getAllDependentTypes()) {
|
||||||
|
|||||||
@@ -379,10 +379,9 @@ SpecializedProtocolConformance::getTypeWitnessSubstAndDecl(
|
|||||||
auto conformingModule = conformingDC->getParentModule();
|
auto conformingModule = conformingDC->getParentModule();
|
||||||
|
|
||||||
auto *genericEnv = GenericConformance->getGenericEnvironment();
|
auto *genericEnv = GenericConformance->getGenericEnvironment();
|
||||||
auto *genericSig = GenericConformance->getGenericSignature();
|
|
||||||
|
|
||||||
auto substitutionMap = genericEnv->getSubstitutionMap(
|
auto substitutionMap = genericEnv->getSubstitutionMap(
|
||||||
conformingModule, genericSig, GenericSubstitutions);
|
conformingModule, GenericSubstitutions);
|
||||||
|
|
||||||
auto genericWitnessAndDecl
|
auto genericWitnessAndDecl
|
||||||
= GenericConformance->getTypeWitnessSubstAndDecl(assocType, resolver);
|
= GenericConformance->getTypeWitnessSubstAndDecl(assocType, resolver);
|
||||||
@@ -534,10 +533,9 @@ ProtocolConformance::getInheritedConformance(ProtocolDecl *protocol) const {
|
|||||||
auto *conformingDC = spec->getDeclContext();
|
auto *conformingDC = spec->getDeclContext();
|
||||||
auto *conformingModule = conformingDC->getParentModule();
|
auto *conformingModule = conformingDC->getParentModule();
|
||||||
|
|
||||||
auto *sig = conformingDC->getGenericSignatureOfContext();
|
|
||||||
auto *env = conformingDC->getGenericEnvironmentOfContext();
|
auto *env = conformingDC->getGenericEnvironmentOfContext();
|
||||||
|
|
||||||
auto subMap = env->getSubstitutionMap(conformingModule, sig, subs);
|
auto subMap = env->getSubstitutionMap(conformingModule, subs);
|
||||||
|
|
||||||
auto r = inherited->subst(conformingModule, getType(), subMap);
|
auto r = inherited->subst(conformingModule, getType(), subMap);
|
||||||
assert(getType()->isEqual(r->getType())
|
assert(getType()->isEqual(r->getType())
|
||||||
|
|||||||
@@ -547,9 +547,8 @@ ArrayRef<Substitution> SILFunction::getForwardingSubstitutions() {
|
|||||||
if (!env)
|
if (!env)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto sig = getLoweredFunctionType()->getGenericSignature();
|
|
||||||
auto *M = getModule().getSwiftModule();
|
auto *M = getModule().getSwiftModule();
|
||||||
ForwardingSubs = env->getForwardingSubstitutions(M, sig);
|
ForwardingSubs = env->getForwardingSubstitutions(M);
|
||||||
|
|
||||||
return *ForwardingSubs;
|
return *ForwardingSubs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1964,8 +1964,7 @@ public:
|
|||||||
|
|
||||||
// Map interface types to archetypes.
|
// Map interface types to archetypes.
|
||||||
if (auto *env = constantInfo.GenericEnv) {
|
if (auto *env = constantInfo.GenericEnv) {
|
||||||
auto sig = constantInfo.SILFnType->getGenericSignature();
|
auto subs = env->getForwardingSubstitutions(M);
|
||||||
auto subs = env->getForwardingSubstitutions(M, sig);
|
|
||||||
methodTy = methodTy->substGenericArgs(F.getModule(), M, subs);
|
methodTy = methodTy->substGenericArgs(F.getModule(), M, subs);
|
||||||
}
|
}
|
||||||
assert(!methodTy->isPolymorphic());
|
assert(!methodTy->isPolymorphic());
|
||||||
|
|||||||
@@ -78,11 +78,9 @@ emitBridgeNativeToObjectiveC(SILGenFunction &gen,
|
|||||||
// FIXME: Substitute the type substitutions into the witness, because
|
// FIXME: Substitute the type substitutions into the witness, because
|
||||||
// SpecializedProtocolConformance::getWitness() doesn't do it for us.
|
// SpecializedProtocolConformance::getWitness() doesn't do it for us.
|
||||||
GenericEnvironment *witnessEnv = witness.getSyntheticEnvironment();
|
GenericEnvironment *witnessEnv = witness.getSyntheticEnvironment();
|
||||||
GenericSignature *witnessSig = witness.getSyntheticSignature();
|
|
||||||
|
|
||||||
SubstitutionMap typeSubMap = witnessEnv
|
SubstitutionMap typeSubMap = witnessEnv
|
||||||
->getSubstitutionMap(gen.SGM.SwiftModule,
|
->getSubstitutionMap(gen.SGM.SwiftModule,
|
||||||
witnessSig,
|
|
||||||
typeSubstitutions);
|
typeSubstitutions);
|
||||||
for (auto sub : witnessSubstitutions) {
|
for (auto sub : witnessSubstitutions) {
|
||||||
substitutionsBuf.push_back(sub.subst(gen.SGM.SwiftModule, typeSubMap));
|
substitutionsBuf.push_back(sub.subst(gen.SGM.SwiftModule, typeSubMap));
|
||||||
|
|||||||
@@ -490,9 +490,8 @@ void SILGenFunction::emitClassConstructorAllocator(ConstructorDecl *ctor) {
|
|||||||
// Call the initializer.
|
// Call the initializer.
|
||||||
ArrayRef<Substitution> forwardingSubs;
|
ArrayRef<Substitution> forwardingSubs;
|
||||||
if (auto *genericEnv = ctor->getGenericEnvironmentOfContext()) {
|
if (auto *genericEnv = ctor->getGenericEnvironmentOfContext()) {
|
||||||
auto *genericSig = ctor->getGenericSignatureOfContext();
|
|
||||||
forwardingSubs = genericEnv->getForwardingSubstitutions(
|
forwardingSubs = genericEnv->getForwardingSubstitutions(
|
||||||
SGM.SwiftModule, genericSig);
|
SGM.SwiftModule);
|
||||||
}
|
}
|
||||||
std::tie(initVal, initTy, subs)
|
std::tie(initVal, initTy, subs)
|
||||||
= emitSiblingMethodRef(Loc, selfValue, initConstant, forwardingSubs);
|
= emitSiblingMethodRef(Loc, selfValue, initConstant, forwardingSubs);
|
||||||
@@ -882,9 +881,8 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
|
|||||||
ArrayRef<Substitution> subs;
|
ArrayRef<Substitution> subs;
|
||||||
auto *genericEnv = dc->getGenericEnvironmentOfContext();
|
auto *genericEnv = dc->getGenericEnvironmentOfContext();
|
||||||
if (genericEnv) {
|
if (genericEnv) {
|
||||||
auto *genericSig = dc->getGenericSignatureOfContext();
|
|
||||||
subs = genericEnv->getForwardingSubstitutions(
|
subs = genericEnv->getForwardingSubstitutions(
|
||||||
SGM.SwiftModule, genericSig);
|
SGM.SwiftModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the type of the initialization result, in terms
|
// Get the type of the initialization result, in terms
|
||||||
|
|||||||
@@ -815,8 +815,7 @@ void SILGenFunction::emitCurryThunk(ValueDecl *vd,
|
|||||||
ArrayRef<Substitution> subs;
|
ArrayRef<Substitution> subs;
|
||||||
auto constantInfo = getConstantInfo(to);
|
auto constantInfo = getConstantInfo(to);
|
||||||
if (auto *env = constantInfo.GenericEnv) {
|
if (auto *env = constantInfo.GenericEnv) {
|
||||||
auto sig = constantInfo.SILFnType->getGenericSignature();
|
subs = env->getForwardingSubstitutions(SGM.SwiftModule);
|
||||||
subs = env->getForwardingSubstitutions(SGM.SwiftModule, sig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SILValue toFn = getNextUncurryLevelRef(*this, vd, to, from.isDirectReference,
|
SILValue toFn = getNextUncurryLevelRef(*this, vd, to, from.isDirectReference,
|
||||||
|
|||||||
@@ -1582,9 +1582,8 @@ SILGenModule::getNonMemberVarDeclSubstitutions(VarDecl *var) {
|
|||||||
ArrayRef<Substitution> substitutions;
|
ArrayRef<Substitution> substitutions;
|
||||||
auto *dc = var->getDeclContext();
|
auto *dc = var->getDeclContext();
|
||||||
if (auto *genericEnv = dc->getGenericEnvironmentOfContext()) {
|
if (auto *genericEnv = dc->getGenericEnvironmentOfContext()) {
|
||||||
auto *genericSig = dc->getGenericSignatureOfContext();
|
|
||||||
substitutions = genericEnv->getForwardingSubstitutions(
|
substitutions = genericEnv->getForwardingSubstitutions(
|
||||||
SwiftModule, genericSig);
|
SwiftModule);
|
||||||
}
|
}
|
||||||
return substitutions;
|
return substitutions;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user