@@ -1942,6 +1942,10 @@ namespace {
1942
1942
ConformanceDescription Description;
1943
1943
ConformanceFlags Flags;
1944
1944
1945
+ using PlaceholderPosition =
1946
+ ConstantAggregateBuilderBase::PlaceholderPosition;
1947
+ Optional<PlaceholderPosition> FlagsPP;
1948
+
1945
1949
public:
1946
1950
ProtocolConformanceDescriptorBuilder (
1947
1951
IRGenModule &IGM,
@@ -1960,6 +1964,11 @@ namespace {
1960
1964
addResilientWitnesses ();
1961
1965
addGenericWitnessTable ();
1962
1966
1967
+ // We fill the flags last, since we continue filling them in
1968
+ // after the call to addFlags() deposits the placeholder.
1969
+ B.fillPlaceholderWithInt (*FlagsPP, IGM.Int32Ty ,
1970
+ Flags.getIntValue ());
1971
+
1963
1972
B.suggestType (IGM.ProtocolConformanceDescriptorTy );
1964
1973
}
1965
1974
@@ -1981,13 +1990,6 @@ namespace {
1981
1990
}
1982
1991
1983
1992
void addWitnessTable () {
1984
- // Note the number of conditional requirements.
1985
- unsigned numConditional = 0 ;
1986
- if (auto normal = dyn_cast<NormalProtocolConformance>(Conformance)) {
1987
- numConditional = normal->getConditionalRequirements ().size ();
1988
- }
1989
- Flags = Flags.withNumConditionalRequirements (numConditional);
1990
-
1991
1993
// Relative reference to the witness table.
1992
1994
B.addRelativeAddressOrNull (Description.pattern );
1993
1995
}
@@ -2001,13 +2003,9 @@ namespace {
2001
2003
Flags = Flags.withIsRetroactive (false )
2002
2004
.withIsSynthesizedNonUnique (false );
2003
2005
}
2004
- Flags = Flags.withHasResilientWitnesses (
2005
- !Description.resilientWitnesses .empty ());
2006
- Flags =
2007
- Flags.withHasGenericWitnessTable (Description.requiresSpecialization );
2008
2006
2009
- // Add the flags.
2010
- B. addInt32 (Flags. getIntValue () );
2007
+ // Add a placeholder for the flags.
2008
+ FlagsPP = B. addPlaceholderWithSize (IGM. Int32Ty );
2011
2009
}
2012
2010
2013
2011
void addContext () {
@@ -2025,19 +2023,42 @@ namespace {
2025
2023
2026
2024
void addConditionalRequirements () {
2027
2025
auto normal = dyn_cast<NormalProtocolConformance>(Conformance);
2028
- if (!normal || normal-> getConditionalRequirements (). empty () )
2026
+ if (!normal)
2029
2027
return ;
2030
2028
2031
- auto nominal = normal->getType ()->getAnyNominal ();
2032
- irgen::addGenericRequirements (IGM, B,
2033
- nominal->getGenericSignatureOfContext (),
2034
- normal->getConditionalRequirements ());
2029
+ auto condReqs = normal->getConditionalRequirements ();
2030
+ if (condReqs.empty ())
2031
+ return ;
2032
+
2033
+ Flags = Flags.withNumConditionalRequirements (condReqs.size ());
2034
+
2035
+ auto nominal = normal->getDeclContext ()->getSelfNominalTypeDecl ();
2036
+ auto sig = nominal->getGenericSignatureOfContext ();
2037
+ auto metadata = irgen::addGenericRequirements (IGM, B, sig, condReqs);
2038
+
2039
+ Flags = Flags.withNumConditionalPackDescriptors (
2040
+ metadata.GenericPackArguments .size ());
2041
+
2042
+ // Collect the shape classes from the nominal type's generic signature.
2043
+ sig->forEachParam ([&](GenericTypeParamType *param, bool canonical) {
2044
+ if (canonical && param->isParameterPack ()) {
2045
+ auto reducedShape = sig->getReducedShape (param)->getCanonicalType ();
2046
+ if (reducedShape->isEqual (param))
2047
+ metadata.ShapeClasses .push_back (reducedShape);
2048
+ }
2049
+ });
2050
+
2051
+ irgen::addGenericPackShapeDescriptors (
2052
+ IGM, B, metadata.ShapeClasses ,
2053
+ metadata.GenericPackArguments );
2035
2054
}
2036
2055
2037
2056
void addResilientWitnesses () {
2038
2057
if (Description.resilientWitnesses .empty ())
2039
2058
return ;
2040
2059
2060
+ Flags = Flags.withHasResilientWitnesses (true );
2061
+
2041
2062
// TargetResilientWitnessesHeader
2042
2063
ArrayRef<llvm::Constant *> witnesses = Description.resilientWitnesses ;
2043
2064
B.addInt32 (witnesses.size ());
@@ -2098,6 +2119,8 @@ namespace {
2098
2119
if (!Description.requiresSpecialization )
2099
2120
return ;
2100
2121
2122
+ Flags = Flags.withHasGenericWitnessTable (true );
2123
+
2101
2124
// WitnessTableSizeInWords
2102
2125
B.addInt (IGM.Int16Ty , Description.witnessTableSize );
2103
2126
// WitnessTablePrivateSizeInWordsAndRequiresInstantiation
0 commit comments