@@ -1924,114 +1924,6 @@ bool IRGenModule::isPOD(SILType type, ResilienceScope scope) {
1924
1924
}
1925
1925
1926
1926
1927
- namespace {
1928
- struct ClassifyTypeSize : CanTypeVisitor<ClassifyTypeSize, ObjectSize> {
1929
- IRGenModule &IGM;
1930
- ResilienceScope Scope;
1931
- ClassifyTypeSize (IRGenModule &IGM, ResilienceScope scope)
1932
- : IGM(IGM), Scope(scope) {}
1933
-
1934
- #define ALWAYS (KIND, RESULT ) \
1935
- ObjectSize visit##KIND##Type(KIND##Type *t) { return ObjectSize::RESULT; }
1936
-
1937
- ALWAYS (Builtin, Fixed )
1938
- ALWAYS (SILFunction, Fixed )
1939
- ALWAYS (Class, Fixed )
1940
- ALWAYS (BoundGenericClass, Fixed )
1941
- ALWAYS (Protocol, Fixed )
1942
- ALWAYS (ProtocolComposition, Fixed )
1943
- ALWAYS (LValue, Dependent)
1944
- #undef ALWAYS
1945
-
1946
- ObjectSize visitArchetypeType (CanArchetypeType archetype) {
1947
- if (archetype->requiresClass ())
1948
- return ObjectSize::Fixed ;
1949
- return ObjectSize::Dependent;
1950
- }
1951
-
1952
- ObjectSize visitTupleType (CanTupleType tuple) {
1953
- ObjectSize result = ObjectSize::Fixed ;
1954
- for (auto eltType : tuple.getElementTypes ()) {
1955
- result = std::max (result, visit (eltType));
1956
- }
1957
- return result;
1958
- }
1959
-
1960
- ObjectSize visitStructType (CanStructType type) {
1961
- if (type->getDecl ()->getGenericParamsOfContext ())
1962
- return visitGenericStructType (type, type->getDecl ());
1963
- if (IGM.isResilient (type->getDecl (), Scope))
1964
- return ObjectSize::Resilient;
1965
- return ObjectSize::Fixed ;
1966
- }
1967
-
1968
- ObjectSize visitBoundGenericStructType (CanBoundGenericStructType type) {
1969
- return visitGenericStructType (type, type->getDecl ());
1970
- }
1971
-
1972
- ObjectSize visitGenericStructType (CanType type, StructDecl *D) {
1973
- assert (D->getGenericParamsOfContext ());
1974
-
1975
- // If a generic struct is resilient, we have to assume that any
1976
- // unknown fields might be dependently-sized.
1977
- if (IGM.isResilient (D, Scope))
1978
- return ObjectSize::Dependent;
1979
-
1980
- auto structType = SILType::getPrimitiveAddressType (type);
1981
-
1982
- ObjectSize result = ObjectSize::Fixed ;
1983
- for (auto field : D->getStoredProperties ()) {
1984
- auto fieldType = structType.getFieldType (field, *IGM.SILMod );
1985
- result = std::max (result, visitSILType (fieldType));
1986
- }
1987
- return result;
1988
- }
1989
-
1990
- ObjectSize visitEnumType (CanEnumType type) {
1991
- if (type->getDecl ()->getGenericParamsOfContext ())
1992
- return visitGenericEnumType (type, type->getDecl ());
1993
- if (IGM.isResilient (type->getDecl (), Scope))
1994
- return ObjectSize::Resilient;
1995
- return ObjectSize::Fixed ;
1996
- }
1997
-
1998
- ObjectSize visitBoundGenericEnumType (CanBoundGenericEnumType type) {
1999
- return visitGenericEnumType (type, type->getDecl ());
2000
- }
2001
-
2002
- ObjectSize visitGenericEnumType (CanType type, EnumDecl *D) {
2003
- assert (D->getGenericParamsOfContext ());
2004
-
2005
- // If a generic enum is resilient, we have to assume that any
2006
- // unknown elements might be dependently-sized.
2007
- if (IGM.isResilient (D, Scope))
2008
- return ObjectSize::Dependent;
2009
-
2010
- auto enumType = SILType::getPrimitiveAddressType (type);
2011
-
2012
- ObjectSize result = ObjectSize::Fixed ;
2013
- for (auto elt : D->getAllElements ()) {
2014
- if (!elt->hasArgumentType ()) continue ;
2015
- auto eltType = enumType.getEnumElementType (elt, *IGM.SILMod );
2016
- result = std::max (result, visitSILType (eltType));
2017
- }
2018
- return result;
2019
- }
2020
-
2021
- ObjectSize visitType (CanType type) {
2022
- return ObjectSize::Fixed ;
2023
- }
2024
-
2025
- ObjectSize visitSILType (SILType type) {
2026
- return visit (type.getSwiftRValueType ());
2027
- }
2028
- };
2029
- }
2030
-
2031
- ObjectSize IRGenModule::classifyTypeSize (SILType type, ResilienceScope scope) {
2032
- return ClassifyTypeSize (*this , scope).visitSILType (type);
2033
- }
2034
-
2035
1927
SpareBitVector IRGenModule::getSpareBitsForType (llvm::Type *scalarTy, Size size) {
2036
1928
auto it = SpareBitsForTypes.find (scalarTy);
2037
1929
if (it != SpareBitsForTypes.end ())
0 commit comments