Skip to content

Commit 74a5a5e

Browse files
authored
Merge pull request #68002 from eeckstein/fix-performance-diagnostic
PerformanceDiagnostics: fix handling of nested closures
2 parents 1d24662 + 1603035 commit 74a5a5e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ bool PerformanceDiagnostics::checkClosureValue(SILValue closure,
259259
closure = bb->getOperand();
260260
} else if (auto *cv = dyn_cast<ConvertFunctionInst>(closure)) {
261261
closure = cv->getOperand();
262+
} else if (auto *md = dyn_cast<MarkDependenceInst>(closure)) {
263+
closure = md->getValue();
262264
} else if (acceptFunctionArgs && isa<SILFunctionArgument>(closure)) {
263265
// We can assume that a function closure argument is already checked at
264266
// the call site.

test/SILOptimizer/performance-annotations.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,23 @@ func testPointerToX() -> UnsafePointer<Int> {
385385
return pointerToX
386386
}
387387

388+
func foo<T>(_ body: () -> (T)) -> T {
389+
return body()
390+
}
391+
392+
func bar<T>(_ body: () -> (T)) -> T {
393+
return body()
394+
}
395+
396+
func baz<T>(t: T) -> T {
397+
foo {
398+
bar {
399+
return t
400+
}
401+
}
402+
}
403+
404+
@_noLocks
405+
func nestedClosures() -> Int {
406+
return baz(t: 42)
407+
}

0 commit comments

Comments
 (0)