Skip to content

Commit 5a87435

Browse files
committed
[Runtime] Simplify ProtocolConformanceDescriptor::getWitnessTable().
Use SubstGenericParametersFromMetadata to handle substitutions when checking generic requirements, extending SubstGenericParametersFromMetadata for this purpose.
1 parent 0a775da commit 5a87435

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,12 @@ swift_getTypeByMangledNameImpl(const char *typeNameStart, size_t typeNameLength,
12231223
return swift_checkMetadataState(MetadataState::Complete, metadata).Value;
12241224
}
12251225

1226+
const Metadata *
1227+
SubstGenericParametersFromMetadata::operator()(unsigned flatIndex) const {
1228+
// FIXME: Adjust for non-key arguments.
1229+
return base->getGenericArgs()[flatIndex];
1230+
}
1231+
12261232
const Metadata *
12271233
SubstGenericParametersFromMetadata::operator()(
12281234
unsigned depth, unsigned index) const {
@@ -1259,6 +1265,7 @@ SubstGenericParametersFromMetadata::operator()(
12591265
if (index >= currentContext->getNumGenericParams())
12601266
return nullptr;
12611267

1268+
// FIXME: Adjust for non-key arguments.
12621269
return base->getGenericArgs()[flatIndex];
12631270
}
12641271

stdlib/public/runtime/Private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class TypeInfo {
248248
explicit SubstGenericParametersFromMetadata(const Metadata *base)
249249
: base(base) { }
250250

251+
const Metadata *operator()(unsigned flatIndex) const;
251252
const Metadata *operator()(unsigned depth, unsigned index) const;
252253
};
253254

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,11 @@ ProtocolConformanceDescriptor::getWitnessTable(const Metadata *type) const {
177177

178178
case ConformanceFlags::ConformanceKind::ConditionalWitnessTableAccessor: {
179179
// Check the conditional requirements.
180-
std::vector<unsigned> genericParamCounts;
181-
(void)_gatherGenericParameterCounts(type->getTypeContextDescriptor(),
182-
genericParamCounts);
183-
auto genericArgs = type->getGenericArgs();
180+
SubstGenericParametersFromMetadata substitutions(type);
184181
std::vector<const void *> conditionalArgs;
185182
bool failed =
186183
_checkGenericRequirements(getConditionalRequirements(), conditionalArgs,
187-
[&](unsigned flatIndex) {
188-
// FIXME: Adjust for non-key type parameters.
189-
return genericArgs[flatIndex];
190-
},
191-
[&](unsigned depth, unsigned index) -> const Metadata * {
192-
// FIXME: Adjust for non-key type parameters.
193-
if (auto flatIndex = _depthIndexToFlatIndex(depth, index,
194-
genericParamCounts)) {
195-
return genericArgs[*flatIndex];
196-
}
197-
198-
return nullptr;
199-
});
184+
substitutions, substitutions);
200185
if (failed) return nullptr;
201186

202187
return getWitnessTableAccessor()(

0 commit comments

Comments
 (0)