Skip to content

Commit 2d863cb

Browse files
committedMar 6, 2025
Fix the order problem by sorting them in the specialize function
1 parent 19700df commit 2d863cb

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed
 

‎source/slang/slang-ir-autodiff.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
18611861
sharedContext->differentiableInterfaceType,
18621862
(IRType*)pairType);
18631863

1864+
// Add WitnessTableEntry only once
18641865
if (table->getFirstDecorationOrChild() == nullptr)
18651866
{
18661867
// And place it in the synthesized witness table.
@@ -1946,6 +1947,7 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
19461947
sharedContext->differentiablePtrInterfaceType,
19471948
(IRType*)pairType);
19481949

1950+
// Add WitnessTableEntry only once
19491951
if (table->getFirstDecorationOrChild() == nullptr)
19501952
{
19511953
// And place it in the synthesized witness table.
@@ -1992,6 +1994,7 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
19921994
sharedContext->differentiableInterfaceType,
19931995
(IRType*)arrayType);
19941996

1997+
// Add WitnessTableEntry only once
19951998
if (table->getFirstDecorationOrChild() == nullptr)
19961999
{
19972000
// And place it in the synthesized witness table.
@@ -2074,6 +2077,7 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
20742077
sharedContext->differentiablePtrInterfaceType,
20752078
(IRType*)arrayType);
20762079

2080+
// Add WitnessTableEntry only once
20772081
if (table->getFirstDecorationOrChild() == nullptr)
20782082
{
20792083
// And place it in the synthesized witness table.
@@ -2118,6 +2122,7 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
21182122
sharedContext->differentiableInterfaceType,
21192123
(IRType*)inTupleType);
21202124

2125+
// Add WitnessTableEntry only once
21212126
if (table->getFirstDecorationOrChild() == nullptr)
21222127
{
21232128
// And place it in the synthesized witness table.
@@ -2234,6 +2239,7 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
22342239
sharedContext->differentiablePtrInterfaceType,
22352240
(IRType*)inTupleType);
22362241

2242+
// Add WitnessTableEntry only once
22372243
if (table->getFirstDecorationOrChild() == nullptr)
22382244
{
22392245
// And place it in the synthesized witness table.
@@ -3096,6 +3102,7 @@ struct AutoDiffPass : public InstPassBase
30963102
builder.createWitnessTable(autodiffContext->differentiableInterfaceType, originalType);
30973103
result.diffWitness = origTypeIsDiffWitness;
30983104

3105+
// Add WitnessTableEntry only once
30993106
if (origTypeIsDiffWitness->getFirstDecorationOrChild() == nullptr)
31003107
{
31013108
builder.createWitnessTableEntry(
@@ -3116,6 +3123,7 @@ struct AutoDiffPass : public InstPassBase
31163123
addMethod);
31173124
}
31183125

3126+
// Add WitnessTableEntry only once
31193127
if (diffTypeIsDiffWitness->getFirstDecorationOrChild() == nullptr)
31203128
{
31213129
builder.createWitnessTableEntry(
@@ -3212,6 +3220,7 @@ struct AutoDiffPass : public InstPassBase
32123220
auto witnessTableType = innerResult.diffWitness->getFullType();
32133221
auto newWitnessTable = builder.createWitnessTable(witnessTableType, concreteType);
32143222

3223+
// Add WitnessTableEntry only once
32153224
if (newWitnessTable->getFirstDecorationOrChild() == nullptr)
32163225
{
32173226
builder.setInsertInto(newWitnessTable);

‎source/slang/slang-lower-to-ir.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -8016,9 +8016,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
80168016
irWitnessTableBaseType,
80178017
irWitnessTable->getConcreteType());
80188018

8019-
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return an
8020-
// IRWitnessTable that already has decorations/children. We need to avoid
8021-
// adding them more than once.
8019+
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return
8020+
// an IRWitnessTable that already has decorations/children. We should
8021+
// add them only once.
8022+
//
80228023
if (irSatisfyingWitnessTable->getFirstDecorationOrChild() == nullptr)
80238024
{
80248025
auto mangledName = getMangledNameForConformanceWitness(
@@ -8040,9 +8041,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
80408041
astReqWitnessTable,
80418042
irSatisfyingWitnessTable,
80428043
mapASTToIRWitnessTable);
8043-
}
80448044

8045-
irSatisfyingWitnessTable->moveToEnd();
8045+
irSatisfyingWitnessTable->moveToEnd();
8046+
}
80468047
}
80478048
irSatisfyingVal = irSatisfyingWitnessTable;
80488049
}
@@ -8168,9 +8169,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
81688169
inheritanceDecl,
81698170
LoweredValInfo::simple(findOuterMostGeneric(irWitnessTable)));
81708171

8171-
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return an
8172-
// IRWitnessTable that already has decorations/children. We need to avoid adding them
8173-
// more than once.
8172+
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return
8173+
// an IRWitnessTable that already has decorations/children. We should
8174+
// add them only once.
81748175
//
81758176
if (irWitnessTable->getFirstDecorationOrChild() == nullptr)
81768177
{
@@ -8214,9 +8215,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
82148215
irWitnessTable,
82158216
mapASTToIRWitnessTable);
82168217
}
8217-
}
82188218

8219-
irWitnessTable->moveToEnd();
8219+
irWitnessTable->moveToEnd();
8220+
}
82208221

82218222
return LoweredValInfo::simple(
82228223
finishOuterGenerics(subBuilder, irWitnessTable, outerGeneric));

0 commit comments

Comments
 (0)