Skip to content

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