mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] Factor out GenericSignature::forInvalid
Factor out the common logic from `getPlaceholderGenericSignature`.
This commit is contained in:
@@ -120,6 +120,10 @@ public:
|
||||
ArrayRef<Requirement> requirements,
|
||||
bool isKnownCanonical = false);
|
||||
|
||||
/// Create a new placeholder generic signature from a set of generic
|
||||
/// parameters. This is necessary for recovery in invalid cases.
|
||||
static GenericSignature forInvalid(ArrayRef<GenericTypeParamType *> params);
|
||||
|
||||
/// Produce a new generic signature which drops all of the marker
|
||||
/// protocol conformance requirements associated with this one.
|
||||
GenericSignature withoutMarkerProtocols() const;
|
||||
|
||||
@@ -6007,6 +6007,25 @@ GenericSignature::get(ArrayRef<GenericTypeParamType *> params,
|
||||
return newSig;
|
||||
}
|
||||
|
||||
GenericSignature
|
||||
GenericSignature::forInvalid(ArrayRef<GenericTypeParamType *> params) {
|
||||
ASSERT(!params.empty());
|
||||
auto &ctx = params.front()->getASTContext();
|
||||
|
||||
SmallVector<Requirement, 2> requirements;
|
||||
for (auto *param : params) {
|
||||
if (param->isValue())
|
||||
continue;
|
||||
|
||||
for (auto ip : InvertibleProtocolSet::allKnown()) {
|
||||
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
|
||||
requirements.emplace_back(RequirementKind::Conformance, param,
|
||||
proto->getDeclaredInterfaceType());
|
||||
}
|
||||
}
|
||||
return GenericSignature::get(params, requirements);
|
||||
}
|
||||
|
||||
GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
|
||||
auto &ctx = signature->getASTContext();
|
||||
|
||||
|
||||
@@ -1660,22 +1660,13 @@ static GenericSignature getPlaceholderGenericSignature(
|
||||
gpLists[i]->setDepth(i);
|
||||
|
||||
SmallVector<GenericTypeParamType *, 2> genericParams;
|
||||
SmallVector<Requirement, 2> requirements;
|
||||
|
||||
for (auto *gpList : gpLists) {
|
||||
for (auto *genericParam : *gpList) {
|
||||
auto type = genericParam->getDeclaredInterfaceType();
|
||||
genericParams.push_back(type->castTo<GenericTypeParamType>());
|
||||
|
||||
for (auto ip : InvertibleProtocolSet::allKnown()) {
|
||||
auto proto = ctx.getProtocol(getKnownProtocolKind(ip));
|
||||
requirements.emplace_back(RequirementKind::Conformance, type,
|
||||
proto->getDeclaredInterfaceType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GenericSignature::get(genericParams, requirements);
|
||||
return GenericSignature::forInvalid(genericParams);
|
||||
}
|
||||
|
||||
GenericSignature GenericContext::getGenericSignature() const {
|
||||
|
||||
@@ -750,26 +750,6 @@ AbstractGenericSignatureRequest::evaluate(
|
||||
}
|
||||
}
|
||||
|
||||
/// If completion fails, build a dummy generic signature where everything is
|
||||
/// Copyable and Escapable, to avoid spurious downstream diagnostics
|
||||
/// concerning move-only types.
|
||||
static GenericSignature getPlaceholderGenericSignature(
|
||||
ASTContext &ctx, ArrayRef<GenericTypeParamType *> genericParams) {
|
||||
SmallVector<Requirement, 2> requirements;
|
||||
for (auto param : genericParams) {
|
||||
if (param->isValue())
|
||||
continue;
|
||||
|
||||
for (auto ip : InvertibleProtocolSet::allKnown()) {
|
||||
auto proto = ctx.getProtocol(getKnownProtocolKind(ip));
|
||||
requirements.emplace_back(RequirementKind::Conformance, param,
|
||||
proto->getDeclaredInterfaceType());
|
||||
}
|
||||
}
|
||||
|
||||
return GenericSignature::get(genericParams, requirements);
|
||||
}
|
||||
|
||||
GenericSignatureWithError
|
||||
InferredGenericSignatureRequest::evaluate(
|
||||
Evaluator &evaluator,
|
||||
@@ -996,7 +976,7 @@ InferredGenericSignatureRequest::evaluate(
|
||||
diag::requirement_machine_completion_rule,
|
||||
rule);
|
||||
|
||||
auto result = getPlaceholderGenericSignature(ctx, genericParams);
|
||||
auto result = GenericSignature::forInvalid(genericParams);
|
||||
|
||||
if (rewriteCtx.getDebugOptions().contains(DebugFlags::Timers)) {
|
||||
rewriteCtx.endTimer("InferredGenericSignatureRequest");
|
||||
|
||||
Reference in New Issue
Block a user