Skip to content

[AST] NFC: Formalize Decl validation tracking via RAII #16655

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

Conversation

davezarzycki
Copy link
Contributor

@davezarzycki davezarzycki commented May 16, 2018

After this change, RAII ensures that the validation state is accurate as possible.

@davezarzycki
Copy link
Contributor Author

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

I like the idea of using RAII to set some of these new flags, but I’m not a fan of the renaming.

@davezarzycki
Copy link
Contributor Author

What would you propose then for the names? The problem as I see it was twofold:

  1. Before this change, isBeingValidated() returned false before validation was actually done. This was done to enable name lookup, etc for later validation logic. I tried to clarify what was going on with the new API names. Do you have any better naming ideas for this scenario?
  2. setValidationStarted() is misleading name that dates back to when there was an actual "validation started" bit which no longer exists. In practice, the API is used to mark decls as valid. Would you prefer setValidated()? Something else?

@slavapestov
Copy link
Contributor

Before this change, isBeingValidated() returned false before validation was actually done. This was done to enable name lookup, etc for later validation logic.

I'm not sure that's why. The "is being validated" flag exists to catch re-entrant calls to validateDecl() from taking place. If the declaration is already being validated or has completed validation, we want to return. Otherwise, we can begin validation.

The "validation completed" state is distinct from "has interface type" because type declarations get an interface type before getting a generic signature.

@davezarzycki davezarzycki force-pushed the formalize_DeclIsBeingValidatedRAII branch from 7a4a062 to f5ae64a Compare May 17, 2018 14:53
@davezarzycki
Copy link
Contributor Author

Hi @slavapestov – I think your feedback was fair. I "shot from the hip" with this pull request. I've now done a more thorough review.

@swift-ci please smoke test

@davezarzycki
Copy link
Contributor Author

The failure looks unrelated.

@swift-ci please clean smoke test

@davezarzycki
Copy link
Contributor Author

@swift-ci please smoke test

@davezarzycki
Copy link
Contributor Author

Ping.

@davezarzycki davezarzycki requested review from xedin and CodaFi May 24, 2018 16:25
@davezarzycki
Copy link
Contributor Author

Ping. Are there any changes that are wanted?

@davezarzycki
Copy link
Contributor Author

Ping.

@davezarzycki
Copy link
Contributor Author

Ping. It has been almost a month. Should I abandon this pull request?

After this change, RAII ensures that the validation state is accurate as
possible.
@davezarzycki davezarzycki force-pushed the formalize_DeclIsBeingValidatedRAII branch from f5ae64a to b29d278 Compare July 12, 2018 14:32
@davezarzycki
Copy link
Contributor Author

Hi @DougGregor – If you could be so kind, how should I interpret the lack of responses to "pings"?

@swift-ci please test

@davezarzycki
Copy link
Contributor Author

@slavapestov and @DougGregor – Ping. Feedback would be appreciated. Thanks!

@slavapestov
Copy link
Contributor

@davezarzycki What is the concrete benefit of this change? Are you using the new validation state for anything? In the long term, we would like to switch everything over to use the request evaluator, and validateDecl(), together with these state bits, will go away entirely. They're too imprecise and error prone.

case ValidationState::Unchecked:
case ValidationState::Checked:
return false;
default:
Copy link
Member

Choose a reason for hiding this comment

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

How about listing out the two cases here, rather than using default?

// See how validateDecl() sets the generic environment on alias members
// explicitly.
//
// FIXME: Hopefully this can all go away with the ITC.
Copy link
Member

Choose a reason for hiding this comment

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

The ITC is now gone. Our hopes and dreams are pinned on the request-evaluator ;)

@davezarzycki
Copy link
Contributor Author

I agree that the current validation tracking is imprecise and error prone. That is why I thought that RAII seemed like a natural way of trending in the right direction. If the validation tracking can go away, that's even better. What do you want to do in the short to medium term?

For the record, I'm not using the improved tracking in this pull request for feature work. Just better/easier compiler debugging.

@DougGregor
Copy link
Member

The use of RAII here is adding more discipline to a messy area. While it's true that we expect this mess of state to go away with the request-evaluator (once we've peeled off enough requests that validateDecl can effectively go away), that could take awhile... weeks at least, months probably. I'm fine with merging this PR as an incremental improvement to the status quo.

@slavapestov slavapestov merged commit 8d6a55f into swiftlang:master Jul 17, 2018
@davezarzycki davezarzycki deleted the formalize_DeclIsBeingValidatedRAII branch July 17, 2018 21:11
@@ -3666,6 +3664,8 @@ void TypeChecker::validateDecl(ValueDecl *D) {
// up to the caller, who must call hasValidSignature() to
// check that validateDecl() returned a fully-formed decl.
if (D->hasValidationStarted()) {
if (!(D->isBeingValidated() || D->hasValidSignature()))
D->dump();
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this call to dump() after fetching the latest sources and seeing a build warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. @slavapestov has a pull request that removes it: #18025

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