Skip to content

Fix an inliner crash when inlining begin_apply with scoped lifetime dependence #82033

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
Jun 12, 2025

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Jun 5, 2025

LifetimeDependenceInsertion inserts mark_dependence on token result of a begin_apply when it yields a lifetime dependent value. When such a begin_apply gets inlined, the inliner can crash because of the remaining uses of the token result.

Fix this by inserting mark_dependence on parameter operands that are lifetime dependence sources and deleting the mark_dependence on token results in the inliner.

Fixes rdar://151568816

Fixes #81595

@meg-gupta meg-gupta requested review from atrick and removed request for jckarter and eeckstein June 5, 2025 20:54
@meg-gupta
Copy link
Contributor Author

@swift-ci test

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 think this is fine as a short-term fix. A few requests

  • Preemptively file a bug against me with test case for the duplicate diagnostic. We do need to fix that as soon as possible.

  • add a unit test where the token dependency is actually required and check the SIL to ensure that the an inlined dependency exists after inlining that has the same effect as the deleted mark_dependence

  • clarify the comment that commented on here...

// mark_dependence/mark_dependence_addr may have begin_apply's token result
// as their operand. This is needed for diagnosing lifetime dependencies for
// ~Escapable yields. Delete them while inlining the begin_apply since the
// dependence is also represented by lifetime dependence sources.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is a little off...

The mark_dependence on the coroutine token represents a dependency on the coroutine context. That is different from a dependency on one of the coroutine parameters. For example, the yielded value may depend on a value created inside the coroutine.

I guess we can assume that inlining the coroutine will expose any dependencies within the coroutine implementation, so we can delete the dependency on the context after inlining, but I haven't investigated that at all. It would be worth adding a unit test for that case that checks the SIL after inlining.

…ependence

LifetimeDependenceInsertion inserts mark_dependence on token result of a begin_apply
when it yields a lifetime dependent value. When such a begin_apply gets inlined,
the inliner can crash because of the remaining uses of the token result.

Fix this by inserting mark_dependence on parameter operands that are lifetime dependence sources
and deleting the mark_dependence on token results in the inliner.

Fixes rdar://151568816
@meg-gupta
Copy link
Contributor Author

@atrick Created rdar://153175960 to track removing duplicate diagnostics and made updates to tests and comments.

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta enabled auto-merge June 12, 2025 09:40
@meg-gupta meg-gupta merged commit e42b564 into swiftlang:main Jun 12, 2025
5 checks passed
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.

Crash Analyzing Escapability in Autoclosure Argument
2 participants