From a670bafc121c20168624f70a388dbe8556402c7f Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 9 Jul 2025 11:25:29 -0500 Subject: no_diff diagnostics improvement (#7655) close #6286. This PR is to improve the diagnostics for no_diff usage. In a differentiable function, any calls to a non-diff function with constant arguments should not require no_diff attribute. This PR adds this extra check at `checkAutoDiffUsages` where it checks the differentiability on IR. In a differentiable method, we will force to use `[NoDiffThis]` attribute if there is access to non-differentiable `This` type. Once this access is detected we will report a warning to bring users attention that this access won't generate any derivative, they have to use `[NoDiffThis]` to suppress that warning. This PR adds this check at type checking stage, because it's the easiest way to find out all the `This` accesses. --- tests/autodiff/dynamic-object-bwd-diff.slang | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/autodiff/dynamic-object-bwd-diff.slang') diff --git a/tests/autodiff/dynamic-object-bwd-diff.slang b/tests/autodiff/dynamic-object-bwd-diff.slang index a10c48f9b..a80025d52 100644 --- a/tests/autodiff/dynamic-object-bwd-diff.slang +++ b/tests/autodiff/dynamic-object-bwd-diff.slang @@ -26,7 +26,9 @@ struct C : IInterface2 struct A : IInterface { float a; + [BackwardDifferentiable] + [NoDiffThis] float calc(IInterface2 i2, float x) { float b = no_diff(i2.innerCalc(x)); @@ -37,7 +39,9 @@ struct A : IInterface struct B : IInterface { float a; + [BackwardDifferentiable] + [NoDiffThis] float calc(IInterface2 i2, float x) { float b = no_diff(i2.innerCalc(x)); -- cgit v1.2.3