Skip to content

Eliminate all vestiges of Substitution and SubstitutionList. #16568

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 1 commit into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/Identifier.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/AST/SubstitutionList.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/Basic/LangOptions.h"
Expand Down Expand Up @@ -95,7 +94,6 @@ namespace swift {
class SourceManager;
class ValueDecl;
class DiagnosticEngine;
class Substitution;
class TypeCheckerDebugConsumer;
struct RawComment;
class DocComment;
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/GenericEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef SWIFT_AST_GENERIC_ENVIRONMENT_H
#define SWIFT_AST_GENERIC_ENVIRONMENT_H

#include "swift/AST/SubstitutionList.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/GenericParamKey.h"
Expand Down
13 changes: 3 additions & 10 deletions include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "swift/AST/PrintOptions.h"
#include "swift/AST/Requirement.h"
#include "swift/AST/SubstitutionList.h"
#include "swift/AST/Type.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FoldingSet.h"
Expand All @@ -32,7 +31,6 @@ namespace swift {
class GenericSignatureBuilder;
class ProtocolConformanceRef;
class ProtocolType;
class Substitution;
class SubstitutionMap;

/// An access path used to find a particular protocol conformance within
Expand Down Expand Up @@ -177,9 +175,9 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
return Mem;
}

/// Build an interface type substitution map from a vector of Substitutions
/// that correspond to the generic parameters in this generic signature.
SubstitutionMap getSubstitutionMap(SubstitutionList args) const;
/// Build a substitution map for this generic signature by looking up
/// substitutions in the given substitution map.
SubstitutionMap getSubstitutionMap(SubstitutionMap subs) const;

/// Build an interface type substitution map from a type substitution function
/// and conformance lookup function.
Expand All @@ -193,11 +191,6 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
Optional<ProtocolConformanceRef>
lookupConformance(CanType depTy, ProtocolDecl *proto) const;

/// Build an array of substitutions from an interface type substitution map,
/// using the given function to look up conformances.
void getSubstitutions(const SubstitutionMap &subMap,
SmallVectorImpl<Substitution> &result) const;

/// Enumerate all of the dependent types in the type signature that will
/// occur in substitution lists (in order), along with the set of
/// conformance requirements placed on that dependent type.
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class NominalTypeDecl;
class NormalProtocolConformance;
class ProtocolConformance;
class ProtocolDecl;
class Substitution;
class TypeDecl;
class ValueDecl;
class VarDecl;
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "swift/AST/ConcreteDeclRef.h"
#include "swift/AST/Decl.h"
#include "swift/AST/SubstitutionList.h"
#include "swift/AST/Type.h"
#include "swift/AST/Types.h"
#include "swift/AST/TypeAlignments.h"
Expand Down
64 changes: 0 additions & 64 deletions include/swift/AST/Substitution.h

This file was deleted.

39 changes: 0 additions & 39 deletions include/swift/AST/SubstitutionList.h

This file was deleted.

17 changes: 2 additions & 15 deletions include/swift/AST/SubstitutionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ namespace swift {

class GenericSignature;
class GenericEnvironment;
class Substitution;
class SubstitutableType;
typedef CanTypeWrapper<GenericTypeParamType> CanGenericTypeParamType;

// FIXME: Soon this will go away.
using SubstitutionList = ArrayRef<Substitution>;

template<class Type> class CanTypeWrapper;
typedef CanTypeWrapper<SubstitutableType> CanSubstitutableType;

Expand Down Expand Up @@ -109,10 +105,9 @@ class SubstitutionMap {
}

/// Build an interface type substitution map for the given generic
/// signature and a vector of Substitutions that correspond to the
/// requirements of this generic signature.
/// signature using the mapping in the given substitutions.
static SubstitutionMap get(GenericSignature *genericSig,
SubstitutionList substitutions);
SubstitutionMap substitutions);

/// Build an interface type substitution map for the given generic signature
/// from a type substitution function and conformance lookup function.
Expand Down Expand Up @@ -196,14 +191,6 @@ class SubstitutionMap {
GenericSignature *derivedSig,
Optional<SubstitutionMap> derivedSubs);

/// Produce a substitution list for the given substitution map.
///
/// Note: we are moving away from using Substitutions, so this should only
/// be used at the edges where part of the compiler is still working
/// directly with Substitution/SubstitutionList and hasn't been converted
/// to SubstitutionMap.
SubstitutionList toList() const;

/// Combine two substitution maps as follows.
///
/// The result is written in terms of the generic parameters of 'genericSig'.
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeAlignments.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace swift {
class ProtocolConformance;
class SILFunction;
class Stmt;
class Substitution;
class TypeVariableType;
class TypeBase;
class TypeDecl;
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "swift/AST/ProtocolConformanceRef.h"
#include "swift/AST/Requirement.h"
#include "swift/AST/SILLayout.h"
#include "swift/AST/SubstitutionList.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/Witness.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define SWIFT_AST_WITNESS_H

#include "swift/AST/ConcreteDeclRef.h"
#include "swift/AST/SubstitutionList.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/Compiler.h"

Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class SILArgument;
class SILUndef;
class Stmt;
class StringLiteralExpr;
class Substitution;
class ValueDecl;
class VarDecl;
class FunctionRefInst;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/TypeSubstCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
RecursiveSubs = AI.getFunction()
->getLoweredFunctionType()
->getGenericSignature()
->getSubstitutionMap(Subs.toList());
->getSubstitutionMap(Subs);

// Use the new set of substitutions to compute the new
// substituted callee type.
Expand Down
22 changes: 0 additions & 22 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2792,20 +2792,6 @@ void TypeRepr::dump() const {
llvm::errs() << '\n';
}

void Substitution::dump() const {
dump(llvm::errs());
}

void Substitution::dump(llvm::raw_ostream &out, unsigned indent) const {
out.indent(indent);
print(out);
out << '\n';

for (auto &c : Conformance) {
c.dump(out, indent + 2);
}
}

void ProtocolConformanceRef::dump() const {
dump(llvm::errs());
}
Expand All @@ -2822,14 +2808,6 @@ void ProtocolConformanceRef::dump(llvm::raw_ostream &out,
}
}

void swift::dump(SubstitutionList subs) {
unsigned i = 0;
for (const auto &s : subs) {
llvm::errs() << i++ << ": ";
s.dump();
}
}

void ProtocolConformance::dump() const {
auto &out = llvm::errs();
dump(out);
Expand Down
5 changes: 0 additions & 5 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4176,11 +4176,6 @@ void ProtocolConformance::printName(llvm::raw_ostream &os,
}
}

void Substitution::print(llvm::raw_ostream &os,
const PrintOptions &PO) const {
Replacement->print(os, PO);
}

void swift::printEnumElementsAsCases(
llvm::DenseSet<EnumElementDecl *> &UnhandledElements,
llvm::raw_ostream &OS) {
Expand Down
1 change: 0 additions & 1 deletion lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ add_swift_library(swiftAST STATIC
SyntaxASTMap.cpp
SILLayout.cpp
Stmt.cpp
Substitution.cpp
SubstitutionMap.cpp
SwiftNameTranslation.cpp
Type.cpp
Expand Down
39 changes: 1 addition & 38 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ bool GenericSignature::enumeratePairedRequirements(
}

SubstitutionMap
GenericSignature::getSubstitutionMap(SubstitutionList subs) const {
GenericSignature::getSubstitutionMap(SubstitutionMap subs) const {
return SubstitutionMap::get(const_cast<GenericSignature *>(this), subs);
}

Expand All @@ -478,43 +478,6 @@ getSubstitutionMap(TypeSubstitutionFn subs,
subs, lookupConformance);
}

void GenericSignature::
getSubstitutions(const SubstitutionMap &subMap,
SmallVectorImpl<Substitution> &result) const {

// Enumerate all of the requirements that require substitution.
enumeratePairedRequirements([&](Type depTy, ArrayRef<Requirement> reqs) {
auto &ctx = getASTContext();

// Compute the replacement type.
Type currentReplacement = depTy.subst(subMap);
if (!currentReplacement)
currentReplacement = ErrorType::get(depTy);

// Collect the conformances.
SmallVector<ProtocolConformanceRef, 4> currentConformances;
for (auto req: reqs) {
assert(req.getKind() == RequirementKind::Conformance);
auto protoDecl = req.getSecondType()->castTo<ProtocolType>()->getDecl();
if (auto conformance = subMap.lookupConformance(depTy->getCanonicalType(),
protoDecl)) {
currentConformances.push_back(*conformance);
} else {
if (!currentReplacement->hasError())
currentReplacement = ErrorType::get(currentReplacement);
currentConformances.push_back(ProtocolConformanceRef(protoDecl));
}
}

// Add it to the final substitution list.
result.push_back({
currentReplacement,
ctx.AllocateCopy(currentConformances)
});

return false;
});
}

bool GenericSignature::requiresClass(Type type) {
if (!type->isTypeParameter()) return false;
Expand Down
Loading