Skip to content

Commit 403e3d3

Browse files
committed
Fix async_let playground transform
Async-let pattern-binding-decls can't be logged since they haven't been await'd yet. This patch fixes it so the playground transform doesn't try to log the async-let.
1 parent 812868e commit 403e3d3

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,14 @@ class Instrumenter : InstrumenterBase {
576576
} else if (auto *D = Element.dyn_cast<Decl *>()) {
577577
D->walk(CF);
578578
if (auto *PBD = dyn_cast<PatternBindingDecl>(D)) {
579-
if (VarDecl *VD = PBD->getSingleVar()) {
580-
if (VD->getParentInitializer()) {
581-
Added<Stmt *> Log = logVarDecl(VD);
582-
if (*Log) {
583-
Elements.insert(Elements.begin() + (EI + 1), *Log);
584-
++EI;
579+
if (!PBD->isAsyncLet()) {
580+
if (VarDecl *VD = PBD->getSingleVar()) {
581+
if (VD->getParentInitializer()) {
582+
Added<Stmt *> Log = logVarDecl(VD);
583+
if (*Log) {
584+
Elements.insert(Elements.begin() + (EI + 1), *Log);
585+
++EI;
586+
}
585587
}
586588
}
587589
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -whole-module-optimization -module-name PlaygroundSupport -emit-module-path %t/PlaygroundSupport.swiftmodule -parse-as-library -c -o %t/PlaygroundSupport.o %S/Inputs/SilentPCMacroRuntime.swift %S/Inputs/PlaygroundsRuntime.swift
4+
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -Xfrontend -playground -o %t/main -I=%t %t/PlaygroundSupport.o %t/main.swift
5+
// RUN: %target-codesign %t/main
6+
// RUN: %target-run %t/main | %FileCheck %s
7+
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -Xfrontend -pc-macro -Xfrontend -playground -o %t/main2 -I=%t %t/PlaygroundSupport.o %t/main.swift
8+
// RUN: %target-codesign %t/main2
9+
// RUN: %target-run %t/main2 | %FileCheck %s
10+
11+
// REQUIRES: executable_test
12+
// REQUIRES: concurrency
13+
14+
// rdar://76038845
15+
// REQUIRES: concurrency_runtime
16+
// UNSUPPORTED: back_deployment_runtime
17+
18+
import PlaygroundSupport
19+
20+
func factorial(_ x : Int) async -> Int {
21+
if x < 1 {
22+
return 1
23+
}
24+
return await x * factorial(x - 1)
25+
}
26+
27+
async let fac4 = factorial(4)
28+
print(await fac4)
29+
30+
// return await x * factorial(x - 1)
31+
// CHECK: [22:{{[[:digit:]]+}}-22:{{[[:digit:]]+}}] __builtin_log[='1']
32+
33+
// return await x * factorial(x - 1)
34+
// CHECK: [24:{{[[:digit:]]+}}-24:{{[[:digit:]]+}}] __builtin_log[='1']
35+
36+
// return await x * factorial(x - 1)
37+
// CHECK: [24:{{[[:digit:]]+}}-24:{{[[:digit:]]+}}] __builtin_log[='2']
38+
39+
// return await x * factorial(x - 1)
40+
// CHECK: [24:{{[[:digit:]]+}}-24:{{[[:digit:]]+}}] __builtin_log[='6']
41+
42+
// return await x * factorial(x - 1)
43+
// CHECK: [24:{{[[:digit:]]+}}-24:{{[[:digit:]]+}}] __builtin_log[='24']
44+
45+
// func factorial(_ x : Int) { ... }
46+
// CHECK-NEXT: [20:{{[[:digit:]]+}}-25:{{[[:digit:]]+}}] __builtin_log_scope_exit
47+
48+
// (actually print the thing)
49+
// CHECK-NEXT: 24
50+
51+
// print(await fac4)
52+
// CHECK-NEXT: [28:{{[[:digit:]]+}}-28:{{[[:digit:]]+}}] __builtin_postPrint

0 commit comments

Comments
 (0)