1515//
1616// ===----------------------------------------------------------------------===//
1717
18- #include " GenericSignatureBuilder.h"
19- #include " swift/AST/Types.h"
2018#include " swift/AST/CanTypeVisitor.h"
19+ #include " swift/AST/Decl.h"
20+ #include " swift/AST/GenericSignature.h"
21+ #include " swift/AST/Requirement.h"
22+ #include " swift/AST/Types.h"
2123#include " llvm/ADT/DenseMap.h"
2224
2325using namespace swift ;
@@ -34,13 +36,8 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
3436 llvm::DenseMap<std::pair<CanType, ProtocolDecl*>,
3537 ProtocolConformanceRef> substConformances;
3638
37- Optional<GenericSignatureBuilder> sigBuilderStorage;
38-
39- GenericSignatureBuilder &sigBuilder () {
40- if (!sigBuilderStorage)
41- sigBuilderStorage.emplace (ctx);
42- return *sigBuilderStorage;
43- }
39+ SmallVector<GenericTypeParamType *, 2 > addedParameters;
40+ SmallVector<Requirement, 2 > addedRequirements;
4441
4542public:
4643 Generalizer (ASTContext &ctx) : ctx(ctx) {}
@@ -53,11 +50,13 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
5350
5451 SubstitutionMap getGeneralizationSubstitutions () {
5552 // If we never introduced a generalization parameter, we're done.
56- if (!sigBuilderStorage) return SubstitutionMap ();
53+ if (addedParameters.empty () && addedRequirements.empty ())
54+ return SubstitutionMap ();
5755
5856 // Finish the signature.
59- auto sig = std::move (*sigBuilderStorage).computeGenericSignature ();
60- sigBuilderStorage.reset ();
57+ auto sig = buildGenericSignature (ctx, GenericSignature (),
58+ addedParameters,
59+ addedRequirements);
6160
6261 // TODO: minimize the signature by removing redundant generic
6362 // parameters.
@@ -217,10 +216,7 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
217216 assert (optNewReq && " generalization substitution failed" );
218217 auto &newReq = *optNewReq;
219218
220- auto source = GenericSignatureBuilder::
221- FloatingRequirementSource::forInferred (SourceLoc ());
222-
223- sigBuilder ().addRequirement (newReq, source, nullptr );
219+ addedRequirements.push_back (newReq);
224220
225221 substConformances.insert ({{newReq.getFirstType ()->getCanonicalType (),
226222 newReq.getProtocolDecl ()},
@@ -259,7 +255,8 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
259255 /* depth*/ 0 ,
260256 /* index*/ substTypes.size (),
261257 ctx);
262- sigBuilder ().addGenericParameter (newParam);
258+ addedParameters.push_back (newParam);
259+
263260 substTypes.insert ({CanType (newParam), origArg});
264261 return newParam;
265262 }
0 commit comments