Skip to content

SILGenCleanup: extend to handle trivial local var scopes #78830

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
Jan 25, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jan 23, 2025

Improves OSSALifetimeCompletion to handle trivial variables when running from SILGenCleanup. This only affects lifetime dependence diagnostics.

For the purpose of lifetime diagnostics, trivial local variables are only valid within their lexical scope. Sadly, SILGen only know how to insert cleanup code on normal function exits. SILGenCleanup relies on lifetime completion to fix lifetimes on dead end paths.

  %var = move_value [var_decl]
  try_apply %f() : $..., normal bb1, error error
error:
  extend_lifetime %var <=== insert this
  unreachable

This allows Span to depend on local unsafe pointers AND be used within throwing closures:

    _ = a.withUnsafeBufferPointer {
      let buffer = $0
      let view = Span(_unsafeElements: buffer)
      return view.withUnsafeBufferPointer(\.count)
    }

@atrick atrick force-pushed the fix-lifedep-trivial-deadend branch 2 times, most recently from a0127a9 to 29a3192 Compare January 23, 2025 00:39
@atrick
Copy link
Contributor Author

atrick commented Jan 23, 2025

@swift-ci test

@atrick atrick enabled auto-merge January 23, 2025 20:27
@atrick
Copy link
Contributor Author

atrick commented Jan 23, 2025

@swift-ci smoke test

Improves OSSALifetimeCompletion to handle trivial variables when running from
SILGenCleanup. This only affects lifetime dependence diagnostics.

For the purpose of lifetime diagnostics, trivial local variables are only valid
within their lexical scope. Sadly, SILGen only know how to insert cleanup code
on normal function exits. SILGenCleanup relies on lifetime completion to fix
lifetimes on dead end paths.

  %var = move_value [var_decl]
  try_apply %f() : $..., normal bb1, error error
error:
  extend_lifetime %var <=== insert this
  unreachable

This allows Span to depend on local unsafe pointers AND be used within
throwing closures:

    _ = a.withUnsafeBufferPointer {
      let buffer = $0
      let view = Span(_unsafeElements: buffer)
      return view.withUnsafeBufferPointer(\.count)
    }
@atrick
Copy link
Contributor Author

atrick commented Jan 24, 2025

This PR has been blocked on module not found errors since yesterday. The latest error is:

<unknown>:0: error: could not find module 'CxxStdlib' for target 'arm64-apple-macos'; found: x86_64-apple-macos, at: /Users/ec2-user/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/build/buildbot_incremental/swift-macosx-x86_64/lib/swift/macosx/CxxStdlib.swiftmodule

@atrick
Copy link
Contributor Author

atrick commented Jan 24, 2025

@swift-ci smoke test

1 similar comment
@atrick
Copy link
Contributor Author

atrick commented Jan 24, 2025

@swift-ci smoke test

@atrick atrick force-pushed the fix-lifedep-trivial-deadend branch from 29a3192 to 1b72c7b Compare January 24, 2025 04:27
@atrick
Copy link
Contributor Author

atrick commented Jan 24, 2025

@swift-ci smoke test

2 similar comments
@atrick
Copy link
Contributor Author

atrick commented Jan 24, 2025

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Jan 25, 2025

@swift-ci smoke test

@atrick atrick merged commit f0144ab into swiftlang:main Jan 25, 2025
3 checks passed
@atrick atrick deleted the fix-lifedep-trivial-deadend branch January 26, 2025 01:43
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.

1 participant