diff options
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 10 | ||||
| -rw-r--r-- | tests/autodiff/avoid-double-lowering.slang | 26 |
2 files changed, 31 insertions, 5 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 52d24ff7d..8e1f85f8e 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -10756,6 +10756,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> }); } + // Register the value now, to avoid any possible infinite recursion when lowering the body + // or attributes. + IRFunc* irFunc = subBuilder->createFunc(); + context->setGlobalValue(decl, LoweredValInfo::simple(findOuterMostGeneric(irFunc))); + FuncDeclBaseTypeInfo info; _lowerFuncDeclBaseTypeInfo( subContext, @@ -10763,15 +10768,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> info); // need to create an IR function here - - IRFunc* irFunc = subBuilder->createFunc(); addNameHint(subContext, irFunc, decl); addLinkageDecoration(subContext, irFunc, decl); maybeAddDebugLocationDecoration(subContext, irFunc); - // Register the value now, to avoid any possible infinite recursion when lowering the body - // or attributes. - context->setGlobalValue(decl, LoweredValInfo::simple(findOuterMostGeneric(irFunc))); // Always force inline diff setter accessor to prevent downstream compiler from complaining // fields are not fully initialized for the first `inout` parameter. diff --git a/tests/autodiff/avoid-double-lowering.slang b/tests/autodiff/avoid-double-lowering.slang new file mode 100644 index 000000000..354d1d27b --- /dev/null +++ b/tests/autodiff/avoid-double-lowering.slang @@ -0,0 +1,26 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): +// CHECK-NOT: an internal error threw +// CHECK-NOT: error: + +interface IFoo<T, int N>: IDifferentiable + where T : __BuiltinFloatingPointType +{ + This myFunc(This other); +} + +struct Foo<T, int N> + where T : __BuiltinFloatingPointType +{ + [BackwardDifferentiable] + This myFunc(This other) + { + [MaxIters(N)] + for (int i = 0; i < N; i++) {} + + return this; + } +} + +extension <T, int N> Foo<T, N> : IFoo<T, N> + where T : __BuiltinFloatingPointType {} + |
