Skip to content

LifetimeDependence type check: infer trivial _read accessor #82268

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 17, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jun 16, 2025

This fixes a small oversight in the type checker's LifetimeDependence
inference. Allow inference on _read accessors even when 'self' is a trivial
type. This is needed because the compiler synthesizes a _read accessor even when
the user defines a getter (this is probably a mistake, but it's easire to just
fix inference at this point). There is no workaround because it defining both a
getter and '_read' is illegal!

extension UnsafeMutableRawBufferPointer {
  var mutableBytes: MutableRawSpan {
    @_lifetime(borrow self)
    get {
      unsafe MutableRawSpan(_unsafeBytes: self)
    }
  }
}

Fixes rdar://153346478 (Can't compile the
UnsafeMutableRawBufferPointer.mutableBytes property)

This fixes a small oversight in the type checker's LifetimeDependence
inference. Allow inference on _read accessors even when 'self' is a trivial
type. This is needed because the compiler synthesizes a _read accessor even when
the user defines a getter (this is probably a mistake, but it's easire to just
fix inference at this point). There is no workaround because it defining both a
getter and '_read' is illegal!

    extension UnsafeMutableRawBufferPointer {
      var mutableBytes: MutableRawSpan {
        @_lifetime(borrow self)
        get {
          unsafe MutableRawSpan(_unsafeBytes: self)
        }
      }
    }

Fixes rdar://153346478 (Can't compile the
UnsafeMutableRawBufferPointer.mutableBytes property)
@atrick
Copy link
Contributor Author

atrick commented Jun 16, 2025

@swift-ci test

@atrick atrick enabled auto-merge June 16, 2025 17:55
@atrick atrick requested a review from meg-gupta June 16, 2025 17:55
Copy link
Contributor

@meg-gupta meg-gupta left a comment

Choose a reason for hiding this comment

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

lgtm

@glessard
Copy link
Contributor

@swift-ci please test macOS platform

@atrick atrick merged commit 5a1d3a8 into swiftlang:main Jun 17, 2025
5 checks passed
@atrick atrick deleted the infer-implicit-read branch June 17, 2025 04:17
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