Skip to content

Commit f63117e

Browse files
committed
ManualOwnership: don't diagnose unknown callees
Since the annotation is non-viral, we don't want to emit an error when we counter a callee that is unknown. resolves rdar://161407417
1 parent a96e494 commit f63117e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ bool PerformanceDiagnostics::visitFunction(SILFunction *function,
208208
if (auto *fri = dyn_cast<FunctionRefInst>(bi->getArguments()[1])) {
209209
if (visitCallee(bi, fri->getReferencedFunction(), perfConstr, parentLoc))
210210
return true;
211-
} else {
211+
} else if (perfConstr != PerformanceConstraints::ManualOwnership) {
212212
LocWithParent loc(inst.getLoc().getSourceLoc(), parentLoc);
213213
diagnose(loc, diag::performance_unknown_callees);
214214
return true;
@@ -250,6 +250,12 @@ bool PerformanceDiagnostics::checkClosureValue(SILValue closure,
250250
SILInstruction *callInst,
251251
PerformanceConstraints perfConstr,
252252
LocWithParent *parentLoc) {
253+
// Closures within a function are pre-annotated with [manual_ownership]
254+
// within SILGen, if they're visible to users for annotation at all.
255+
// So no recursive closure checking is needed here.
256+
if (perfConstr == PerformanceConstraints::ManualOwnership)
257+
return false;
258+
253259
// Walk through the definition of the closure until we find the "underlying"
254260
// function_ref instruction.
255261
while (!isa<FunctionRefInst>(closure)) {

test/SIL/manual_ownership.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ func basic_methods_consuming_fixed(_ t1: Triangle) {
144144
(copy t2).consuming() // FIXME: why is this not propagated?
145145
}
146146

147+
open class OpenClass {
148+
open func classMethod() {}
149+
}
150+
@_manualOwnership
151+
func callOpenMethod(_ c: OpenClass) {
152+
return c.classMethod()
153+
}
154+
147155
@_manualOwnership
148156
@discardableResult
149157
func consumingFunc(_ t0: consuming Triangle) -> Bool { return false }

0 commit comments

Comments
 (0)