Skip to content

Commit fd1af46

Browse files
authored
Merge pull request #69121 from eeckstein/fix-perf-diagnostics
PerformanceDiagnostics: fix handling of infinite loops and change error handling
2 parents 4d8c0c8 + e2a268e commit fd1af46

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,11 @@ bool PerformanceDiagnostics::visitFunction(SILFunction *function,
157157
if (!function->isDefinition())
158158
return false;
159159

160-
ReachingReturnBlocks rrBlocks(function);
161-
NonErrorHandlingBlocks neBlocks(function);
162-
163160
for (SILBasicBlock &block : *function) {
164-
if (!rrBlocks.reachesReturn(&block) || !neBlocks.isNonErrorHandling(&block))
161+
// Exclude fatal-error blocks.
162+
if (isa<UnreachableInst>(block.getTerminator()))
165163
continue;
164+
166165
for (SILInstruction &inst : block) {
167166
if (visitInst(&inst, perfConstr, parentLoc))
168167
return true;

test/SILOptimizer/performance-annotations.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ func testMemoryLayout() -> Int {
9494
class MyError : Error {}
9595

9696
@_noLocks
97-
func noDiagnosticsInThrowPath(_ b: Bool) throws -> Int {
97+
func errorExistential(_ b: Bool) throws -> Int {
9898
if b {
9999
return 28
100100
}
101-
throw MyError()
101+
throw MyError() // expected-error {{Using type 'MyError' can cause metadata allocation or locks}}
102102
}
103103

104104
@_noLocks
105-
func noDiagnosticsInCatch(_ b: Bool) throws -> Int? {
105+
func testCatch(_ b: Bool) throws -> Int? {
106106
do {
107-
return try noDiagnosticsInThrowPath(true)
108-
} catch let e as MyError {
107+
return try errorExistential(true)
108+
} catch let e as MyError { // expected-error {{this code performs reference counting operations which can cause locking}}
109109
print(e)
110110
return nil
111111
}
@@ -405,3 +405,10 @@ func baz<T>(t: T) -> T {
405405
func nestedClosures() -> Int {
406406
return baz(t: 42)
407407
}
408+
409+
@_noAllocation
410+
func testInfiniteLoop(_ c: Cl) {
411+
c.classMethod() // expected-error {{called function is not known at compile time and can have unpredictable performance}}
412+
while true {}
413+
}
414+

0 commit comments

Comments
 (0)