Skip to content

Runtime: Properly handle demangling nested generic typerefs with symbolic manglings. #15781

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,20 @@ class DecodedMetadataBuilder {
// Figure out the various levels of generic parameters we have in
// this type.
std::vector<unsigned> genericParamCounts;
bool innermostIsGeneric =
_gatherGenericParameterCounts(typeDecl, genericParamCounts);
bool innermostIsGeneric;

// If we have no parent given, try to form the whole type in one go.
if (!parent) {
innermostIsGeneric = !genericArgs.empty();
if (innermostIsGeneric) {
genericParamCounts.push_back(genericArgs.size());
}
// Otherwise, we'll need to steal the generic arguments from the parent
// type to build a nested type.
} else {
innermostIsGeneric = _gatherGenericParameterCounts(typeDecl,
genericParamCounts);
}
bool isGeneric = !genericParamCounts.empty();

// Gather the generic arguments.
Expand Down
16 changes: 16 additions & 0 deletions test/stdlib/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,20 @@ mirrors.test("String.init") {
expectEqual("42", String(reflecting: 42))
expectEqual("\"42\"", String(reflecting: "42"))
}

struct a<b> {
enum c{}
}
class d {}
struct e<f> {
var constraints: [Int: a<f>.c] = [:]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another silly case to test is a type nested inside an extension of a generic type that makes one of its generic parameters concrete, or more generally, any constrained extension

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, having a couple levels of generic/non-generic nesting interleaved is great for sussing out bugs in this code. test/Runtime/demangleToMetadata.swift has some examples.


mirrors.test("field with generic nested type") {
let x = e<d>()

expectTrue(type(of: Mirror(reflecting: x).children.first!.value)
== [Int: a<d>.c].self)
}

runAllTests()