Skip to content

SILOptimizer: fix a stack nesting problem when inlining coroutines #22285

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, 2019

Conversation

eeckstein
Copy link
Contributor

Beside fixing the compiler crash, this change also improves the stack-nesting correction mechanisms in the inliners:

  • Instead of trying to correct the nesting after each inlining of a callee, correct the nesting once when inlining is finished for a caller function.
    This fixes a potential compile time problem, because StackNesting iterates over the whole function.
    In worst case this can lead to quadratic behavior in case many begin_apply instructions with overlapping stack locations are inlined.

  • Because we are doing it only once for a caller, we can remove the complex logic for checking if it is necessary.
    We can just do it unconditionally in case any coroutine gets inlined.
    The inliners iterate over all instruction of a function anyway, so this does not increase the computational complexity (StackNesting is roughly linear with the number of instructions).

rdar://problem/47615442

@eeckstein eeckstein changed the title Inliner: fix a stack nesting problem when inlining coroutines SILOptimizer: fix a stack nesting problem when inlining coroutines Feb 1, 2019
@eeckstein eeckstein requested a review from rjmccall February 1, 2019 00:49
@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 7b0c78f071c1a762c14fb68003c16d000895e20d

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Approved with a minor request.

///
/// In this case stack nesting must be corrected after inlining with the
/// StackNesting utility.
static bool needUpdateStackNesting(FullApplySite apply) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually predicates are written in the third-person singular present, so I think this should be needsUpdateStackNesting.

Beside fixing the compiler crash, this change also improves the stack-nesting correction mechanisms in the inliners:

* Instead of trying to correct the nesting after each inlining of a callee, correct the nesting once when inlining is finished for a caller function.
This fixes a potential compile time problem, because StackNesting iterates over the whole function.
In worst case this can lead to quadratic behavior in case many begin_apply instructions with overlapping stack locations are inlined.

* Because we are doing it only once for a caller, we can remove the complex logic for checking if it is necessary.
We can just do it unconditionally in case any coroutine gets inlined.
The inliners iterate over all instruction of a function anyway, so this does not increase the computational complexity (StackNesting is roughly linear with the number of instructions).

rdar://problem/47615442
@eeckstein eeckstein force-pushed the fix-inlining-stack-nesting branch from 7b0c78f to 767ad5e Compare February 1, 2019 16:32
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 9718e5a into swiftlang:master Feb 1, 2019
@eeckstein eeckstein deleted the fix-inlining-stack-nesting branch February 1, 2019 17:41
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.

3 participants