Skip to content

Commit c347b66

Browse files
authored
Merge pull request #78283 from atrick/remove-trivial-feature
Remove the experimental LifetimeDependenceDiagnoseTrivial feature.
2 parents a3d9776 + 5581ab8 commit c347b66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+91
-100
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
101101
private func analyze(dependence: LifetimeDependence, _ context: FunctionPassContext) -> Bool {
102102
log("Dependence scope:\n\(dependence)")
103103

104-
// Early versions of Span in the standard library violate trivial lifetimes. Contemporary versions of the compiler
105-
// simply ignored dependencies on trivial values.
106-
if !context.options.hasFeature(.LifetimeDependenceDiagnoseTrivial) {
107-
if dependence.parentValue.type.objectType.isTrivial(in: dependence.function) {
104+
// Briefly, some versions of Span in the standard library violated trivial lifetimes; versions of the compiler built
105+
// at that time simply ignored dependencies on trivial values. For now, disable trivial dependencies to allow newer
106+
// compilers to build against those older standard libraries. This check is only relevant for ~6 mo (until July 2025).
107+
if dependence.parentValue.type.objectType.isTrivial(in: dependence.function) {
108+
if let sourceFileKind = dependence.function.sourceFileKind, sourceFileKind == .interface {
108109
return true
109110
}
110111
}

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
256256
fatalError()
257257
}
258258
}
259+
260+
public enum SourceFileKind {
261+
case library /// A normal .swift file.
262+
case main /// A .swift file that can have top-level code.
263+
case sil /// Came from a .sil file.
264+
case interface /// Came from a .swiftinterface file, representing another module.
265+
case macroExpansion /// Came from a macro expansion.
266+
case defaultArgument /// Came from default argument at caller side
267+
};
268+
269+
public var sourceFileKind: SourceFileKind? {
270+
switch bridged.getSourceFileKind() {
271+
case .Library: return .library
272+
case .Main: return .main
273+
case .SIL: return .sil
274+
case .Interface: return .interface
275+
case .MacroExpansion: return .macroExpansion
276+
case .DefaultArgument: return .defaultArgument
277+
case .None: return nil
278+
}
279+
}
259280
}
260281

261282
public func == (lhs: Function, rhs: Function) -> Bool { lhs === rhs }

include/swift/Basic/Features.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,6 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
362362
/// Enable returning non-escapable types from functions.
363363
EXPERIMENTAL_FEATURE(LifetimeDependence, true)
364364

365-
/// Enable LifetimeDependence diagnostics for trivial types.
366-
EXPERIMENTAL_FEATURE(LifetimeDependenceDiagnoseTrivial, false)
367-
368365
/// Enable the `@_staticExclusiveOnly` attribute.
369366
EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
370367

include/swift/SIL/SILBridging.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ struct BridgedFunction {
477477
IsSerializedForPackage
478478
};
479479

