From 3a97766bb3397c39cdd323cd9077cfba3bd18745 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 8 Jun 2023 16:33:14 -0700 Subject: [PATCH] Avoid emitting variable debug info for closure captures. Variable debug info is triggered by pattern bindings, however, inside a closure capture list, this should be avoided by setting the appropriate flag in the initializer object. rdar://110329894 --- lib/SILGen/RValue.cpp | 2 +- lib/SILGen/SILGenDecl.cpp | 6 ++++-- test/DebugInfo/captures.swift | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/DebugInfo/captures.swift diff --git a/lib/SILGen/RValue.cpp b/lib/SILGen/RValue.cpp index 393c1a97320ee..bd9016ffa42c3 100644 --- a/lib/SILGen/RValue.cpp +++ b/lib/SILGen/RValue.cpp @@ -547,7 +547,7 @@ SILValue RValue::forwardAsSingleStorageValue(SILGenFunction &SGF, return SGF.emitConversionFromSemanticValue(l, result, storageType); } -void RValue::forwardInto(SILGenFunction &SGF, SILLocation loc, +void RValue::forwardInto(SILGenFunction &SGF, SILLocation loc, Initialization *I) && { assert(isComplete() && "rvalue is not complete"); assert(isPlusOneOrTrivial(SGF) && "Can not forward borrowed RValues"); diff --git a/lib/SILGen/SILGenDecl.cpp b/lib/SILGen/SILGenDecl.cpp index cb43a356d86f3..e544e8afbb5fc 100644 --- a/lib/SILGen/SILGenDecl.cpp +++ b/lib/SILGen/SILGenDecl.cpp @@ -1789,8 +1789,10 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest, InitializationPtr SILGenFunction::emitPatternBindingInitialization( Pattern *P, JumpDest failureDest, bool generateDebugInfo) { - return InitializationForPattern(*this, failureDest, generateDebugInfo) - .visit(P); + auto init = + InitializationForPattern(*this, failureDest, generateDebugInfo).visit(P); + init->setEmitDebugValueOnInit(generateDebugInfo); + return init; } /// Enter a cleanup to deallocate the given location. diff --git a/test/DebugInfo/captures.swift b/test/DebugInfo/captures.swift new file mode 100644 index 0000000000000..984108ef95547 --- /dev/null +++ b/test/DebugInfo/captures.swift @@ -0,0 +1,26 @@ +// RUN: %target-swift-frontend %s -parse-as-library -module-name a -emit-sil -g -o - | %FileCheck %s +struct S {} +public class UIView {} +public protocol View {} +public final class Signal { + public func map(_ transform: @escaping (Value) -> U) -> Signal { + return Signal() + } +} +public final class C: UIView { + private let t1: C? = nil + private let t2: C? = nil + func foo() -> Signal<(S, UIView)> { + // CHECK: sil {{.*}}s1a1CC3foo + // CHECK: debug_value {{.*}} name "self" + // CHECK-NOT: debug_value {{.*}} name "view" + // CHECK: return % + return ( + Signal() + .map { [view = t1!] in ($0, view) }, + Signal() + .map { [view = t2!] in ($0, view) } + ).0 + } +} +