Skip to content

Display generic function type parameters in backtraces. #8703

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
merged 3 commits into from
May 7, 2024

Conversation

adrian-prantl
Copy link

This patch changes the behavior of SwiftLanguage::GetFunctionDisplayName()
so it now:

  • (if exe_ctx && sc available) does generic parameter binding
  • (if only sc availble) shows the archetype name
  • the letter τ will now only appear if neither no context whatsover is available
  • (drive by) omits self

rdar://126883922

There was a global cache for Swift display names, however, it didn't
take the symbol context into account, which means the demangling
result is non-deterministic depending on whether the symbol context
had the necessary debug info to resolve the names of archetypes or
not.

In addition to that Display names are not supposed to be on a hot path
(unlike names, which are used to resolve breakpoints).
This patch changes the behavior of SwiftLanguage::GetFunctionDisplayName()
so it now:
- (if exe_ctx && sc available) does generic parameter binding
- (if only sc availble) shows the archetype name
- the letter τ will now only appear if neither no context whatsover is available
- (drive by) omits self

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

@swift-ci test

@adrian-prantl
Copy link
Author

@swift-ci test linux

@@ -1730,6 +1735,8 @@ bool SwiftLanguage::GetFunctionDisplayName(
VariableSP var_sp(args.GetVariableAtIndex(arg_idx));
ValueObjectSP var_value_sp(
ValueObjectVariable::Create(exe_scope, var_sp));
if (!var_sp || !var_value_sp || var_sp->IsArtificial())

Choose a reason for hiding this comment

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

I assume this is the self bit you mentioned in the commit message?

Copy link
Author

Choose a reason for hiding this comment

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

Yes.

Choose a reason for hiding this comment

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

can you explain a little more, where is self being omitted? Is there a test for it that I've overlooked?

Copy link

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

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

LGTM! Very excited to see this

@@ -498,10 +498,10 @@ bool Function::IsTopLevelFunction() {
return result;
}

ConstString Function::GetDisplayName(const SymbolContext *sc) const {

Choose a reason for hiding this comment

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

What's the reason the SymbolContext is no longer plumbed through?

stream = lldb.SBStream()
bkpt.GetLocationAtIndex(0).GetDescription(stream, 1)
desc = stream.GetData()
self.assertIn("C.f<T>(T, U) -> ()", desc)

Choose a reason for hiding this comment

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

shouldn't this be C.f<U>(T, U)? The function's generic parameter is named U in the source, and its containing class has the generic type named T. If this test is passing, do we have a bug?

Copy link
Author

Choose a reason for hiding this comment

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

Uh, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

I'll track that separately and fix it in a follow-up, since it isn't a regression.

@adrian-prantl adrian-prantl merged commit 715517d into swiftlang:swift/release/6.0 May 7, 2024
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