480+
enum class OptionalSourceFileKind {
481+
Library,
482+
Main,
483+
SIL,
484+
Interface,
485+
MacroExpansion,
486+
DefaultArgument, // must match swift::SourceFileKind::DefaultArgument
487+
None
488+
};
489+
480490
SWIFT_NAME("init(obj:)")
481491
BridgedFunction(SwiftObject obj) : obj(obj) {}
482492
BridgedFunction() {}
@@ -529,6 +539,7 @@ struct BridgedFunction {
529539
bool isAutodiffVJP() const;
530540
SwiftInt specializationLevel() const;
531541
SWIFT_IMPORT_UNSAFE BridgedSubstitutionMap getMethodSubstitutions(BridgedSubstitutionMap contextSubs) const;
542+
BRIDGED_INLINE OptionalSourceFileKind getSourceFileKind() const;
532543

533544
enum class ParseEffectsMode {
534545
argumentEffectsFromSource,

include/swift/SIL/SILBridgingImpl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "SILBridging.h"
2323
#include "swift/AST/Builtins.h"
2424
#include "swift/AST/Decl.h"
25+
#include "swift/AST/SourceFile.h"
2526
#include "swift/AST/SubstitutionMap.h"
2627
#include "swift/AST/Types.h"
2728
#include "swift/Basic/BasicBridging.h"
@@ -924,6 +925,14 @@ swift::SILFunction * _Nullable OptionalBridgedFunction::getFunction() const {
924925
return static_cast<swift::SILFunction *>(obj);
925926
}
926927

928+
BridgedFunction::OptionalSourceFileKind BridgedFunction::getSourceFileKind() const {
929+
if (auto *dc = getFunction()->getDeclContext()) {
930+
if (auto *sourceFile = dc->getParentSourceFile())
931+
return (OptionalSourceFileKind)sourceFile->Kind;
932+
}
933+
return OptionalSourceFileKind::None;
934+
}
935+
927936
//===----------------------------------------------------------------------===//
928937
// BridgedGlobalVar
929938
//===----------------------------------------------------------------------===//

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ static bool usesFeatureLifetimeDependence(Decl *decl) {
263263
->hasLifetimeDependencies();
264264
}
265265

266-
UNINTERESTING_FEATURE(LifetimeDependenceDiagnoseTrivial)
267-
268266
UNINTERESTING_FEATURE(DynamicActorIsolation)
269267
UNINTERESTING_FEATURE(NonfrozenEnumExhaustivity)
270268
UNINTERESTING_FEATURE(ClosureIsolation)

stdlib/public/Cxx/CxxSpan.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ internal func unsafeBitCast<T: ~Escapable, U>(
1818
Builtin.reinterpretCast(x)
1919
}
2020

21+
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
22+
/// a value identical to `dependent` with a lifetime dependency on the caller's
23+
/// borrow scope of the `source` argument.
24+
@unsafe
25+
@_unsafeNonescapableResult
26+
@_alwaysEmitIntoClient
27+
@_transparent
28+
@lifetime(borrow source)
29+
internal func _overrideLifetime<
30+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
31+
>(
32+
_ dependent: consuming T, borrowing source: borrowing U
33+
) -> T {
34+
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
35+
// should be expressed by a builtin that is hidden within the function body.
36+
dependent
37+
}
38+
2139
/// A C++ type that is an object that can refer to a contiguous sequence of objects.
2240
///
2341
/// C++ standard library type `std::span` conforms to this protocol.
@@ -62,12 +80,15 @@ extension CxxSpan {
6280
@available(SwiftStdlib 6.1, *)
6381
extension Span {
6482
@_alwaysEmitIntoClient
65-
@lifetime(immortal)
6683
@unsafe
84+
@lifetime(borrow span)
6785
public init<T: CxxSpan<Element>>(
68-
_unsafeCxxSpan span: T,
86+
_unsafeCxxSpan span: borrowing T,
6987
) {
70-
self.init(_unsafeElements: .init(start: span.__dataUnsafe(), count: Int(span.size())))
88+
let buffer = UnsafeBufferPointer(start: span.__dataUnsafe(), count: Int(span.size()))
89+
let newSpan = Span(_unsafeElements: buffer)
90+
// 'self' is limited to the caller's scope of the variable passed to the 'span' argument.
91+
self = _overrideLifetime(newSpan, borrowing: span)
7192
}
7293
}
7394

test/Generics/inverse_generics.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-typecheck-verify-swift \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: -enable-experimental-feature SuppressedAssociatedTypes
54

65
// REQUIRES: swift_feature_LifetimeDependence
7-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
86
// REQUIRES: swift_feature_SuppressedAssociatedTypes
97

108
// expected-note@+1 {{'T' has '~Copyable' constraint preventing implicit 'Copyable' conformance}}

test/SIL/Parser/basic2_noncopyable_generics.sil

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
// RUN: %target-sil-opt \
22
// RUN: %s \
33
// RUN: -enable-experimental-feature LifetimeDependence \
4-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
54
// RUN: | \
65
// RUN: %target-sil-opt \
76
// RUN: -enable-experimental-feature LifetimeDependence \
8-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
97
// RUN: | \
108
// RUN: %FileCheck %s
119

1210
// REQUIRES: swift_feature_LifetimeDependence
13-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
1411

1512
// For -enable-experimental-feature LifetimeDependence
1613

test/SIL/Parser/lifetime_dependence.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-sil-opt %s \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: | %FileCheck %s
54

65
// REQUIRES: swift_feature_LifetimeDependence
7-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
86

97
sil_stage canonical
108

test/SIL/explicit_lifetime_dependence_specifiers.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// RUN: -emit-sil \
33
// RUN: -enable-builtin-module \
44
// RUN: -enable-experimental-feature LifetimeDependence \
5-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
65
// RUN: | %FileCheck %s
76

87
// REQUIRES: swift_feature_LifetimeDependence
9-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
108

119
import Builtin
1210

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// RUN: %target-swift-frontend %s \
22
// RUN: -emit-sil -target %target-swift-5.1-abi-triple \
33
// RUN: -enable-experimental-feature LifetimeDependence \
4-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
54
// RUN: | %FileCheck %s
65

76
// REQUIRES: swift_feature_LifetimeDependence
8-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
97

108
@_unsafeNonescapableResult
119
@lifetime(source)

test/SIL/lifetime_dependence_generics.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// RUN: %target-swift-frontend %s -emit-sil \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: -enable-experimental-feature SuppressedAssociatedTypes \
54
// RUN: | %FileCheck %s
65

76
// REQUIRES: swift_in_compiler
87
// REQUIRES: swift_feature_LifetimeDependence
9-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
108
// REQUIRES: swift_feature_SuppressedAssociatedTypes
119

1210
protocol P {

test/SIL/lifetime_dependence_param_position_test.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-swift-frontend %s -emit-silgen \
2-
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial
2+
// RUN: -enable-experimental-feature LifetimeDependence
43

54
// REQUIRES: swift_in_compiler
65
// REQUIRES: swift_feature_LifetimeDependence
7-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
86

97

108
public struct Span<Element> : ~Escapable {

test/SIL/lifetime_dependence_span_lifetime_attr.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// RUN: %target-swift-frontend %s -emit-sil \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: | %FileCheck %s
54

65
// REQUIRES: swift_in_compiler
76
// REQUIRES: swift_feature_LifetimeDependence
8-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
97

108
// TODO: Use real Range
119
public struct FakeRange<Bound> {

test/SIL/type_lowering_unit.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-sil-opt -test-runner \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: %s -o /dev/null 2>&1 | %FileCheck %s
54

65
// REQUIRES: swift_feature_LifetimeDependence
7-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
86

97
sil_stage raw
108

test/SILGen/accessor_borrow.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-swift-emit-silgen -module-name accessor_borrow \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: %s | %FileCheck %s
54

65
// REQUIRES: swift_feature_LifetimeDependence
7-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
86

97
struct NE: ~Escapable {}
108

test/SILGen/addressors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func test1() -> Int32 {
9797
// CHECK: [[PTR:%.*]] = apply [[ACCESSOR]]({{%.*}}, [[A]]) : $@convention(method) (Int32, A) -> UnsafePointer<Int32>
9898
// CHECK: [[T0:%.*]] = struct_extract [[PTR]] : $UnsafePointer<Int32>, #UnsafePointer._rawValue
9999
// CHECK: [[T1:%.*]] = pointer_to_address [[T0]] : $Builtin.RawPointer to [strict] $*Int32
100-
// CHECK: [[MD:%.*]] = mark_dependence [nonescaping] [[T1]] : $*Int32 on [[A]] : $A
100+
// CHECK: [[MD:%.*]] = mark_dependence [[T1]] : $*Int32 on [[A]] : $A
101101
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unsafe] [[MD]] : $*Int32
102102
// CHECK: [[T2:%.*]] = load [[ACCESS]] : $*Int32
103103
// CHECK: return [[T2]] : $Int32

test/SILOptimizer/argument_conventions.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// RUN: %target-sil-opt -test-runner %s \
22
// RUN: -sil-verify-all \
33
// RUN: -enable-experimental-feature LifetimeDependence \
4-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
54
// RUN: 2>&1 | %FileCheck %s
65

76
// REQUIRES: swift_in_compiler
87
// REQUIRES: swift_feature_LifetimeDependence
9-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
108

119
import Builtin
1210

test/SILOptimizer/capture_promotion_ownership.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// RUN: %target-sil-opt -sil-print-types -enable-sil-verify-all %s -capture-promotion \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: -module-name Swift \
54
// RUN: | %FileCheck %s
65

76
// REQUIRES: swift_feature_LifetimeDependence
8-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
97

108
// Check to make sure that the process of promoting closure captures results in
119
// a correctly cloned and modified closure function body. This test

test/SILOptimizer/lifetime_dependence/coroutine.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// RUN: %target-swift-frontend %s -emit-sil \
22
// RUN: -enable-experimental-feature LifetimeDependence \
3-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
43
// RUN: | %FileCheck %s
54

65
// REQUIRES: swift_in_compiler
76
// REQUIRES: swift_feature_LifetimeDependence
8-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
97

108
struct View : ~Escapable {
119
let ptr: UnsafeRawBufferPointer

test/SILOptimizer/lifetime_dependence/diagnostic_passes.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-sil-opt -test-runner %s \
22
// RUN: -diagnostics -sil-verify-all \
33
// RUN: -enable-experimental-feature LifetimeDependence \
4-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
54
// RUN: 2>&1 | %FileCheck %s
65

76
// Test SIL expected from SILGen output. Run all diagnostic passes which includes lifetime dependence handling:
@@ -13,7 +12,6 @@
1312

1413
// REQUIRES: swift_in_compiler
1514
// REQUIRES: swift_feature_LifetimeDependence
16-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
1715

1816
sil_stage raw
1917

test/SILOptimizer/lifetime_dependence/diagnostic_passes_todo.sil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// RUN: %target-sil-opt -test-runner %s \
22
// RUN: -diagnostics -sil-verify-all \
33
// RUN: -enable-experimental-feature LifetimeDependence \
4-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
54
// RUN: 2>&1 | %FileCheck %s
65

76
// REQUIRES: swift_feature_LifetimeDependence
8-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
97

108
// Test SIL expected from SILGen output. Run all diagnostic passes which includes lifetime dependence handling.
119
// These tests are not fully implemented.

test/SILOptimizer/lifetime_dependence/initializer.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// RUN: -verify \
44
// RUN: -sil-verify-all \
55
// RUN: -module-name test \
6-
// RUN: -enable-experimental-feature LifetimeDependence \
7-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial
6+
// RUN: -enable-experimental-feature LifetimeDependence
87

98
// REQUIRES: swift_in_compiler
109
// REQUIRES: swift_feature_LifetimeDependence
11-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
1210

1311
struct Span<T>: ~Escapable {
1412
private var base: UnsafePointer<T>

test/SILOptimizer/lifetime_dependence/inout.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// RUN: -verify \
44
// RUN: -sil-verify-all \
55
// RUN: -module-name test \
6-
// RUN: -enable-experimental-feature LifetimeDependence \
7-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial
6+
// RUN: -enable-experimental-feature LifetimeDependence
87

98
// REQUIRES: swift_in_compiler
109
// REQUIRES: swift_feature_LifetimeDependence
11-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
1210

1311
struct Span<T>: ~Escapable {
1412
private var base: UnsafePointer<T>

test/SILOptimizer/lifetime_dependence/lifetime_dependence.sil

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// RUN: -o /dev/null \
33
// RUN: -sil-verify-all \
44
// RUN: -module-name Swift \
5-
// RUN: -enable-experimental-feature LifetimeDependence \
6-
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial
5+
// RUN: -enable-experimental-feature LifetimeDependence
76

87
// REQUIRES: swift_in_compiler
98
// REQUIRES: swift_feature_LifetimeDependence
10-
// REQUIRES: swift_feature_LifetimeDependenceDiagnoseTrivial
119

1210
// Test the SIL representation for lifetime dependence.
1311

0 commit comments

Comments
 (0)