Skip to content

[lldb] Fix typealias not being emitted for weakly captured generic #7526

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

Merged

Conversation

augusto2112
Copy link

The typealias to $__lldb_context (the self type) was not being emitted when self was weakly captured and the type of self was a generic class type. Fix this, and also make AddRequiredAliases return an error code in case it was unable to emit one of the required aliases.

rdar://104697539

@augusto2112
Copy link
Author

@swift-ci test

@augusto2112
Copy link
Author

macOS test failures seem to be unrelated.

@augusto2112
Copy link
Author

Ping :)

@@ -532,7 +532,7 @@ lldb::VariableSP SwiftExpressionParser::FindSelfVariable(Block *block) {
return variable_list_sp->FindVariable(ConstString("self"));
}

static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
static bool AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,

Choose a reason for hiding this comment

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

Can you document what the return value means?

Choose a reason for hiding this comment

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

Should you instead return a Status that contains an error message about what failed?

Copy link
Author

Choose a reason for hiding this comment

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

I added the error messages, but I wonder if having them is better than a generic error. They aren't really actionable from the user's point of view.

Copy link
Author

Choose a reason for hiding this comment

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

@PortalPete what do you think?

Choose a reason for hiding this comment

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

I generally think more information is helpful to the community. The error messages certainly help me understand what the code is doing a bit better.

My answer hinges on what you mean by "actionable" and who could take action. Even if the message isn't about the developer's code that they're debugging, it could potentially inform them it's not responsible for the issue at hand.

Copy link

@PortalPete PortalPete left a comment

Choose a reason for hiding this comment

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

Hi Augusto,

As my editor said to me on my first day as a tech writer, "You're going to see a lot of red, and that's ok!"
In this case it's actually green, but you get the idea. 🙂

I'd start with this one on line 535 (ish)
because it's the most interesting.
I know Stash sometimes mixes up the order of things in the Conversation tab.

The rest are just classic fixes for active voice and/or present tense, and you'll see the wording patterns right away.


if (!self_class_type)
return;
// Only class types can be weakly captured.

Choose a reason for hiding this comment

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

Suggested change
// Only class types can be weakly captured.
// The Swift expression parser can only weakly capture class types.

Copy link
Author

Choose a reason for hiding this comment

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

In this case it's not the Swift expression parser, it's in the rules of the Swift language that only a class type can be weakly captured. Also, "strongly captured" and "weakly captured" are already part of the Swift lingo.

I'll change it to:

// In Swift only class types can be weakly captured.

// Only class types can be weakly captured.
if (!llvm::isa<swift::ClassType>(first_arg_type) &&
!llvm::isa<swift::BoundGenericClassType>(first_arg_type))
return Status("Could not add required aliases: weakly captured type is "

Choose a reason for hiding this comment

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

Suggested change
return Status("Could not add required aliases: weakly captured type is "
return Status("Unable to add the aliases the expression needs because "

If the word "Unable" isn't a valid option, then I suggest the contraction "Couldn't".

Copy link
Author

Choose a reason for hiding this comment

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

Since "weakly captured" is already part of the Swift lingo I think we should keep it, maybe:

"Unable to add the aliases the expression needs because weakly captured type is not a class type"?

Copy link

@PortalPete PortalPete left a comment

Choose a reason for hiding this comment

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

A found a few more things that I missed yesterday.

Other than that, I noticed there's a few cases of self inside backticks and some more without. I suggest choosing one way for consistency.

Personally, I prefer `self` with backticks because it refers to the language's keyword as opposed to the normal English word self.

@augusto2112
Copy link
Author

A found a few more things that I missed yesterday.

Other than that, I noticed there's a few cases of self inside backticks and some more without. I suggest choosing one way for consistency.

Personally, I prefer `self` with backticks because it refers to the language's keyword as opposed to the normal English word self.

Hmm, I think we should do it without backticks because:

  • We don't use backticks on error messages anywhere else.
  • This will be printed in the console, backticks won't change the formatting of self.

The typealias to $__lldb_context (the self type) was not being emitted
when self was weakly captured and the type of self was a generic class
type. Fix this, and also make AddRequiredAliases return an error code in
case it was unable to emit one of the required aliases.

rdar://104697539
@augusto2112 augusto2112 merged commit 7f8a88f into swiftlang:stable/20230725 Oct 5, 2023
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