Skip to content

[5.10] [Profiler] Fix handling of property wrapper backing inits #70118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/SIL/IR/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ struct MapRegionCounters : public ASTWalker {
return LazyInitializerWalking::InAccessor;
}

bool shouldWalkIntoPropertyWrapperPlaceholderValue() override {
// Don't walk into PropertyWrapperValuePlaceholderExprs, these should be
// mapped as part of the wrapped value initialization.
return false;
}

void mapRegion(ASTNode N) {
mapRegion(ProfileCounterRef::node(N));
}
Expand Down Expand Up @@ -584,6 +590,12 @@ struct PGOMapping : public ASTWalker {
return LazyInitializerWalking::InAccessor;
}

bool shouldWalkIntoPropertyWrapperPlaceholderValue() override {
// Don't walk into PropertyWrapperValuePlaceholderExprs, these should be
// mapped as part of the wrapped value initialization.
return false;
}

MacroWalking getMacroWalkingBehavior() const override {
return MacroWalking::Expansion;
}
Expand Down Expand Up @@ -945,6 +957,12 @@ struct CoverageMapping : public ASTWalker {
return LazyInitializerWalking::InAccessor;
}

bool shouldWalkIntoPropertyWrapperPlaceholderValue() override {
// Don't walk into PropertyWrapperValuePlaceholderExprs, these should be
// mapped as part of the wrapped value initialization.
return false;
}

MacroWalking getMacroWalkingBehavior() const override {
return MacroWalking::Expansion;
}
Expand Down
58 changes: 58 additions & 0 deletions test/Profiler/coverage_property_wrapper_backing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ struct PassThroughWrapper<T> {
// CHECK: [[BB]]:
// CHECK-NEXT: increment_profiler_counter 1

// CHECK-LABEL: sil hidden @$s33coverage_property_wrapper_backing1UV1xSivpfP : $@convention(thin) (Int) -> Wrapper<Int>
// CHECK: function_ref @$sSb6randomSbyFZ : $@convention(method) (@thin Bool.Type) -> Bool
// CHECK: cond_br {{%[0-9]+}}, [[BB_TRUE:bb[0-9]+]], [[BB_FALSE:bb[0-9]+]]
//
// CHECK: [[BB_FALSE]]:
// CHECK: integer_literal {{.*}}, 2
//
// CHECK: [[BB_TRUE]]:
// CHECK: increment_profiler_counter 1
// CHECK: integer_literal {{.*}}, 1

// CHECK-LABEL: sil hidden [transparent] @$s33coverage_property_wrapper_backing1UV2_{{.*}}7WrapperVySiGvpfi : $@convention(thin) () -> Int
// CHECK: increment_profiler_counter 0
// CHECK: function_ref @$sSb6randomSbyFZ : $@convention(method) (@thin Bool.Type) -> Bool
// CHECK: cond_br {{%[0-9]+}}, [[BB_TRUE:bb[0-9]+]], [[BB_FALSE:bb[0-9]+]]

// CHECK: [[BB_FALSE]]:
// CHECK: integer_literal {{.*}}, 4
//
// CHECK: [[BB_TRUE]]:
// CHECK: increment_profiler_counter 1
// CHECK: integer_literal {{.*}}, 3

struct S {
// CHECK-LABEL: sil_coverage_map {{.*}} "$s33coverage_property_wrapper_backing1SV1iSivpfP" {{.*}} // property wrapper backing initializer of coverage_property_wrapper_backing.S.i
// CHECK-NEXT: [[@LINE+4]]:4 -> [[@LINE+4]]:30 : 0
Expand Down Expand Up @@ -55,3 +78,38 @@ struct T {
@Wrapper(.random() ? 1 : 2)
var k = 3
}

// rdar://118939162 - Make sure we don't include the initialization expression
// in the backing initializer.
struct U {
// CHECK-LABEL: sil_coverage_map {{.*}} // property wrapper backing initializer of coverage_property_wrapper_backing.U.x
// CHECK-NEXT: [[@LINE+4]]:4 -> [[@LINE+4]]:30 : 0
// CHECK-NEXT: [[@LINE+3]]:24 -> [[@LINE+3]]:25 : 1
// CHECK-NEXT: [[@LINE+2]]:28 -> [[@LINE+2]]:29 : (0 - 1)
// CHECK-NEXT: }
@Wrapper(.random() ? 1 : 2)
var x = if .random() { 3 } else { 4 }
// CHECK-LABEL: sil_coverage_map {{.*}} // variable initialization expression of coverage_property_wrapper_backing.U.(_x
// CHECK-NEXT: [[@LINE-2]]:11 -> [[@LINE-2]]:40 : 0
// CHECK-NEXT: [[@LINE-3]]:14 -> [[@LINE-3]]:23 : 0
// CHECK-NEXT: [[@LINE-4]]:24 -> [[@LINE-4]]:29 : 1
// CHECK-NEXT: [[@LINE-5]]:29 -> [[@LINE-5]]:40 : 0
// CHECK-NEXT: [[@LINE-6]]:35 -> [[@LINE-6]]:40 : (0 - 1)
// CHECK-NEXT: [[@LINE-7]]:40 -> [[@LINE-7]]:40 : 0
// CHECK-NEXT: }
}

struct V {
// CHECK-LABEL: sil_coverage_map {{.*}} // property wrapper backing initializer of coverage_property_wrapper_backing.V.x
// CHECK-NEXT: [[@LINE+2]]:4 -> [[@LINE+2]]:14 : 0
// CHECK-NEXT: }
@Wrapper(0)
var x = switch Bool.random() { case true: 0 case false: 0 }
// CHECK-LABEL: sil_coverage_map {{.*}} // variable initialization expression of coverage_property_wrapper_backing.V.(_x
// CHECK-NEXT: [[@LINE-2]]:11 -> [[@LINE-2]]:62 : 0
// CHECK-NEXT: [[@LINE-3]]:18 -> [[@LINE-3]]:31 : 0
// CHECK-NEXT: [[@LINE-4]]:34 -> [[@LINE-4]]:46 : 1
// CHECK-NEXT: [[@LINE-5]]:47 -> [[@LINE-5]]:60 : 2
// CHECK-NEXT: [[@LINE-6]]:62 -> [[@LINE-6]]:62 : (1 + 2)
// CHECK-NEXT: }
}