@@ -82,15 +82,15 @@ class ReabstractionInfo {
82
82
83
83
// / If set, indirect to direct conversions should be performed by the generic
84
84
// / specializer.
85
- bool ConvertIndirectToDirect;
85
+ bool ConvertIndirectToDirect = true ;
86
86
87
87
// / If true, drop metatype arguments.
88
88
// / See `droppedMetatypeArgs`.
89
89
bool dropMetatypeArgs = false ;
90
90
91
91
// / The first NumResults bits in Conversions refer to formal indirect
92
92
// / out-parameters.
93
- unsigned NumFormalIndirectResults;
93
+ unsigned NumFormalIndirectResults = 0 ;
94
94
95
95
// / The function type after applying the substitutions used to call the
96
96
// / specialized function.
@@ -101,7 +101,7 @@ class ReabstractionInfo {
101
101
CanSILFunctionType SpecializedType;
102
102
103
103
// / The generic environment to be used by the specialization.
104
- GenericEnvironment *SpecializedGenericEnv;
104
+ GenericEnvironment *SpecializedGenericEnv = nullptr ;
105
105
106
106
// / The generic signature of the specialization.
107
107
// / It is nullptr if the specialization is not polymorphic.
@@ -125,7 +125,7 @@ class ReabstractionInfo {
125
125
SubstitutionMap ClonerParamSubMap;
126
126
127
127
// Reference to the original generic non-specialized callee function.
128
- SILFunction *Callee;
128
+ SILFunction *Callee = nullptr ;
129
129
130
130
// The module the specialization is created in.
131
131
ModuleDecl *TargetModule = nullptr ;
@@ -136,7 +136,7 @@ class ReabstractionInfo {
136
136
ApplySite Apply;
137
137
138
138
// Set if a specialized function has unbound generic parameters.
139
- bool HasUnboundGenericParams;
139
+ bool HasUnboundGenericParams = false ;
140
140
141
141
// Substitutions to be used for creating a new function type
142
142
// for the specialized function.
@@ -149,7 +149,7 @@ class ReabstractionInfo {
149
149
bool isPrespecialization = false ;
150
150
151
151
// Is the generated specialization going to be serialized?
152
- IsSerialized_t Serialized;
152
+ IsSerialized_t Serialized = IsNotSerialized ;
153
153
154
154
enum TypeCategory {
155
155
NotLoadable,
@@ -162,7 +162,9 @@ class ReabstractionInfo {
162
162
SubstitutionMap SubstMap,
163
163
bool HasUnboundGenericParams);
164
164
165
+ public:
165
166
void createSubstitutedAndSpecializedTypes ();
167
+ private:
166
168
167
169
TypeCategory getReturnTypeCategory (const SILResultInfo &RI,
168
170
const SILFunctionConventions &substConv,
@@ -205,6 +207,12 @@ class ReabstractionInfo {
205
207
SILFunction *Callee, GenericSignature SpecializedSig,
206
208
bool isPrespecialization = false );
207
209
210
+ ReabstractionInfo (CanSILFunctionType substitutedType,
211
+ SILModule &M) :
212
+ SubstitutedType (substitutedType),
213
+ isWholeModule (M.isWholeModule()) {}
214
+
215
+
208
216
bool isPrespecialized () const { return isPrespecialization; }
209
217
210
218
IsSerialized_t isSerialized () const {
@@ -400,6 +408,64 @@ class GenericFuncSpecializer {
400
408
// / prespecialization for -Onone support.
401
409
bool isKnownPrespecialization (StringRef SpecName);
402
410
411
+ class TypeReplacements {
412
+ private:
413
+ llvm::Optional<SILType> resultType;
414
+ llvm::MapVector<unsigned , CanType> indirectResultTypes;
415
+ llvm::MapVector<unsigned , CanType> paramTypeReplacements;
416
+ llvm::MapVector<unsigned , CanType> yieldTypeReplacements;
417
+
418
+ public:
419
+ llvm::Optional<SILType> getResultType () const { return resultType; }
420
+
421
+ void setResultType (SILType type) { resultType = type; }
422
+
423
+ bool hasResultType () const { return resultType.has_value (); }
424
+
425
+ const llvm::MapVector<unsigned , CanType> &getIndirectResultTypes () const {
426
+ return indirectResultTypes;
427
+ }
428
+
429
+ void addIndirectResultType (unsigned index, CanType type) {
430
+ indirectResultTypes.insert (std::make_pair (index , type));
431
+ }
432
+
433
+ bool hasIndirectResultTypes () const { return !indirectResultTypes.empty (); }
434
+
435
+ const llvm::MapVector<unsigned , CanType> &getParamTypeReplacements () const {
436
+ return paramTypeReplacements;
437
+ }
438
+
439
+ void addParameterTypeReplacement (unsigned index, CanType type) {
440
+ paramTypeReplacements.insert (std::make_pair (index , type));
441
+ }
442
+
443
+ bool hasParamTypeReplacements () const {
444
+ return !paramTypeReplacements.empty ();
445
+ }
446
+
447
+ const llvm::MapVector<unsigned , CanType> &getYieldTypeReplacements () const {
448
+ return yieldTypeReplacements;
449
+ }
450
+
451
+ void addYieldTypeReplacement (unsigned index, CanType type) {
452
+ yieldTypeReplacements.insert (std::make_pair (index , type));
453
+ }
454
+
455
+ bool hasYieldTypeReplacements () const {
456
+ return !yieldTypeReplacements.empty ();
457
+ }
458
+
459
+ bool hasTypeReplacements () const {
460
+ return hasResultType () || hasParamTypeReplacements () ||
461
+ hasIndirectResultTypes () || hasYieldTypeReplacements ();
462
+ }
463
+ };
464
+
465
+ ApplySite replaceWithSpecializedCallee (
466
+ ApplySite applySite, SILValue callee, const ReabstractionInfo &reInfo,
467
+ const TypeReplacements &typeReplacements = {});
468
+
403
469
// / Checks if all OnoneSupport pre-specializations are included in the module
404
470
// / as public functions.
405
471
// /
0 commit comments