Skip to content
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

[SE-0335] Introduce existential any #40282

Merged
merged 16 commits into from
Dec 10, 2021
Merged

Conversation

hborla
Copy link
Member

@hborla hborla 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
Member Author

hborla commented Nov 21, 2021

@swift-ci please build toolchain

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@hborla hborla force-pushed the existential-any branch 2 times, most recently from a00f954 to f90f614 Compare November 22, 2021 01:45
@hborla hborla force-pushed the existential-any branch 3 times, most recently from e83c521 to 00841a5 Compare December 7, 2021 01:02
@hborla
Copy link
Member Author

hborla commented Dec 7, 2021

@swift-ci please build toolchain

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@hborla hborla force-pushed the existential-any branch 5 times, most recently from c578fc8 to eb29776 Compare December 9, 2021 07:42
@hborla hborla changed the title [WIP] Introduce existential any [Type System] Introduce existential any Dec 9, 2021
@hborla hborla requested a review from slavapestov December 9, 2021 17:17
@hborla
Copy link
Member Author

hborla commented Dec 9, 2021

@swift-ci please build toolchain

@hborla
Copy link
Member Author

hborla commented Dec 9, 2021

@swift-ci please smoke test

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

This comment has been minimized.

@swift-ci

This comment has been minimized.

hborla added 13 commits December 9, 2021 23:14
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).
…kUnsupportedProtocolType()"

This reverts commit 15f88e9.
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
Member Author

hborla commented Dec 10, 2021

@swift-ci please build toolchain

@hborla
Copy link
Member Author

hborla commented Dec 10, 2021

@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
Member Author

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

@AnthonyLatsis AnthonyLatsis Jan 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.

protocol P {
  associatedtype A
}
do {
  let meta: (any P).Type = (any P).self
}

Copy link
Member Author

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 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