@@ -109,7 +109,7 @@ static inline Optional<StringRef> getObjCClassOrProtocolName(
109
109
template <typename BuilderType>
110
110
class TypeDecoder {
111
111
using BuiltType = typename BuilderType::BuiltType;
112
- using BuiltNominalTypeDecl = typename BuilderType::BuiltNominalTypeDecl ;
112
+ using BuiltTypeDecl = typename BuilderType::BuiltTypeDecl ;
113
113
using BuiltProtocolDecl = typename BuilderType::BuiltProtocolDecl;
114
114
using NodeKind = Demangle::Node::Kind;
115
115
@@ -150,14 +150,18 @@ class TypeDecoder {
150
150
}
151
151
case NodeKind::Enum:
152
152
case NodeKind::Structure:
153
- case NodeKind::TypeAlias: // This can show up for imported Clang decls.
153
+ case NodeKind::TypeAlias:
154
154
case NodeKind::TypeSymbolicReference:
155
155
{
156
- BuiltNominalTypeDecl typeDecl = BuiltNominalTypeDecl ();
156
+ BuiltTypeDecl typeDecl = BuiltTypeDecl ();
157
157
BuiltType parent = BuiltType ();
158
- if (!decodeMangledNominalType (Node, typeDecl, parent))
158
+ bool typeAlias = false ;
159
+ if (!decodeMangledTypeDecl (Node, typeDecl, parent, typeAlias))
159
160
return BuiltType ();
160
161
162
+ if (typeAlias && Node->getKind () == NodeKind::TypeAlias)
163
+ return Builder.createTypeAliasType (typeDecl, parent);
164
+
161
165
return Builder.createNominalType (typeDecl, parent);
162
166
}
163
167
case NodeKind::BoundGenericClass:
@@ -177,13 +181,16 @@ class TypeDecoder {
177
181
}
178
182
case NodeKind::BoundGenericEnum:
179
183
case NodeKind::BoundGenericStructure:
184
+ case NodeKind::BoundGenericTypeAlias:
180
185
case NodeKind::BoundGenericOtherNominalType: {
181
186
if (Node->getNumChildren () < 2 )
182
187
return BuiltType ();
183
188
184
- BuiltNominalTypeDecl typeDecl = BuiltNominalTypeDecl ();
189
+ BuiltTypeDecl typeDecl = BuiltTypeDecl ();
185
190
BuiltType parent = BuiltType ();
186
- if (!decodeMangledNominalType (Node->getChild (0 ), typeDecl, parent))
191
+ bool typeAlias = false ;
192
+ if (!decodeMangledTypeDecl (Node->getChild (0 ), typeDecl,
193
+ parent, typeAlias))
187
194
return BuiltType ();
188
195
189
196
std::vector<BuiltType> args;
@@ -200,9 +207,43 @@ class TypeDecoder {
200
207
201
208
return Builder.createBoundGenericType (typeDecl, args, parent);
202
209
}
210
+ case NodeKind::BoundGenericProtocol: {
211
+ // This is a special case. When you write a protocol typealias with a
212
+ // concrete type base, for example:
213
+ //
214
+ // protocol P { typealias A<T> = ... }
215
+ // struct S : P {}
216
+ // let x: S.A<Int> = ...
217
+ //
218
+ // The mangling tree looks like this:
219
+ //
220
+ // BoundGenericProtocol ---> BoundGenericTypeAlias
221
+ // | |
222
+ // | |
223
+ // --> Protocol: P --> TypeAlias: A
224
+ // | |
225
+ // --> TypeList: --> TypeList:
226
+ // | |
227
+ // --> Structure: S --> Structure: Int
228
+ //
229
+ // When resolving the mangling tree to a decl, we strip off the
230
+ // BoundGenericProtocol's *argument*, leaving behind only the
231
+ // protocol reference.
232
+ //
233
+ // But when resolving it to a type, we want to *keep* the argument
234
+ // so that the parent type becomes 'S' and not 'P'.
235
+ if (Node->getNumChildren () < 2 )
236
+ return BuiltType ();
237
+
238
+ const auto &genericArgs = Node->getChild (1 );
239
+ if (genericArgs->getNumChildren () != 1 )
240
+ return BuiltType ();
241
+
242
+ return decodeMangledType (genericArgs->getChild (0 ));
243
+ }
203
244
case NodeKind::BuiltinTypeName: {
204
245
auto mangledName = Demangle::mangleNode (Node);
205
- return Builder.createBuiltinType (mangledName);
246
+ return Builder.createBuiltinType (Node-> getText (), mangledName);
206
247
}
207
248
case NodeKind::Metatype:
208
249
case NodeKind::ExistentialMetatype: {
@@ -288,7 +329,16 @@ class TypeDecoder {
288
329
289
330
return BuiltType ();
290
331
}
332
+ case NodeKind::DynamicSelf: {
333
+ if (Node->getNumChildren () != 1 )
334
+ return BuiltType ();
291
335
336
+ auto selfType = decodeMangledType (Node->getChild (0 ));
337
+ if (!selfType)
338
+ return BuiltType ();
339
+
340
+ return Builder.createDynamicSelfType (selfType);
341
+ }
292
342
case NodeKind::DependentGenericParamType: {
293
343
auto depth = Node->getChild (0 )->getIndex ();
294
344
auto index = Node->getChild (1 )->getIndex ();
@@ -464,7 +514,7 @@ class TypeDecoder {
464
514
auto member = Node->getChild (1 )->getText ();
465
515
auto assocTypeChild = Node->getChild (1 );
466
516
if (assocTypeChild->getNumChildren () < 1 )
467
- return BuiltType ( );
517
+ return Builder. createDependentMemberType (member, base );
468
518
469
519
auto protocol = decodeMangledProtocolType (assocTypeChild->getChild (0 ));
470
520
if (!protocol)
@@ -516,24 +566,26 @@ class TypeDecoder {
516
566
case NodeKind::SILBoxTypeWithLayout: {
517
567
// TODO: Implement SILBoxTypeRefs with layout. As a stopgap, specify the
518
568
// NativeObject type ref.
519
- return Builder.createBuiltinType (" Bo" );
569
+ return Builder.createBuiltinType (" Builtin.NativeObject " , " Bo" );
520
570
}
521
571
default :
522
572
return BuiltType ();
523
573
}
524
574
}
525
575
526
576
private:
527
- bool decodeMangledNominalType (Demangle::NodePointer node,
528
- BuiltNominalTypeDecl &typeDecl,
529
- BuiltType &parent) {
577
+ bool decodeMangledTypeDecl (Demangle::NodePointer node,
578
+ BuiltTypeDecl &typeDecl,
579
+ BuiltType &parent,
580
+ bool &typeAlias) {
530
581
if (node->getKind () == NodeKind::Type)
531
- return decodeMangledNominalType (node->getChild (0 ), typeDecl, parent);
582
+ return decodeMangledTypeDecl (node->getChild (0 ), typeDecl,
583
+ parent, typeAlias);
532
584
533
- Demangle::NodePointer nominalNode ;
585
+ Demangle::NodePointer declNode ;
534
586
if (node->getKind () == NodeKind::TypeSymbolicReference) {
535
587
// A symbolic reference can be directly resolved to a nominal type.
536
- nominalNode = node;
588
+ declNode = node;
537
589
} else {
538
590
if (node->getNumChildren () < 2 )
539
591
return false ;
@@ -545,7 +597,7 @@ class TypeDecoder {
545
597
// in addition to a reference to the parent type. The
546
598
// mangled name already includes the module and parent
547
599
// types, if any.
548
- nominalNode = node;
600
+ declNode = node;
549
601
switch (parentContext->getKind ()) {
550
602
case Node::Kind::Module:
551
603
break ;
@@ -559,12 +611,12 @@ class TypeDecoder {
559
611
parent = decodeMangledType (parentContext);
560
612
// Remove any generic arguments from the context node, producing a
561
613
// node that references the nominal type declaration.
562
- nominalNode =
614
+ declNode =
563
615
stripGenericArgsFromContextNode (node, Builder.getNodeFactory ());
564
616
break ;
565
617
}
566
618
}
567
- typeDecl = Builder.createNominalTypeDecl (nominalNode );
619
+ typeDecl = Builder.createTypeDecl (declNode, typeAlias );
568
620
if (!typeDecl) return false ;
569
621
570
622
return true ;
0 commit comments