@@ -82,15 +82,15 @@ class ReabstractionInfo {
8282
8383 // / If set, indirect to direct conversions should be performed by the generic
8484 // / specializer.
85- bool ConvertIndirectToDirect;
85+ bool ConvertIndirectToDirect = true ;
8686
8787 // / If true, drop metatype arguments.
8888 // / See `droppedMetatypeArgs`.
8989 bool dropMetatypeArgs = false ;
9090
9191 // / The first NumResults bits in Conversions refer to formal indirect
9292 // / out-parameters.
93- unsigned NumFormalIndirectResults;
93+ unsigned NumFormalIndirectResults = 0 ;
9494
9595 // / The function type after applying the substitutions used to call the
9696 // / specialized function.
@@ -101,7 +101,7 @@ class ReabstractionInfo {
101101 CanSILFunctionType SpecializedType;
102102
103103 // / The generic environment to be used by the specialization.
104- GenericEnvironment *SpecializedGenericEnv;
104+ GenericEnvironment *SpecializedGenericEnv = nullptr ;
105105
106106 // / The generic signature of the specialization.
107107 // / It is nullptr if the specialization is not polymorphic.
@@ -125,7 +125,7 @@ class ReabstractionInfo {
125125 SubstitutionMap ClonerParamSubMap;
126126
127127 // Reference to the original generic non-specialized callee function.
128- SILFunction *Callee;
128+ SILFunction *Callee = nullptr ;
129129
130130 // The module the specialization is created in.
131131 ModuleDecl *TargetModule = nullptr ;
@@ -136,7 +136,7 @@ class ReabstractionInfo {
136136 ApplySite Apply;
137137
138138 // Set if a specialized function has unbound generic parameters.
139- bool HasUnboundGenericParams;
139+ bool HasUnboundGenericParams = false ;
140140
141141 // Substitutions to be used for creating a new function type
142142 // for the specialized function.
@@ -149,7 +149,7 @@ class ReabstractionInfo {
149149 bool isPrespecialization = false ;
150150
151151 // Is the generated specialization going to be serialized?
152- IsSerialized_t Serialized;
152+ IsSerialized_t Serialized = IsNotSerialized ;
153153
154154 enum TypeCategory {
155155 NotLoadable,
@@ -162,7 +162,9 @@ class ReabstractionInfo {
162162 SubstitutionMap SubstMap,
163163 bool HasUnboundGenericParams);
164164
165+ public:
165166 void createSubstitutedAndSpecializedTypes ();
167+ private:
166168
167169 TypeCategory getReturnTypeCategory (const SILResultInfo &RI,
168170 const SILFunctionConventions &substConv,
@@ -205,6 +207,12 @@ class ReabstractionInfo {
205207 SILFunction *Callee, GenericSignature SpecializedSig,
206208 bool isPrespecialization = false );
207209
210+ ReabstractionInfo (CanSILFunctionType substitutedType,
211+ SILModule &M) :
212+ SubstitutedType (substitutedType),
213+ isWholeModule (M.isWholeModule()) {}
214+
215+
208216 bool isPrespecialized () const { return isPrespecialization; }
209217
210218 IsSerialized_t isSerialized () const {
@@ -400,6 +408,64 @@ class GenericFuncSpecializer {
400408// / prespecialization for -Onone support.
401409bool isKnownPrespecialization (StringRef SpecName);
402410
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+
403469// / Checks if all OnoneSupport pre-specializations are included in the module
404470// / as public functions.
405471// /
0 commit comments