Skip to content

[TypeJoin] Implement Type::join for protocols and protocol compositions. #19677

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 3 commits into from
Oct 3, 2018
Merged

[TypeJoin] Implement Type::join for protocols and protocol compositions. #19677

merged 3 commits into from
Oct 3, 2018

Conversation

rudkx
Copy link
Contributor

@rudkx rudkx commented Oct 3, 2018

This is mostly complete, but we still need to add support for joins
between these two types and other types.

This is mostly complete, but we still need to add support for joins
between these two types and other types.
@rudkx rudkx requested review from DougGregor and xedin October 3, 2018 00:45
@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please smoke test

@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please test source compatibility

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

LGTM! Very nice!

assert(First != second);

// FIXME: Handle other types here.
if (First->getKind() != TypeKind::Protocol &&
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be using isa<> instead of getKind(), 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.

Ah yes, I'll fix that up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that because isa<> strips sugar? I still can’t say when it would make sense to use getKind vs. isa<> with confidence... is getKind supposed to be used only by switch statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general that's a good reason to use is<> and getAs<>, but in this case we're working with CanTypes so that shouldn't make a difference (*). It's generally shorter and more idiomatic to use these templated functions.

Add a comment explaining that the distributive law isn't generally
true for lattices but should be for ours, and fix up the test case
to not use the real stdlib Strideable protocol in a couple places.
@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please smoke test

@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please test source compatibility

assert(First != second);

// FIXME: Handle other types here.
if (!First->is<ProtocolType>() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This is First->isExistentialType()

}

// Return true if the first ProtocolDecl is a supertype of the second.
static bool isSupertypeOf(ProtocolDecl *super, ProtocolDecl *sub) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not the same as ProtocolDecl::inheritsFrom()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Close enough for my purposes, but the function I defined returns true if they are the same type. It shouldn't be calling them with the same type though, so I'll change it.

@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please smoke test

@rudkx
Copy link
Contributor Author

rudkx commented Oct 3, 2018

@swift-ci Please test source compatibility

@rudkx rudkx merged commit 6172679 into swiftlang:master Oct 3, 2018
@rudkx rudkx deleted the join-protocol-compositions branch October 3, 2018 14:20
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.

3 participants