Skip to content

Commit 58d41a1

Browse files
authored
Merge pull request #66803 from eeckstein/fix-performance-diagnostics
PerformanceDiagnostics: fix two small issues which result in false alarms
2 parents b77a8d9 + bfb5d21 commit 58d41a1

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
901901
if (pa->isOnStack()) {
902902
for (SILValue arg : pa->getArguments()) {
903903
if (!arg->getType().isTrivial(*pa->getFunction()))
904-
rt |= RuntimeEffect::RefCounting;
904+
rt |= ifNonTrivial(arg->getType(), RuntimeEffect::RefCounting);
905905
}
906906
} else {
907907
rt |= RuntimeEffect::Allocating | RuntimeEffect::Releasing;

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ bool PerformanceDiagnostics::checkClosureValue(SILValue closure,
217217
closure = tfi->getOperand();
218218
} else if (auto *cp = dyn_cast<CopyValueInst>(closure)) {
219219
closure = cp->getOperand();
220+
} else if (auto *bb = dyn_cast<BeginBorrowInst>(closure)) {
221+
closure = bb->getOperand();
220222
} else if (auto *cv = dyn_cast<ConvertFunctionInst>(closure)) {
221223
closure = cv->getOperand();
222224
} else if (acceptFunctionArgs && isa<SILFunctionArgument>(closure)) {

test/SILOptimizer/performance-annotations.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,31 @@ public func testCollectionSort(a: X) -> Int {
302302
return 0
303303
}
304304

305+
public struct Y {
306+
var a, b, c: Int
307+
}
308+
309+
extension Y {
310+
func with2(_ body: () -> ()) {
311+
body()
312+
}
313+
314+
func with1(_ body: (Int) -> (Int)) -> Int {
315+
with2 {
316+
_ = body(48)
317+
}
318+
return 777
319+
}
320+
321+
func Xsort() -> Int {
322+
with1 { i in
323+
i
324+
}
325+
}
326+
}
327+
328+
@_noLocks
329+
public func testClosurePassing(a: inout Y) -> Int {
330+
return a.Xsort()
331+
}
332+

0 commit comments

Comments
 (0)