@@ -52,11 +52,9 @@ class Conversion {
52
52
// / A subtype conversion.
53
53
Subtype,
54
54
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,
60
58
};
61
59
62
60
static bool isBridgingKind (KindTy kind) {
@@ -69,17 +67,15 @@ class Conversion {
69
67
case Subtype:
70
68
return true ;
71
69
72
- case OrigToSubst:
73
- case SubstToOrig:
70
+ case Reabstract:
74
71
return false ;
75
72
}
76
73
llvm_unreachable (" bad kind" );
77
74
}
78
75
79
76
static bool isReabstractionKind (KindTy kind) {
80
77
switch (kind) {
81
- case OrigToSubst:
82
- case SubstToOrig:
78
+ case Reabstract:
83
79
return true ;
84
80
85
81
case BridgeToObjC:
@@ -104,12 +100,12 @@ class Conversion {
104
100
};
105
101
106
102
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 ;
113
109
};
114
110
115
111
using Members = ExternalUnionMembers<BridgingTypes, ReabstractionTypes>;
@@ -124,8 +120,7 @@ class Conversion {
124
120
case Subtype:
125
121
return Members::indexOf<BridgingTypes>();
126
122
127
- case OrigToSubst:
128
- case SubstToOrig:
123
+ case Reabstract:
129
124
return Members::indexOf<ReabstractionTypes>();
130
125
}
131
126
llvm_unreachable (" bad kind" );
@@ -142,32 +137,41 @@ class Conversion {
142
137
loweredResultTy, isExplicit);
143
138
}
144
139
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);
150
148
}
151
149
152
150
public:
153
151
static Conversion getOrigToSubst (AbstractionPattern origType,
154
152
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);
157
157
}
158
158
159
159
static Conversion getSubstToOrig (AbstractionPattern origType,
160
160
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);
163
165
}
164
166
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);
171
175
}
172
176
173
177
static Conversion getBridging (KindTy kind, CanType origType,
@@ -194,20 +198,28 @@ class Conversion {
194
198
return isReabstractionKind (getKind ());
195
199
}
196
200
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 ;
199
211
}
200
212
201
- CanType getReabstractionSubstSourceType () const {
202
- return Types.get <ReabstractionTypes>(Kind).SubstSourceType ;
213
+ AbstractionPattern getReabstractionOutputOrigType () const {
214
+ return Types.get <ReabstractionTypes>(Kind).OutputOrigType ;
203
215
}
204
216
205
- CanType getReabstractionSubstResultType () const {
206
- return Types.get <ReabstractionTypes>(Kind).SubstResultType ;
217
+ CanType getReabstractionOutputSubstType () const {
218
+ return Types.get <ReabstractionTypes>(Kind).OutputSubstType ;
207
219
}
208
220
209
- SILType getReabstractionLoweredResultType () const {
210
- return Types.get <ReabstractionTypes>(Kind).LoweredResultType ;
221
+ SILType getReabstractionOutputLoweredType () const {
222
+ return Types.get <ReabstractionTypes>(Kind).OutputLoweredTy ;
211
223
}
212
224
213
225
bool isBridgingExplicit () const {
@@ -259,7 +271,10 @@ class ConversionPeepholeHint {
259
271
260
272
// / The inner conversion is a subtype conversion and can be done implicitly
261
273
// / as part of the outer conversion.
262
- SubtypeIntoSubstToOrig,
274
+ SubtypeIntoReabstract,
275
+
276
+ // / Both conversions are reabstractions and can be combined.
277
+ Reabstract,
263
278
};
264
279
265
280
private:
0 commit comments