Skip to content

Commit ecd47e0

Browse files
committed
PlaygroundTransform: Use a global TmpNameIndex to avoid having multiple
temporaries with the same name in the same scope. rdar://problem/24318554
1 parent 6c19796 commit ecd47e0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Instrumenter {
5959
std::mt19937_64 &RNG;
6060
ASTContext &Context;
6161
DeclContext *TypeCheckDC;
62-
unsigned TmpNameIndex = 0;
62+
unsigned &TmpNameIndex;
6363
bool HighPerformance;
6464

6565
struct BracePair {
@@ -170,10 +170,11 @@ class Instrumenter {
170170
ClosureFinder CF;
171171

172172
public:
173-
Instrumenter (ASTContext &C, DeclContext *DC, std::mt19937_64 &RNG,
174-
bool HP) :
175-
RNG(RNG), Context(C), TypeCheckDC(DC), HighPerformance(HP), CF(*this) { }
176-
173+
Instrumenter(ASTContext &C, DeclContext *DC, std::mt19937_64 &RNG, bool HP,
174+
unsigned &TmpNameIndex)
175+
: RNG(RNG), Context(C), TypeCheckDC(DC), TmpNameIndex(TmpNameIndex),
176+
HighPerformance(HP), CF(*this) {}
177+
177178
Stmt *transformStmt(Stmt *S) {
178179
switch (S->getKind()) {
179180
default:
@@ -1085,15 +1086,16 @@ void swift::performPlaygroundTransform(SourceFile &SF,
10851086
private:
10861087
std::mt19937_64 RNG;
10871088
bool HighPerformance;
1089+
unsigned TmpNameIndex = 0;
10881090
public:
1089-
ExpressionFinder(bool HP) : HighPerformance(HP) { }
1091+
ExpressionFinder(bool HP) : HighPerformance(HP) {}
10901092

10911093
virtual bool walkToDeclPre(Decl *D) {
10921094
if (AbstractFunctionDecl *FD = dyn_cast<AbstractFunctionDecl>(D)) {
10931095
if (!FD->isImplicit()) {
10941096
if (BraceStmt *Body = FD->getBody()) {
10951097
ASTContext &ctx = FD->getASTContext();
1096-
Instrumenter I(ctx, FD, RNG, HighPerformance);
1098+
Instrumenter I(ctx, FD, RNG, HighPerformance, TmpNameIndex);
10971099
BraceStmt *NewBody = I.transformBraceStmt(Body);
10981100
if (NewBody != Body) {
10991101
FD->setBody(NewBody);
@@ -1106,7 +1108,7 @@ void swift::performPlaygroundTransform(SourceFile &SF,
11061108
if (!TLCD->isImplicit()) {
11071109
if (BraceStmt *Body = TLCD->getBody()) {
11081110
ASTContext &ctx = static_cast<Decl*>(TLCD)->getASTContext();
1109-
Instrumenter I(ctx, TLCD, RNG, HighPerformance);
1111+
Instrumenter I(ctx, TLCD, RNG, HighPerformance, TmpNameIndex);
11101112
BraceStmt *NewBody = I.transformBraceStmt(Body, true);
11111113
if (NewBody != Body) {
11121114
TLCD->setBody(NewBody);

0 commit comments

Comments
 (0)