Skip to content

[Sema] Use ExistentialType for Any and AnyObject.#41909

Merged
hborla merged 5 commits intoswiftlang:mainfrom
hborla:existential-any-anyobject
Jun 25, 2022
Merged

[Sema] Use ExistentialType for Any and AnyObject.#41909
hborla merged 5 commits intoswiftlang:mainfrom
hborla:existential-any-anyobject

Conversation

@hborla
Copy link
Copy Markdown
Member

@hborla hborla commented Mar 19, 2022

This change models existential Any and AnyObject using ExistentialType. Previously, these two existential types still were modeled with ProtocolCompositionType because they're not required to be written with any, but this allowed using any on these types in conformance constraint context, e.g.

func generic<T>(value: T) where T: any Any { ... } // okay??

This also forced all code that operates on existential types to handle both ExistentialType and ProtocolCompositionType. This change enables cleaning up all of that code, getting rid of TypeBase::isExistentialType in favor of TypeBase::is<ExistentialType>, adding ASTVerifier checks to ensure that no expressions have a protocol composition type to catch more bugs, etc

Note that Any and AnyObject still do not print with any in the ASTPrinter, except when it's needed to distinguish between the existential metatype and the singleton metatype, e.g. any Any.Type vs (any Any).Type.

@hborla hborla marked this pull request as ready for review March 19, 2022 05:48
@hborla hborla requested a review from slavapestov March 19, 2022 05:48
@hborla
Copy link
Copy Markdown
Member Author

hborla commented Mar 19, 2022

@swift-ci please test source compatibility

@hborla
Copy link
Copy Markdown
Member Author

hborla commented Mar 19, 2022

@swift-ci please test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you turn this into a bitfield on TypeBase?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should already be canonical, you can do return CanType(ExistentialType::get(TheAnyType)) instead (it will assert if its not canonical)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this similarly be split up into constraint/existential versions, or do we not need the former anywhere?

Comment on lines 4228 to 4277
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ExistentialMetatypeType is probably retiring soon, but I wonder if this is better off as an assertion.

@hborla
Copy link
Copy Markdown
Member Author

hborla commented Jun 16, 2022

@swift-ci please smoke test

1 similar comment
@hborla
Copy link
Copy Markdown
Member Author

hborla commented Jun 16, 2022

@swift-ci please smoke test

@hborla
Copy link
Copy Markdown
Member Author

hborla commented Jun 16, 2022

@swift-ci please test source compatibility

@hborla hborla force-pushed the existential-any-anyobject branch from d1de655 to 27ae04e Compare June 18, 2022 01:29
@hborla
Copy link
Copy Markdown
Member Author

hborla commented Jun 18, 2022

swiftlang/llvm-project#4852

@swift-ci please smoke test

@hborla
Copy link
Copy Markdown
Member Author

hborla commented Jun 25, 2022

@swift-ci please smoke test

@hborla hborla merged commit 0053526 into swiftlang:main Jun 25, 2022
@hborla hborla deleted the existential-any-anyobject branch June 25, 2022 03:51
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