Skip to content

Commit ccc0e92

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents d491d29 + f3b9b84 commit ccc0e92

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,26 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
329329
}
330330
}
331331

332+
// Enforce exclusivity restrictions on recursive uses of non-escaping closures.
333+
// Exclusivity requires a Non-Escaping Recursion Restriction rule (SE-0176):
334+
// A non-escaping closure A may not be recursively invoked during the
335+
// execution of a non-escaping closure B which captures the same local
336+
// variable or inout parameter unless:
337+
// - A is defined within B or
338+
// - A is a local function declaration which is referenced directly by B.
339+
//
340+
// This is conservatively approximated with a Non-Escaping Parameter Call
341+
// Restriction rule (NPCR), as implemented below:
342+
// A function may not call a non-escaping function parameter passing a
343+
// non-escaping function parameter as an argument.
344+
// For the purposes of this rule, a closure which captures a non-escaping
345+
// function parameter is treated the same as the parameter.
346+
//
347+
// Note: The compiler does not enforce recursion via
348+
// withoutActuallyEscaping. This undefined behavior is exposed to programmers.
349+
//
350+
// TODO: Verify that all uses of noescaping function arguments are SIL patterns
351+
// that are recognized below to prove that this diagnostic is complete.
332352
static void checkApply(ASTContext &Context, FullApplySite site) {
333353
auto isNoEscapeParam = [&](SILValue value) -> const ParamDecl * {
334354
// If the value is an escaping, do not enforce any restrictions.

test/Generics/non_generic_derived_class.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ class Base<T> {
99
class Derived : Base<Int> {}
1010

1111
var a = Derived.f(42)
12+
13+
protocol SR9160_EmptyProtocol {}
14+
class SR9160_AbstractFoobar<Foo> {}
15+
// This used to cause the swift compiler to never finish compiling.
16+
final class SR9160_SomeFoobar: SR9160_AbstractFoobar<SR9160_SomeFoobar.Foo> {
17+
enum Foo: SR9160_EmptyProtocol {}
18+
}

0 commit comments

Comments
 (0)