Skip to content

Commit bf9b4b9

Browse files
committed
[Profiler] Only map implicit getters for lazy vars
This is the only implicit getter case we care about, the rest do not contain user-written code. This means that we now otherwise only ever map explicit decls, which we need to SILGen anyway. As such I believe this should fix rdar://39332957. We do still potentially map implicit expressions, but should only do so for explicit property initializers. There is one remaining bug where we can map an implicit property wrapper backing initalizer, which I'm tracking in rdar://99931619.
1 parent 5039c1c commit bf9b4b9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ static bool isUnmapped(ASTNode N) {
7777
return true;
7878
}
7979

80-
// Map implicit getters.
81-
if (auto *accessor = dyn_cast<AccessorDecl>(AFD))
82-
if (accessor->isImplicit() && accessor->isGetter())
80+
// Map implicit getters for lazy variables.
81+
if (auto *accessor = dyn_cast<AccessorDecl>(AFD)) {
82+
if (accessor->isImplicit() && accessor->isGetter() &&
83+
accessor->getStorage()->getAttrs().hasAttribute<LazyAttr>()) {
8384
return false;
85+
}
86+
}
8487
}
8588

8689
// Skip any remaining implicit, or otherwise unsupported decls.

test/Profiler/unmapped.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -suppress-warnings -profile-generate -profile-coverage-mapping -emit-sorted-sil -emit-sil -module-name unmapped %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -emit-ir %s
3+
4+
// This test is exclusively for AST that we should never profile, as there is
5+
// no interesting user-written code.
6+
7+
// CHECK-NOT: increment_profiler_counter
8+
// CHECK-NOT: sil_coverage_map
9+
10+
struct S {
11+
// Don't profile the implicit accessor, or the implicit constructor.
12+
var x: Int
13+
}
14+
15+
// Don't profile any synthesized codable methods.
16+
struct R : Codable {
17+
var x: String
18+
var y: Int
19+
}
20+
21+
// Don't profile the implicit rawValue.
22+
enum E : Int {
23+
case a
24+
}

0 commit comments

Comments
 (0)