From 48afbf9a1075fcf541b2c196c6313aeda57e9637 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Fri, 10 Oct 2025 19:41:13 +0300 Subject: Specialize interfaces in DebugFunction (#8617) E.g. in [generic-extension-2.slang](https://github.com/shader-slang/slang/blob/master/tests/language-feature/extensions/generic-extension-2.slang), incorrect DebugFunctions are generated for `getFirstOuter`: ``` let %33 : Void = DebugFunction("getFirstOuter", 18 : UInt, 3 : UInt, %26, Func(Int, 0 : Int)) ``` This happens because specialization passes are leaving a `%IFoo` in the function type, instead of replacing with a concrete type: ``` let %34 : Void = DebugFunction("getFirstOuter", 18 : UInt, 3 : UInt, %26, Func(Int, %IFoo)) ``` and later, `cleanUpInterfaceTypes()` just replaces all interfaces with the literal zero. So now we have a parameter type which isn't actually a type at all, but an IntLit instead. I'm not sure if the approach I picked is good, though. Some other options that crossed my mind were: * Make `fixUpFuncType` also update related DebugFunctions - But is there a reason why DebugFunctions separately carry a function type in the first place? * Make `cleanUpInterfaceTypes` less aggressive or at least replace types with a type instead of a value - But this will still make the debug info incorrect :( --- source/slang/slang-ir.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index ba8864684..7b7d5ec17 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -815,6 +815,37 @@ IRType* IRFunc::getParamType(UInt index) return getDataType()->getParamType(index); } +void fixUpDebugFuncType(IRFunc* func) +{ + SLANG_ASSERT(func); + + if (auto debugFuncDecor = func->findDecoration()) + { + auto funcType = func->getDataType(); + auto oldDebugFunc = cast(debugFuncDecor->getDebugFunc()); + + // If the existing debug func type is already the same, there's no need + // to do anything. + if (isTypeEqual(funcType, as(oldDebugFunc->getDebugType()))) + return; + + auto irModule = func->getModule(); + SLANG_ASSERT(irModule); + + IRBuilder builder(irModule); + builder.setInsertInto(irModule->getModuleInst()); + + auto newDebugFunc = builder.emitDebugFunction( + oldDebugFunc->getName(), + oldDebugFunc->getLine(), + oldDebugFunc->getCol(), + oldDebugFunc->getFile(), + funcType); + debugFuncDecor->removeAndDeallocate(); + builder.addDecoration(funcType, kIROp_DebugFuncDecoration, newDebugFunc); + } +} + void fixUpFuncType(IRFunc* func, IRType* resultType) { SLANG_ASSERT(func); -- cgit v1.2.3