Skip to content

[lldb] Initialize a shared, blank SwiftASTContext in Objective-C frames #10851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from

Conversation

adrian-prantl
Copy link

The result of an Objective-C expression can be a Swift ValueObject. This means that po foo in Objective-C may run a Swift expression to print the object description of the result of the Objective-C expression foo. That expression has very few dependencies:

Swift._DebuggerSupport.stringForPrintObject(Swift.unsafeBitCast(0x001234, to: AnyObject.self))

To avoid scanning potentially incompatible compiler flags and/or doing implicit imports in anotherwise explicitly built project, this patch ensures that one SwiftASTContext per triple is created, with no other contextual information. This makes po in ObjC much faster and reliable, the downside of this is that

expr -l Swift -- import ModuleName

will only work reliably for SDK modules outside of Swift frames.

rdar://153332037

@adrian-prantl adrian-prantl requested a review from a team as a code owner June 17, 2025 00:37
@kastiglione
Copy link

expr -l Swift -- import ModuleName

will only work reliably for SDK modules outside of Swift frames.

I'm presuming someone out there will be affected, but hopefully not many. Do we have a workaround so that they accomplish whatever it is they're doing?

@kastiglione
Copy link

Why can't lldb call the ObjC description function? Let's assume the following objc code:

SwiftThing *thing = ...;
NSLog(@"thing: %@", [thing description]);
// break here

Are there cases where the objc call to -description would fail? If not, why can't lldb call the objc description too?

std::string m_description;
{
StreamString ss;
ss << "SwiftASTContext";
if (for_expressions)
ss << "ForExpressions";
ss << "(module: " << '"' << key << "\", " << "cu: " << '"';
if (cu)
if (cu && swift_context)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove cu here since swift_context checks for it

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you delete all of these files on purpose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test relies on the behavior that no longer works after this patch.

@adrian-prantl
Copy link
Author

expr -l Swift -- import ModuleName
will only work reliably for SDK modules outside of Swift frames.

I'm presuming someone out there will be affected, but hopefully not many. Do we have a workaround so that they accomplish whatever it is they're doing?

Yes, you can always manually pass Swift compiler flags to the expression evaluator; that code path is still active after the patch.

@adrian-prantl adrian-prantl force-pushed the 153332037 branch 2 times, most recently from 3449991 to db04e90 Compare June 17, 2025 16:42
@adrian-prantl
Copy link
Author

Why can't lldb call the ObjC description function? Let's assume the following objc code:

SwiftThing *thing = ...;
NSLog(@"thing: %@", [thing description]);
// break here

Are there cases where the objc call to -description would fail? If not, why can't lldb call the objc description too?

I don't know yet, but that is what I would like to try next, after this patch.

@adrian-prantl
Copy link
Author

@swift-ci test

The result of an Objective-C expression can be a Swift
ValueObject. This means that `po foo` in Objective-C may run a Swift
expression to print the object description of the result of the
Objective-C expression `foo`. That expression has very few
dependencies:

```
Swift._DebuggerSupport.stringForPrintObject(Swift.unsafeBitCast(0x001234, to: AnyObject.self))
```

To avoid scanning potentially incompatible compiler flags and/or doing
implicit imports in anotherwise explicitly built project, this patch
ensures that one SwiftASTContext per triple is created, with no other
contextual information. This makes `po` in ObjC much faster and
reliable, the downside of this is that

```expr -l Swift -- import ModuleName```

will only work reliably for SDK modules outside of Swift frames.

rdar://153332037
@adrian-prantl
Copy link
Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants