@@ -177,9 +177,6 @@ enum TypeVariableOptions {
177
177
// / to, what specific types it might be and, eventually, the fixed type to
178
178
// / which it is assigned.
179
179
class TypeVariableType ::Implementation {
180
- // / Type variable options.
181
- unsigned Options : 3 ;
182
-
183
180
// / \brief The locator that describes where this type variable was generated.
184
181
constraints::ConstraintLocator *locator;
185
182
@@ -191,45 +188,53 @@ class TypeVariableType::Implementation {
191
188
// / The corresponding node in the constraint graph.
192
189
constraints::ConstraintGraphNode *GraphNode = nullptr ;
193
190
194
- // / Index into the list of type variables, as used by the
195
- // / constraint graph.
196
- unsigned GraphIndex;
197
-
198
191
friend class constraints ::SavedTypeVariableBinding;
199
192
200
193
public:
194
+ // / \brief Retrieve the type variable associated with this implementation.
195
+ TypeVariableType *getTypeVariable () {
196
+ return reinterpret_cast <TypeVariableType *>(this ) - 1 ;
197
+ }
198
+
199
+ // / \brief Retrieve the type variable associated with this implementation.
200
+ const TypeVariableType *getTypeVariable () const {
201
+ return reinterpret_cast <const TypeVariableType *>(this ) - 1 ;
202
+ }
203
+
201
204
explicit Implementation (constraints::ConstraintLocator *locator,
202
205
unsigned options)
203
- : Options(options), locator(locator),
204
- ParentOrFixed(getTypeVariable()) { }
206
+ : locator(locator), ParentOrFixed(getTypeVariable()) {
207
+ getTypeVariable ()->TypeVariableTypeBits .Options = options;
208
+ }
205
209
206
210
// / \brief Retrieve the unique ID corresponding to this type variable.
207
211
unsigned getID () const { return getTypeVariable ()->getID (); }
208
212
213
+ unsigned getRawOptions () const {
214
+ return getTypeVariable ()->TypeVariableTypeBits .Options ;
215
+ }
216
+
217
+ void setRawOptions (unsigned bits) {
218
+ getTypeVariable ()->TypeVariableTypeBits .Options = bits;
219
+ assert (getTypeVariable ()->TypeVariableTypeBits .Options == bits
220
+ && " Trucation" );
221
+ }
222
+
209
223
// / Whether this type variable can bind to an lvalue type.
210
- bool canBindToLValue () const { return Options & TVO_CanBindToLValue; }
224
+ bool canBindToLValue () const { return getRawOptions () & TVO_CanBindToLValue; }
211
225
212
226
// / Whether this type variable can bind to an inout type.
213
- bool canBindToInOut () const { return Options & TVO_CanBindToInOut; }
227
+ bool canBindToInOut () const { return getRawOptions () & TVO_CanBindToInOut; }
214
228
215
229
// / Whether this type variable prefers a subtype binding over a supertype
216
230
// / binding.
217
231
bool prefersSubtypeBinding () const {
218
- return Options & TVO_PrefersSubtypeBinding;
232
+ return getRawOptions () & TVO_PrefersSubtypeBinding;
219
233
}
220
234
221
235
bool mustBeMaterializable () const {
222
- return !(Options & TVO_CanBindToInOut) && !(Options & TVO_CanBindToLValue);
223
- }
224
-
225
- // / \brief Retrieve the type variable associated with this implementation.
226
- TypeVariableType *getTypeVariable () {
227
- return reinterpret_cast <TypeVariableType *>(this ) - 1 ;
228
- }
229
-
230
- // / \brief Retrieve the type variable associated with this implementation.
231
- const TypeVariableType *getTypeVariable () const {
232
- return reinterpret_cast <const TypeVariableType *>(this ) - 1 ;
236
+ return !(getRawOptions () & TVO_CanBindToInOut) &&
237
+ !(getRawOptions () & TVO_CanBindToLValue);
233
238
}
234
239
235
240
// / Retrieve the corresponding node in the constraint graph.
@@ -243,11 +248,13 @@ class TypeVariableType::Implementation {
243
248
// / Retrieve the index into the constraint graph's list of type variables.
244
249
unsigned getGraphIndex () const {
245
250
assert (GraphNode && " Graph node isn't set" );
246
- return GraphIndex;
251
+ return getTypeVariable ()-> TypeVariableTypeBits . GraphIndex ;
247
252
}
248
253
249
254
// / Set the index into the constraint graph's list of type variables.
250
- void setGraphIndex (unsigned newIndex) { GraphIndex = newIndex; }
255
+ void setGraphIndex (unsigned newIndex) {
256
+ getTypeVariable ()->TypeVariableTypeBits .GraphIndex = newIndex;
257
+ }
251
258
252
259
// / \brief Check whether this type variable either has a representative that
253
260
// / is not itself or has a fixed type binding.
@@ -339,8 +346,8 @@ class TypeVariableType::Implementation {
339
346
if (!mustBeMaterializable () && otherRep->getImpl ().mustBeMaterializable ()) {
340
347
if (record)
341
348
recordBinding (*record);
342
- Options &= ~TVO_CanBindToLValue;
343
- Options &= ~TVO_CanBindToInOut;
349
+ getTypeVariable ()-> TypeVariableTypeBits . Options &= ~TVO_CanBindToLValue;
350
+ getTypeVariable ()-> TypeVariableTypeBits . Options &= ~TVO_CanBindToInOut;
344
351
}
345
352
}
346
353
@@ -381,8 +388,10 @@ class TypeVariableType::Implementation {
381
388
if (!rep->getImpl ().mustBeMaterializable ()) {
382
389
if (record)
383
390
rep->getImpl ().recordBinding (*record);
384
- rep->getImpl ().Options &= ~TVO_CanBindToLValue;
385
- rep->getImpl ().Options &= ~TVO_CanBindToInOut;
391
+ rep->getImpl ().getTypeVariable ()->TypeVariableTypeBits .Options
392
+ &= ~TVO_CanBindToLValue;
393
+ rep->getImpl ().getTypeVariable ()->TypeVariableTypeBits .Options
394
+ &= ~TVO_CanBindToInOut;
386
395
}
387
396
}
388
397
0 commit comments