summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-09-30 20:54:24 -0400
committerGitHub <noreply@github.com>2024-09-30 20:54:24 -0400
commit81c015e027aa34f2c43394e21f9c1e2c3f7ff1d1 (patch)
tree182e3e07fe3940c002eca87a60381436b863d1fb /source
parenta5d67ad992823ee0323efef07e97ad11814f2eec (diff)
Fix diagnostics for [PreferRecompute] (#5159)
* Fix diagnostics for [PreferRecompute] * Update dont-warn-on-simple-prefer-recompute.slang * Update slang-ir-autodiff.cpp * Update dont-warn-on-simple-prefer-recompute.slang * Update warn-on-prefer-recompute-side-effects.slang
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-diagnostic-defs.h2
-rw-r--r--source/slang/slang-ir-autodiff.cpp10
2 files changed, 9 insertions, 3 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 3a1444117..9a14b71e4 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -790,7 +790,7 @@ DIAGNOSTIC(41904, Error, unableToAlignOf, "alignof could not be performed for ty
DIAGNOSTIC(42001, Error, invalidUseOfTorchTensorTypeInDeviceFunc, "invalid use of TorchTensor type in device/kernel functions. use `TensorView` instead.")
-DIAGNOSTIC(42050, Warning, potentialIssuesWithPreferRecomputeOnSideEffectMethod, "$0 has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [NoSideEffect]")
+DIAGNOSTIC(42050, Warning, potentialIssuesWithPreferRecomputeOnSideEffectMethod, "$0 has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [__NoSideEffect]")
DIAGNOSTIC(45001, Error, unresolvedSymbol, "unresolved external symbol '$0'.")
diff --git a/source/slang/slang-ir-autodiff.cpp b/source/slang/slang-ir-autodiff.cpp
index 6c729ea63..bed6a68e4 100644
--- a/source/slang/slang-ir-autodiff.cpp
+++ b/source/slang/slang-ir-autodiff.cpp
@@ -2416,9 +2416,15 @@ void checkAutodiffPatterns(
if (auto func = as<IRFunc>(inst))
{
if (func->sourceLoc.isValid() && // Don't diagnose for synthesized functions
- func->findDecoration<IRPreferRecomputeDecoration>() &&
- !func->findDecoration<IRNoSideEffectDecoration>())
+ func->findDecoration<IRPreferRecomputeDecoration>())
{
+ // If we don't have any side-effect behavior, we should warn (note: read-none is a stronger
+ // guarantee than no-side-effect)
+ //
+ if (func->findDecoration<IRNoSideEffectDecoration>() ||
+ func->findDecoration<IRReadNoneDecoration>())
+ continue;
+
auto preferRecomputeDecor = func->findDecoration<IRPreferRecomputeDecoration>();
auto sideEffectBehavior = as<IRIntLit>(preferRecomputeDecor->getOperand(0))->getValue();