@@ -170,6 +170,14 @@ namespace Slang
170
170
}
171
171
}
172
172
173
+ IRInst* findInnerMostSpecializingBase (IRSpecialize* inst)
174
+ {
175
+ auto result = inst->getBase ();
176
+ while (auto specialize = as<IRSpecialize>(result))
177
+ result = specialize->getBase ();
178
+ return result;
179
+ }
180
+
173
181
void lowerCallToSpecializedFunc (IRCall* callInst, IRSpecialize* specializeInst)
174
182
{
175
183
// If we see a call(specialize(gFunc, Targs), args),
@@ -180,9 +188,23 @@ namespace Slang
180
188
// them here.
181
189
if (loweredFunc->op == kIROp_Generic )
182
190
{
183
- // This is an intrinsic function, don't transform.
184
191
return ;
185
192
}
193
+ else if (loweredFunc->op == kIROp_Specialize )
194
+ {
195
+ // All nested generic functions are supposed to be flattend before this pass.
196
+ // If they are not, they represent an intrinsic function that should not be
197
+ // modified in this pass.
198
+ auto innerMostFunc = findInnerMostSpecializingBase (static_cast <IRSpecialize*>(loweredFunc));
199
+ if (innerMostFunc && innerMostFunc->op == kIROp_Generic )
200
+ {
201
+ innerMostFunc =
202
+ findInnerMostGenericReturnVal (static_cast <IRGeneric*>(innerMostFunc));
203
+ }
204
+ if (innerMostFunc->findDecoration <IRTargetIntrinsicDecoration>())
205
+ return ;
206
+ SLANG_UNEXPECTED (" Nested generics specialization." );
207
+ }
186
208
IRFuncType* funcType = cast<IRFuncType>(loweredFunc->getDataType ());
187
209
translateCallInst (callInst, funcType, loweredFunc, specializeInst);
188
210
}
@@ -193,6 +215,9 @@ namespace Slang
193
215
// all occurences of associatedtypes.
194
216
auto funcType = cast<IRFuncType>(lookupInst->getDataType ());
195
217
auto loweredFunc = lookupInst;
218
+ if (isBuiltin (cast<IRWitnessTableType>(
219
+ lookupInst->getWitnessTable ()->getDataType ())->getConformanceType ()))
220
+ return ;
196
221
translateCallInst (callInst, funcType, loweredFunc, nullptr );
197
222
}
198
223
0 commit comments