Skip to content

Commit 48f2453

Browse files
committed
[NFC] Rearrange irgen::MetadataSource initializers
Preparing to accommodate additional layouts for MetadataSource.
1 parent 9da193e commit 48f2453

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ class PolymorphicConvention {
134134

135135
private:
136136
void initGenerics();
137-
void considerNewTypeSource(MetadataSource::Kind kind, unsigned paramIndex,
138-
CanType type, IsExact_t isExact);
137+
138+
template <typename ...Args>
139+
void considerNewTypeSource(IsExact_t isExact, MetadataSource::Kind kind,
140+
CanType type, Args... args);
139141
bool considerType(CanType type, IsExact_t isExact,
140142
unsigned sourceIndex, MetadataPath &&path);
141143

@@ -302,14 +304,15 @@ void PolymorphicConvention::initGenerics() {
302304
Generics = FnType->getInvocationGenericSignature();
303305
}
304306

305-
void PolymorphicConvention::considerNewTypeSource(MetadataSource::Kind kind,
306-
unsigned paramIndex,
307+
template <typename ...Args>
308+
void PolymorphicConvention::considerNewTypeSource(IsExact_t isExact,
309+
MetadataSource::Kind kind,
307310
CanType type,
308-
IsExact_t isExact) {
311+
Args... args) {
309312
if (!Fulfillments.isInterestingTypeForFulfillments(type)) return;
310313

311314
// Prospectively add a source.
312-
Sources.emplace_back(kind, paramIndex, type);
315+
Sources.emplace_back(kind, type, std::forward<Args>(args)...);
313316

314317
// Consider the source.
315318
if (!considerType(type, isExact, Sources.size() - 1, MetadataPath())) {
@@ -333,9 +336,7 @@ void PolymorphicConvention::considerWitnessSelf(CanSILFunctionType fnType) {
333336
auto conformance = fnType->getWitnessMethodConformanceOrInvalid();
334337

335338
// First, bind type metadata for Self.
336-
Sources.emplace_back(MetadataSource::Kind::SelfMetadata,
337-
MetadataSource::InvalidSourceIndex,
338-
selfTy);
339+
Sources.emplace_back(MetadataSource::Kind::SelfMetadata, selfTy);
339340

340341
if (selfTy->is<GenericTypeParamType>()) {
341342
// The Self type is abstract, so we can fulfill its metadata from
@@ -347,8 +348,7 @@ void PolymorphicConvention::considerWitnessSelf(CanSILFunctionType fnType) {
347348

348349
// The witness table for the Self : P conformance can be
349350
// fulfilled from the Self witness table parameter.
350-
Sources.emplace_back(MetadataSource::Kind::SelfWitnessTable,
351-
MetadataSource::InvalidSourceIndex, selfTy);
351+
Sources.emplace_back(MetadataSource::Kind::SelfWitnessTable, selfTy);
352352
addSelfWitnessTableFulfillment(selfTy, conformance);
353353
}
354354

@@ -359,8 +359,7 @@ void PolymorphicConvention::considerObjCGenericSelf(CanSILFunctionType fnType) {
359359
unsigned paramIndex = fnType->getParameters().size() - 1;
360360

361361
// Bind type metadata for Self.
362-
Sources.emplace_back(MetadataSource::Kind::ClassPointer, paramIndex,
363-
selfTy);
362+
Sources.emplace_back(MetadataSource::Kind::ClassPointer, selfTy, paramIndex);
364363

365364
if (isa<GenericTypeParamType>(selfTy))
366365
addSelfMetadataFulfillment(selfTy);
@@ -385,8 +384,9 @@ void PolymorphicConvention::considerParameter(SILParameterInfo param,
385384
case ParameterConvention::Indirect_InoutAliasable:
386385
if (!isSelfParameter) return;
387386
if (type->getNominalOrBoundGenericNominal()) {
388-
considerNewTypeSource(MetadataSource::Kind::GenericLValueMetadata,
389-
paramIndex, type, IsExact);
387+
considerNewTypeSource(IsExact,
388+
MetadataSource::Kind::GenericLValueMetadata,
389+
type, paramIndex);
390390
}
391391
return;
392392

@@ -395,15 +395,15 @@ void PolymorphicConvention::considerParameter(SILParameterInfo param,
395395
case ParameterConvention::Direct_Guaranteed:
396396
// Classes are sources of metadata.
397397
if (type->getClassOrBoundGenericClass()) {
398-
considerNewTypeSource(MetadataSource::Kind::ClassPointer,
399-
paramIndex, type, IsInexact);
398+
considerNewTypeSource(IsInexact, MetadataSource::Kind::ClassPointer,
399+
type, paramIndex);
400400
return;
401401
}
402402

403403
if (isa<GenericTypeParamType>(type)) {
404404
if (auto superclassTy = getSuperclassBound(type)) {
405-
considerNewTypeSource(MetadataSource::Kind::ClassPointer,
406-
paramIndex, superclassTy, IsInexact);
405+
considerNewTypeSource(IsInexact, MetadataSource::Kind::ClassPointer,
406+
superclassTy, paramIndex);
407407
return;
408408

409409
}
@@ -421,8 +421,8 @@ void PolymorphicConvention::considerParameter(SILParameterInfo param,
421421
if (classDecl->isTypeErasedGenericClass())
422422
return;
423423

424-
considerNewTypeSource(MetadataSource::Kind::Metadata,
425-
paramIndex, objTy, IsInexact);
424+
considerNewTypeSource(IsInexact, MetadataSource::Kind::Metadata, objTy,
425+
paramIndex);
426426
return;
427427
}
428428

lib/IRGen/GenProto.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,21 @@ namespace irgen {
217217
public:
218218
CanType Type;
219219

220-
MetadataSource(Kind kind, unsigned index, CanType type)
220+
MetadataSource(Kind kind, CanType type)
221+
: TheKind(kind), Index(InvalidSourceIndex), Type(type)
222+
{
223+
assert(!requiresSourceIndex(kind));
224+
}
225+
226+
227+
MetadataSource(Kind kind, CanType type, unsigned index)
221228
: TheKind(kind), Index(index), Type(type) {
222-
assert(index != InvalidSourceIndex || !requiresSourceIndex(kind));
229+
assert(requiresSourceIndex(kind));
230+
assert(index != InvalidSourceIndex);
223231
}
224232

225233
Kind getKind() const { return TheKind; }
234+
226235
unsigned getParamIndex() const {
227236
assert(requiresSourceIndex(getKind()));
228237
return Index;

0 commit comments

Comments
 (0)