Skip to content

Eliminate most uses of SubstitutionList #16563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8c770f9
[SILOptimizer] Remove dead swift::hasArchetypes().
DougGregor May 11, 2018
761b7c6
[SIL] SubstitutionList -> SubstitutionMap in devirtualizer.
DougGregor May 11, 2018
42fe2c1
[SIL] Remove SubstitutionList from the rest of the generic specializer.
DougGregor May 11, 2018
921d41c
[SILGen] Eliminate emitApplyOfLibraryIntrinsic() for SubstitutionList.
DougGregor May 11, 2018
17572ce
[SILGen] Eliminate useConformancesFromSubstitutions() on Substitution…
DougGregor May 11, 2018
1af6cb9
[SILGen] Remove SubstitutionList from most of key-path SIL generation.
DougGregor May 11, 2018
7490289
[IRGen] Eliminate SubstitutionList from IRGen.
DougGregor May 11, 2018
3f5beab
[SIL] Eliminate SubstitutionList from collectTypeDependentOperands().
DougGregor May 11, 2018
482f55d
[SILPrinter] Eliminate SubstitutionList.
DougGregor May 11, 2018
0bf0a1e
[SILGen] Eliminate more SubstitutionLists for accessor calls.
DougGregor May 11, 2018
c9b50e0
[SILGen] Eliminate SubstitutionList from the LValue infrastructure.
DougGregor May 11, 2018
5c0733f
[SILGen] Eliminate Substitution from key-path equals/hash generation.
DougGregor May 11, 2018
9a0e57f
[SILGen] Simplify SubstitutionMap handling in emitApplyOfLibraryIntri…
DougGregor May 11, 2018
cb3bf10
[SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply().
DougGregor May 11, 2018
049c56d
Eliminate getForwardingSubstitutions().
DougGregor May 12, 2018
911ed60
Eliminate dead code making use of SubstitutionList.
DougGregor May 12, 2018
467456e
[SILGen] Get keypath emission logic off Substitution.
DougGregor May 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/AST/GenericEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
Type getSugaredType(Type type) const;

SubstitutionMap getForwardingSubstitutionMap() const;
SubstitutionList getForwardingSubstitutions() const;

void dump(raw_ostream &os) const;

Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3055,10 +3055,6 @@ class GenericFunctionType final : public AnyFunctionType,
/// Retrieve the requirements of this polymorphic function type.
ArrayRef<Requirement> getRequirements() const;

/// Substitute the given generic arguments into this generic
/// function type and return the resulting non-generic type.
FunctionType *substGenericArgs(SubstitutionList subs);

/// Substitute the given generic arguments into this generic
/// function type and return the resulting non-generic type.
FunctionType *substGenericArgs(const SubstitutionMap &subs);
Expand Down Expand Up @@ -4036,8 +4032,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
ABICompatibilityCheckResult
isABICompatibleWith(CanSILFunctionType other) const;

CanSILFunctionType substGenericArgs(SILModule &silModule,
SubstitutionList subs);
CanSILFunctionType substGenericArgs(SILModule &silModule,
const SubstitutionMap &subs);
CanSILFunctionType substGenericArgs(SILModule &silModule,
Expand Down
7 changes: 0 additions & 7 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ class SILFunction
/// Only set if this function is a specialization of another function.
const GenericSpecializationInformation *SpecializationInfo;

/// The forwarding substitutions, lazily computed.
Optional<SubstitutionList> ForwardingSubs;

/// The forwarding substitution map, lazily computed.
SubstitutionMap ForwardingSubMap;

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

/// Return the identity substitutions necessary to forward this call if it is
/// generic.
SubstitutionList getForwardingSubstitutions();

/// Return the identity substitutions necessary to forward this call if it is
/// generic.
SubstitutionMap getForwardingSubstitutionMap();
Expand Down
19 changes: 0 additions & 19 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1792,9 +1792,6 @@ class ApplyInstBase<Impl, Base, false> : public Base {
return Substitutions.hasAnySubstitutableParams();
}

/// The substitutions used to bind the generic arguments of this function.
SubstitutionList getSubstitutions() const { return Substitutions.toList(); }

/// The substitutions used to bind the generic arguments of this function.
SubstitutionMap getSubstitutionMap() const { return Substitutions; }

Expand Down Expand Up @@ -1892,7 +1889,6 @@ class ApplyInstBase<Impl, Base, true>
using super::getSubstCalleeType;
using super::getSubstCalleeConv;
using super::hasSubstitutions;
using super::getSubstitutions;
using super::getNumArguments;
using super::getArgument;
using super::getArguments;
Expand Down Expand Up @@ -7700,26 +7696,11 @@ class ApplySite {
FOREACH_IMPL_RETURN(hasSubstitutions());
}

/// The substitutions used to bind the generic arguments of this function.
SubstitutionList getSubstitutions() const {
FOREACH_IMPL_RETURN(getSubstitutions());
}

/// The substitutions used to bind the generic arguments of this function.
SubstitutionMap getSubstitutionMap() const {
FOREACH_IMPL_RETURN(getSubstitutionMap());
}

/// Return a begin iterator for the substitution array.
auto subs_begin() const -> decltype(getSubstitutions().begin()) {
return getSubstitutions().begin();
}

/// Return an end iterator for the substitution array.
auto subs_end() const -> decltype(getSubstitutions().end()) {
return getSubstitutions().end();
}

/// The arguments passed to this instruction.
MutableArrayRef<Operand> getArgumentOperands() const {
FOREACH_IMPL_RETURN(getArgumentOperands());
Expand Down
7 changes: 0 additions & 7 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,6 @@ class SILType {
return SILType(getASTType().getReferenceStorageReferent(), getCategory());
}

/// Transform the function type SILType by replacing all of its interface
/// generic args with the appropriate item from the substitution.
///
/// Only call this with function types!
SILType substGenericArgs(SILModule &M,
SubstitutionList Subs) const;

/// Transform the function type SILType by replacing all of its interface
/// generic args with the appropriate item from the substitution.
///
Expand Down
4 changes: 0 additions & 4 deletions include/swift/SILOptimizer/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ ProjectBoxInst *getOrCreateProjectBox(AllocBoxInst *ABI, unsigned Index);
/// if possible.
void replaceDeadApply(ApplySite Old, ValueBase *New);

/// \brief Return true if the substitution list contains replacement types
/// that are dependent on the type parameters of the caller.
bool hasArchetypes(SubstitutionList Subs);

/// \brief Return true if any call inside the given function may bind dynamic
/// 'Self' to a generic argument of the callee.
bool mayBindDynamicSelf(SILFunction *F);
Expand Down
9 changes: 0 additions & 9 deletions lib/AST/GenericEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ SubstitutionMap GenericEnvironment::getForwardingSubstitutionMap() const {
MakeAbstractConformanceForGenericType());
}

SubstitutionList
GenericEnvironment::getForwardingSubstitutions() const {
auto *genericSig = getGenericSignature();

SmallVector<Substitution, 4> result;
genericSig->getSubstitutions(getForwardingSubstitutionMap(), result);
return genericSig->getASTContext().AllocateCopy(result);
}

std::pair<Type, ProtocolConformanceRef>
GenericEnvironment::mapConformanceRefIntoContext(GenericEnvironment *genericEnv,
Type conformingType,
Expand Down
5 changes: 0 additions & 5 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,11 +2765,6 @@ bool AnyFunctionType::isCanonicalFunctionInputType(Type input) {
return isa<TypeVariableType>(input.getPointer());
}

FunctionType *
GenericFunctionType::substGenericArgs(SubstitutionList args) {
return substGenericArgs(getGenericSignature()->getSubstitutionMap(args));
}

FunctionType *
GenericFunctionType::substGenericArgs(const SubstitutionMap &subs) {
Type input = getInput().subst(subs);
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/CallEmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CallEmission {

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

SubstitutionList getSubstitutions() const {
SubstitutionMap getSubstitutions() const {
return CurCallee.getSubstitutions();
}

Expand Down
13 changes: 8 additions & 5 deletions lib/IRGen/Callee.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ namespace irgen {

/// The archetype substitutions under which the function is being
/// called.
std::vector<Substitution> Substitutions;
SubstitutionMap Substitutions;

CalleeInfo(CanSILFunctionType origFnType,
CanSILFunctionType substFnType,
SubstitutionList substitutions)
SubstitutionMap substitutions)
: OrigFnType(origFnType), SubstFnType(substFnType),
Substitutions(substitutions.begin(), substitutions.end()) {
Substitutions(substitutions) {
}
};

Expand Down Expand Up @@ -159,8 +159,11 @@ namespace irgen {
return Info.SubstFnType;
}

bool hasSubstitutions() const { return !Info.Substitutions.empty(); }
SubstitutionList getSubstitutions() const { return Info.Substitutions; }
bool hasSubstitutions() const {
return Info.Substitutions.hasAnySubstitutableParams();
}

SubstitutionMap getSubstitutions() const { return Info.Substitutions; }

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

Expand Down
3 changes: 1 addition & 2 deletions lib/IRGen/GenKeyPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ getAccessorForComputedComponent(IRGenModule &IGM,
// Use the bound generic metadata to form a call to the original generic
// accessor.
WitnessMetadata ignoreWitnessMetadata;
auto forwardingSubs = genericEnv->getGenericSignature()->getSubstitutionMap(
genericEnv->getForwardingSubstitutions());
auto forwardingSubs = genericEnv->getForwardingSubstitutionMap();
emitPolymorphicArguments(IGF, accessor->getLoweredFunctionType(),
forwardingSubs,
&ignoreWitnessMetadata,
Expand Down
17 changes: 8 additions & 9 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ static llvm::Value *getObjCClassForValue(IRGenFunction &IGF,

static llvm::Value *emitWitnessTableForLoweredCallee(IRGenSILFunction &IGF,
CanSILFunctionType origCalleeType,
SubstitutionList subs) {
SubstitutionMap subs) {
llvm::Value *wtable;

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

llvm::Value *argMetadata = IGF.emitTypeMetadataRef(substSelfType);
wtable = emitWitnessTableRef(IGF, substSelfType, &argMetadata,
Expand Down Expand Up @@ -2193,7 +2191,7 @@ static CallEmission getCallEmissionForLoweredValue(IRGenSILFunction &IGF,
CanSILFunctionType substCalleeType,
const LoweredValue &lv,
llvm::Value *selfValue,
const SubstitutionList &substitutions,
SubstitutionMap substitutions,
WitnessMetadata *witnessMetadata,
Explosion &args) {
Callee callee = lv.getCallee(IGF, selfValue,
Expand Down Expand Up @@ -2282,7 +2280,8 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
WitnessMetadata witnessMetadata;
CallEmission emission =
getCallEmissionForLoweredValue(*this, origCalleeType, substCalleeType,
calleeLV, selfValue, site.getSubstitutions(),
calleeLV, selfValue,
site.getSubstitutionMap(),
&witnessMetadata, llArgs);

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

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

// Get the function value.
auto result = getPartialApplicationFunction(*this, i->getCallee(),
i->getSubstitutions());
i->getSubstitutionMap());
FunctionPointer calleeFn = std::get<0>(result);
llvm::Value *innerContext = std::get<1>(result);
CanSILFunctionType origCalleeTy = std::get<2>(result);
Expand Down
12 changes: 0 additions & 12 deletions lib/SIL/SILFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,6 @@ void SILFunction::convertToDeclaration() {
getBlocks().clear();
}

SubstitutionList SILFunction::getForwardingSubstitutions() {
if (ForwardingSubs)
return *ForwardingSubs;

auto *env = getGenericEnvironment();
if (!env)
return {};

ForwardingSubs = env->getForwardingSubstitutions();
return *ForwardingSubs;
}

SubstitutionMap SILFunction::getForwardingSubstitutionMap() {
if (ForwardingSubMap)
return ForwardingSubMap;
Expand Down
17 changes: 0 additions & 17 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,23 +2451,6 @@ SILType SILType::subst(SILModule &silModule, const SubstitutionMap &subs) const{
LookUpConformanceInSubstitutionMap(subs));
}

/// Apply a substitution to this polymorphic SILFunctionType so that
/// it has the form of the normal SILFunctionType for the substituted
/// type, except using the original conventions.
CanSILFunctionType
SILFunctionType::substGenericArgs(SILModule &silModule,
SubstitutionList subs) {
if (subs.empty()) {
assert(
(!isPolymorphic() || getGenericSignature()->areAllParamsConcrete()) &&
"no args for non-concrete polymorphic substitution");
return CanSILFunctionType(this);
}

auto subMap = GenericSig->getSubstitutionMap(subs);
return substGenericArgs(silModule, subMap);
}

/// Apply a substitution to this polymorphic SILFunctionType so that
/// it has the form of the normal SILFunctionType for the substituted
/// type, except using the original conventions.
Expand Down
14 changes: 7 additions & 7 deletions lib/SIL/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ static void collectTypeDependentOperands(
SILOpenedArchetypesState &OpenedArchetypesState,
SILFunction &F,
CanType Ty,
SubstitutionList subs = SubstitutionList()) {
SubstitutionMap subs = { }) {
SmallVector<CanArchetypeType, 4> openedArchetypes;
bool hasDynamicSelf = false;
collectDependentTypeInfo(Ty, openedArchetypes, hasDynamicSelf);
for (auto sub : subs) {
for (Type replacement : subs.getReplacementTypes()) {
// Substitutions in SIL should really be canonical.
auto ReplTy = sub.getReplacement()->getCanonicalType();
auto ReplTy = replacement->getCanonicalType();
collectDependentTypeInfo(ReplTy, openedArchetypes, hasDynamicSelf);
}
buildTypeDependentOperands(openedArchetypes, hasDynamicSelf,
Expand Down Expand Up @@ -427,7 +427,7 @@ ApplyInst::create(SILDebugLocation Loc, SILValue Callee, SubstitutionMap Subs,

SmallVector<SILValue, 32> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
SubstCalleeSILTy.getASTType(), Subs.toList());
SubstCalleeSILTy.getASTType(), Subs);
void *Buffer =
allocateTrailingInst<ApplyInst, Operand>(
F, getNumAllOperands(Args, TypeDependentOperands));
Expand Down Expand Up @@ -487,7 +487,7 @@ BeginApplyInst::create(SILDebugLocation loc, SILValue callee,

SmallVector<SILValue, 32> typeDependentOperands;
collectTypeDependentOperands(typeDependentOperands, openedArchetypes, F,
substCalleeType, subs.toList());
substCalleeType, subs);
void *buffer =
allocateTrailingInst<BeginApplyInst, Operand,
MultipleValueInstruction*, BeginApplyResult>(
Expand Down Expand Up @@ -531,7 +531,7 @@ PartialApplyInst *PartialApplyInst::create(

SmallVector<SILValue, 32> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
SubstCalleeTy.getASTType(), Subs.toList());
SubstCalleeTy.getASTType(), Subs);
void *Buffer =
allocateTrailingInst<PartialApplyInst, Operand>(
F, getNumAllOperands(Args, TypeDependentOperands));
Expand Down Expand Up @@ -568,7 +568,7 @@ TryApplyInst *TryApplyInst::create(
SmallVector<SILValue, 32> typeDependentOperands;
collectTypeDependentOperands(typeDependentOperands, openedArchetypes, F,
substCalleeTy.getASTType(),
subs.toList());
subs);
void *buffer =
allocateTrailingInst<TryApplyInst, Operand>(
F, getNumAllOperands(args, typeDependentOperands));
Expand Down
12 changes: 6 additions & 6 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ void SILDeclRef::dump() const {
static void printGenericSpecializationInfo(
raw_ostream &OS, StringRef Kind, StringRef Name,
const GenericSpecializationInformation *SpecializationInfo,
SubstitutionList Subs = SubstitutionList()) {
SubstitutionMap Subs = { }) {
if (!SpecializationInfo)
return;

auto PrintSubstitutions = [&](SubstitutionList Subs) {
auto PrintSubstitutions = [&](SubstitutionMap Subs) {
OS << '<';
interleave(Subs,
[&](const Substitution &s) { OS << s.getReplacement(); },
interleave(Subs.getReplacementTypes(),
[&](Type type) { OS << type; },
[&] { OS << ", "; });
OS << '>';
};
Expand All @@ -396,7 +396,7 @@ static void printGenericSpecializationInfo(
OS << "// Caller: " << SpecializationInfo->getCaller()->getName() << '\n';
OS << "// Parent: " << SpecializationInfo->getParent()->getName() << '\n';
OS << "// Substitutions: ";
PrintSubstitutions(SpecializationInfo->getSubstitutions().toList());
PrintSubstitutions(SpecializationInfo->getSubstitutions());
OS << '\n';
OS << "//\n";
if (!SpecializationInfo->getCaller()->isSpecialization())
Expand Down Expand Up @@ -638,7 +638,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
if (AI.getSpecializationInfo() && AI.getCalleeFunction())
printGenericSpecializationInfo(
PrintState.OS, "call-site", AI.getCalleeFunction()->getName(),
AI.getSpecializationInfo(), AI.getSubstitutions());
AI.getSpecializationInfo(), AI.getSubstitutionMap());
}
print(&I);
}
Expand Down
Loading