Skip to content

Commit 14b1499

Browse files
authored
Merge pull request #16563 from DougGregor/kill-more-substitution-lists
Eliminate most uses of SubstitutionList
2 parents 1e2ac7f + 467456e commit 14b1499

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+265
-409
lines changed

include/swift/AST/GenericEnvironment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
171171
Type getSugaredType(Type type) const;
172172

173173
SubstitutionMap getForwardingSubstitutionMap() const;
174-
SubstitutionList getForwardingSubstitutions() const;
175174

176175
void dump(raw_ostream &os) const;
177176

include/swift/AST/Types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,10 +3055,6 @@ class GenericFunctionType final : public AnyFunctionType,
30553055
/// Retrieve the requirements of this polymorphic function type.
30563056
ArrayRef<Requirement> getRequirements() const;
30573057

3058-
/// Substitute the given generic arguments into this generic
3059-
/// function type and return the resulting non-generic type.
3060-
FunctionType *substGenericArgs(SubstitutionList subs);
3061-
30623058
/// Substitute the given generic arguments into this generic
30633059
/// function type and return the resulting non-generic type.
30643060
FunctionType *substGenericArgs(const SubstitutionMap &subs);
@@ -4036,8 +4032,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40364032
ABICompatibilityCheckResult
40374033
isABICompatibleWith(CanSILFunctionType other) const;
40384034

