Skip to content

Commit 0a70bdd

Browse files
committed
LifetimeDependenceDiagnostics: handle undiagnosed mark_depends
Mark unresolved mark_depends as nonescaping so they don't leak into the optimizer pipeline.
1 parent a0b21d5 commit 0a70bdd

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
4545
// Indirect results are not checked here. Type checking ensures
4646
// that they have a lifetime dependence.
4747
if let lifetimeDep = LifetimeDependence(argument, context) {
48-
analyze(dependence: lifetimeDep, context)
48+
_ = analyze(dependence: lifetimeDep, context)
4949
}
5050
}
5151
for instruction in function.instructions {
5252
if let markDep = instruction as? MarkDependenceInst, markDep.isUnresolved {
5353
if let lifetimeDep = LifetimeDependence(markDep, context) {
54-
analyze(dependence: lifetimeDep, context)
54+
if analyze(dependence: lifetimeDep, context) {
55+
// Note: This promotes the mark_dependence flag but does not invalidate SIL; preserving analyses is good,
56+
// but the change won't appear in -sil-print-function. Ideally, we could notify context of a flag change
57+
// without invalidating analyses.
58+
lifetimeDep.resolve(context)
59+
}
60+
} else {
61+
// For now, if the mark_dependence wasn't recognized as a lifetime dependence, conservatively settle it as
62+
// escaping. In the future, we should not need this because, for escapable types, mark_dependence [unresolved]
63+
// will all be settled during an early LifetimeNormalization pass.
64+
markDep.settleToEscaping()
5565
}
5666
continue
5767
}
@@ -61,7 +71,7 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
6171
apply.resultOrYields.forEach {
6272
if let lifetimeDep = LifetimeDependence(unsafeApplyResult: $0,
6373
context) {
64-
analyze(dependence: lifetimeDep, context)
74+
_ = analyze(dependence: lifetimeDep, context)
6575
}
6676
}
6777
continue
@@ -74,8 +84,9 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
7484
/// 1. Compute the LifetimeDependence scope.
7585
///
7686
/// 2. Walk down all dependent values checking that they are within range.
77-
private func analyze(dependence: LifetimeDependence,
78-
_ context: FunctionPassContext) {
87+
///
88+
/// Return true on success.
89+
private func analyze(dependence: LifetimeDependence, _ context: FunctionPassContext) -> Bool {
7990
log("Dependence scope:\n\(dependence)")
8091

8192
// Compute this dependence scope.
@@ -91,10 +102,7 @@ private func analyze(dependence: LifetimeDependence,
91102
var walker = DiagnoseDependenceWalker(diagnostics, context)
92103
defer { walker.deinitialize() }
93104
_ = walker.walkDown(root: dependence.dependentValue)
94-
95-
if !error {
96-
dependence.resolve(context)
97-
}
105+
return !error
98106
}
99107

100108
/// Analyze and diagnose a single LifetimeDependence.

0 commit comments

Comments
 (0)