@@ -1861,17 +1861,20 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
1861
1861
sharedContext->differentiableInterfaceType ,
1862
1862
(IRType*)pairType);
1863
1863
1864
- // And place it in the synthesized witness table.
1865
- builder->createWitnessTableEntry (
1866
- table,
1867
- sharedContext->differentialAssocTypeStructKey ,
1868
- diffDiffPairType);
1869
- builder->createWitnessTableEntry (
1870
- table,
1871
- sharedContext->differentialAssocTypeWitnessStructKey ,
1872
- table);
1873
- builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
1874
- builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
1864
+ if (table->getFirstDecorationOrChild () == nullptr )
1865
+ {
1866
+ // And place it in the synthesized witness table.
1867
+ builder->createWitnessTableEntry (
1868
+ table,
1869
+ sharedContext->differentialAssocTypeStructKey ,
1870
+ diffDiffPairType);
1871
+ builder->createWitnessTableEntry (
1872
+ table,
1873
+ sharedContext->differentialAssocTypeWitnessStructKey ,
1874
+ table);
1875
+ builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
1876
+ builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
1877
+ }
1875
1878
1876
1879
bool isUserCodeType = as<IRDifferentialPairUserCodeType>(pairType) ? true : false ;
1877
1880
@@ -1943,15 +1946,18 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
1943
1946
sharedContext->differentiablePtrInterfaceType ,
1944
1947
(IRType*)pairType);
1945
1948
1946
- // And place it in the synthesized witness table.
1947
- builder->createWitnessTableEntry (
1948
- table,
1949
- sharedContext->differentialAssocRefTypeStructKey ,
1950
- diffDiffPairType);
1951
- builder->createWitnessTableEntry (
1952
- table,
1953
- sharedContext->differentialAssocRefTypeWitnessStructKey ,
1954
- table);
1949
+ if (table->getFirstDecorationOrChild () == nullptr )
1950
+ {
1951
+ // And place it in the synthesized witness table.
1952
+ builder->createWitnessTableEntry (
1953
+ table,
1954
+ sharedContext->differentialAssocRefTypeStructKey ,
1955
+ diffDiffPairType);
1956
+ builder->createWitnessTableEntry (
1957
+ table,
1958
+ sharedContext->differentialAssocRefTypeWitnessStructKey ,
1959
+ table);
1960
+ }
1955
1961
}
1956
1962
1957
1963
return table;
@@ -1986,17 +1992,20 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
1986
1992
sharedContext->differentiableInterfaceType ,
1987
1993
(IRType*)arrayType);
1988
1994
1989
- // And place it in the synthesized witness table.
1990
- builder->createWitnessTableEntry (
1991
- table,
1992
- sharedContext->differentialAssocTypeStructKey ,
1993
- diffArrayType);
1994
- builder->createWitnessTableEntry (
1995
- table,
1996
- sharedContext->differentialAssocTypeWitnessStructKey ,
1997
- table);
1998
- builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
1999
- builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
1995
+ if (table->getFirstDecorationOrChild () == nullptr )
1996
+ {
1997
+ // And place it in the synthesized witness table.
1998
+ builder->createWitnessTableEntry (
1999
+ table,
2000
+ sharedContext->differentialAssocTypeStructKey ,
2001
+ diffArrayType);
2002
+ builder->createWitnessTableEntry (
2003
+ table,
2004
+ sharedContext->differentialAssocTypeWitnessStructKey ,
2005
+ table);
2006
+ builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
2007
+ builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
2008
+ }
2000
2009
2001
2010
auto elementType = as<IRArrayTypeBase>(diffArrayType)->getElementType ();
2002
2011
@@ -2065,15 +2074,18 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
2065
2074
sharedContext->differentiablePtrInterfaceType ,
2066
2075
(IRType*)arrayType);
2067
2076
2068
- // And place it in the synthesized witness table.
2069
- builder->createWitnessTableEntry (
2070
- table,
2071
- sharedContext->differentialAssocRefTypeStructKey ,
2072
- diffArrayType);
2073
- builder->createWitnessTableEntry (
2074
- table,
2075
- sharedContext->differentialAssocRefTypeWitnessStructKey ,
2076
- table);
2077
+ if (table->getFirstDecorationOrChild () == nullptr )
2078
+ {
2079
+ // And place it in the synthesized witness table.
2080
+ builder->createWitnessTableEntry (
2081
+ table,
2082
+ sharedContext->differentialAssocRefTypeStructKey ,
2083
+ diffArrayType);
2084
+ builder->createWitnessTableEntry (
2085
+ table,
2086
+ sharedContext->differentialAssocRefTypeWitnessStructKey ,
2087
+ table);
2088
+ }
2077
2089
}
2078
2090
else
2079
2091
{
@@ -2106,17 +2118,20 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
2106
2118
sharedContext->differentiableInterfaceType ,
2107
2119
(IRType*)inTupleType);
2108
2120
2109
- // And place it in the synthesized witness table.
2110
- builder->createWitnessTableEntry (
2111
- table,
2112
- sharedContext->differentialAssocTypeStructKey ,
2113
- diffTupleType);
2114
- builder->createWitnessTableEntry (
2115
- table,
2116
- sharedContext->differentialAssocTypeWitnessStructKey ,
2117
- table);
2118
- builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
2119
- builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
2121
+ if (table->getFirstDecorationOrChild () == nullptr )
2122
+ {
2123
+ // And place it in the synthesized witness table.
2124
+ builder->createWitnessTableEntry (
2125
+ table,
2126
+ sharedContext->differentialAssocTypeStructKey ,
2127
+ diffTupleType);
2128
+ builder->createWitnessTableEntry (
2129
+ table,
2130
+ sharedContext->differentialAssocTypeWitnessStructKey ,
2131
+ table);
2132
+ builder->createWitnessTableEntry (table, sharedContext->addMethodStructKey , addMethod);
2133
+ builder->createWitnessTableEntry (table, sharedContext->zeroMethodStructKey , zeroMethod);
2134
+ }
2120
2135
2121
2136
// Fill in differential method implementations.
2122
2137
{
@@ -2219,15 +2234,18 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
2219
2234
sharedContext->differentiablePtrInterfaceType ,
2220
2235
(IRType*)inTupleType);
2221
2236
2222
- // And place it in the synthesized witness table.
2223
- builder->createWitnessTableEntry (
2224
- table,
2225
- sharedContext->differentialAssocRefTypeStructKey ,
2226
- diffTupleType);
2227
- builder->createWitnessTableEntry (
2228
- table,
2229
- sharedContext->differentialAssocRefTypeWitnessStructKey ,
2230
- table);
2237
+ if (table->getFirstDecorationOrChild () == nullptr )
2238
+ {
2239
+ // And place it in the synthesized witness table.
2240
+ builder->createWitnessTableEntry (
2241
+ table,
2242
+ sharedContext->differentialAssocRefTypeStructKey ,
2243
+ diffTupleType);
2244
+ builder->createWitnessTableEntry (
2245
+ table,
2246
+ sharedContext->differentialAssocRefTypeWitnessStructKey ,
2247
+ table);
2248
+ }
2231
2249
}
2232
2250
2233
2251
return table;
@@ -3078,39 +3096,45 @@ struct AutoDiffPass : public InstPassBase
3078
3096
builder.createWitnessTable (autodiffContext->differentiableInterfaceType , originalType);
3079
3097
result.diffWitness = origTypeIsDiffWitness;
3080
3098
3081
- builder.createWitnessTableEntry (
3082
- origTypeIsDiffWitness,
3083
- autodiffContext->differentialAssocTypeStructKey ,
3084
- diffType);
3085
- builder.createWitnessTableEntry (
3086
- origTypeIsDiffWitness,
3087
- autodiffContext->differentialAssocTypeWitnessStructKey ,
3088
- diffTypeIsDiffWitness);
3089
- builder.createWitnessTableEntry (
3090
- origTypeIsDiffWitness,
3091
- autodiffContext->zeroMethodStructKey ,
3092
- zeroMethod);
3093
- builder.createWitnessTableEntry (
3094
- origTypeIsDiffWitness,
3095
- autodiffContext->addMethodStructKey ,
3096
- addMethod);
3097
-
3098
- builder.createWitnessTableEntry (
3099
- diffTypeIsDiffWitness,
3100
- autodiffContext->differentialAssocTypeStructKey ,
3101
- diffType);
3102
- builder.createWitnessTableEntry (
3103
- diffTypeIsDiffWitness,
3104
- autodiffContext->differentialAssocTypeWitnessStructKey ,
3105
- diffTypeIsDiffWitness);
3106
- builder.createWitnessTableEntry (
3107
- diffTypeIsDiffWitness,
3108
- autodiffContext->zeroMethodStructKey ,
3109
- zeroMethod);
3110
- builder.createWitnessTableEntry (
3111
- diffTypeIsDiffWitness,
3112
- autodiffContext->addMethodStructKey ,
3113
- addMethod);
3099
+ if (origTypeIsDiffWitness->getFirstDecorationOrChild () == nullptr )
3100
+ {
3101
+ builder.createWitnessTableEntry (
3102
+ origTypeIsDiffWitness,
3103
+ autodiffContext->differentialAssocTypeStructKey ,
3104
+ diffType);
3105
+ builder.createWitnessTableEntry (
3106
+ origTypeIsDiffWitness,
3107
+ autodiffContext->differentialAssocTypeWitnessStructKey ,
3108
+ diffTypeIsDiffWitness);
3109
+ builder.createWitnessTableEntry (
3110
+ origTypeIsDiffWitness,
3111
+ autodiffContext->zeroMethodStructKey ,
3112
+ zeroMethod);
3113
+ builder.createWitnessTableEntry (
3114
+ origTypeIsDiffWitness,
3115
+ autodiffContext->addMethodStructKey ,
3116
+ addMethod);
3117
+ }
3118
+
3119
+ if (diffTypeIsDiffWitness->getFirstDecorationOrChild () == nullptr )
3120
+ {
3121
+ builder.createWitnessTableEntry (
3122
+ diffTypeIsDiffWitness,
3123
+ autodiffContext->differentialAssocTypeStructKey ,
3124
+ diffType);
3125
+ builder.createWitnessTableEntry (
3126
+ diffTypeIsDiffWitness,
3127
+ autodiffContext->differentialAssocTypeWitnessStructKey ,
3128
+ diffTypeIsDiffWitness);
3129
+ builder.createWitnessTableEntry (
3130
+ diffTypeIsDiffWitness,
3131
+ autodiffContext->zeroMethodStructKey ,
3132
+ zeroMethod);
3133
+ builder.createWitnessTableEntry (
3134
+ diffTypeIsDiffWitness,
3135
+ autodiffContext->addMethodStructKey ,
3136
+ addMethod);
3137
+ }
3114
3138
return result;
3115
3139
}
3116
3140
@@ -3178,6 +3202,7 @@ struct AutoDiffPass : public InstPassBase
3178
3202
for (auto param : genType->getParams ())
3179
3203
args.add (param);
3180
3204
3205
+ // Create a new WitnessTable with a different concreteType.
3181
3206
auto concreteType = as<IRType>(builder.emitSpecializeInst (
3182
3207
builder.getTypeKind (),
3183
3208
originalType,
@@ -3187,13 +3212,16 @@ struct AutoDiffPass : public InstPassBase
3187
3212
auto witnessTableType = innerResult.diffWitness ->getFullType ();
3188
3213
auto newWitnessTable = builder.createWitnessTable (witnessTableType, concreteType);
3189
3214
3190
- // Copy all entries from the old witness table to the new one
3191
- for (auto entry : as<IRWitnessTable>(innerResult.diffWitness )->getEntries ())
3215
+ if (newWitnessTable->getFirstDecorationOrChild () == nullptr )
3192
3216
{
3193
- builder.createWitnessTableEntry (
3194
- newWitnessTable,
3195
- entry->getRequirementKey (),
3196
- entry->getSatisfyingVal ());
3217
+ builder.setInsertInto (newWitnessTable);
3218
+ for (auto entry : as<IRWitnessTable>(innerResult.diffWitness )->getEntries ())
3219
+ {
3220
+ builder.createWitnessTableEntry (
3221
+ newWitnessTable,
3222
+ entry->getRequirementKey (),
3223
+ entry->getSatisfyingVal ());
3224
+ }
3197
3225
}
3198
3226
3199
3227
result.diffWitness =
0 commit comments