Skip to content

Commit 86e0059

Browse files
authored
Merge pull request #60909 from hamishknight/top-tier-coverage
2 parents 5f49ba1 + 27b27a4 commit 86e0059

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ static bool isUnmapped(ASTNode N) {
5151
}
5252

5353
if (auto *E = N.dyn_cast<Expr *>()) {
54-
if (isa<LiteralExpr>(E)) {
55-
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: literal expr\n");
56-
return true;
57-
}
58-
5954
if (auto *CE = dyn_cast<AbstractClosureExpr>(E)) {
6055
// Only map closure expressions with bodies.
6156
if (!doesClosureHaveBody(CE)) {

lib/SILGen/SILGenFunction.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
981981

982982
void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
983983
bool EmitProfilerIncrement) {
984+
auto *const topLevelValue = value;
984985
auto *dc = function.getDecl()->getInnermostDeclContext();
985986
MagicFunctionName = SILGenModule::getMagicFunctionName(function);
986987

@@ -1034,8 +1035,12 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
10341035
auto interfaceType = value->getType()->mapTypeOutOfContext();
10351036
emitProlog(captureInfo, params, /*selfParam=*/nullptr,
10361037
dc, interfaceType, /*throws=*/false, SourceLoc());
1037-
if (EmitProfilerIncrement)
1038-
emitProfilerIncrement(value);
1038+
if (EmitProfilerIncrement) {
1039+
// Emit a profiler increment for the top-level value, not looking through
1040+
// any function conversions. This is necessary as the counter would have
1041+
// been recorded for this expression, not the sub-expression.
1042+
emitProfilerIncrement(topLevelValue);
1043+
}
10391044
prepareEpilog(interfaceType, false, CleanupLocation(Loc));
10401045

10411046
{

test/Profiler/coverage_var_init.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sorted-sil -emit-sil -module-name coverage_var_init %s | %FileCheck %s
22
// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -emit-ir %s
33

4+
struct S {
5+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1iSivpfi" {{.*}} // variable initialization expression of coverage_var_init.S.i
6+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+1]]:12 : 0
7+
var i = 0
8+
9+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1jSivpfi" {{.*}} // variable initialization expression of coverage_var_init.S.j
10+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+1]]:16 : 0
11+
var j = 1 + 2
12+
13+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1kSiycvpfi" {{.*}} // variable initialization expression of coverage_var_init.S.k
14+
// CHECK-NEXT: [[@LINE+3]]:11 -> [[@LINE+3]]:20 : 0
15+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1kSiycvpfiSiycfU_" {{.*}} // closure #1 () -> Swift.Int in variable initialization expression of coverage_var_init.S.k
16+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+1]]:20 : 0
17+
var k = { 1 + 2 }
18+
19+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1lSivpfi" {{.*}} // variable initialization expression of coverage_var_init.S.l
20+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+1]]:16 : 0
21+
var l = #line
22+
23+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1mSaySiGvpfi" {{.*}} // variable initialization expression of coverage_var_init.S.m
24+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+1]]:20 : 0
25+
var m = [1, 2, 3]
26+
27+
// CHECK-LABEL: sil_coverage_map {{.*}} "$s17coverage_var_init1SV1nSSvpfi" {{.*}} // variable initialization expression of coverage_var_init.S.n
28+
// CHECK-NEXT: [[@LINE+3]]:11 -> [[@LINE+3]]:33 : 0
29+
// CHECK-NEXT: [[@LINE+2]]:26 -> [[@LINE+2]]:27 : 1
30+
// CHECK-NEXT: [[@LINE+1]]:30 -> [[@LINE+1]]:31 : (0 - 1)
31+
var n = "\(.random() ? 1 : 2)"
32+
}
33+
434
final class VarInit {
535
// CHECK: sil_coverage_map {{.*}} "$s17coverage_var_init7VarInitC018initializedWrapperE0SivpfP"
636
// CHECK-NEXT: [[@LINE+1]]:4 -> [[@LINE+1]]:42 : 0
737
@Wrapper var initializedWrapperInit = 2
838

39+
// CHECK: sil_coverage_map {{.*}} // variable initialization expression of coverage_var_init.VarInit.(_autoclosureWrapperInit
40+
// CHECK-NEXT: [[@LINE+1]]:52 -> [[@LINE+1]]:53
41+
@AutoClosureWrapper var autoclosureWrapperInit = 3
42+
943
// CHECK: sil_coverage_map {{.*}} "$s17coverage_var_init7VarInitC04lazydE033_49373CB2DFB47C8DC62FA963604688DFLLSSvgSSyXEfU_"
1044
// CHECK-NEXT: [[@LINE+1]]:42 -> [[@LINE+3]]:4 : 0
1145
private lazy var lazyVarInit: String = {
@@ -37,4 +71,12 @@ final class VarInit {
3771
var wrappedValue: Int { 1 }
3872
}
3973

74+
@propertyWrapper
75+
struct AutoClosureWrapper<T> {
76+
var wrappedValue: T
77+
init(wrappedValue: @autoclosure () -> T) {
78+
self.wrappedValue = wrappedValue()
79+
}
80+
}
81+
4082
VarInit().coverageFunction()

0 commit comments

Comments
 (0)