Skip to content

[IRGen/Runtime] Anonymous context descriptors can (should be) generic. #21455

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
3 changes: 2 additions & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ namespace {

void layout() {
super::layout();
asImpl().addGenericSignature();
}

ConstantReference getParent() {
Expand All @@ -522,7 +523,7 @@ namespace {
}

GenericSignature *getGenericSignature() {
return nullptr;
return DC->getGenericSignatureOfContext();
}

bool isUniqueDescriptor() {
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/runtime/Demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ swift::_buildDemanglingForContext(const ContextDescriptor *context,
[&](const ContextDescriptor *context) -> NodePointer {
if (demangledGenerics.empty())
return nullptr;

if (context->getKind() == ContextDescriptorKind::Anonymous)
return nullptr;

auto generics = context->getGenericContext();
if (!generics)
Expand Down
23 changes: 23 additions & 0 deletions test/IRGen/anonymous_context_descriptors.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s

import Builtin
import Swift

protocol P { }

class Blah<T: P> {
private struct Inner<U: P> { }
}

// Anonymous descriptor
// CHECK: @"$s29anonymous_context_descriptors4BlahC5Inner33{{.*}}MXX" =

// Flags: anonymous (2) + generic (0x80) + unique (0x40)
// CHECK-SAME: i32 194

// Parent
// CHECK-SAME: $s29anonymous_context_descriptors4BlahCMn

// # generic header
// CHECK-SAME: i16 2, i16 2
// CHECK-SAME: i16 4, i16 0
19 changes: 19 additions & 0 deletions test/Runtime/associated_type_demangle_private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ private protocol P2 {
associatedtype A
}

private func getP2_A<T: P2>(_: T.Type) -> Any.Type {
return T.A.self
}

struct Bar: P2 {
typealias A = Int
}
Expand All @@ -55,4 +59,19 @@ AssociatedTypeDemangleTests.test("private protocols") {
expectEqual("C2<Bar>", String(describing: C2<Bar>.self))
}

// rdar://problem/46853806
class C3<T: P>: P2 {
fileprivate struct Inner<U: P> { }
fileprivate typealias A = Inner<T>
}

extension Int: P {
typealias A = Int
}

AssociatedTypeDemangleTests.test("generic anonymous contexts") {
expectEqual("Inner<Int>", String(describing: getP2_A(C3<Int>.self)))
}


runAllTests()