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

Kill validateExtension #27279

merged 3 commits into from
Sep 21, 2019

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Sep 20, 2019

Discharge the work the callers of validateExtension actually wanted done into those callers. This patch is bittersweet: It kills one dead cycle check, but adds another unrelated one.

@CodaFi CodaFi requested a review from slavapestov September 20, 2019 21:05
@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 20, 2019

@swift-ci please smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 20, 2019

No idea what the LLDB failure is.

@swift-ci please smoke test macOS platform

@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 20, 2019

And because moving cycles changes adopters for awful reasons:

@swift-ci please test source compatibility

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress so far! Feel free to land this whenever it works -- we can address the follow-up work later.

lib/AST/Type.cpp Outdated
if (auto valueDecl = dyn_cast<ValueDecl>(decl))
resolver->resolveDeclSignature(valueDecl);
if (auto valueDecl = decl->getAsGenericContext())
(void)valueDecl->getGenericSignature();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, we can use getGenericContextDepth() directly to compute the depth here.

// Validate the nominal type declaration being extended.
TC.validateDecl(nominal);
// Don't bother computing the generic signature if the extended nominal
// type didn't pass validation so we don't crash.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests that crash without the isInvalid() check? It's unfortunate. We should fix that in a follow-up too.

tc.validateDecl(extendedNominal);
if (extendedNominal->isInvalid())
return true;

// Assume unconstrained concrete extensions we found witnesses in are
// always viable.
if (!isa<ProtocolDecl>(extendedNominal))
return !extension->isConstrainedExtension();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isConstrainedExtension() calls getGenericSignature(). It could probably just be a syntactic property instead, by checking for the presence of a parsed where clause.

// Build a generic signature.
tc.validateExtension(extension);


// FIXME: The extension may not have a generic signature set up yet as
// resolving signatures may trigger associated type inference. This cycle
// is now detectable and we should look into untangling it
// - see rdar://55263708
if (!extension->hasComputedGenericSignature())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the above isConstrainedExtension() check, this is only going to be hit for protocol extensions...

if (auto ext = dyn_cast<ExtensionDecl>(D)) {
if (auto *nominal = ext->getExtendedNominal()) {
// Validate the nominal type declaration being extended.
TC.validateDecl(nominal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably unnecessary

@@ -1017,10 +1017,6 @@ class TypeChecker final : public LazyResolver {
validateDecl(proto);
}

virtual void resolveExtension(ExtensionDecl *ext) override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay!

If it's going to validate the declaration, it wants to know if there's an interface type.  Computing the generic signature can be done on demand.
The general class of cycle here is when validation asks for the generic signature which triggers requirement checking which forces us to ask for the generic signature of the extension again.  We should look into a more principled solution.

See rdar://55263708
@CodaFi CodaFi force-pushed the eggs-tension-service branch from 1218e16 to e7fccde Compare September 21, 2019 03:39
@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 21, 2019

@swift-ci please smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 21, 2019

⛵️

@CodaFi CodaFi merged commit 9913470 into swiftlang:master Sep 21, 2019
@CodaFi CodaFi deleted the eggs-tension-service branch September 21, 2019 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants