Skip to content

SIL: Detect and bail out on infinite aggregates. #41111

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 1 commit into from
Feb 1, 2022

Conversation

jckarter
Copy link
Contributor

Sema diagnoses obvious cases of value types defined in terms of themselves,
but it can't catch cases that arise as a result of generic substitution,
such as if a generic struct has a field of associated type that becomes the
same as the struct type itself. SIL may end up handling these types, even
though they can't be instantiated (the runtime will complain and crash if
the metadata is requested), either during SILGen because they were written
in source code, or as a result of generic specialization during optimization.
SIL thus can't rely on diagnostics preventing such types from appearing, so
it needs to be able to continue gracefully when they show up. Add checks
in type lowering for when a struct or enum lowering ends up depending on
itself, and generate an infinite type lowering that's opaque and address-only.

Fixes rdar://80310017

Sema diagnoses obvious cases of value types defined in terms of themselves,
but it can't catch cases that arise as a result of generic substitution,
such as if a generic struct has a field of associated type that becomes the
same as the struct type itself. SIL may end up handling these types, even
though they can't be instantiated (the runtime will complain and crash if
the metadata is requested), either during SILGen because they were written
in source code, or as a result of generic specialization during optimization.
SIL thus can't rely on diagnostics preventing such types from appearing, so
it needs to be able to continue gracefully when they show up. Add checks
in type lowering for when a struct or enum lowering ends up depending on
itself, and generate an infinite type lowering that's opaque and address-only.

Fixes rdar://80310017
@jckarter jckarter requested a review from slavapestov January 31, 2022 23:23
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit 23557b8 into swiftlang:main Feb 1, 2022
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.

1 participant