Skip to content

Commit 73587af

Browse files
Merge pull request #8775 from adrian-prantl/126783312-test
Allow switching the Swift version in expressions
2 parents 0a6c83e + 112c7c4 commit 73587af

File tree

8 files changed

+307
-281
lines changed

8 files changed

+307
-281
lines changed

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 258 additions & 269 deletions
Large diffs are not rendered by default.

lldb/bindings/python/static-binding/lldb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5571,7 +5571,7 @@ def SetTrapExceptions(self, trap_exceptions=True):
55715571
def SetLanguage(self, *args):
55725572
r"""
55735573
SetLanguage(SBExpressionOptions self, lldb::LanguageType language)
5574-
SetLanguage(SBExpressionOptions self, SBSourceLanguageName name, uint32_t version)
5574+
SetLanguage(SBExpressionOptions self, lldb::SBSourceLanguageName name, uint32_t version)
55755575
Sets the language that LLDB should assume the expression is written in
55765576
"""
55775577
return _lldb.SBExpressionOptions_SetLanguage(self, *args)

lldb/include/lldb/API/SBExpressionOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class LLDB_API SBExpressionOptions {
7171
/// Set the language using a pair of language code and version as
7272
/// defined by the DWARF 6 specification.
7373
/// WARNING: These codes may change until DWARF 6 is finalized.
74-
void SetLanguage(SBSourceLanguageName name, uint32_t version);
74+
void SetLanguage(lldb::SBSourceLanguageName name, uint32_t version);
7575

7676
#ifndef SWIG
7777
void SetCancelCallback(lldb::ExpressionCancelCallback callback, void *baton);

lldb/source/API/SBExpressionOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
156156
m_opaque_up->SetLanguage(language);
157157
}
158158

159-
void SBExpressionOptions::SetLanguage(SBSourceLanguageName name,
159+
void SBExpressionOptions::SetLanguage(lldb::SBSourceLanguageName name,
160160
uint32_t version) {
161161
LLDB_INSTRUMENT_VA(this, name, version);
162162

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)