Skip to content

Commit e541dfc

Browse files
author
git apple-llvm automerger
committed
Merge commit '33f962f8be32' from swift/release/6.2 into stable/20240723
2 parents a05f062 + 33f962f commit e541dfc

File tree

14 files changed

+83
-129
lines changed

14 files changed

+83
-129
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,17 +2705,18 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27052705

27062706
CompileUnit *cu = sc.comp_unit;
27072707
const char *key = TypeSystemSwiftTypeRef::DeriveKeyFor(sc);
2708+
bool swift_context = cu && cu->GetLanguage() == eLanguageTypeSwift;
27082709
std::string m_description;
27092710
{
27102711
StreamString ss;
27112712
ss << "SwiftASTContext";
27122713
if (for_expressions)
27132714
ss << "ForExpressions";
27142715
ss << "(module: " << '"' << key << "\", " << "cu: " << '"';
2715-
if (cu)
2716+
if (cu && swift_context)
27162717
ss << cu->GetPrimaryFile().GetFilename();
27172718
else
2718-
ss << "null";
2719+
ss << "*";
27192720
ss << '"' << ')';
27202721
m_description = ss.GetString();
27212722
}
@@ -2795,7 +2796,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27952796
ModuleList module_module;
27962797
if (!target_sp)
27972798
module_module.Append(module_sp);
2798-
ModuleList &modules = target_sp ? target_sp->GetImages() : module_module;
2799+
ModuleList &modules =
2800+
(target_sp && swift_context) ? target_sp->GetImages() : module_module;
27992801
const size_t num_images = modules.GetSize();
28002802

28012803
// Set the SDK path prior to doing search paths. Otherwise when we
@@ -3131,7 +3133,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
31313133
}
31323134
}
31333135
};
3134-
scan_module(module_sp, 0);
3136+
if (swift_context)
3137+
scan_module(module_sp, 0);
31353138
for (size_t mi = 0; mi != num_images; ++mi) {
31363139
auto image_sp = modules.GetModuleAtIndex(mi);
31373140
if (!visited_modules.count(image_sp.get()))

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,15 +2072,14 @@ ConstString TypeSystemSwiftTypeRef::GetSwiftModuleFor(const SymbolContext &sc) {
20722072
}
20732073

20742074
const char *TypeSystemSwiftTypeRef::DeriveKeyFor(const SymbolContext &sc) {
2075-
if (sc.function)
2075+
if (sc.comp_unit && sc.comp_unit->GetLanguage() == eLanguageTypeSwift)
20762076
if (ConstString name = GetSwiftModuleFor(sc))
20772077
return name.GetCString();
20782078

2079-
if (sc.module_sp) {
2080-
if (sc.module_sp->GetFileSpec())
2081-
return sc.module_sp->GetFileSpec().GetFilename().GetCString();
2082-
return sc.module_sp->GetObjectName().GetCString();
2083-
}
2079+
// Otherwise create a catch-all context per unique triple.
2080+
if (sc.module_sp)
2081+
return ConstString(sc.module_sp->GetArchitecture().GetTriple().str()).AsCString();
2082+
20842083
return nullptr;
20852084
}
20862085

@@ -2563,6 +2562,9 @@ template <> bool Equivalent<CompilerType>(CompilerType l, CompilerType r) {
25632562
ConstString rhs = r.GetMangledTypeName();
25642563
if (lhs == ConstString("$sSiD") && rhs == ConstString("$sSuD"))
25652564
return true;
2565+
if (lhs.GetStringRef() == "$sSPySo0023unnamedstruct_hEEEdhdEaVGSgD" &&
2566+
rhs.GetStringRef() == "$ss13OpaquePointerVSgD")
2567+
return true;
25662568
// Ignore missing sugar.
25672569
swift::Demangle::Demangler dem;
25682570
auto l_node = GetDemangledType(dem, lhs.GetStringRef());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@import Foundation;
2+
@interface Base : NSObject
3+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
import Base
3+
4+
private class Bar : Base {
5+
}
6+
7+
extension Bar {
8+
override var debugDescription : String { "Hello from Swift" }
9+
}
10+
11+
@objc public class Foo : NSObject {
12+
@objc public func getBase() -> Base? {
13+
return Bar()
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OBJC_SOURCES := main.m
2+
CFLAGS_EXTRAS = $(MANDATORY_MODULE_BUILD_CFLAGS) -I. -I$(BUILDDIR)
3+
4+
SWIFT_SOURCES := Foo.swift
5+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR) -emit-objc-header-path Foo.h -parse-as-library
6+
7+
all: Foo.swift.o $(EXE)
8+
9+
include Makefile.rules
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestSwiftPOObjC(TestBase):
7+
#NO_DEBUG_INFO_TESTCASE = True
8+
@skipUnlessDarwin
9+
@swiftTest
10+
def test(self):
11+
"""Test running po on a Swift object from Objective-C. This
12+
should initialize a generic SwiftASTContext with no parsing of
13+
Swift modules happening"""
14+
self.build()
15+
16+
lldbutil.run_to_source_breakpoint(
17+
self, "break here", lldb.SBFileSpec('main.m'))
18+
19+
log = self.getBuildArtifact("types.log")
20+
self.expect('log enable lldb types -f "%s"' % log)
21+
self.expect("expr -O -- base", substrs=["Hello from Swift"])
22+
self.filecheck('platform shell cat "%s"' % log, __file__)
23+
### -cc1 should be round-tripped so there is no more `-cc1` in the extra args. Look for `-triple` which is a cc1 flag.
24+
# CHECK-NOT: parsed module "a"
25+
# CHECK: SwiftASTContextForExpressions(module: "{{.*-.*-.*}}", cu: "*")::LogConfiguration()
26+
self.expect("expr -- base", substrs=["a.Bar"])
27+
self.expect("expr -- *base", substrs=["a.Bar"])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@import Foundation;
2+
@import Base;
3+
#import "Foo.h"
4+
5+
@implementation Base
6+
@end
7+
8+
int main(int argc, char **argv) {
9+
Foo *foo = [[Foo alloc] init];
10+
Base *base = [foo getBase];
11+
return 0; // break here
12+
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Base { header "Base.h" }

lldb/test/API/lang/swift/unit-tests/Info.plist

Lines changed: 0 additions & 8 deletions
This file was deleted.

lldb/test/API/lang/swift/unit-tests/Makefile

Lines changed: 0 additions & 16 deletions
This file was deleted.

lldb/test/API/lang/swift/unit-tests/TestSwiftUnitTests.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

lldb/test/API/lang/swift/unit-tests/dylib.mk

Lines changed: 0 additions & 21 deletions
This file was deleted.

lldb/test/API/lang/swift/unit-tests/test.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

lldb/test/API/lang/swift/unit-tests/xctest.c

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)