Skip to content

Commit 911ed60

Browse files
committed
Eliminate dead code making use of SubstitutionList.
1 parent 049c56d commit 911ed60

File tree

14 files changed

+19
-86
lines changed

14 files changed

+19
-86
lines changed

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/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
///

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/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/SILType.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,6 @@ bool SILType::isAddressOnly(SILModule &M) const {
178178
return M.getTypeLowering(*this).isAddressOnly();
179179
}
180180

181-
SILType SILType::substGenericArgs(SILModule &M,
182-
SubstitutionList Subs) const {
183-
auto fnTy = castTo<SILFunctionType>();
184-
auto canFnTy = CanSILFunctionType(fnTy->substGenericArgs(M, Subs));
185-
return SILType::getPrimitiveObjectType(canFnTy);
186-
}
187-
188181
SILType SILType::substGenericArgs(SILModule &M,
189182
const SubstitutionMap &SubMap) const {
190183
auto fnTy = castTo<SILFunctionType>();

lib/SIL/SILVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
10811081
};
10821082

10831083
// Search for opened archetypes and dynamic self.
1084-
for (auto &Sub : AS.getSubstitutions()) {
1085-
Sub.getReplacement()->getCanonicalType().visit(HandleType);
1084+
for (auto Replacement : AS.getSubstitutionMap().getReplacementTypes()) {
1085+
Replacement->getCanonicalType().visit(HandleType);
10861086
}
10871087
AS.getSubstCalleeType().visit(HandleType);
10881088

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,7 @@ SILCombiner::createApplyWithConcreteType(FullApplySite AI,
805805
// replaced by a concrete type.
806806
SubstitutionMap Substitutions;
807807
if (FnTy->isPolymorphic()) {
808-
auto FnSubsMap =
809-
FnTy->getGenericSignature()->getSubstitutionMap(AI.getSubstitutions());
808+
auto FnSubsMap = AI.getSubstitutionMap();
810809
Substitutions = FnSubsMap.subst(
811810
[&](SubstitutableType *type) -> Type {
812811
if (type == OpenedArchetype)

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ static bool tryToCSEOpenExtCall(OpenExistentialAddrInst *From,
10431043
"Invalid number of arguments");
10441044

10451045
// Don't handle any apply instructions that involve substitutions.
1046-
if (ToAI->getSubstitutions().size() != 1) return false;
1046+
if (ToAI->getSubstitutionMap().getReplacementTypes().size() != 1)
1047+
return false;
10471048

10481049
// Prepare the Apply args.
10491050
SmallVector<SILValue, 8> Args;

lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ static bool usesGenerics(SILFunction *F,
285285
}
286286
// Scan all substitutions of apply instructions.
287287
if (auto AI = ApplySite::isa(&I)) {
288-
auto Subs = AI.getSubstitutions();
289-
for (auto Sub : Subs) {
290-
Sub.getReplacement().visit(FindArchetypesAndGenericTypes);
288+
auto Subs = AI.getSubstitutionMap();
289+
for (auto Replacement : Subs.getReplacementTypes()) {
290+
Replacement.visit(FindArchetypesAndGenericTypes);
291291
}
292292
}
293293
// Scan all substitutions of builtin instructions.

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ bool SILPerformanceInliner::isProfitableToInline(
475475
/// It returns None if the decision cannot be made without a more complex
476476
/// analysis.
477477
static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
478-
assert(!AI.getSubstitutions().empty() &&
478+
assert(AI.hasSubstitutions() &&
479479
"Expected a generic apply");
480480

481481
SILFunction *Callee = AI.getReferencedFunction();
@@ -516,7 +516,7 @@ bool SILPerformanceInliner::decideInWarmBlock(
516516
FullApplySite AI, Weight CallerWeight, ConstantTracker &callerTracker,
517517
int &NumCallerBlocks,
518518
const llvm::DenseMap<SILBasicBlock *, uint64_t> &BBToWeightMap) {
519-
if (!AI.getSubstitutions().empty()) {
519+
if (AI.hasSubstitutions()) {
520520
// Only inline generics if definitively clear that it should be done.
521521
auto ShouldInlineGeneric = shouldInlineGeneric(AI);
522522
if (ShouldInlineGeneric.hasValue())
@@ -540,7 +540,7 @@ bool SILPerformanceInliner::decideInWarmBlock(
540540
/// Return true if inlining this call site into a cold block is profitable.
541541
bool SILPerformanceInliner::decideInColdBlock(FullApplySite AI,
542542
SILFunction *Callee) {
543-
if (!AI.getSubstitutions().empty()) {
543+
if (AI.hasSubstitutions()) {
544544
// Only inline generics if definitively clear that it should be done.
545545
auto ShouldInlineGeneric = shouldInlineGeneric(AI);
546546
if (ShouldInlineGeneric.hasValue())

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,7 @@ getSubstitutionsForCallee(SILModule &M,
441441
M.getSwiftModule(), baseClassDecl);
442442
}
443443

444-
SubstitutionMap origSubMap;
445-
if (auto origCalleeSig = AI.getOrigCalleeType()->getGenericSignature())
446-
origSubMap = origCalleeSig->getSubstitutionMap(AI.getSubstitutions());
444+
SubstitutionMap origSubMap = AI.getSubstitutionMap();
447445

448446
Type calleeSelfType = AI.getOrigCalleeType()->getSelfParameter().getType();
449447
if (auto metatypeType = calleeSelfType->getAs<MetatypeType>())

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
290290
<< "Caller: " << Caller->getName() << "\n"
291291
<< "Callee: " << Callee->getName() << "\n";
292292
llvm::dbgs() << "Substitutions:\n";
293-
for (auto Sub: Apply.getSubstitutions()) {
294-
Sub.getReplacement()->dump();
295-
});
293+
Apply.getSubstitutionMap().dump(llvm::dbgs());
294+
);
296295

297296
auto *CurSpecializationInfo = Apply.getSpecializationInfo();
298297
if (CurSpecializationInfo) {

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ static bool calleeHasPartialApplyWithOpenedExistentials(FullApplySite AI) {
560560
return false;
561561

562562
SILFunction *Callee = AI.getReferencedFunction();
563-
auto Subs = AI.getSubstitutions();
563+
auto SubsMap = AI.getSubstitutionMap();
564564

565565
// Bail if there are no open existentials in the list of substitutions.
566566
bool HasNoOpenedExistentials = true;
567-
for (auto Sub : Subs) {
568-
if (Sub.getReplacement()->hasOpenedExistential()) {
567+
for (auto Replacement : SubsMap.getReplacementTypes()) {
568+
if (Replacement->hasOpenedExistential()) {
569569
HasNoOpenedExistentials = false;
570570
break;
571571
}
@@ -574,9 +574,6 @@ static bool calleeHasPartialApplyWithOpenedExistentials(FullApplySite AI) {
574574
if (HasNoOpenedExistentials)
575575
return false;
576576

577-
auto SubsMap = Callee->getLoweredFunctionType()
578-
->getGenericSignature()->getSubstitutionMap(Subs);
579-
580577
for (auto &BB : *Callee) {
581578
for (auto &I : BB) {
582579
if (auto PAI = dyn_cast<PartialApplyInst>(&I)) {
@@ -630,7 +627,7 @@ static bool isCallerAndCalleeLayoutConstraintsCompatible(FullApplySite AI) {
630627
SILFunction *Callee = AI.getReferencedFunction();
631628
auto CalleeSig = Callee->getLoweredFunctionType()->getGenericSignature();
632629
auto SubstParams = CalleeSig->getSubstitutableParams();
633-
auto AISubs = AI.getSubstitutions();
630+
auto AISubs = AI.getSubstitutionMap();
634631
for (auto idx : indices(SubstParams)) {
635632
auto Param = SubstParams[idx];
636633
// Map the parameter into context
@@ -643,7 +640,7 @@ static bool isCallerAndCalleeLayoutConstraintsCompatible(FullApplySite AI) {
643640
continue;
644641
// The generic parameter has a layout constraint.
645642
// Check that the substitution has the same constraint.
646-
auto AIReplacement = AISubs[idx].getReplacement();
643+
auto AIReplacement = Type(Param).subst(AISubs);
647644
auto AIArchetype = AIReplacement->getAs<ArchetypeType>();
648645
if (!AIArchetype)
649646
return false;

0 commit comments

Comments
 (0)