Skip to content

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

Merged
merged 1 commit into from
Jan 7, 2017
Merged

Fix one source of exponential behavior in the type checker. #6629

merged 1 commit into from
Jan 7, 2017

Conversation

rudkx
Copy link
Contributor

@rudkx rudkx commented Jan 7, 2017

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.

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.
@rudkx rudkx self-assigned this Jan 7, 2017
@rudkx rudkx requested a review from DougGregor January 7, 2017 00:06
@rudkx
Copy link
Contributor Author

rudkx commented Jan 7, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 7, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 1efafbc
Test requested by - @rudkx

@rudkx
Copy link
Contributor Author

rudkx commented Jan 7, 2017

Failure appears to be due to #6624. I've started a PR to revert that PR to unblock.

@rudkx
Copy link
Contributor Author

rudkx commented Jan 7, 2017

@swift-ci Please test

@rudkx
Copy link
Contributor Author

rudkx commented Jan 7, 2017

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

@rudkx rudkx merged commit bd5f05c into swiftlang:master Jan 7, 2017
@rudkx rudkx deleted the fix-iuo-collections branch January 7, 2017 04:27
Copy link
Member

@DougGregor DougGregor left a 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();
Copy link
Member

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.

Copy link
Contributor Author

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.

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