Skip to content

Kill validateExtension #27279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ class GenericContext : private _GenericContext, public DeclContext {
/// \endcode
bool isGeneric() const { return getGenericParams() != nullptr; }
bool hasComputedGenericSignature() const;
bool isComputingGenericSignature() const;

/// Retrieve the trailing where clause for this extension, if any.
TrailingWhereClause *getTrailingWhereClause() const {
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ GenericParamList *GenericContext::getGenericParams() const {
bool GenericContext::hasComputedGenericSignature() const {
return GenericSigAndBit.getInt();
}

bool GenericContext::isComputingGenericSignature() const {
return getASTContext().evaluator.hasActiveRequest(
GenericSignatureRequest{const_cast<GenericContext*>(this)});
}

GenericSignature *GenericContext::getGenericSignature() const {
return evaluateOrDefault(
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
// If the decl is currently being validated, this is likely a recursive
// reference and we'll want to skip ahead so as to avoid having its type
// attempt to desugar itself.
if (!decl->hasValidSignature())
if (!decl->hasInterfaceType())
continue;

// FIXME: the canonical type makes a poor signature, because we don't
Expand Down
34 changes: 14 additions & 20 deletions lib/AST/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
assert(CRState == ConditionalRequirementsState::Computing);
CRState = ConditionalRequirementsState::Uncomputed;
};

auto &ctxt = getProtocol()->getASTContext();
auto DC = getDeclContext();
// A non-extension conformance won't have conditional requirements.
Expand All @@ -550,30 +550,24 @@ void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
return;
}

// The type is generic, but the extension doesn't have a signature yet, so
// we might be in a recursive validation situation.
if (!ext->hasComputedGenericSignature()) {
// If the extension is invalid, it won't ever get a signature, so we
// "succeed" with an empty result instead.
if (ext->isInvalid()) {
success({});
return;
}
// If the extension is invalid, it won't ever get a signature, so we
// "succeed" with an empty result instead.
if (ext->isInvalid()) {
success({});
return;
}

// Otherwise we'll try again later.
// Recursively validating the signature comes up frequently as expanding
// conformance requirements might re-enter this method. We can at least catch
// this and come back to these requirements later.
//
// FIXME: In the long run, break this cycle in a more principled way.
if (ext->isComputingGenericSignature()) {
failure();
return;
}

// FIXME: All of this will be removed when validateExtension goes away.
auto extensionSig = ext->getGenericSignature();
if (!extensionSig) {
if (auto lazyResolver = ctxt.getLazyResolver()) {
lazyResolver->resolveExtension(ext);
extensionSig = ext->getGenericSignature();
}
}

auto extensionSig = ext->getGenericSignature();
auto canExtensionSig = extensionSig->getCanonicalSignature();
auto canTypeSig = typeSig->getCanonicalSignature();
if (canTypeSig == canExtensionSig) {
Expand Down
10 changes: 0 additions & 10 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,6 @@ Type ConstraintSystem::openUnboundGenericType(UnboundGenericType *unbound,
ConstraintLocatorBuilder locator,
OpenedTypeMap &replacements) {
auto unboundDecl = unbound->getDecl();

// If the unbound decl hasn't been validated yet, we have a circular
// dependency that isn't being diagnosed properly.
//
// FIXME: Delete this condition. He's dead Jim.
if (!unboundDecl->hasComputedGenericSignature()) {
TC.diagnose(unboundDecl, diag::circular_reference);
return Type();
}

auto parentTy = unbound->getParent();
if (parentTy) {
parentTy = openUnboundGenericType(parentTy, locator);
Expand Down