diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2024-04-27 02:27:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-26 23:27:28 -0700 |
| commit | 2b87c00c671b156b8e5926f8967003bf12c65aa7 (patch) | |
| tree | c993872a1b9a568ea4c963b2c710c12f496cc559 | |
| parent | e91bd3b0bdc50f66bfd302ff079c65fba5126474 (diff) | |
Fix invoke resolution when dealing with overloded type expressions (#4043)
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 16 | ||||
| -rw-r--r-- | tests/autodiff/differential-type-constructor.slang | 25 | ||||
| -rw-r--r-- | tests/autodiff/differential-type-constructor.slang.expected.txt | 6 |
3 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 6180ccda8..703771e6e 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -2093,7 +2093,21 @@ namespace Slang typeCheckingCache->resolvedOperatorOverloadCache[key] = *context.bestCandidate; return CompleteOverloadCandidate(context, *context.bestCandidate); } - else if (auto typetype = as<TypeType>(funcExprType)) + + // If absolutely no viable candidates were extracted from the overloaded expression, + // we may be dealing with a composite type or an overloaded expression with composite types. + // + + auto typeExpr = funcExpr; + if (auto overloadedExpr = as<OverloadedExpr>(funcExpr)) + { + if (overloadedExpr->lookupResult2.isValid() && overloadedExpr->lookupResult2.isOverloaded()) + { + typeExpr = maybeResolveOverloadedExpr(overloadedExpr, LookupMask::type, nullptr); + } + } + + if (auto typetype = as<TypeType>(typeExpr->type)) { // We allow a special case when `funcExpr` represents a composite type, // in which case we will try to construct the type via memberwise assignment from the arguments. diff --git a/tests/autodiff/differential-type-constructor.slang b/tests/autodiff/differential-type-constructor.slang new file mode 100644 index 000000000..9afff878d --- /dev/null +++ b/tests/autodiff/differential-type-constructor.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type + +struct MyStruct: IDifferentiable +{ + float a; + int b; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + var dp = diffPair(MyStruct(), MyStruct.Differential()); + + outputBuffer[0] = dp.d.a; + + var dp2 = diffPair<MyStruct>(MyStruct(), MyStruct.Differential(1.f)); + + outputBuffer[1] = dp2.d.a; + } +}
\ No newline at end of file diff --git a/tests/autodiff/differential-type-constructor.slang.expected.txt b/tests/autodiff/differential-type-constructor.slang.expected.txt new file mode 100644 index 000000000..d9eca87b2 --- /dev/null +++ b/tests/autodiff/differential-type-constructor.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +0.000000 +1.000000 +0.000000 +0.000000 +0.000000 |
