Skip to content

[SE-0335] Introduce existential any#40282

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 16 commits into from
Dec 10, 2021
Merged

Conversation

hborla
Copy link
Member

@hborlahborla commented Nov 21, 2021

Implementation for SE-0335 Introduce existential any.

The feature is currently behind the frontend flag -enable-explicit-existential-types.

Resolves: rdar://86032280

@hborla
Copy link
MemberAuthor

@swift-ci please build toolchain

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@hborlahborlaforce-pushed the existential-any branch 2 times, most recently from a00f954 to f90f614CompareNovember 22, 2021 01:45
@hborlahborlaforce-pushed the existential-any branch 3 times, most recently from e83c521 to 00841a5CompareDecember 7, 2021 01:02
@hborla
Copy link
MemberAuthor

@swift-ci please build toolchain

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@hborlahborlaforce-pushed the existential-any branch 5 times, most recently from c578fc8 to eb29776CompareDecember 9, 2021 07:42
@hborlahborla changed the title [WIP] Introduce existential any[Type System] Introduce existential anyDec 9, 2021
@hborla
Copy link
MemberAuthor

@swift-ci please build toolchain

@hborla
Copy link
MemberAuthor

@swift-ci please smoke test

@hborlahborla marked this pull request as ready for review December 9, 2021 17:41
@hborlahborla changed the title [Type System] Introduce existential any[SE-0335] Introduce existential anyDec 9, 2021
@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

The new type, called ExistentialType, is not yet used in type resolution. Later, existential types written with `any` will resolve to this type, and bare protocol names will resolve to this type depending on context.
explicit existential types are enabled. Note that existential metatypes still resolve to ExistentialMetatypeType, but later this type can be replaced with ExistentialType(MetatypeType).
flip the return value in the implementation accordingly.
requirements to be spelled with 'any' when explicit existential types are enabled.
…lType when explicit existentials are enabled.
@hborla
Copy link
MemberAuthor

@swift-ci please build toolchain

@hborla
Copy link
MemberAuthor

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - f96104d

Install command
tar zxf swift-PR-40282-746-ubuntu16.04.tar.gz
More info

Comment on lines +2322 to 2324
case TypeReprKind::Existential:
return { };

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not recurse into the constraint repr?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so, but today it probably doesn't matter since we don't allow writing things like extension any P or any other construct that uses this code path.

if (auto meta2 = type2->getAs<ExistentialMetatypeType>()) {
ExistentialMetatypeType *meta2;
if (auto existential = type2->getAs<ExistentialType>()) {
meta2 = existential->getConstraintType()->getAs<ExistentialMetatypeType>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems superfluous: we already have an early return for ExistentialMetatypeType in ExistentialType::get.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, some of these are redundant now (I wrote this code before I made ExistentialType::get return early for some of the types that aren't "supported" yet in my follow up PR). I'm holding off on doing major cleanups on main, including making all of the code paths only operate on ExistentialType, in case I need to cherry-pick bug fixes to release/5.6.

Copy link
Collaborator

@AnthonyLatsisAnthonyLatsisJan 20, 2022

Choose a reason for hiding this comment

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

Thank you for letting me know!

in case I need to cherry-pick bug fixes to release/5.6

FYI, the following code is miscompiling on main. Looks like we're parsing any in the initializer as a decl ref.

protocolP{associatedtypeA}do{letmeta:(anyP).Type =(anyP).self }
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thanks! Here's the fix: #40949

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants
@hborla@swift-ci@slavapestov@AnthonyLatsis
close