Skip to content

[SE-0335] Enable explicit existential types. #40666

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 24 commits into from
Jan 15, 2022

Conversation

hborla
Copy link
Member

@hborla hborla commented Dec 21, 2021

This change enables explicit existential types by default, which changes the representation of existential types to use ExistentialType, and allows the any keyword in the source language.

Note that many of the conditional getAs<ExistentialType>() variable bindings are temporary. After explicit existential types are enabled, existential types will always resolve to ExistentialType (regardless of whether or not they're spelled with any), and the isExistentialType() checks can be changed to is<ExistentialType>(). I'm holding off on making that change for now to allow explicit existential types to be turned off if needed.

Resolves: rdar://86347236

@hborla hborla force-pushed the explicit-existential-fixes branch from c1a9a0f to 54783da Compare December 22, 2021 03:10
@hborla hborla force-pushed the explicit-existential-fixes branch 2 times, most recently from 2e4e40b to 1c1ea77 Compare January 8, 2022 07:22
@hborla
Copy link
Member Author

hborla commented Jan 8, 2022

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 8, 2022

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Jan 8, 2022

Build failed
Swift Test Linux Platform
Git Sha - 1c1ea7703266075446bb34b15bc0ddcbb9cf933c

@swift-ci
Copy link
Contributor

swift-ci commented Jan 8, 2022

Build failed
Swift Test OS X Platform
Git Sha - 1c1ea7703266075446bb34b15bc0ddcbb9cf933c

@hborla hborla changed the title [Type System] Various bug fixes for explicit existential types. [SE-0335] Enable explicit existential types. Jan 8, 2022
@hborla hborla force-pushed the explicit-existential-fixes branch 2 times, most recently from dfb922f to 8d2e059 Compare January 8, 2022 23:56
@hborla
Copy link
Member Author

hborla commented Jan 9, 2022

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 9, 2022

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2022

Build failed
Swift Test Linux Platform
Git Sha - 8d2e059c90debc9252b229d5dc55b4e23a4a3fb6

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2022

Build failed
Swift Test OS X Platform
Git Sha - 8d2e059c90debc9252b229d5dc55b4e23a4a3fb6

@@ -2731,6 +2734,8 @@ class ExistentialMetatypeType : public AnyMetatypeType {
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::ExistentialMetatype;
}

Type getExistentialInstanceType();
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like the existence of this method, but it messes up TypeWalker if I make AnyMetatypeType::getInstanceType() return ExistentialType for existential metatypes. Alternatively, I could add getRawInstanceType() or something like that for the few places that actually need the stored InstanceType. Really, I'd like to just replace ExistentialMetatypeType with ExistentialType(MetatypeType(...))

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 your longer-term goal of removing ExistentialMetatypeType is good and in the meantime, this workaround is reasonable.

@hborla hborla marked this pull request as ready for review January 10, 2022 20:20
@hborla
Copy link
Member Author

hborla commented Jan 11, 2022

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 11, 2022

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7d9661eb79ff558bb40f94ac01605329487d6110

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d9661eb79ff558bb40f94ac01605329487d6110

@hborla hborla force-pushed the explicit-existential-fixes branch from 7d9661e to a7b50a0 Compare January 11, 2022 17:28
@hborla
Copy link
Member Author

hborla commented Jan 11, 2022

@swift-ci please test source compatibility

@hborla
Copy link
Member Author

hborla commented Jan 12, 2022

swiftlang/llvm-project#3777

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a7b50a06a4ceec3756d399c681f5e8affc9e3bc5

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a7b50a06a4ceec3756d399c681f5e8affc9e3bc5

@hborla
Copy link
Member Author

hborla commented Jan 12, 2022

swiftlang/llvm-project#3777

@swift-ci please test

hborla added 19 commits January 13, 2022 19:30
in ExistentialType for the type of error values.
…able

initializer requirements with explicit existential Encodable and Decodable
parameters.
finding the protocol decl for an existential type.
explicit ExistentialType.

The ASTDemangler needs to produce ExistentialType based on context, not
unconditionally when producing a protocol composition. This is tricky
because existential types are mangled the same way as other protocol
references, e.g. in conformance requirements. For now, drop the explicit
existentials when reconstructing types.
resolve to ProtocolType or ProtocolCompositionType are always existential
types.

This can happen because type aliases to protocol constraints can also be
used as type witnesses. The type alias itself is still a constraint,
because it can be used in generic signatures in addition to being used
as an existential type, e.g. in parameter position. So, we need to wrap
the type alias in an ExistentialType during type witness resolution.
metatypes always wrap the constraint type directly, and the instance
type of an existential metatype is an existential type.
existential types.

Use the correct type resolver context when resolving SIL metatypes
and function types, and diagnose an error if an explicit existential
type appears in a protocol composition.
various places that expect ProtocolType or ProtocoolCompositionType.
are printed with the `any` keyword.

For now, printing `any` is off by default in order to turn on explicit
existential types with minimal changes to the test suite. The option
will also allow control over how existential types are printed in
Swift interfaces.
…Type

by propagating whether the decoded type is for a requirement through
TypeDecoder.
existential arguments to not return before checking the second
argument type.
@hborla hborla force-pushed the explicit-existential-fixes branch from a7b50a0 to 6608bf8 Compare January 14, 2022 03:31
…ence

when the member is a typealias to a protocol or composition.
@hborla
Copy link
Member Author

hborla commented Jan 14, 2022

@swift-ci please test source compatibility

@hborla
Copy link
Member Author

hborla commented Jan 14, 2022

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Jan 14, 2022

@swift-ci please smoke test macOS platform

@hborla hborla merged commit d146b69 into swiftlang:main Jan 15, 2022
@hborla hborla deleted the explicit-existential-fixes branch January 15, 2022 00:38
@ahoppen
Copy link
Member

ahoppen commented Jan 17, 2022

This PR caused is causing a few crashes in the stress tester: SR-15742.

@@ -1183,6 +1183,10 @@ namespace {
}
}

if (bridgedType->isConstraintType() &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can bridgedType really happen to be an protocol/composition here, or was this a forethought?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it can be Error

Comment on lines 286 to 292
auto joinInstance = join(firstConstraint, secondConstraint);
if (!joinInstance)
return CanType();

if (joinInstance->is<ExistentialMetatypeType>() ||
joinInstance->isAny() ||
joinInstance->isAnyObject())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: is<ExistentialMetatypeType>() seems unnecessary here.

Copy link
Member Author

@hborla hborla Jan 26, 2022

Choose a reason for hiding this comment

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

I believe I removed this code in my follow-up PR but I'm not certain

EDIT: oops, this is my follow up PR, I got it confused with the original 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I did remove this bit of code in a follow-up commit in this PR. You're right that it's unnecessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoops, sorry, I ought to have checked if it's still there on main.

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.

5 participants