@@ -52,11 +52,9 @@ class Conversion {
5252 // / A subtype conversion.
5353 Subtype,
5454
55- // / An orig-to-subst conversion.
56- OrigToSubst,
57-
58- // / A subst-to-orig conversion. These can always be annihilated.
59- SubstToOrig,
55+ // / A reabstraction conversion. There can also be a subtype difference
56+ // / between the substituted types.
57+ Reabstract,
6058 };
6159
6260 static bool isBridgingKind (KindTy kind) {
@@ -69,17 +67,15 @@ class Conversion {
6967 case Subtype:
7068 return true ;
7169
72- case OrigToSubst:
73- case SubstToOrig:
70+ case Reabstract:
7471 return false ;
7572 }
7673 llvm_unreachable (" bad kind" );
7774 }
7875
7976 static bool isReabstractionKind (KindTy kind) {
8077 switch (kind) {
81- case OrigToSubst:
82- case SubstToOrig:
78+ case Reabstract:
8379 return true ;
8480
8581 case BridgeToObjC:
@@ -104,12 +100,12 @@ class Conversion {
104100 };
105101
106102 struct ReabstractionTypes {
107- // Whether this abstraction pattern applies to the input or output
108- // substituted type is determined by the kind.
109- AbstractionPattern OrigType ;
110- CanType SubstSourceType ;
111- CanType SubstResultType ;
112- SILType LoweredResultType ;
103+ AbstractionPattern InputOrigType;
104+ AbstractionPattern OutputOrigType;
105+ CanType InputSubstType ;
106+ CanType OutputSubstType ;
107+ SILType InputLoweredTy ;
108+ SILType OutputLoweredTy ;
113109 };
114110
115111 using Members = ExternalUnionMembers<BridgingTypes, ReabstractionTypes>;
@@ -124,8 +120,7 @@ class Conversion {
124120 case Subtype:
125121 return Members::indexOf<BridgingTypes>();
126122
127- case OrigToSubst:
128- case SubstToOrig:
123+ case Reabstract:
129124 return Members::indexOf<ReabstractionTypes>();
130125 }
131126 llvm_unreachable (" bad kind" );
@@ -142,32 +137,41 @@ class Conversion {
142137 loweredResultTy, isExplicit);
143138 }
144139
145- Conversion (KindTy kind, AbstractionPattern origType, CanType substSourceType,
146- CanType substResultType, SILType loweredResultTy)
147- : Kind(kind) {
148- Types.emplaceAggregate <ReabstractionTypes>(kind, origType, substSourceType,
149- substResultType, loweredResultTy);
140+ Conversion (AbstractionPattern inputOrigType, CanType inputSubstType,
141+ SILType inputLoweredTy,
142+ AbstractionPattern outputOrigType, CanType outputSubstType,
143+ SILType outputLoweredTy)
144+ : Kind(Reabstract) {
145+ Types.emplaceAggregate <ReabstractionTypes>(Kind, inputOrigType, outputOrigType,
146+ inputSubstType, outputSubstType,
147+ inputLoweredTy, outputLoweredTy);
150148 }
151149
152150public:
153151 static Conversion getOrigToSubst (AbstractionPattern origType,
154152 CanType substType,
155- SILType loweredResultTy) {
156- return Conversion (OrigToSubst, origType, substType, substType, loweredResultTy);
153+ SILType inputLoweredTy,
154+ SILType outputLoweredTy) {
155+ return getReabstract (origType, substType, inputLoweredTy,
156+ AbstractionPattern (substType), substType, outputLoweredTy);
157157 }
158158
159159 static Conversion getSubstToOrig (AbstractionPattern origType,
160160 CanType substType,
161- SILType loweredResultTy) {
162- return Conversion (SubstToOrig, origType, substType, substType, loweredResultTy);
161+ SILType inputLoweredTy,
162+ SILType outputLoweredTy) {
163+ return getReabstract (AbstractionPattern (substType), substType, inputLoweredTy,
164+ origType, substType, outputLoweredTy);
163165 }
164166
165- static Conversion getSubstToOrig (CanType inputSubstType,
166- AbstractionPattern outputOrigType,
167- CanType outputSubstType,
168- SILType loweredResultTy) {
169- return Conversion (SubstToOrig, outputOrigType, inputSubstType,
170- outputSubstType, loweredResultTy);
167+ static Conversion getReabstract (AbstractionPattern inputOrigType,
168+ CanType inputSubstType,
169+ SILType inputLoweredTy,
170+ AbstractionPattern outputOrigType,
171+ CanType outputSubstType,
172+ SILType outputLoweredTy) {
173+ return Conversion (inputOrigType, inputSubstType, inputLoweredTy,
174+ outputOrigType, outputSubstType, outputLoweredTy);
171175 }
172176
173177 static Conversion getBridging (KindTy kind, CanType origType,
@@ -194,20 +198,28 @@ class Conversion {
194198 return isReabstractionKind (getKind ());
195199 }
196200
197- AbstractionPattern getReabstractionOrigType () const {
198- return Types.get <ReabstractionTypes>(Kind).OrigType ;
201+ AbstractionPattern getReabstractionInputOrigType () const {
202+ return Types.get <ReabstractionTypes>(Kind).InputOrigType ;
203+ }
204+
205+ CanType getReabstractionInputSubstType () const {
206+ return Types.get <ReabstractionTypes>(Kind).InputSubstType ;
207+ }
208+
209+ SILType getReabstractionInputLoweredType () const {
210+ return Types.get <ReabstractionTypes>(Kind).InputLoweredTy ;
199211 }
200212
201- CanType getReabstractionSubstSourceType () const {
202- return Types.get <ReabstractionTypes>(Kind).SubstSourceType ;
213+ AbstractionPattern getReabstractionOutputOrigType () const {
214+ return Types.get <ReabstractionTypes>(Kind).OutputOrigType ;
203215 }
204216
205- CanType getReabstractionSubstResultType () const {
206- return Types.get <ReabstractionTypes>(Kind).SubstResultType ;
217+ CanType getReabstractionOutputSubstType () const {
218+ return Types.get <ReabstractionTypes>(Kind).OutputSubstType ;
207219 }
208220
209- SILType getReabstractionLoweredResultType () const {
210- return Types.get <ReabstractionTypes>(Kind).LoweredResultType ;
221+ SILType getReabstractionOutputLoweredType () const {
222+ return Types.get <ReabstractionTypes>(Kind).OutputLoweredTy ;
211223 }
212224
213225 bool isBridgingExplicit () const {
@@ -259,7 +271,10 @@ class ConversionPeepholeHint {
259271
260272 // / The inner conversion is a subtype conversion and can be done implicitly
261273 // / as part of the outer conversion.
262- SubtypeIntoSubstToOrig,
274+ SubtypeIntoReabstract,
275+
276+ // / Both conversions are reabstractions and can be combined.
277+ Reabstract,
263278 };
264279
265280private:
0 commit comments