mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add Feature: NonescapableAccessorOnTrivial
To guard the new UnsafeMutablePointer.mutableSpan APIs.
This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:
error: cannot infer lifetime dependence on the '_read' accessor because 'self'
is BitwiseCopyable, specify '@lifetime(borrow self)'
I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.
Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)
(cherry picked from commit cc357f4f32)
This commit is contained in:
@@ -77,3 +77,21 @@ extension Container {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test feature guard: NonescapableAccessorOnTrivial
|
||||
extension UnsafeMutableBufferPointer where Element: ~Copyable {
|
||||
public var span: Span<Element> {
|
||||
@lifetime(borrow self)
|
||||
@_alwaysEmitIntoClient
|
||||
get {
|
||||
unsafe Span(_unsafeElements: self)
|
||||
}
|
||||
}
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(borrow self)
|
||||
@_alwaysEmitIntoClient
|
||||
get {
|
||||
unsafe MutableSpan(_unsafeElements: self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
|
||||
// RUN: -enable-experimental-feature LifetimeDependence \
|
||||
// RUN: -suppress-warnings \
|
||||
// RUN: -o %t/lifetime_dependence.swiftmodule \
|
||||
// RUN: -emit-module-interface-path %t/lifetime_dependence.swiftinterface \
|
||||
// RUN: %S/Inputs/lifetime_dependence.swift
|
||||
@@ -41,3 +42,13 @@ import lifetime_dependence
|
||||
// CHECK: extension lifetime_dependence.Container {
|
||||
// CHECK-NEXT: #if compiler(>=5.3) && $NonescapableTypes && $LifetimeDependence
|
||||
// CHECK-NEXT: public var storage: lifetime_dependence.BufferView {
|
||||
|
||||
// CHECK-LABEL: extension Swift.UnsafeMutableBufferPointer where Element : ~Copyable {
|
||||
// CHECK: #if compiler(>=5.3) && $LifetimeDependence
|
||||
// CHECK: public var span: Swift.Span<Element> {
|
||||
// CHECK: @lifetime(borrow self)
|
||||
// CHECK: @_alwaysEmitIntoClient get {
|
||||
// CHECK: #if compiler(>=5.3) && $LifetimeDependence && $NonescapableAccessorOnTrivial
|
||||
// CHECK: public var mutableSpan: Swift.MutableSpan<Element> {
|
||||
// CHECK: @lifetime(borrow self)
|
||||
// CHECK: @_alwaysEmitIntoClient get {
|
||||
|
||||
Reference in New Issue
Block a user