Skip to content

Commit 8079a6f

Browse files
committed
Support async function calls in the expression evaluator and REPL.
Async function calls require a new SIL pass (LowerHopToActor) that wasn't previously part of ther expression evaluator's pass pipeline. To avoid such a problem in the future, this patch replaces LLDB's ad-hoc SIL lowering pipeline with the "official" SIL lowering pass pipeline which currently consists of LowerHopToActor (New!) OwnershipModelEliminator (Previously also manually scheduled by LLDB) IRGenPrepare (New, removes poundAssert, staticReport, and lowers condFailMessage) AddressLowering (New, for SIL opaque values, currently no effect since not enabled) rdar://79408099 (cherry picked from commit 1fa5bf9)
1 parent d7f78e9 commit 8079a6f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
17381738
}
17391739

17401740
runSILDiagnosticPasses(*sil_module);
1741-
runSILOwnershipEliminatorPass(*sil_module);
1741+
runSILLoweringPasses(*sil_module);
17421742

17431743
if (log) {
17441744
std::string s;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import _Concurrency
2+
import Darwin
3+
// Test that the pass pipeline is set up to support concurrency.
4+
var i: Int = 0
5+
6+
if #available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) {
7+
8+
actor Actor {
9+
func f() -> Int { return 42 }
10+
}
11+
12+
let queue = Actor()
13+
async {
14+
i = await queue.f()
15+
}
16+
17+
} else {
18+
// Still make the test pass if we don't have concurrency.
19+
i = 42
20+
}
21+
22+
while (i == 0) { sleep(1) }
23+
i - 19

lldb/test/API/lang/swift/playgrounds/TestPlaygrounds.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def get_run_triple(self):
6868

6969
@skipUnlessDarwin
7070
@swiftTest
71+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
7172
@skipIf(debug_info=decorators.no_match("dsym"))
7273
def test_cross_module_extension(self):
7374
"""Test that playgrounds work"""
@@ -123,9 +124,7 @@ def do_test(self, force_target):
123124
options.SetPlaygroundTransformEnabled()
124125

125126
self.frame().EvaluateExpression(contents, options)
126-
127127
ret = self.frame().EvaluateExpression("get_output()")
128-
129128
playground_output = ret.GetSummary()
130129
if not force_target:
131130
# This is expected to fail because the deployment target
@@ -139,3 +138,13 @@ def do_test(self, force_target):
139138
self.assertTrue("b=\\'5\\'" in playground_output)
140139
self.assertTrue("=\\'8\\'" in playground_output)
141140
self.assertTrue("=\\'11\\'" in playground_output)
141+
142+
# Test concurrency
143+
contents = "error"
144+
with open('Concurrency.swift', 'r') as contents_file:
145+
contents = contents_file.read()
146+
res = self.frame().EvaluateExpression(contents, options)
147+
ret = self.frame().EvaluateExpression("get_output()")
148+
playground_output = ret.GetSummary()
149+
self.assertTrue(playground_output is not None)
150+
self.assertTrue("=\\'23\\'" in playground_output)

0 commit comments

Comments
 (0)