Skip to content

Requestify Witness Resolution #28009

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

Closed
wants to merge 1 commit into from
Closed

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Nov 1, 2019

Witness matching is a source of a lot of ad-hoc cycles, and mixes the
logic that performs resolution, caching, validation, and cycle breaking into one
place. To make matters worse, some checkers kick off other checks in
order to cache work for further declarations, and access an internal
cache on their subject conformance for many requirements at once, or
sometimes just one requirement.

None of this fits into the request evaluator's central view of
caching. This is further evidenced by the fact that if you attempt to
move the caching step into the evaluator, it overcaches the same
witness and trips asserts.

As a start, define requests for the resolution steps, and flush some
hacks around forcing witness resolution. The caching logic is mostly
untouched (the requests don't actually cache anything), but some cycle
breaking is now handled in the evaluator itself. Once witness matching
has been refactored to cache with the evaluator, all of these hacks can
go away.

My urge to destroy the LazyResolver outweighs the compromises here.

@CodaFi CodaFi requested a review from slavapestov November 1, 2019 06:41
@CodaFi
Copy link
Contributor Author

CodaFi commented Nov 1, 2019

@swift-ci please test

@CodaFi
Copy link
Contributor Author

CodaFi commented Nov 1, 2019

@swift-ci please test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented Nov 1, 2019

@DougGregor I think the right way to do this is to make a checker that acts like a pure function from a top-level target requirement and a (partial) NormalConformance to a [Type]Witness. If further requirements need to get validated, then we can spawn sub-checkers with those requirements as targets. Each checker would be responsible for caching only its target requirement on the conformance.

@swift-ci
Copy link
Contributor

swift-ci commented Nov 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - db6b24c91105eb1b7c6e28b12c44e2e541222a31

@swift-ci
Copy link
Contributor

swift-ci commented Nov 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - db6b24c91105eb1b7c6e28b12c44e2e541222a31


void swift::simple_display(llvm::raw_ostream &out,
const ProtocolConformance *conf) {
conf->dump(out);
Copy link
Member

Choose a reason for hiding this comment

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

Should I worry about this causing other requests to fire?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a placeholder... I'll fix it up.

Copy link
Contributor Author

@CodaFi CodaFi Nov 2, 2019

Choose a reason for hiding this comment

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

Oh wow, the printer can kick off interface type requests for var decls which can perform arbitrarily large amounts of type checking. Lovely.

}

void TypeWitnessRequest::cacheResult(TypeWitnessAndDecl typeWitAndDecl) const {
// FIXME: Refactor this to be the thing that warms the cache.
Copy link
Member

Choose a reason for hiding this comment

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

Yikes, but okay; I see your goal here.

Witness matching is a source of a lot of ad-hoc cycles, and mixes the
logic that performs resolution, caching, validation, and cycle detection into one
place.  To make matters worse, some checkers kick off other checks in
order to cache work for further declarations, and access an internal
cache on their subject conformance for many requirements at once, or
sometimes just one requirement.

None of this fits into the request evaluator's central view of the
caching.  This is further evidenced by the fact that if you attempt to
move the caching step into the evaluator, it overcaches the same
witness and trips asserts.

As a start, define requests for the resolution steps, and flush some
hacks around forcing witness resolution. The caching logic is mostly
untouched (the requests don't actually cache anything), but some cycle
breaking is now handled in the evaluator itself.  Once witness matching
has been refactored to cache with the evaluator, all of these hacks can
go away.

My urge to destroy the LazyResolver outweighs the compromises here.
@CodaFi
Copy link
Contributor Author

CodaFi commented Nov 2, 2019

@swift-ci please smoke test

@CodaFi CodaFi mentioned this pull request Nov 5, 2019
@CodaFi CodaFi closed this Nov 6, 2019
@CodaFi CodaFi deleted the witness-requests branch November 6, 2019 07: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.

4 participants