4039-
CanSILFunctionType substGenericArgs(SILModule &silModule,
4040-
SubstitutionList subs);
40414035
CanSILFunctionType substGenericArgs(SILModule &silModule,
40424036
const SubstitutionMap &subs);
40434037
CanSILFunctionType substGenericArgs(SILModule &silModule,

include/swift/SIL/SILFunction.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ class SILFunction
121121
/// Only set if this function is a specialization of another function.
122122
const GenericSpecializationInformation *SpecializationInfo;
123123

124-
/// The forwarding substitutions, lazily computed.
125-
Optional<SubstitutionList> ForwardingSubs;
126-
127124
/// The forwarding substitution map, lazily computed.
128125
SubstitutionMap ForwardingSubMap;
129126

@@ -684,10 +681,6 @@ class SILFunction
684681
/// Converts the given function definition to a declaration.
685682
void convertToDeclaration();
686683

687-
/// Return the identity substitutions necessary to forward this call if it is
688-
/// generic.
689-
SubstitutionList getForwardingSubstitutions();
690-
691684
/// Return the identity substitutions necessary to forward this call if it is
692685
/// generic.
693686
SubstitutionMap getForwardingSubstitutionMap();

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,6 @@ class ApplyInstBase<Impl, Base, false> : public Base {
17921792
return Substitutions.hasAnySubstitutableParams();
17931793
}
17941794

1795-
/// The substitutions used to bind the generic arguments of this function.
1796-
SubstitutionList getSubstitutions() const { return Substitutions.toList(); }
1797-
17981795
/// The substitutions used to bind the generic arguments of this function.
17991796
SubstitutionMap getSubstitutionMap() const { return Substitutions; }
18001797

@@ -1892,7 +1889,6 @@ class ApplyInstBase<Impl, Base, true>
18921889
using super::getSubstCalleeType;
18931890
using super::getSubstCalleeConv;
18941891
using super::hasSubstitutions;
1895-
using super::getSubstitutions;
18961892
using super::getNumArguments;
18971893
using super::getArgument;
18981894
using super::getArguments;
@@ -7700,26 +7696,11 @@ class ApplySite {
77007696
FOREACH_IMPL_RETURN(hasSubstitutions());
77017697
}
77027698

7703-
/// The substitutions used to bind the generic arguments of this function.
7704-
SubstitutionList getSubstitutions() const {
7705-
FOREACH_IMPL_RETURN(getSubstitutions());
7706-
}
7707-
77087699
/// The substitutions used to bind the generic arguments of this function.
77097700
SubstitutionMap getSubstitutionMap() const {
77107701
FOREACH_IMPL_RETURN(getSubstitutionMap());
77117702
}
77127703

7713-
/// Return a begin iterator for the substitution array.
7714-
auto subs_begin() const -> decltype(getSubstitutions().begin()) {
7715-
return getSubstitutions().begin();
7716-
}
7717-
7718-
/// Return an end iterator for the substitution array.
7719-
auto subs_end() const -> decltype(getSubstitutions().end()) {
7720-
return getSubstitutions().end();
7721-
}
7722-
77237704
/// The arguments passed to this instruction.
77247705
MutableArrayRef<Operand> getArgumentOperands() const {
77257706
FOREACH_IMPL_RETURN(getArgumentOperands());

include/swift/SIL/SILType.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,6 @@ class SILType {
434434
return SILType(getASTType().getReferenceStorageReferent(), getCategory());
435435
}
436436

437-
/// Transform the function type SILType by replacing all of its interface
438-
/// generic args with the appropriate item from the substitution.
439-
///
440-
/// Only call this with function types!
441-
SILType substGenericArgs(SILModule &M,
442-
SubstitutionList Subs) const;
443-
444437
/// Transform the function type SILType by replacing all of its interface
445438
/// generic args with the appropriate item from the substitution.
446439
///

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ ProjectBoxInst *getOrCreateProjectBox(AllocBoxInst *ABI, unsigned Index);
124124
/// if possible.
125125
void replaceDeadApply(ApplySite Old, ValueBase *New);
126126

127-
/// \brief Return true if the substitution list contains replacement types
128-
/// that are dependent on the type parameters of the caller.
129-
bool hasArchetypes(SubstitutionList Subs);
130-
131127
/// \brief Return true if any call inside the given function may bind dynamic
132128
/// 'Self' to a generic argument of the callee.
133129
bool mayBindDynamicSelf(SILFunction *F);

lib/AST/GenericEnvironment.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,6 @@ SubstitutionMap GenericEnvironment::getForwardingSubstitutionMap() const {
225225
MakeAbstractConformanceForGenericType());
226226
}
227227

228-
SubstitutionList
229-
GenericEnvironment::getForwardingSubstitutions() const {
230-
auto *genericSig = getGenericSignature();
231-
232-
SmallVector<Substitution, 4> result;
233-
genericSig->getSubstitutions(getForwardingSubstitutionMap(), result);
234-
return genericSig->getASTContext().AllocateCopy(result);
235-
}
236-
237228
std::pair<Type, ProtocolConformanceRef>
238229
GenericEnvironment::mapConformanceRefIntoContext(GenericEnvironment *genericEnv,
239230
Type conformingType,

lib/AST/Type.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,11 +2765,6 @@ bool AnyFunctionType::isCanonicalFunctionInputType(Type input) {
27652765
return isa<TypeVariableType>(input.getPointer());
27662766
}
27672767

2768-
FunctionType *
2769-
GenericFunctionType::substGenericArgs(SubstitutionList args) {
2770-
return substGenericArgs(getGenericSignature()->getSubstitutionMap(args));
2771-
}
2772-
27732768
FunctionType *
27742769
GenericFunctionType::substGenericArgs(const SubstitutionMap &subs) {
27752770
Type input = getInput().subst(subs);

lib/IRGen/CallEmission.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CallEmission {
7575

7676
const Callee &getCallee() const { return CurCallee; }
7777

78-
SubstitutionList getSubstitutions() const {
78+
SubstitutionMap getSubstitutions() const {
7979
return CurCallee.getSubstitutions();
8080
}
8181

lib/IRGen/Callee.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ namespace irgen {
4141

4242
/// The archetype substitutions under which the function is being
4343
/// called.
44-
std::vector<Substitution> Substitutions;
44+
SubstitutionMap Substitutions;
4545

4646
CalleeInfo(CanSILFunctionType origFnType,
4747
CanSILFunctionType substFnType,
48-
SubstitutionList substitutions)
48+
SubstitutionMap substitutions)
4949
: OrigFnType(origFnType), SubstFnType(substFnType),
50-
Substitutions(substitutions.begin(), substitutions.end()) {
50+
Substitutions(substitutions) {
5151
}
5252
};
5353

@@ -159,8 +159,11 @@ namespace irgen {
159159
return Info.SubstFnType;
160160
}
161161

162-
bool hasSubstitutions() const { return !Info.Substitutions.empty(); }
163-
SubstitutionList getSubstitutions() const { return Info.Substitutions; }
162+
bool hasSubstitutions() const {
163+
return Info.Substitutions.hasAnySubstitutableParams();
164+
}
165+
166+
SubstitutionMap getSubstitutions() const { return Info.Substitutions; }
164167

165168
const FunctionPointer &getFunctionPointer() const { return Fn; }
166169

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ getAccessorForComputedComponent(IRGenModule &IGM,
230230
// Use the bound generic metadata to form a call to the original generic
231231
// accessor.
232232
WitnessMetadata ignoreWitnessMetadata;
233-
auto forwardingSubs = genericEnv->getGenericSignature()->getSubstitutionMap(
234-
genericEnv->getForwardingSubstitutions());
233+
auto forwardingSubs = genericEnv->getForwardingSubstitutionMap();
235234
emitPolymorphicArguments(IGF, accessor->getLoweredFunctionType(),
236235
forwardingSubs,
237236
&ignoreWitnessMetadata,

lib/IRGen/IRGenSIL.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ static llvm::Value *getObjCClassForValue(IRGenFunction &IGF,
20782078

20792079
static llvm::Value *emitWitnessTableForLoweredCallee(IRGenSILFunction &IGF,
20802080
CanSILFunctionType origCalleeType,
2081-
SubstitutionList subs) {
2081+
SubstitutionMap subs) {
20822082
llvm::Value *wtable;
20832083

20842084
if (auto *proto = origCalleeType->getDefaultWitnessMethodProtocol()) {
@@ -2087,11 +2087,9 @@ static llvm::Value *emitWitnessTableForLoweredCallee(IRGenSILFunction &IGF,
20872087
//
20882088
// We recover the witness table from the substitution that was used to
20892089
// produce the substituted callee type.
2090-
auto subMap = origCalleeType->getGenericSignature()
2091-
->getSubstitutionMap(subs);
20922090
auto origSelfType = proto->getSelfInterfaceType()->getCanonicalType();
2093-
auto substSelfType = origSelfType.subst(subMap)->getCanonicalType();
2094-
auto conformance = *subMap.lookupConformance(origSelfType, proto);
2091+
auto substSelfType = origSelfType.subst(subs)->getCanonicalType();
2092+
auto conformance = *subs.lookupConformance(origSelfType, proto);
20952093

20962094
llvm::Value *argMetadata = IGF.emitTypeMetadataRef(substSelfType);
20972095
wtable = emitWitnessTableRef(IGF, substSelfType, &argMetadata,
@@ -2193,7 +2191,7 @@ static CallEmission getCallEmissionForLoweredValue(IRGenSILFunction &IGF,
21932191
CanSILFunctionType substCalleeType,
21942192
const LoweredValue &lv,
21952193
llvm::Value *selfValue,
2196-
const SubstitutionList &substitutions,
2194+
SubstitutionMap substitutions,
21972195
WitnessMetadata *witnessMetadata,
21982196
Explosion &args) {
21992197
Callee callee = lv.getCallee(IGF, selfValue,
@@ -2282,7 +2280,8 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
22822280
WitnessMetadata witnessMetadata;
22832281
CallEmission emission =
22842282
getCallEmissionForLoweredValue(*this, origCalleeType, substCalleeType,
2285-
calleeLV, selfValue, site.getSubstitutions(),
2283+
calleeLV, selfValue,
2284+
site.getSubstitutionMap(),
22862285
&witnessMetadata, llArgs);
22872286

22882287
// Lower the arguments and return value in the callee's generic context.
@@ -2398,7 +2397,7 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
23982397
/// applying to 'v'.
23992398
static std::tuple<FunctionPointer, llvm::Value*, CanSILFunctionType>
24002399
getPartialApplicationFunction(IRGenSILFunction &IGF, SILValue v,
2401-
SubstitutionList subs) {
2400+
SubstitutionMap subs) {
24022401
LoweredValue &lv = IGF.getLoweredValue(v);
24032402
auto fnType = v->getType().castTo<SILFunctionType>();
24042403

@@ -2507,7 +2506,7 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) {
25072506

25082507
// Get the function value.
25092508
auto result = getPartialApplicationFunction(*this, i->getCallee(),
2510-
i->getSubstitutions());
2509+
i->getSubstitutionMap());
25112510
FunctionPointer calleeFn = std::get<0>(result);
25122511
llvm::Value *innerContext = std::get<1>(result);
25132512
CanSILFunctionType origCalleeTy = std::get<2>(result);

lib/SIL/SILFunction.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,18 +482,6 @@ void SILFunction::convertToDeclaration() {
482482
getBlocks().clear();
483483
}
484484

485-
SubstitutionList SILFunction::getForwardingSubstitutions() {
486-
if (ForwardingSubs)
487-
return *ForwardingSubs;
488-
489-
auto *env = getGenericEnvironment();
490-
if (!env)
491-
return {};
492-
493-
ForwardingSubs = env->getForwardingSubstitutions();
494-
return *ForwardingSubs;
495-
}
496-
497485
SubstitutionMap SILFunction::getForwardingSubstitutionMap() {
498486
if (ForwardingSubMap)
499487
return ForwardingSubMap;

lib/SIL/SILFunctionType.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,23 +2451,6 @@ SILType SILType::subst(SILModule &silModule, const SubstitutionMap &subs) const{
24512451
LookUpConformanceInSubstitutionMap(subs));
24522452
}
24532453

2454-
/// Apply a substitution to this polymorphic SILFunctionType so that
2455-
/// it has the form of the normal SILFunctionType for the substituted
2456-
/// type, except using the original conventions.
2457-
CanSILFunctionType
2458-
SILFunctionType::substGenericArgs(SILModule &silModule,
2459-
SubstitutionList subs) {
2460-
if (subs.empty()) {
2461-
assert(
2462-
(!isPolymorphic() || getGenericSignature()->areAllParamsConcrete()) &&
2463-
"no args for non-concrete polymorphic substitution");
2464-
return CanSILFunctionType(this);
2465-
}
2466-
2467-
auto subMap = GenericSig->getSubstitutionMap(subs);
2468-
return substGenericArgs(silModule, subMap);
2469-
}
2470-
24712454
/// Apply a substitution to this polymorphic SILFunctionType so that
24722455
/// it has the form of the normal SILFunctionType for the substituted
24732456
/// type, except using the original conventions.

lib/SIL/SILInstructions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ static void collectTypeDependentOperands(
9898
SILOpenedArchetypesState &OpenedArchetypesState,
9999
SILFunction &F,
100100
CanType Ty,
101-
SubstitutionList subs = SubstitutionList()) {
101+
SubstitutionMap subs = { }) {
102102
SmallVector<CanArchetypeType, 4> openedArchetypes;
103103
bool hasDynamicSelf = false;
104104
collectDependentTypeInfo(Ty, openedArchetypes, hasDynamicSelf);
105-
for (auto sub : subs) {
105+
for (Type replacement : subs.getReplacementTypes()) {
106106
// Substitutions in SIL should really be canonical.
107-
auto ReplTy = sub.getReplacement()->getCanonicalType();
107+
auto ReplTy = replacement->getCanonicalType();
108108
collectDependentTypeInfo(ReplTy, openedArchetypes, hasDynamicSelf);
109109
}
110110
buildTypeDependentOperands(openedArchetypes, hasDynamicSelf,
@@ -427,7 +427,7 @@ ApplyInst::create(SILDebugLocation Loc, SILValue Callee, SubstitutionMap Subs,
427427

428428
SmallVector<SILValue, 32> TypeDependentOperands;
429429
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
430-
SubstCalleeSILTy.getASTType(), Subs.toList());
430+
SubstCalleeSILTy.getASTType(), Subs);
431431
void *Buffer =
432432
allocateTrailingInst<ApplyInst, Operand>(
433433
F, getNumAllOperands(Args, TypeDependentOperands));
@@ -487,7 +487,7 @@ BeginApplyInst::create(SILDebugLocation loc, SILValue callee,
487487

488488
SmallVector<SILValue, 32> typeDependentOperands;
489489
collectTypeDependentOperands(typeDependentOperands, openedArchetypes, F,
490-
substCalleeType, subs.toList());
490+
substCalleeType, subs);
491491
void *buffer =
492492
allocateTrailingInst<BeginApplyInst, Operand,
493493
MultipleValueInstruction*, BeginApplyResult>(
@@ -531,7 +531,7 @@ PartialApplyInst *PartialApplyInst::create(
531531

532532
SmallVector<SILValue, 32> TypeDependentOperands;
533533
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
534-
SubstCalleeTy.getASTType(), Subs.toList());
534+
SubstCalleeTy.getASTType(), Subs);
535535
void *Buffer =
536536
allocateTrailingInst<PartialApplyInst, Operand>(
537537
F, getNumAllOperands(Args, TypeDependentOperands));
@@ -568,7 +568,7 @@ TryApplyInst *TryApplyInst::create(
568568
SmallVector<SILValue, 32> typeDependentOperands;
569569
collectTypeDependentOperands(typeDependentOperands, openedArchetypes, F,
570570
substCalleeTy.getASTType(),
571-
subs.toList());
571+
subs);
572572
void *buffer =
573573
allocateTrailingInst<TryApplyInst, Operand>(
574574
F, getNumAllOperands(args, typeDependentOperands));

lib/SIL/SILPrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,14 @@ void SILDeclRef::dump() const {
372372
static void printGenericSpecializationInfo(
373373
raw_ostream &OS, StringRef Kind, StringRef Name,
374374
const GenericSpecializationInformation *SpecializationInfo,
375-
SubstitutionList Subs = SubstitutionList()) {
375+
SubstitutionMap Subs = { }) {
376376
if (!SpecializationInfo)
377377
return;
378378

379-
auto PrintSubstitutions = [&](SubstitutionList Subs) {
379+
auto PrintSubstitutions = [&](SubstitutionMap Subs) {
380380
OS << '<';
381-
interleave(Subs,
382-
[&](const Substitution &s) { OS << s.getReplacement(); },
381+
interleave(Subs.getReplacementTypes(),
382+
[&](Type type) { OS << type; },
383383
[&] { OS << ", "; });
384384
OS << '>';
385385
};
@@ -396,7 +396,7 @@ static void printGenericSpecializationInfo(
396396
OS << "// Caller: " << SpecializationInfo->getCaller()->getName() << '\n';
397397
OS << "// Parent: " << SpecializationInfo->getParent()->getName() << '\n';
398398
OS << "// Substitutions: ";
399-
PrintSubstitutions(SpecializationInfo->getSubstitutions().toList());
399+
PrintSubstitutions(SpecializationInfo->getSubstitutions());
400400
OS << '\n';
401401
OS << "//\n";
402402
if (!SpecializationInfo->getCaller()->isSpecialization())
@@ -638,7 +638,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
638638
if (AI.getSpecializationInfo() && AI.getCalleeFunction())
639639
printGenericSpecializationInfo(
640640
PrintState.OS, "call-site", AI.getCalleeFunction()->getName(),
641-
AI.getSpecializationInfo(), AI.getSubstitutions());
641+
AI.getSpecializationInfo(), AI.getSubstitutionMap());
642642
}
643643
print(&I);
644644
}

0 commit comments

Comments
 (0)