Skip to content

TypeCheckType: Fix existential any migration diagnostics for extra-modular protocols #65112

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

AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented Apr 12, 2023

There are two issues:

  • The evaluation of ExistentialRequiresAnyRequest is dependent on whether the ExistentialAny feature is enabled in the current compiler invocation, but the evaluation is bypassed for deserialized protocols because the result of the request is part of the serialized record. This made existentialRequiresAny() independent of the feature state for deserialized protocols (Enabling upcoming feature ExistentialAny does not work for standard library protocols. #65034).
  • The evaluation of ExistentialRequiresAnyRequest must not depend on the feature state, or else is will persist in module files and override the feature state for protocols originating in those modules. In other words, the feature must not be enforced on protocols originating in a different module just because that module was compiled with the feature enabled.

Resolves #65034


IMO there is no reason not to accept this into 5.9, but I would also vote to take it into 5.8 because the issue affects the new migration experience for a pretty impactful upcoming feature.

/// value requirement.
///
/// @Note This method does not take the state of language features into
/// account.
Copy link
Member

Choose a reason for hiding this comment

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

You could also pass in the usage context into existentialRequiresAny so the method itself accounts for language feature state, but the ExistentialRequiresAny request does not. Thoughts?

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Apr 12, 2023

Choose a reason for hiding this comment

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

I was going to but that is what the serializer calls to obtain the evaluation result, which is somewhat misleading in my opinion. I think we should rename the request to something like HasSelfOrAssociatedTypeRequirements and pair it with a method to use in the serializer so that existentialRequiresAny could account for language feature state.

Copy link
Member

Choose a reason for hiding this comment

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

👍 that sounds like a good approach to me (and we don't need to do that as part of this PR)

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

Thank you!

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@hborla
Copy link
Member

hborla commented Apr 12, 2023

[...]
forward_trailing_closure_errors.swift -swift-version 6
--
Exit Code: 1

Command Output (stderr):
--
/Users/ec2-user/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/swift/test/expr/postfix/call/forward_trailing_closure_errors.swift:23:14: error: unexpected error produced: use of protocol 'Error' as a type must be written 'any Error'
  onError: ((Error) -> Void)? = nil,
             ^

Hah. That's true!

@AnthonyLatsis AnthonyLatsis force-pushed the existential-any-multimodule branch from 1939ca0 to 8d1d526 Compare April 13, 2023 00:37
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis AnthonyLatsis merged commit c3877c8 into swiftlang:main Apr 13, 2023
@AnthonyLatsis AnthonyLatsis deleted the existential-any-multimodule branch April 13, 2023 03:35
@hborla
Copy link
Member

hborla commented Apr 13, 2023

@AnthonyLatsis will you please cherry-pick this to release/5.9 and ping me for branch manager approval?

@AnthonyLatsis
Copy link
Collaborator Author

Sure. I was waiting for a green light on #65132 so that I can cherry-pick it as well. I’ve got more related fixes coming up and I would prefer them to layer up cleanly on both branches.

@AnthonyLatsis AnthonyLatsis changed the title TypeCheckType: Fix existential 'any' migration diagnostics for extra-modular protocols TypeCheckType: Fix existential any migration diagnostics for extra-modular protocols Apr 13, 2023
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.

Enabling upcoming feature ExistentialAny does not work for standard library protocols.
2 participants