Skip to content

Commit c407dc6

Browse files
authored
Merge pull request #37469 from hborla/5.5-05142021-local-wrapper-capture
[5.5-05142021][SILGen] Allow capturing local wrapped properties.
2 parents 4f0cadc + 58d15b0 commit c407dc6

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2829,8 +2829,15 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
28292829
// of its accessors.
28302830
if (auto capturedVar = dyn_cast<VarDecl>(capture.getDecl())) {
28312831
auto collectAccessorCaptures = [&](AccessorKind kind) {
2832-
if (auto *accessor = capturedVar->getParsedAccessor(kind))
2832+
if (auto *accessor = capturedVar->getParsedAccessor(kind)) {
28332833
collectFunctionCaptures(accessor);
2834+
} else if (capturedVar->hasAttachedPropertyWrapper() ||
2835+
capturedVar->getOriginalWrappedProperty(
2836+
PropertyWrapperSynthesizedPropertyKind::Projection)) {
2837+
// Wrapped properties have synthesized accessors.
2838+
if (auto *accessor = capturedVar->getSynthesizedAccessor(kind))
2839+
collectFunctionCaptures(accessor);
2840+
}
28342841
};
28352842

28362843
// 'Lazy' properties don't fit into the below categorization,

test/SILGen/property_wrapper_local.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,20 @@ func testLocalReference(count: Int) {
173173
// setter of value #1 in testLocalReference(count:)
174174
// CHECK: sil private [ossa] @$s22property_wrapper_local18testLocalReference5countySi_tF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var BoundedNumber<Int> }) -> ()
175175
}
176+
177+
func takesAutoclosure(_: @autoclosure () -> Int) {}
178+
179+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local12testCapturesyyF : $@convention(thin) () -> ()
180+
func testCaptures() {
181+
@Wrapper var value = 10
182+
takesAutoclosure(value)
183+
// implicit closure #1 in testCaptures()
184+
// CHECK-LABEL: sil private [transparent] [ossa] @$s22property_wrapper_local12testCapturesyyFSiyXEfu_ : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Int
185+
186+
let _: () -> Void = {
187+
_ = value
188+
value = 100
189+
}
190+
// closure #1 in testCaptures()
191+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local12testCapturesyyFyycfU_ : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> ()
192+
}

test/SILGen/property_wrapper_parameter.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,41 @@ func testImplicitWrapperWithResilientStruct() {
301301
// property wrapper init from projected value of $value #1 in closure #1 in implicit closure #1 in testImplicitWrapperWithResilientStruct()
302302
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_yAHcfU_6$valueL_AHvpfW : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
303303
}
304+
305+
func takesAutoclosure(_: @autoclosure () -> Int) {}
306+
307+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtF : $@convention(thin) (Int, Wrapper<Int>) -> ()
308+
func testCaptures(@ClassWrapper ref: Int, @Wrapper value: Int) {
309+
takesAutoclosure(ref)
310+
// implicit closure #1 in testCaptures(ref:value:)
311+
// CHECK-LABEL: sil private [transparent] [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFSiyXEfu_ : $@convention(thin) (@guaranteed ClassWrapper<Int>) -> Int
312+
313+
let _: () -> Void = {
314+
_ = ref
315+
ref = 100
316+
}
317+
// closure #1 in testCaptures(ref:value:)
318+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFyycfU_ : $@convention(thin) (@guaranteed ClassWrapper<Int>) -> ()
319+
320+
let _: () -> Projection<Int> = { $value }
321+
// closure #2 in testCaptures(ref:value:)
322+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFAA10ProjectionVySiGycfU0_ : $@convention(thin) (Wrapper<Int>) -> Projection<Int>
323+
324+
let _: (ProjectionWrapper<Int>) -> Void = { $x in
325+
_ = { x }
326+
_ = { $x }
327+
}
328+
// Make sure there are 4 closures here with the right arguments
329+
330+
// implicit closure #2 in testCaptures(ref:value:)
331+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFyAA010ProjectionH0VySiGcfu0_ : $@convention(thin) (ProjectionWrapper<Int>) -> ()
332+
333+
// closure #3 in implicit closure #2 in testCaptures(ref:value:)
334+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFyAA010ProjectionH0VySiGcfu0_yAJcfU1_ : $@convention(thin) (ProjectionWrapper<Int>) -> ()
335+
336+
// closure #1 in closure #2 in implicit closure #2 in testCaptures(ref:value:)
337+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFyAA010ProjectionH0VySiGcfu0_yAJcfU1_SiycfU_ : $@convention(thin) (ProjectionWrapper<Int>) -> Int
338+
339+
// closure #2 in closure #2 in implicit closure #2 in testCaptures(ref:value:)
340+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter12testCaptures3ref5valueySi_AA7WrapperVySiGtFyAA010ProjectionH0VySiGcfu0_yAJcfU1_AJycfU0_ : $@convention(thin) (ProjectionWrapper<Int>) -> ProjectionWrapper<Int>
341+
}

0 commit comments

Comments
 (0)