Skip to content

[Distributed] Require that SerReq can only be used with protocols #42348

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 1 commit into from
Apr 16, 2022

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Apr 13, 2022

In order to in the future support non "ad-hoc" protocol requirements we must make it possible to express T: SerializationRequirement in the future.

Since the : implies being a class or protocol, and currently we only have use cases for protocols, let us ban other things so we can figure it out in the near future.

resolves rdar://91663499

@ktoso ktoso requested review from xedin and hborla April 13, 2022 15:27
@ktoso
Copy link
Contributor Author

ktoso commented Apr 13, 2022

@swift-ci please smoke test

@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Apr 13, 2022
@@ -4631,6 +4631,9 @@ ERROR(distributed_actor_func_param_not_codable,none,
ERROR(distributed_actor_target_result_not_codable,none,
"result type %0 of %1 %2 does not conform to serialization requirement '%3'",
(Type, DescriptiveDeclKind, Identifier, StringRef))
ERROR(distributed_actor_system_serialization_req_must_be_protocol,none,
"'SerializationRequirement' type witness %0 must be a protocol type",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe - 'SerializationRequirement' requires [a] value of [a] protocol type or something like this? WDYT, @hborla and @xwu?

Copy link
Member

Choose a reason for hiding this comment

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

I definitely think the term "type witness" should not be used in diagnostics. The requirement also isn't satisfied by a value, but rather a protocol conformance requirement. What about 'SerializationRequirement' must be satisfied by a protocol? Perhaps with a note that says 'SerializationRequirement' is used as a protocol conformance requirement

Copy link
Contributor

Choose a reason for hiding this comment

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

... must be satisfied by protocol or protocol composition then maybe? This is going to be diagnosed in typealias SerializationRequirement = any ... position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'll reword somehow like this hmm

if (auto alias = dyn_cast<TypeAliasType>(existentialRequirementTy.getPointer())) {
auto ty = alias->getDesugaredType();
if (isa<ClassType>(ty) || isa<StructType>(ty) || isa<EnumType>(ty)) {
// SerializationRequirement cannot be class or struct nowadays
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should explain this better - it cannot be anything other then a protocol because it would be used to constrain a generic parameter associated with serialization methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

And might be check for !ty->is<ProtocolType>() to make it simpler :)

Copy link
Member

Choose a reason for hiding this comment

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

I think you should use !ty->isConstraintType() which also includes protocol composition types and was added for exactly this purpose 🙂 I think the code right now also doesn't handle bound generic types, e.g. BoundGenericClassType, so checking specifically for constraint types would fix that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, isConstraintType is the best option here.

Copy link
Member

Choose a reason for hiding this comment

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

I forgot that in the conformance it's written as an existential type, so this should actually check for isExistentialType() I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks for the info!

Copy link
Member

Choose a reason for hiding this comment

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

I'm still confused by this code. Why are we explicitly looking for a TypeAliasType here rather than doing a purely semantic check for "is existential type" and then verifying that the only requirements are protocol requirements?

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 folks for the delay, back to it now after the WWDC crunch 🙏
Will send in a PR to clean this up according to comments -- thanks @hborla !

@ktoso ktoso merged commit 8d8c652 into swiftlang:main Apr 16, 2022
@ktoso ktoso deleted the ban-non-protocol-serialization-reqs branch April 16, 2022 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants