Skip to content

[5.10] Fix MemoryLifetimeVerifier to ignore thin functions. #70224

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
Dec 6, 2023

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Dec 5, 2023

SILGen optimizes creation of closure down a thin function when it has no captures:

  %1 = thin_to_thick_function %0
  : $@convention(thin) () -> () to $@callee_guaranteed () -> ()

ValueOwnership.cpp has a sketchy optimization that treat the result like a trivial type, even though it is not:

>  CONSTANT_OWNERSHIP_INST(None, ThinToThickFunction)

commit 8c5737d1d5f87d6d2379e6b074797557561e82aa
Date:   Fri Oct 23 15:12:18 2020 -0700

    [ownership] Change thin_to_thick function to always produce a none value.

This creates a mismatch between the SILType and the SILValue ownership. This is not a coherent design--we have a similar problem with enums which is endlessly buggy--but reverting the decision will be hard. Instead, I'll hack the memory verifier to silence this case.

Fixes rdar://115735132 (Lifetime verifier error with opaque return type and closure)

(cherry picked from commit 047be39)

main PR: #70223

--- CCC ---

Explanation: SILGen optimizes closures with no captures to direct calls. OSSA optimizes direct calls to have owenrship "none". This creates a mismatch between the SILType and the SILValue ownership. This causes the memory verifier to diagnose an error when the memory is not deinitialized.

Scope: This only affects the non-production (asserts) compiler. The issue was introduced three years ago.

commit 8c5737d
Date: Fri Oct 23 15:12:18 2020 -0700
[ownership] Change thin_to_thick function to always produce a none value.

Issue: rdar://115735132 (Lifetime verifier error with opaque return type and closure)

Risk: Very low. Adds a single, very specific condition which used to trigger diagnostics by the memory verifier to now be ignored.

PR to main: #70223

Testing: Added regression test to the test suite.

Reviewer: @eeckstein

@atrick atrick requested a review from a team as a code owner December 5, 2023 01:57
SILGen optimizes creation of closure down a thin function when it has
no captures:

  %1 = thin_to_thick_function %0
  : $@convention(thin) () -> () to $@callee_guaranteed () -> ()

ValueOwnership.cpp has a sketchy optimization that treat the result
like a trivial type, even though it is not:

>  CONSTANT_OWNERSHIP_INST(None, ThinToThickFunction)

commit 8c5737d
Date:   Fri Oct 23 15:12:18 2020 -0700

    [ownership] Change thin_to_thick function to always produce a none value.

This creates a mismatch between the SILType and the SILValue
ownership. This is not a coherent design--we have a similar problem
with enums which is endlessly buggy--but reverting the decision will
be hard. Instead, I'll hack the memory verifier to silence this case.

Fixes rdar://115735132 (Lifetime verifier error with opaque return
type and closure)

(cherry picked from commit 23ddaaf)
@atrick atrick force-pushed the 510-fix-lifetime-verifier branch from 129044f to da9d60c Compare December 5, 2023 17:17
@atrick
Copy link
Contributor Author

atrick commented Dec 5, 2023

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Dec 5, 2023

@tbkka 5.10 cherry pick

@atrick atrick merged commit 45ba90e into swiftlang:release/5.10 Dec 6, 2023
@atrick atrick deleted the 510-fix-lifetime-verifier branch December 6, 2023 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants