@@ -639,3 +639,238 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const {
639
639
}
640
640
llvm_unreachable (" bad link entity kind" );
641
641
}
642
+
643
+ llvm::Type *LinkEntity::getDefaultDeclarationType (IRGenModule &IGM) const {
644
+ switch (getKind ()) {
645
+ case Kind::ModuleDescriptor:
646
+ case Kind::ExtensionDescriptor:
647
+ case Kind::AnonymousDescriptor:
648
+ case Kind::NominalTypeDescriptor:
649
+ case Kind::PropertyDescriptor:
650
+ return IGM.TypeContextDescriptorTy ;
651
+ case Kind::ProtocolDescriptor:
652
+ return IGM.ProtocolDescriptorStructTy ;
653
+ case Kind::AssociatedTypeDescriptor:
654
+ case Kind::AssociatedConformanceDescriptor:
655
+ case Kind::ProtocolRequirementsBaseDescriptor:
656
+ return IGM.ProtocolRequirementStructTy ;
657
+ case Kind::ProtocolConformanceDescriptor:
658
+ return IGM.ProtocolConformanceDescriptorTy ;
659
+ case Kind::ObjCClassRef:
660
+ return IGM.ObjCClassPtrTy ;
661
+ case Kind::ObjCClass:
662
+ case Kind::ObjCMetaclass:
663
+ case Kind::SwiftMetaclassStub:
664
+ return IGM.ObjCClassStructTy ;
665
+ case Kind::TypeMetadataLazyCacheVariable:
666
+ return IGM.TypeMetadataPtrTy ;
667
+ case Kind::TypeMetadataSingletonInitializationCache:
668
+ // TODO: put a cache variable on IGM
669
+ return llvm::StructType::get (IGM.getLLVMContext (),
670
+ {IGM.TypeMetadataPtrTy , IGM.Int8PtrTy });
671
+ case Kind::TypeMetadata:
672
+ switch (getMetadataAddress ()) {
673
+ case TypeMetadataAddress::FullMetadata:
674
+ if (getType ().getClassOrBoundGenericClass ())
675
+ return IGM.FullHeapMetadataStructTy ;
676
+ else
677
+ return IGM.FullTypeMetadataStructTy ;
678
+ case TypeMetadataAddress::AddressPoint:
679
+ return IGM.TypeMetadataStructTy ;
680
+ }
681
+
682
+ case Kind::TypeMetadataPattern:
683
+ // TODO: Use a real type?
684
+ return IGM.Int8Ty ;
685
+
686
+ case Kind::ClassMetadataBaseOffset:
687
+ // TODO: put a cache variable on IGM
688
+ return llvm::StructType::get (IGM.getLLVMContext (), {
689
+ IGM.SizeTy , // Immediate members offset
690
+ IGM.Int32Ty , // Negative size in words
691
+ IGM.Int32Ty // Positive size in words
692
+ });
693
+
694
+ case Kind::TypeMetadataInstantiationCache:
695
+ // TODO: put a cache variable on IGM
696
+ return llvm::ArrayType::get (IGM.Int8PtrTy ,
697
+ NumGenericMetadataPrivateDataWords);
698
+ case Kind::ReflectionBuiltinDescriptor:
699
+ case Kind::ReflectionFieldDescriptor:
700
+ case Kind::ReflectionAssociatedTypeDescriptor:
701
+ return IGM.FieldDescriptorTy ;
702
+ case Kind::ValueWitnessTable:
703
+ case Kind::DirectProtocolWitnessTable:
704
+ case Kind::ProtocolWitnessTablePattern:
705
+ return IGM.WitnessTableTy ;
706
+ case Kind::FieldOffset:
707
+ return IGM.SizeTy ;
708
+ case Kind::EnumCase:
709
+ return IGM.Int32Ty ;
710
+ case Kind::ProtocolWitnessTableLazyCacheVariable:
711
+ return IGM.WitnessTablePtrTy ;
712
+ case Kind::SILFunction:
713
+ return IGM.FunctionPtrTy ->getPointerTo ();
714
+ case Kind::MethodDescriptor:
715
+ case Kind::MethodDescriptorInitializer:
716
+ case Kind::MethodDescriptorAllocator:
717
+ return IGM.MethodDescriptorStructTy ;
718
+
719
+ default :
720
+ llvm_unreachable (" declaration LLVM type not specified" );
721
+ }
722
+ }
723
+
724
+ Alignment LinkEntity::getAlignment (IRGenModule &IGM) const {
725
+ switch (getKind ()) {
726
+ case Kind::ModuleDescriptor:
727
+ case Kind::ExtensionDescriptor:
728
+ case Kind::AnonymousDescriptor:
729
+ case Kind::NominalTypeDescriptor:
730
+ case Kind::ProtocolDescriptor:
731
+ case Kind::AssociatedTypeDescriptor:
732
+ case Kind::AssociatedConformanceDescriptor:
733
+ case Kind::ProtocolConformanceDescriptor:
734
+ case Kind::ProtocolRequirementsBaseDescriptor:
735
+ case Kind::ReflectionBuiltinDescriptor:
736
+ case Kind::ReflectionFieldDescriptor:
737
+ case Kind::ReflectionAssociatedTypeDescriptor:
738
+ case Kind::PropertyDescriptor:
739
+ case Kind::EnumCase:
740
+ case Kind::MethodDescriptor:
741
+ case Kind::MethodDescriptorInitializer:
742
+ case Kind::MethodDescriptorAllocator:
743
+ return Alignment (4 );
744
+ case Kind::ObjCClassRef:
745
+ case Kind::ObjCClass:
746
+ case Kind::TypeMetadataLazyCacheVariable:
747
+ case Kind::TypeMetadataSingletonInitializationCache:
748
+ case Kind::TypeMetadata:
749
+ case Kind::TypeMetadataPattern:
750
+ case Kind::ClassMetadataBaseOffset:
751
+ case Kind::TypeMetadataInstantiationCache:
752
+ case Kind::ValueWitnessTable:
753
+ case Kind::FieldOffset:
754
+ case Kind::ProtocolWitnessTableLazyCacheVariable:
755
+ case Kind::DirectProtocolWitnessTable:
756
+ case Kind::ProtocolWitnessTablePattern:
757
+ case Kind::ObjCMetaclass:
758
+ case Kind::SwiftMetaclassStub:
759
+ return IGM.getPointerAlignment ();
760
+ case Kind::SILFunction:
761
+ return Alignment (1 );
762
+ default :
763
+ llvm_unreachable (" alignment not specified" );
764
+ }
765
+ }
766
+
767
+ const SourceFile *LinkEntity::getSourceFileForEmission () const {
768
+ const SourceFile *sf;
769
+
770
+ // Shared-linkage entities don't get emitted with any particular file.
771
+ if (hasSharedVisibility (getLinkage (NotForDefinition)))
772
+ return nullptr ;
773
+
774
+ auto getSourceFileForDeclContext =
775
+ [](const DeclContext *dc) -> const SourceFile * {
776
+ if (!dc)
777
+ return nullptr ;
778
+ return dc->getParentSourceFile ();
779
+ };
780
+
781
+ switch (getKind ()) {
782
+ case Kind::DispatchThunk:
783
+ case Kind::DispatchThunkInitializer:
784
+ case Kind::DispatchThunkAllocator:
785
+ case Kind::MethodDescriptor:
786
+ case Kind::MethodDescriptorInitializer:
787
+ case Kind::MethodDescriptorAllocator:
788
+ case Kind::MethodLookupFunction:
789
+ case Kind::EnumCase:
790
+ case Kind::FieldOffset:
791
+ case Kind::ObjCClass:
792
+ case Kind::ObjCMetaclass:
793
+ case Kind::SwiftMetaclassStub:
794
+ case Kind::ClassMetadataBaseOffset:
795
+ case Kind::PropertyDescriptor:
796
+ case Kind::NominalTypeDescriptor:
797
+ case Kind::TypeMetadataPattern:
798
+ case Kind::TypeMetadataInstantiationCache:
799
+ case Kind::TypeMetadataInstantiationFunction:
800
+ case Kind::TypeMetadataSingletonInitializationCache:
801
+ case Kind::TypeMetadataCompletionFunction:
802
+ case Kind::ProtocolDescriptor:
803
+ case Kind::ProtocolRequirementsBaseDescriptor:
804
+ case Kind::AssociatedTypeDescriptor:
805
+ case Kind::AssociatedConformanceDescriptor:
806
+ case Kind::DefaultAssociatedConformanceAccessor:
807
+ sf = getSourceFileForDeclContext (getDecl ()->getDeclContext ());
808
+ if (!sf)
809
+ return nullptr ;
810
+ break ;
811
+
812
+ case Kind::SILFunction:
813
+ sf = getSourceFileForDeclContext (getSILFunction ()->getDeclContext ());
814
+ if (!sf)
815
+ return nullptr ;
816
+ break ;
817
+
818
+ case Kind::SILGlobalVariable:
819
+ if (auto decl = getSILGlobalVariable ()->getDecl ()) {
820
+ sf = getSourceFileForDeclContext (decl->getDeclContext ());
821
+ if (!sf)
822
+ return nullptr ;
823
+ } else {
824
+ return nullptr ;
825
+ }
826
+ break ;
827
+
828
+ case Kind::DirectProtocolWitnessTable:
829
+ case Kind::ProtocolWitnessTablePattern:
830
+ case Kind::ProtocolWitnessTableAccessFunction:
831
+ case Kind::GenericProtocolWitnessTableInstantiationFunction:
832
+ case Kind::AssociatedTypeWitnessTableAccessFunction:
833
+ case Kind::ReflectionAssociatedTypeDescriptor:
834
+ case Kind::ProtocolConformanceDescriptor:
835
+ case Kind::ProtocolWitnessTableLazyCacheVariable:
836
+ case Kind::ProtocolWitnessTableLazyAccessFunction:
837
+ sf = getSourceFileForDeclContext (
838
+ getProtocolConformance ()->getRootNormalConformance ()->getDeclContext ());
839
+ if (!sf)
840
+ return nullptr ;
841
+ break ;
842
+
843
+ case Kind::TypeMetadata: {
844
+ auto ty = getType ();
845
+ // Only fully concrete nominal type metadata gets emitted eagerly.
846
+ auto nom = ty->getAnyNominal ();
847
+ if (!nom || nom->isGenericContext ())
848
+ return nullptr ;
849
+
850
+ sf = getSourceFileForDeclContext (nom);
851
+ if (!sf)
852
+ return nullptr ;
853
+ break ;
854
+ }
855
+
856
+ // Always shared linkage
857
+ case Kind::ModuleDescriptor:
858
+ case Kind::ExtensionDescriptor:
859
+ case Kind::AnonymousDescriptor:
860
+ case Kind::ObjCClassRef:
861
+ case Kind::TypeMetadataAccessFunction:
862
+ case Kind::TypeMetadataLazyCacheVariable:
863
+ case Kind::ForeignTypeMetadataCandidate:
864
+ return nullptr ;
865
+
866
+ // TODO
867
+ case Kind::CoroutineContinuationPrototype:
868
+ case Kind::ReflectionFieldDescriptor:
869
+ case Kind::ReflectionBuiltinDescriptor:
870
+ case Kind::ValueWitness:
871
+ case Kind::ValueWitnessTable:
872
+ return nullptr ;
873
+ }
874
+
875
+ return sf;
876
+ }
0 commit comments