Skip to content

Commit ef1470b

Browse files
committed
Don’t print module selectors in more cases
There were a number of cases where Swift would emit module selectors into module interface files that it was subsequently unable to parse because the compiler at least temporarily represented them as dependent member types. Modify the carve-out so that if *any* of a type’s parents are generic parameters or archetypes, we don’t print a module selector on it. Fixes rdar://166180424.
1 parent cecebdd commit ef1470b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6139,11 +6139,15 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
61396139

61406140
bool isMemberOfGenericParameter(TypeBase *T) {
61416141
Type parent = nullptr;
6142-
if (auto alias = dyn_cast<TypeAliasType>(T))
6142+
if (auto alias = dyn_cast<TypeAliasType>(T)) // don't desugar
61436143
parent = alias->getParent();
61446144
else if (auto generic = T->getAs<AnyGenericType>())
61456145
parent = generic->getParent();
6146-
return parent && parent->isTypeParameter();
6146+
else if (T->is<DependentMemberType>())
6147+
// Parent is always a generic parameter.
6148+
return true;
6149+
return parent && (parent->is<SubstitutableType>() ||
6150+
isMemberOfGenericParameter(parent.getPointer()));
61476151
}
61486152

61496153
bool shouldPrintModuleSelector(TypeBase *T) {

test/ModuleInterface/module_selector.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,47 @@ public protocol Proto {
125125
// CHECK-DISABLED-SAME: TestCase.Struct<Swift.Int>
126126
typealias TypeAlias = Struct<Int>
127127

128+
// CHECK: typealias ID =
129+
// CHECK-SAME: Self.AssocType.ID
130+
typealias ID = AssocType.ID
131+
128132
// CHECK: func requirement() -> Self.AssocType.ID
129133
func requirement() -> AssocType.ID
130134

131135
// CHECK: func requirement2() ->
132-
// CHECK-ENABLED: Self.TypeAlias.TestCase::Nested
133-
// CHECK-DISABLED: Self.TypeAlias.Nested
136+
// CHECK-SAME: Self.TypeAlias.Nested
134137
func requirement2() -> TypeAlias.Nested
135138

136139
// CHECK: }
137140
}
141+
142+
@available(SwiftStdlib 5.1, *)
143+
extension Proto {
144+
public typealias Text = String
145+
}
146+
147+
// Test cases from rdar://166180424
148+
149+
// CHECK-LABEL: func fn3<T>(_ t: T) ->
150+
// CHECK-SAME: T.TypeAlias.Nested
151+
@available(SwiftStdlib 5.1, *)
152+
public func fn3<T: Proto>(_ t: T) -> T.TypeAlias.Nested { fatalError() }
153+
154+
// CHECK-LABEL: struct ProtoSet
155+
@available(SwiftStdlib 5.1, *)
156+
public struct ProtoSet<T: Proto> {
157+
// CHECK: let ids:
158+
// CHECK-ENABLED-SAME: Swift::Set<T.ID>
159+
// CHECK-DISABLED-SAME: Swift.Set<T.ID>
160+
public let ids: Set<T.ID>
161+
162+
// CHECK: let texts:
163+
// CHECK-ENABLED-SAME: Swift::Set<T.Text>
164+
// CHECK-DISABLED-SAME: Swift.Set<T.Text>
165+
public let texts: Set<T.Text>
166+
167+
// CHECK: let singleText:
168+
// CHECK-SAME: T.Text
169+
public let singleText: T.Text
170+
}
171+

0 commit comments

Comments
 (0)