@@ -101,7 +101,7 @@ class GenericTypeParamType;
101
101
// / both the generic type parameters and the requirements placed on those
102
102
// / generic parameters.
103
103
class GenericSignature {
104
- GenericSignatureImpl *Ptr;
104
+ const GenericSignatureImpl *Ptr;
105
105
106
106
public:
107
107
// / Create a new generic signature with the given type parameters and
@@ -118,13 +118,13 @@ class GenericSignature {
118
118
ArrayRef<Requirement> requirements);
119
119
120
120
public:
121
- /* implicit*/ GenericSignature(GenericSignatureImpl *P = 0 ) : Ptr(P) {}
121
+ /* implicit*/ GenericSignature(const GenericSignatureImpl *P = 0 ) : Ptr(P) {}
122
122
123
- GenericSignatureImpl *getPointer () const { return Ptr; }
123
+ const GenericSignatureImpl *getPointer () const { return Ptr; }
124
124
125
125
bool isNull () const { return Ptr == 0 ; }
126
126
127
- GenericSignatureImpl *operator ->() const { return Ptr; }
127
+ const GenericSignatureImpl *operator ->() const { return Ptr; }
128
128
129
129
explicit operator bool () const { return Ptr != 0 ; }
130
130
@@ -175,7 +175,7 @@ class CanGenericSignature : public GenericSignature {
175
175
public:
176
176
CanGenericSignature (std::nullptr_t ) : GenericSignature(nullptr ) {}
177
177
178
- explicit CanGenericSignature (GenericSignatureImpl *P = 0 )
178
+ explicit CanGenericSignature (const GenericSignatureImpl *P = 0 )
179
179
: GenericSignature(P) {
180
180
assert (isActuallyCanonicalOrNull () &&
181
181
" Forming a CanGenericSignature out of a non-canonical signature!" );
@@ -204,8 +204,8 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
204
204
GenericSignatureImpl (const GenericSignatureImpl&) = delete ;
205
205
void operator =(const GenericSignatureImpl&) = delete ;
206
206
207
- unsigned NumGenericParams;
208
- unsigned NumRequirements;
207
+ const unsigned NumGenericParams;
208
+ const unsigned NumRequirements;
209
209
210
210
GenericEnvironment *GenericEnv = nullptr ;
211
211
@@ -220,39 +220,29 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
220
220
return NumRequirements;
221
221
}
222
222
223
- // / Retrieve a mutable version of the generic parameters.
224
- MutableArrayRef<Type> getGenericParamsBuffer () {
225
- return {getTrailingObjects<Type>(), NumGenericParams};
226
- }
227
-
228
- // / Retrieve a mutable version of the requirements.
229
- MutableArrayRef<Requirement> getRequirementsBuffer () {
230
- return {getTrailingObjects<Requirement>(), NumRequirements};
231
- }
232
-
233
223
GenericSignatureImpl (TypeArrayView<GenericTypeParamType> params,
234
224
ArrayRef<Requirement> requirements,
235
225
bool isKnownCanonical);
236
226
237
227
// FIXME: Making this a CanGenericSignature reveals callers are violating
238
228
// the interface's invariants.
239
- mutable llvm::PointerUnion<GenericSignatureImpl *, ASTContext *>
229
+ mutable llvm::PointerUnion<const GenericSignatureImpl *, ASTContext *>
240
230
CanonicalSignatureOrASTContext;
241
231
242
232
void buildConformanceAccessPath (
243
233
SmallVectorImpl<ConformanceAccessPath::Entry> &path,
244
234
ArrayRef<Requirement> reqs,
245
235
const void /* GenericSignatureBuilder::RequirementSource*/ *source,
246
236
ProtocolDecl *conformingProto, Type rootType,
247
- ProtocolDecl *requirementSignatureProto);
237
+ ProtocolDecl *requirementSignatureProto) const ;
248
238
249
239
friend class ArchetypeType ;
250
240
251
241
public:
252
242
// / Retrieve the generic parameters.
253
243
TypeArrayView<GenericTypeParamType> getGenericParams () const {
254
- auto temp = const_cast <GenericSignatureImpl *>( this );
255
- return TypeArrayView<GenericTypeParamType>(temp-> getGenericParamsBuffer () );
244
+ return TypeArrayView<GenericTypeParamType>(
245
+ {getTrailingObjects<Type>(), NumGenericParams} );
256
246
}
257
247
258
248
// / Retrieve the innermost generic parameters.
@@ -263,7 +253,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
263
253
264
254
// / Retrieve the requirements.
265
255
ArrayRef<Requirement> getRequirements () const {
266
- return const_cast <GenericSignatureImpl *>( this )-> getRequirementsBuffer () ;
256
+ return {getTrailingObjects<Requirement>(), NumRequirements} ;
267
257
}
268
258
269
259
// / Only allow allocation by doing a placement new.
@@ -299,7 +289,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
299
289
}
300
290
301
291
// / Return true if these two generic signatures are equal.
302
- bool isEqual (GenericSignature Other);
292
+ bool isEqual (GenericSignature Other) const ;
303
293
304
294
// / Determines whether this GenericSignature is canonical.
305
295
bool isCanonical () const ;
@@ -310,55 +300,55 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
310
300
CanGenericSignature getCanonicalSignature () const ;
311
301
312
302
// / Retrieve the generic signature builder for the given generic signature.
313
- GenericSignatureBuilder *getGenericSignatureBuilder ();
303
+ GenericSignatureBuilder *getGenericSignatureBuilder () const ;
314
304
315
305
// / Returns the generic environment that provides fresh contextual types
316
306
// / (archetypes) that correspond to the interface types in this generic
317
307
// / signature.
318
- GenericEnvironment *getGenericEnvironment ();
308
+ GenericEnvironment *getGenericEnvironment () const ;
319
309
320
310
// / Uniquing for the ASTContext.
321
- void Profile (llvm::FoldingSetNodeID &ID) {
311
+ void Profile (llvm::FoldingSetNodeID &ID) const {
322
312
Profile (ID, getGenericParams (), getRequirements ());
323
313
}
324
314
325
315
// / Determine whether the given dependent type is required to be a class.
326
- bool requiresClass (Type type);
316
+ bool requiresClass (Type type) const ;
327
317
328
318
// / Determine the superclass bound on the given dependent type.
329
- Type getSuperclassBound (Type type);
319
+ Type getSuperclassBound (Type type) const ;
330
320
331
321
// / Determine the set of protocols to which the given dependent type
332
322
// / must conform.
333
- GenericSignature::ConformsToArray getConformsTo (Type type);
323
+ GenericSignature::ConformsToArray getConformsTo (Type type) const ;
334
324
335
325
// / Determine whether the given dependent type conforms to this protocol.
336
- bool conformsToProtocol (Type type, ProtocolDecl *proto);
326
+ bool conformsToProtocol (Type type, ProtocolDecl *proto) const ;
337
327
338
328
// / Determine whether the given dependent type is equal to a concrete type.
339
- bool isConcreteType (Type type);
329
+ bool isConcreteType (Type type) const ;
340
330
341
331
// / Return the concrete type that the given dependent type is constrained to,
342
332
// / or the null Type if it is not the subject of a concrete same-type
343
333
// / constraint.
344
- Type getConcreteType (Type type);
334
+ Type getConcreteType (Type type) const ;
345
335
346
336
// / Return the layout constraint that the given dependent type is constrained
347
337
// / to, or the null LayoutConstraint if it is not the subject of layout
348
338
// / constraint.
349
- LayoutConstraint getLayoutConstraint (Type type);
339
+ LayoutConstraint getLayoutConstraint (Type type) const ;
350
340
351
341
// / Return whether two type parameters represent the same type under this
352
342
// / generic signature.
353
343
// /
354
344
// / The type parameters must be known to not be concrete within the context.
355
- bool areSameTypeParameterInContext (Type type1, Type type2);
345
+ bool areSameTypeParameterInContext (Type type1, Type type2) const ;
356
346
357
347
// / Determine if \c sig can prove \c requirement, meaning that it can deduce
358
348
// / T: Foo or T == U (etc.) with the information it knows. This includes
359
349
// / checking against global state, if any/all of the types in the requirement
360
350
// / are concrete, not type parameters.
361
- bool isRequirementSatisfied (Requirement requirement);
351
+ bool isRequirementSatisfied (Requirement requirement) const ;
362
352
363
353
// / Return the requirements of this generic signature that are not also
364
354
// / satisfied by \c otherSig.
@@ -370,14 +360,15 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
370
360
371
361
// / Return the canonical version of the given type under this generic
372
362
// / signature.
373
- CanType getCanonicalTypeInContext (Type type);
374
- bool isCanonicalTypeInContext (Type type);
363
+ CanType getCanonicalTypeInContext (Type type) const ;
364
+ bool isCanonicalTypeInContext (Type type) const ;
375
365
376
366
// / Return the canonical version of the given type under this generic
377
367
// / signature.
378
368
CanType getCanonicalTypeInContext (Type type,
379
- GenericSignatureBuilder &builder);
380
- bool isCanonicalTypeInContext (Type type, GenericSignatureBuilder &builder);
369
+ GenericSignatureBuilder &builder) const ;
370
+ bool isCanonicalTypeInContext (Type type,
371
+ GenericSignatureBuilder &builder) const ;
381
372
382
373
// / Retrieve the conformance access path used to extract the conformance of
383
374
// / interface \c type to the given \c protocol.
@@ -392,14 +383,14 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
392
383
// /
393
384
// / \seealso ConformanceAccessPath
394
385
ConformanceAccessPath getConformanceAccessPath (Type type,
395
- ProtocolDecl *protocol);
386
+ ProtocolDecl *protocol) const ;
396
387
397
388
// / Get the ordinal of a generic parameter in this generic signature.
398
389
// /
399
390
// / For example, if you have a generic signature for a nested context like:
400
391
// / <t_0_0, t_0_1, t_1_0>
401
392
// / then this will return 0 for t_0_0, 1 for t_0_1, and 2 for t_1_0.
402
- unsigned getGenericParamOrdinal (GenericTypeParamType *param);
393
+ unsigned getGenericParamOrdinal (GenericTypeParamType *param) const ;
403
394
404
395
// / Get a substitution map that maps all of the generic signature's
405
396
// / generic parameters to themselves.
@@ -440,7 +431,7 @@ static inline raw_ostream &operator<<(raw_ostream &OS,
440
431
441
432
// A GenericSignature casts like a GenericSignatureImpl*.
442
433
template <> struct simplify_type <const ::swift::GenericSignature> {
443
- typedef ::swift::GenericSignatureImpl *SimpleType;
434
+ typedef const ::swift::GenericSignatureImpl *SimpleType;
444
435
static SimpleType getSimplifiedValue (const ::swift::GenericSignature &Val) {
445
436
return Val.getPointer ();
446
437
}
0 commit comments