Skip to content

Commit 112c7c4

Browse files
committed
Allow switching the Swift version in expressions
1 parent 518cdae commit 112c7c4

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,16 +1358,16 @@ SwiftExpressionParser::ParseAndImport(
13581358
invocation.getFrontendOptions().ModuleName = expr_name_buf;
13591359
invocation.getIRGenOptions().ModuleName = expr_name_buf;
13601360

1361+
auto &lang_opts = invocation.getLangOptions();
13611362
bool enable_bare_slash_regex_literals =
13621363
m_sc.target_sp->GetSwiftEnableBareSlashRegex();
1363-
if (enable_bare_slash_regex_literals) {
1364-
invocation.getLangOptions().enableFeature(
1365-
swift::Feature::BareSlashRegexLiterals);
1366-
}
1367-
if (uint32_t version = m_expr.Language().version) {
1368-
invocation.getLangOptions().EffectiveLanguageVersion =
1364+
if (enable_bare_slash_regex_literals)
1365+
lang_opts.enableFeature(swift::Feature::BareSlashRegexLiterals);
1366+
if (uint32_t version = m_expr.Language().version)
1367+
lang_opts.EffectiveLanguageVersion =
13691368
llvm::VersionTuple(version / 100, version % 100);
1370-
}
1369+
if (lang_opts.EffectiveLanguageVersion >= swift::version::Version({6}))
1370+
lang_opts.StrictConcurrencyLevel = swift::StrictConcurrency::Complete;
13711371

13721372
auto should_use_prestable_abi = [&]() {
13731373
lldb::StackFrameSP this_frame_sp(m_stack_frame_wp.lock());
@@ -1380,8 +1380,7 @@ SwiftExpressionParser::ParseAndImport(
13801380
return !runtime->IsABIStable();
13811381
};
13821382

1383-
invocation.getLangOptions().UseDarwinPreStableABIBit =
1384-
should_use_prestable_abi();
1383+
lang_opts.UseDarwinPreStableABIBit = should_use_prestable_abi();
13851384

13861385
LLDBNameLookup *external_lookup;
13871386
if (m_options.GetPlaygroundTransformEnabled() || m_options.GetREPLEnabled()) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
class TestSwiftExpressionLanguageVersion(TestBase):
8+
NO_DEBUG_INFO_TESTCASE = True
9+
10+
@swiftTest
11+
def test(self):
12+
"""Test changing the Swift language version"""
13+
self.build()
14+
target, process, thread, bkpt = lldbutil.run_to_name_breakpoint(
15+
self, 'main')
16+
17+
expr = """\
18+
#if swift(>=6.0)
19+
6
20+
#else
21+
5
22+
#endif
23+
"""
24+
25+
def test_version(n):
26+
if self.TraceOn():
27+
print("Testing version %d"%n)
28+
options = lldb.SBExpressionOptions()
29+
options.SetLanguage(lldb.eLanguageNameSwift, n*100 + 0)
30+
value = self.frame().EvaluateExpression(expr, options)
31+
self.assertEquals(value.GetValue(), "%d" % n)
32+
33+
test_version(5)
34+
test_version(6)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("break here")

0 commit comments

Comments
 (0)