Skip to content

[DebugInfo] Generate full debug info for generic structs #69902

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
Jan 22, 2024

Conversation

augusto2112
Copy link
Contributor

No description provided.

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

auto memberTy =
UnsubstitutedType->getTypeOfMember(IGM.getSwiftModule(), VD);
llvm::DIType *DITy = nullptr;
if (llvm::isa<swift::GenericTypeParamType>(memberTy)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just isa<GenericTypeParamType> should work. However, I don't see what is special about generic parameter types here. You can also have a member type (T.A), wouldn't that be the same as a generic parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, this was incorrect.

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@swift-ci test macOS

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

1 similar comment
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@@ -1037,6 +1046,48 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
return DITy;
}

/// Creates debug info for a generic struct with archetypes (eg.:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Creates debug info for a generic struct with archetypes (eg.:
/// Creates debug info for a generic struct with archetypes (e.g.:

}
// Force the creation of the unsubstituted type, don't create it
// directly so it goes through all the caching/verification logic.
getOrCreateType(DbgTy);
Copy link
Contributor

Choose a reason for hiding this comment

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

What holds on to this type so it stays alive in the IR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought getOrCreateType storing it in the type cache would be enough to keep it alive?

    DITypeCache.insert({DbgTy.getType(), llvm::TrackingMDNodeRef(DITy)});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adrian-prantl the type was only being retained because I happened to be using one of its method in the test program (for example, its init). I changed this to always forcibly retain the type instead.

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test Windows

1 similar comment
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test Windows

Generate the full debug info for generic structs. The strategy is to
emit one full entry for the generic type with archetypes, and one
forward declaration per instantiation of the generic type.

For example, given:
```
struct Pair<T, U> {
  let t: T
  let u: U
}
let p1 = Pair<Int, Double>(t: 1, u: 4.2)
let p2 = Pair<String, Bool>(t: "Hello", u: true)
```

DebugInfo will have one entry for Pair<T, U> which includes descriptions
of its fields, one forward declaration of Pair<Int, Double> and one
forward declaration of Pair<String, Bool>. This information is enough
for the algorithms of RemoteMirrors to reconstruct type information for
the fully instantiated types.
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test Windows

@augusto2112 augusto2112 merged commit 0a99491 into swiftlang:main Jan 22, 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