Skip to content

[Runtime] Fix private generic type witness demangling failure #25611

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
Jun 20, 2019
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
13 changes: 7 additions & 6 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,12 +1677,13 @@ buildDescriptorPath(const ContextDescriptor *context) const {
hasNonKeyGenericParams = true;
}

// Form the path element.
descriptorPath.push_back(PathElement{localGenericParams,
context->getNumGenericParams(),
numKeyGenericParamsInParent,
numKeyGenericParamsHere,
hasNonKeyGenericParams});
// Form the path element if there are any generic parameters to be found.
if (numKeyGenericParamsHere != 0)
descriptorPath.push_back(PathElement{localGenericParams,
context->getNumGenericParams(),
numKeyGenericParamsInParent,
numKeyGenericParamsHere,
hasNonKeyGenericParams});
return numKeyGenericParamsInParent + numKeyGenericParamsHere;
}

Expand Down
39 changes: 39 additions & 0 deletions test/Runtime/associated_type_demangle_private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,44 @@ AssociatedTypeDemangleTests.test("generic anonymous contexts") {
expectEqual("Inner<Int>", String(describing: getP2_A(C3<Int>.self)))
}

// rdar://problem/47773183
struct Pair<First, Second> {
var first: First
var second: Second
}

protocol PairConvertible {
associatedtype First
associatedtype Second
associatedtype PairType = Pair<First, Second>

var first: First { get }
var second: Second { get }
}

extension PairConvertible where PairType == Pair<First, Second> {
var pair: PairType { Pair(first: first, second: second) }
}

private struct Parent<Unused> {
struct Nested<First, Second>: PairConvertible {
var first: First
var second: Second
}
}

AssociatedTypeDemangleTests.test("nested private generic types in associated type witnesses") {
// Fixed in custom runtimes.
if #available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, * ) {}
// Fixed in Swift 5.1+ runtimes.
else if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {}
// Bug is still present in Swift 5.0 runtime.
else {
expectCrashLater(withMessage: "failed to demangle witness for associated type 'Second' in conformance")
}

_ = Parent<Never>.Nested(first: "String", second: 0).pair
}


runAllTests()