Skip to content

[DebugInfo] Fix bound generic types debug info generation #71939

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 1 commit into from
Mar 2, 2024

Conversation

augusto2112
Copy link
Contributor

When generating full debug info for generic types, emit the specification type as an opaque struct with the collection of substituted generic parameters.

When generating full debug info for generic types, emit the
specification type as an opaque struct with the collection of
substituted generic parameters.
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

AlignInBits, Flags, MangledName, collectGenericParams(Type),
UnsubstitutedType);
return opaqueType;
auto *OpaqueType = createOpaqueStruct(
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this code doesn't look into the parent type of the nominal type at all, so for example if you have

struct Outer<T> {
  struct InnerGeneric<U> {}
  struct Inner {}
}

The type Outer<Int>.Inner is a StructType and not a BoundGenericStructType, but it is specialized (isSpecialized() returns true) and getParent() returns the BoundGenericStructType Outer<Int>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case "opaque type" is in regards to the debug info representation of the type. An opaque entry is one that doesn't contain any information about the type's fields, only some basic information about the type (like name, size, alignment, etc). The compiler emits complete debug info for the unsubstituted generic type, and then an opaque entry for each substituted type.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case why does the substituted type need to record generic arguments at all? Either you need the complete set and you should walk into the parent type, or you don't need them at all. Just collecting the innermost arguments doesn't seem to make much sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Today we collect them to ensure they survive in the debug info when producing a dSYM. dsymutil may delete any debug info that is unreachable when stitching together debug info from multiple .o files, so if a type happens to only be used as a generic argument, it would be deleted from the debug info.

In the future we might also stop emitting the substituted type's mangled name, and produce it by combining the unsubstituted generic type with the generic arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Today we collect them to ensure they survive in the debug info when producing a dSYM.

It seems that by the same reasoning you should collect the parent type’s generic arguments too then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see what you mean now. You're right, this doesn't address an inner specialized non-generic type at all. I'll address that in a follow up patch.

Scope, Decl->getName().str(), L.File, FwdDeclLine, SizeInBits,
AlignInBits, Flags, MangledName, collectGenericParams(EnumTy),
unsubstitutedDbgTy);
return createOpaqueStruct(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same remark here about generic arguments in the parent type

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Accepting on the basis that this is a strict improvement, but please do address Slava's comments, as well as mine about the name in follow-ups.

// DWARF-SAME: templateParams: ![[PARAMS:[0-9]+]]
// DWARF-SAME: identifier: "$s18BoundGenericStruct1SVySiGD"
// DWARF-SAME: specification_of:
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for just noticing this now, but this field should really be called specification. Otherwise it sounds like "this is the specification of:", which is the exact opposite.

@augusto2112 augusto2112 merged commit 7685371 into swiftlang:main Mar 2, 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.

3 participants