20
20
21
21
#include " TypeLookupError.h"
22
22
#include " swift/Basic/LLVM.h"
23
+ #include " swift/ABI/Metadata.h"
23
24
#include " swift/ABI/MetadataValues.h"
24
25
#include " swift/AST/LayoutConstraintKind.h"
25
26
#include " swift/AST/RequirementBase.h"
@@ -470,29 +471,53 @@ class TypeDecoder {
470
471
public:
471
472
explicit TypeDecoder (BuilderType &Builder) : Builder(Builder) {}
472
473
474
+ // / Given a demangle tree, attempt to turn it into a type.
475
+ TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node) {
476
+ return decodeMangledType (Node, 0 );
477
+ }
478
+
473
479
// / Given a demangle tree, attempt to turn it into a protocol conformance.
474
480
BuiltProtocolConformance decodeMangledProtocolConformance (NodePointer Node) {
475
- if (!Node) return BuiltProtocolConformance ();
481
+ return decodeMangledProtocolConformance (Node, 0 );
482
+ }
483
+
484
+ // / Given a demangle tree, attempt to turn it into a conformance decl.
485
+ BuiltProtocolConformanceDecl
486
+ decodeMangledProtocolConformanceDecl (BuiltType ConformingType,
487
+ NodePointer Node) {
488
+ return decodeMangledProtocolConformanceDecl (ConformingType, Node, 0 );
489
+ }
490
+
491
+ protected:
492
+ static const unsigned MaxDepth = 1024 ;
493
+
494
+ BuiltProtocolConformance decodeMangledProtocolConformance (NodePointer Node,
495
+ unsigned depth) {
496
+ if (!Node || depth > TypeDecoder::MaxDepth)
497
+ return BuiltProtocolConformance ();
476
498
477
499
using NodeKind = Demangle::Node::Kind;
478
500
switch (Node->getKind ()) {
479
501
case NodeKind::Global:
480
502
if (Node->getNumChildren () < 1 )
481
503
return BuiltProtocolConformance ();
482
504
483
- return decodeMangledProtocolConformance (Node->getChild (0 ));
505
+ return decodeMangledProtocolConformance (Node->getChild (0 ), depth + 1 );
484
506
485
507
case NodeKind::ConcreteProtocolConformance: {
486
508
if (Node->getNumChildren () < 3 )
487
509
return BuiltProtocolConformance ();
488
510
489
- auto conformingType = decodeMangledType (Node->getChild (0 ));
490
- if (!conformingType)
511
+ auto conformingTypeOrError = decodeMangledType (Node->getChild (0 ),
512
+ depth + 1 );
513
+ if (conformingTypeOrError.isError ())
491
514
return BuiltProtocolConformance ();
492
515
516
+ auto conformingType = conformingTypeOrError.getValue ();
493
517
auto conformanceDecl
494
518
= decodeMangledProtocolConformanceDecl (conformingType,
495
- Node->getChild (1 ));
519
+ Node->getChild (1 ),
520
+ depth + 1 );
496
521
497
522
if (!conformanceDecl)
498
523
return BuiltProtocolConformance ();
@@ -503,7 +528,7 @@ class TypeDecoder {
503
528
return BuiltProtocolConformance ();
504
529
505
530
for (auto mangledArg : *Node->getChild (2 )) {
506
- auto arg = decodeMangledProtocolConformance (mangledArg);
531
+ auto arg = decodeMangledProtocolConformance (mangledArg, depth + 1 );
507
532
if (!arg)
508
533
return BuiltProtocolConformance ();
509
534
conformanceArgs.push_back (arg);
@@ -518,11 +543,14 @@ class TypeDecoder {
518
543
if (Node->getNumChildren () < 3 )
519
544
return BuiltProtocolConformance ();
520
545
521
- auto conformingType = decodeMangledType (Node->getChild (0 ));
522
- if (!conformingType)
546
+ auto conformingTypeOrError = decodeMangledType (Node->getChild (0 ),
547
+ depth + 1 );
548
+ if (conformingTypeOrError.isError ())
523
549
return BuiltProtocolConformance ();
524
550
525
- auto conformingRequirement = decodeMangledProtocolType (Node->getChild (1 ));
551
+ auto conformingType = conformingTypeOrError.getValue ();
552
+ auto conformingRequirement = decodeMangledProtocolType (Node->getChild (1 ),
553
+ depth + 1 );
526
554
if (!conformingRequirement)
527
555
return BuiltProtocolConformance ();
528
556
@@ -540,7 +568,7 @@ class TypeDecoder {
540
568
if (Node->getNumChildren () < 3 )
541
569
return BuiltProtocolConformance ();
542
570
543
- auto base = decodeMangledProtocolConformance (Node->getChild (0 ));
571
+ auto base = decodeMangledProtocolConformance (Node->getChild (0 ), depth + 1 );
544
572
if (!base)
545
573
return BuiltProtocolConformance ();
546
574
@@ -549,10 +577,13 @@ class TypeDecoder {
549
577
if (Node->getChild (1 )->getNumChildren () < 2 )
550
578
return BuiltProtocolConformance ();
551
579
552
- auto conformingType = decodeMangledType (Node->getChild (1 )->getChild (0 ));
553
- if (!conformingType)
580
+ auto conformingTypeOrError
581
+ = decodeMangledType (Node->getChild (1 )->getChild (0 ), depth + 1 );
582
+ if (conformingTypeOrError.isError ())
554
583
return BuiltProtocolConformance ();
555
- auto conformingRequirement = decodeMangledProtocolType (Node->getChild (1 )->getChild (1 ));
584
+ auto conformingType = conformingTypeOrError.getValue ();
585
+ auto conformingRequirement
586
+ = decodeMangledProtocolType (Node->getChild (1 )->getChild (1 ), depth + 1 );
556
587
if (!conformingRequirement)
557
588
return BuiltProtocolConformance ();
558
589
@@ -571,11 +602,12 @@ class TypeDecoder {
571
602
if (Node->getNumChildren () < 3 )
572
603
return BuiltProtocolConformance ();
573
604
574
- auto base = decodeMangledProtocolConformance (Node->getChild (0 ));
605
+ auto base = decodeMangledProtocolConformance (Node->getChild (0 ), depth + 1 );
575
606
if (!base)
576
607
return BuiltProtocolConformance ();
577
608
578
- auto superRequirement = decodeMangledProtocolType (Node->getChild (1 ));
609
+ auto superRequirement = decodeMangledProtocolType (Node->getChild (1 ),
610
+ depth + 1 );
579
611
if (!superRequirement)
580
612
return BuiltProtocolConformance ();
581
613
@@ -589,22 +621,32 @@ class TypeDecoder {
589
621
index);
590
622
}
591
623
624
+ case NodeKind::AssociatedConformanceProtocolRelativeAccessor:
625
+ case NodeKind::AssociatedConformanceTypeRelativeAccessor: {
626
+ auto witnessFn = reinterpret_cast <AssociatedWitnessTableAccessFunction *>(
627
+ Node->getIndex ());
628
+ return Builder.createProtocolConformanceFromAccessor (witnessFn);
629
+ }
592
630
default :
593
631
return BuiltProtocolConformance ();
594
632
}
595
633
}
596
634
597
- BuiltProtocolConformanceDecl decodeMangledProtocolConformanceDecl (BuiltType ConformingType,
598
- NodePointer Node) {
599
- if (!Node) return BuiltProtocolConformanceDecl ();
635
+ BuiltProtocolConformanceDecl
636
+ decodeMangledProtocolConformanceDecl (BuiltType ConformingType,
637
+ NodePointer Node,
638
+ unsigned depth) {
639
+ if (!Node || depth > TypeDecoder::MaxDepth)
640
+ return BuiltProtocolConformanceDecl ();
600
641
601
642
using NodeKind = Demangle::Node::Kind;
602
643
switch (Node->getKind ()) {
603
644
case NodeKind::ProtocolConformanceRefInTypeModule: {
604
645
if (Node->getNumChildren () < 1 )
605
646
return BuiltProtocolConformanceDecl ();
606
647
607
- auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ));
648
+ auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ),
649
+ depth + 1 );
608
650
if (!protocolRequirement)
609
651
return BuiltProtocolConformanceDecl ();
610
652
@@ -616,7 +658,8 @@ class TypeDecoder {
616
658
if (Node->getNumChildren () < 1 )
617
659
return BuiltProtocolConformanceDecl ();
618
660
619
- auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ));
661
+ auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ),
662
+ depth + 1 );
620
663
if (!protocolRequirement)
621
664
return BuiltProtocolConformanceDecl ();
622
665
@@ -628,7 +671,8 @@ class TypeDecoder {
628
671
if (Node->getNumChildren () < 2 )
629
672
return BuiltProtocolConformanceDecl ();
630
673
631
- auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ));
674
+ auto protocolRequirement = decodeMangledProtocolType (Node->getChild (0 ),
675
+ depth + 1 );
632
676
if (!protocolRequirement)
633
677
return BuiltProtocolConformanceDecl ();
634
678
@@ -639,25 +683,18 @@ class TypeDecoder {
639
683
moduleName);
640
684
}
641
685
642
- /*
643
- case NodeKind::ProtocolConformanceSymbolicReference:
644
- return Builder.createSymbolicProtocolConformanceDecl(ConformingType,
645
- Node);
646
- */
686
+ case NodeKind::ProtocolConformanceDescriptorRef:
687
+ case NodeKind::AssociatedConformanceDescriptorRef: {
688
+ auto desc = reinterpret_cast <ProtocolConformanceDescriptor *>(
689
+ Node->getIndex ());
690
+ return Builder.createProtocolConformanceDeclFromDescriptor (desc);
691
+ }
647
692
648
693
default :
649
- return BuiltProtocolConformance ();
694
+ return BuiltProtocolConformanceDecl ();
650
695
}
651
696
}
652
697
653
- // / Given a demangle tree, attempt to turn it into a type.
654
- TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node) {
655
- return decodeMangledType (Node, 0 );
656
- }
657
-
658
- protected:
659
- static const unsigned MaxDepth = 1024 ;
660
-
661
698
TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node,
662
699
unsigned depth) {
663
700
if (depth > TypeDecoder::MaxDepth)
0 commit comments