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