Skip to content

Commit 9f93bc8

Browse files
committed
[Profiler] Emit increment for property wrapper backing initializers
Previously we were creating a SILProfiler for such functions, but weren't actually emitting the increment, leading to missed coverage. Part of the fix for rdar://99931619
1 parent 11b6e0d commit 9f93bc8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,8 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10251025
f->createProfiler(wrapperInfo.getInitFromWrappedValue(), constant);
10261026
auto varDC = var->getInnermostDeclContext();
10271027
SILGenFunction SGF(*this, *f, varDC);
1028-
SGF.emitGeneratorFunction(constant, wrapperInfo.getInitFromWrappedValue());
1028+
SGF.emitGeneratorFunction(constant, wrapperInfo.getInitFromWrappedValue(),
1029+
/*EmitProfilerIncrement*/ true);
10291030
postEmitFunction(constant, f);
10301031
break;
10311032
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sorted-sil -emit-sil -module-name coverage_property_wrapper_backing %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -emit-ir %s
3+
4+
@propertyWrapper
5+
struct Wrapper<T> {
6+
var wrappedValue: T
7+
init(wrappedValue: T, _ x: Int) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// rdar://99931619 – Make sure we emit the profiler increment for the backing
13+
// initializer.
14+
15+
// CHECK-LABEL: sil hidden @$s33coverage_property_wrapper_backing1SV1iSivpfP : $@convention(thin) (Int) -> Wrapper<Int>
16+
// CHECK: increment_profiler_counter 0
17+
// CHECK: function_ref @$sSb6randomSbyFZ
18+
// CHECK: cond_br {{%[0-9]+}}, [[BB:bb[0-9]]]
19+
// CHECK: [[BB]]:
20+
// CHECK-NEXT: increment_profiler_counter 1
21+
22+
struct S {
23+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s33coverage_property_wrapper_backing1SV1iSivpfP" {{.*}} // property wrapper backing initializer of coverage_property_wrapper_backing.S.i
24+
// CHECK-NEXT: [[@LINE+4]]:4 -> [[@LINE+4]]:30 : 0
25+
// CHECK-NEXT: [[@LINE+3]]:24 -> [[@LINE+3]]:25 : 1
26+
// CHECK-NEXT: [[@LINE+2]]:28 -> [[@LINE+2]]:29 : (0 - 1)
27+
// CHECK-NEXT: }
28+
@Wrapper(.random() ? 1 : 2)
29+
var i = 3
30+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s33coverage_property_wrapper_backing1SV2_i{{.*}}" {{.*}} // variable initialization expression of coverage_property_wrapper_backing.S.(_i in {{.*}}) : coverage_property_wrapper_backing.Wrapper<Swift.Int>
31+
// CHECK-NEXT: [[@LINE-2]]:11 -> [[@LINE-2]]:12 : 0
32+
// CHECK-NEXT: }
33+
}
34+
35+
// FIXME(rdar://99962285): This is currently needed to SILGen the property
36+
// initializer for 'i'.
37+
_ = S().i

0 commit comments

Comments
 (0)