Skip to content

[sil-generic-specializer] Avoid unlimited generic specialization of very deeply nested bound generic types #3504

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
Jul 16, 2016

Conversation

swiftix
Copy link
Contributor

@swiftix swiftix commented Jul 14, 2016

What's in this pull request?

Resolved bug number: (SR-)

rdar://21260480


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

The generic specialized would get out of control in certain cases and would not stop generating specializations of generic functions until it runs out of memory after a while.

@swiftix
Copy link
Contributor Author

swiftix commented Jul 14, 2016

@swift-ci Please test

@swiftix
Copy link
Contributor Author

swiftix commented Jul 14, 2016

@rudkx @bob-wilson What do you think? Should we merge it as a short-time fix? Or should we better wait for now and then come up with a more principle way to fix this kind of issues?

@rudkx
Copy link
Contributor

rudkx commented Jul 14, 2016

Seems clever, and possibly good enough, but I wonder if the threshold is too high.

Also, in the comment you say that Array<Array<Array>> is depth 3, but what is the maximum depth that we specialize too in the implementation of Array (which uses other parameterized types, etc.)?

@swiftix
Copy link
Contributor Author

swiftix commented Jul 15, 2016

@rudkx Before committing it, I discussed the threshold with @gribozavr to figure out what would be the safe bet. And we decided to go for 50.

I agree that it is eventually too high, because on the stdlib and validation suite we never reach even a threshold of 10. I know it, because I did some debug printing and asked it to report any generic apply which has a bound generic argument of depth >= 10.


static unsigned getBoundGenericDepth(Type t) {
unsigned Depth = 0;
if (auto BGT = dyn_cast<BoundGenericType>(t.getCanonicalTypeOrNull())) {
Copy link
Contributor

@slavapestov slavapestov Jul 15, 2016

Choose a reason for hiding this comment

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

@swiftix The correct way of doing this is 't->getAs<BoundGenericType>()'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@slavapestov Ah, yes. I keep forgetting it every time ;-)

@swiftix swiftix force-pushed the generic-specialization-fixes branch from d3f1202 to cdfd722 Compare July 16, 2016 16:02
@swiftix
Copy link
Contributor Author

swiftix commented Jul 16, 2016

@swift-ci Please smoke test

…ery deeply nested bound generic types

The generic specialized would get out of control in certain cases and would not stop generating specializations of generic functions until it runs out of memory after a while.

rdar://21260480
@swiftix swiftix force-pushed the generic-specialization-fixes branch from cdfd722 to 4109f87 Compare July 16, 2016 16:24
@swiftix
Copy link
Contributor Author

swiftix commented Jul 16, 2016

@swift-ci Please smoke test

@swiftix swiftix merged commit 9049d6e into swiftlang:master Jul 16, 2016
kateinoigakukun pushed a commit that referenced this pull request Aug 31, 2022
[pull] swiftwasm from 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.

4 participants