Skip to content

Commit 6341391

Browse files
committed
LifetimeDependenceDiagnostics; handle @_unsafeNonescapableResult.
1 parent 8b24382 commit 6341391

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,21 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
4343
}
4444
}
4545
for instruction in function.instructions {
46-
guard let markDep = instruction as? MarkDependenceInst else { continue }
47-
if let lifetimeDep = LifetimeDependence(markDep, context) {
48-
analyze(dependence: lifetimeDep, context)
46+
if let markDep = instruction as? MarkDependenceInst {
47+
if let lifetimeDep = LifetimeDependence(markDep, context) {
48+
analyze(dependence: lifetimeDep, context)
49+
}
50+
continue
51+
}
52+
if let apply = instruction as? FullApplySite {
53+
// Handle ~Escapable results that do not have a lifetime
54+
// dependence (@_unsafeNonescapableResult).
55+
apply.dependentValues.forEach {
56+
if let lifetimeDep = LifetimeDependence(applyResult: $0, context) {
57+
analyze(dependence: lifetimeDep, context)
58+
}
59+
}
60+
continue
4961
}
5062
}
5163
}

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ extension LifetimeDependence {
174174
self.dependentValue = arg
175175
}
176176

177+
// Handle ~Escapable results that do not have a lifetime dependence
178+
// (@_unsafeNonescapableResult).
179+
init?(applyResult value: Value, _ context: some Context) {
180+
if value.type.isEscapable {
181+
return nil
182+
}
183+
let applySite = value.definingInstruction as! FullApplySite
184+
if applySite.calleeArgumentConventions.resultDependencies != nil {
185+
return nil
186+
}
187+
self.scope = Scope(base: value, context)!
188+
self.dependentValue = value
189+
}
190+
177191
/// Construct LifetimeDependence from mark_dependence [nonescaping]
178192
///
179193
/// TODO: Add SIL verification that all mark_depedence [nonescaping]

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7599,9 +7599,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
75997599
}
76007600
sub->Printer << ") -> ";
76017601

7602-
auto *lifetimeDependenceInfo = T->getLifetimeDependenceInfo();
7603-
if (lifetimeDependenceInfo && !lifetimeDependenceInfo->empty()) {
7604-
sub->Printer << lifetimeDependenceInfo->getString() << " ";
7602+
auto lifetimeDependenceInfo = T->getLifetimeDependenceInfo();
7603+
if (!lifetimeDependenceInfo.empty()) {
7604+
sub->Printer << lifetimeDependenceInfo.getString() << " ";
76057605
}
76067606

76077607
bool parenthesizeResults = mustParenthesizeResults(T);

0 commit comments

Comments
 (0)