15
15
//
16
16
// ===----------------------------------------------------------------------===//
17
17
18
- #include " GenericSignatureBuilder.h"
19
- #include " swift/AST/Types.h"
20
18
#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"
21
23
#include " llvm/ADT/DenseMap.h"
22
24
23
25
using namespace swift ;
@@ -34,13 +36,8 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
34
36
llvm::DenseMap<std::pair<CanType, ProtocolDecl*>,
35
37
ProtocolConformanceRef> substConformances;
36
38
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;
44
41
45
42
public:
46
43
Generalizer (ASTContext &ctx) : ctx(ctx) {}
@@ -53,11 +50,13 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
53
50
54
51
SubstitutionMap getGeneralizationSubstitutions () {
55
52
// If we never introduced a generalization parameter, we're done.
56
- if (!sigBuilderStorage) return SubstitutionMap ();
53
+ if (addedParameters.empty () && addedRequirements.empty ())
54
+ return SubstitutionMap ();
57
55
58
56
// Finish the signature.
59
- auto sig = std::move (*sigBuilderStorage).computeGenericSignature ();
60
- sigBuilderStorage.reset ();
57
+ auto sig = buildGenericSignature (ctx, GenericSignature (),
58
+ addedParameters,
59
+ addedRequirements);
61
60
62
61
// TODO: minimize the signature by removing redundant generic
63
62
// parameters.
@@ -217,10 +216,7 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
217
216
assert (optNewReq && " generalization substitution failed" );
218
217
auto &newReq = *optNewReq;
219
218
220
- auto source = GenericSignatureBuilder::
221
- FloatingRequirementSource::forInferred (SourceLoc ());
222
-
223
- sigBuilder ().addRequirement (newReq, source, nullptr );
219
+ addedRequirements.push_back (newReq);
224
220
225
221
substConformances.insert ({{newReq.getFirstType ()->getCanonicalType (),
226
222
newReq.getProtocolDecl ()},
@@ -259,7 +255,8 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
259
255
/* depth*/ 0 ,
260
256
/* index*/ substTypes.size (),
261
257
ctx);
262
- sigBuilder ().addGenericParameter (newParam);
258
+ addedParameters.push_back (newParam);
259
+
263
260
substTypes.insert ({CanType (newParam), origArg});
264
261
return newParam;
265
262
}
0 commit comments