Skip to content

[Type checker] Refactor override checking #17733

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 8 commits into from
Jul 4, 2018

Conversation

DougGregor
Copy link
Member

Break the gigantic swift::checkOverrides() into a few separable pieces
encapsulated in a new class, OverrideMatcher:

  • Setup: establish whether we can do matching at all
  • Matching: check whether we have a match based on a set of checking rules
  • Checking: check that the selected override is semantically correct
  • Search: apply various matching rules to try to find the overridden declaration

While here, limit the dependencies of override checking somewhat.
Specifically, don’t ask for the type of the declaration until we’ve found
a potential overridden declaration to check against, and even then only do
it when the “simple” checks fail.

This is a separable path; give it its own path and isolate the state changes
to TypeChecker::resolveOverriddenDecl(). NFC.
Break the gigantic swift::checkOverrides() into a few separable pieces
encapsulated in a new class, OverrideMatcher:

* Setup: establish whether we can do matching at all
* Matching: check whether we have a match based on a set of checking rules
* Checking: check that the selected override is semantically correct
* Search: apply various matching rules to try to find the overridden declaration

While here, limit the dependencies of override checking somewhat. 
Specifically, don’t ask for the type of the declaration until we’ve found
a potential overridden declaration to check against, and even then only do
it when the “simple” checks fail.
…-C interop.

For reasons lost to history and not interesting enough to uncover, the
“override” computation performed a check of the overriding declaration’s
Objective-C selector against the potentially-overridden declaration’s
Objective-C selector. This introduced a cycle dependency between
the “is exposed to Objective-C” computation and the “overridden declarations”
computation, because @objc is inherited from an overridden declaration.

We’ll detect the same errors via other, existing diagnostics, so prune
out the Objective-C selector checks from the override path.
ValueDecl::getOverriddenDecl(s)() does this for us automagically.
resolveOverriddenDecl() is meant to be used to provide access to the
overridden declarations, e.g., from another source file. Only resolve
when the declaration has an explicit ‘override’ modifier or is an
initializer (for which there are cases where ‘override’ is not
required).

This does not yet reduce override checking across source files,
because checkOverrides() is still called during
validateDeclForNameLookup(), and we’re still doing too much work to
compute overrides.
…bit.

Because, you know, I’d like it to do what it says it does.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 1b91f00 into swiftlang:master Jul 4, 2018
@DougGregor DougGregor deleted the refactor-override-checking branch July 4, 2018 05:04
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