Skip to content

Commit b80e4c5

Browse files
committed
[PlaygroundTransform] Instrument mutations of inout vars by class methods.
+= is now a class method, which means the playground transform ignores it. This is undesirable, and we have ways to instrument methods that mutate inout parameters the way += does. I have just made it so that if we see a method call and we can't instrument the mutation of the base of the method call, we still instrument the inout argument if there is one. Also added a test case.
1 parent 3757b36 commit b80e4c5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,19 @@ class Instrumenter {
611611
Elements.insert(Elements.begin() + (EI + 1), *Log);
612612
++EI;
613613
}
614+
Handled = true;
614615
}
615-
} else if (DeclRefExpr *DRE = digForInoutDeclRef(AE->getArg())) {
616-
Added<Stmt *> Log = logDeclOrMemberRef(DRE);
617-
if (*Log) {
618-
Elements.insert(Elements.begin() + (EI + 1), *Log);
619-
++EI;
616+
}
617+
if (!Handled) {
618+
if (DeclRefExpr *DRE = digForInoutDeclRef(AE->getArg())) {
619+
Added<Stmt *> Log = logDeclOrMemberRef(DRE);
620+
if (*Log) {
621+
Elements.insert(Elements.begin() + (EI + 1), *Log);
622+
++EI;
623+
}
624+
Handled = true;
620625
}
621626
}
622-
Handled = true;
623627
}
624628
if (!Handled) {
625629
// do the same as for all other expressions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: cp %s %t/main.swift
4+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// REQUIRES: executable_test
7+
8+
var a = "a"
9+
var b = "b"
10+
a += b
11+
// CHECK: [{{.*}}] $builtin_log[a='a']
12+
// CHECK-NEXT: [{{.*}}] $builtin_log[b='b']
13+
// CHECK-NEXT: [{{.*}}] $builtin_log[='ab']

0 commit comments

Comments
 (0)