Skip to content

Commit 1132152

Browse files
authored
Merge pull request #69300 from eeckstein/fix-perf-diagnostics
PerformanceDiagnostics: exclude error handling from performance-checked code
2 parents c90db42 + 1ec71a3 commit 1132152

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

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

160+
NonErrorHandlingBlocks neBlocks(function);
161+
160162
for (SILBasicBlock &block : *function) {
161163
// Exclude fatal-error blocks.
162164
if (isa<UnreachableInst>(block.getTerminator()))
163165
continue;
164166

167+
// TODO: it's not yet clear how to deal with error existentials.
168+
// Ignore them for now. If we have typed throws we could ban error existentials
169+
// because typed throws would provide and alternative.
170+
if (isa<ThrowInst>(block.getTerminator()))
171+
continue;
172+
173+
if (!neBlocks.isNonErrorHandling(&block))
174+
continue;
175+
165176
for (SILInstruction &inst : block) {
166177
if (visitInst(&inst, perfConstr, parentLoc)) {
167178
LLVM_DEBUG(llvm::dbgs() << inst << *inst.getFunction());

test/SILOptimizer/performance-annotations.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ func errorExistential(_ b: Bool) throws -> Int {
9898
if b {
9999
return 28
100100
}
101-
throw MyError() // expected-error {{Using type 'MyError' can cause metadata allocation or locks}}
101+
throw MyError()
102102
}
103103

104104
@_noLocks
105105
func testCatch(_ b: Bool) throws -> Int? {
106106
do {
107107
return try errorExistential(true)
108-
} catch let e as MyError { // expected-error {{this code performs reference counting operations which can cause locking}}
108+
} catch let e as MyError {
109109
print(e)
110110
return nil
111111
}

0 commit comments

Comments
 (0)