Skip to content

[SILGen] Optimize generated dealloc for linearly recursive data struc… #41459

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 9 commits into from
Mar 14, 2022

Conversation

drexin
Copy link
Contributor

@drexin drexin commented Feb 18, 2022

…tures

Adds detection of linearly recursive data structures by finding stored properties that share the type of the class the dealloc is being generated for. Each link will then be deallocated in a loop, while ensuring to keep the next link alive to prevent the recursion. This prevents stack overflows for long chains while also improving performance.

rdar://89162954

…tures

Adds detection of linearly recursive data structures by finding stored properties that share the type of the class the dealloc is being generated for. Each link will then be deallocated in a loop, while ensuring to keep the next link alive to prevent the recursion. This prevents stack overflows for long chains while also improving performance.

rdar://89162954
@drexin
Copy link
Contributor Author

drexin commented Feb 18, 2022

@swift-ci smoke test

@jckarter
Copy link
Contributor

Nice! Do you have any tests?

@drexin
Copy link
Contributor Author

drexin commented Feb 18, 2022

@swift-ci smoke test macos

@drexin drexin marked this pull request as draft February 18, 2022 22:39
@drexin
Copy link
Contributor Author

drexin commented Feb 18, 2022

Nice! Do you have any tests?

Working on it!

@drexin drexin force-pushed the wip-dealloc-recur branch 3 times, most recently from a7b3d61 to 6c69b9a Compare February 19, 2022 00:10
@drexin
Copy link
Contributor Author

drexin commented Feb 19, 2022

@swift-ci smoke test

@drexin drexin force-pushed the wip-dealloc-recur branch 2 times, most recently from 0280334 to aab8413 Compare February 19, 2022 20:29
@drexin
Copy link
Contributor Author

drexin commented Feb 19, 2022

@swift-ci test

@drexin drexin marked this pull request as ready for review February 19, 2022 20:30
@drexin
Copy link
Contributor Author

drexin commented Feb 19, 2022

@jckarter Added some tests.

@drexin
Copy link
Contributor Author

drexin commented Feb 19, 2022

@swift-ci test

@drexin
Copy link
Contributor Author

drexin commented Feb 21, 2022

@swift-ci test

@drexin
Copy link
Contributor Author

drexin commented Feb 21, 2022

@swift-ci test

@drexin drexin requested review from slavapestov and atrick February 22, 2022 18:29
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

I'm in favor of this approach. I'm unfamiliar with the surrounding SILGen. It would be nice to have @slavapestov or @jckarter check the type-system aspects.

I made several comments about implementation details. Mainly wondering why we need to generate extra copies in SILGen.

@drexin
Copy link
Contributor Author

drexin commented Feb 22, 2022

@swift-ci test

@drexin drexin requested a review from atrick February 22, 2022 23:03
@drexin
Copy link
Contributor Author

drexin commented Feb 23, 2022

@swift-ci test macos

@drexin drexin force-pushed the wip-dealloc-recur branch from c0c4997 to dc013ea Compare March 3, 2022 17:25
@drexin
Copy link
Contributor Author

drexin commented Mar 3, 2022

@gottesmm Thanks, addressed all your comments!

@drexin
Copy link
Contributor Author

drexin commented Mar 3, 2022

@swift-ci test

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

A few more comment changes then LGTM. Can you fix those and then feel free to merge. Thanks!

// recursively the same type as `self`, so we can iteratively
// deinitialize them, to prevent deep recursion and potential
// stack overflows.
llvm::SmallSetVector<VarDecl*, 4> recursiveLinks;
Copy link
Contributor

Choose a reason for hiding this comment

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

Another instance showing git-clang-format missing. Can you git-clang-format 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.

git-clang-format appears to accept this as is, as well as with added whitespace. It also accepts Type* variable; and Type *variable;. I'm happy to change this manually, but maybe the formatting rules have to be adjusted?

@drexin drexin force-pushed the wip-dealloc-recur branch from dc013ea to ba0de89 Compare March 9, 2022 21:57
@drexin
Copy link
Contributor Author

drexin commented Mar 9, 2022

@swift-ci please test and merge

@drexin
Copy link
Contributor Author

drexin commented Mar 10, 2022

@swift-ci test Linux

@drexin
Copy link
Contributor Author

drexin commented Mar 10, 2022

@swift-ci test linux

@drexin
Copy link
Contributor Author

drexin commented Mar 11, 2022

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Mar 11, 2022

@swift-ci smoke test linux

@drexin
Copy link
Contributor Author

drexin commented Mar 13, 2022

@swift-ci smoke test

@drexin drexin merged commit 6d55ecd into swiftlang:main Mar 14, 2022
@drexin drexin deleted the wip-dealloc-recur branch March 14, 2022 15:13
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.

5 participants