-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix one source of exponential behavior in the type checker. #6629
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
Conversation
For collection literals that contained implicitly unwrapped optionals, we were attempting three different conversions per element of the collection, resulting in exponential type checking time. We should only ever attempt one of these conversions for any pair of types where one or both is optional. We had several reports of this as it seems quite common for people to write expressions that create a collection of IUOs from class/struct elements, and then either return the collection or some variation that has been filtered and mapped. I am looking at adding the appropriate instrumentation to the type checker so that I can add a scale-test for this and other type checker test cases related to slow type checking so that we can avoid regressing in the future.
@swift-ci Please test |
Build failed |
Failure appears to be due to #6624. I've started a PR to revert that PR to unblock. |
@swift-ci Please test |
@DougGregor If you have a moment it might be worth a peek. I made a subtle mistake earlier which only resulted in one failure in the test suite. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Definitely cleaner this way!
ConstraintKind kind) { | ||
OptionalTypeKind optionalKind1 = OTK_None; | ||
if (auto boundGeneric1 = type1->getAs<BoundGenericType>()) | ||
optionalKind1 = boundGeneric1->getDecl()->classifyAsOptionalType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, you can use TypeBase::getAnyOptionalObjectType()
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I knew that existed and was looking for it but didn't realize it had the same name as the version that just returns the object type. I'll put together a new patch that uses it.
For collection literals that contained implicitly unwrapped optionals,
we were attempting three different conversions per element of the
collection, resulting in exponential type checking time.
We should only ever attempt one of these conversions for any pair of
types where one or both is optional.
We had several reports of this as it seems quite common for people to
write expressions that create a collection of IUOs from class/struct
elements, and then either return the collection or some variation that
has been filtered and mapped.
I am looking at adding the appropriate instrumentation to the type
checker so that I can add a scale-test for this and other type checker
test cases related to slow type checking so that we can avoid regressing
in the future.