From 7740f7905fdebebdbe22011787d432b385f4cd9d Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Tue, 23 Sep 2025 10:12:09 -0500 Subject: fix a crash when using type equality constaint (#8515) Close #8193. When constructing `TransitiveTypeWitness` node, we should check if there is operand that represents two equal times. Currently, we only check whether the operand is `TypeEqualityWitness`, which is not good enough, because a `DeclaredSubtypeWitness` could also be representing two same types, in that case, we should also const fold this kind of witness. Fails to do so, we could finally ends up with a generating a lookup witness IR on a generic parameter that is not supposed to be looked up. --- ...elf-differential-type-equality-constraint.slang | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/autodiff/self-differential-type-equality-constraint.slang (limited to 'tests') diff --git a/tests/autodiff/self-differential-type-equality-constraint.slang b/tests/autodiff/self-differential-type-equality-constraint.slang new file mode 100644 index 000000000..0baaa07d6 --- /dev/null +++ b/tests/autodiff/self-differential-type-equality-constraint.slang @@ -0,0 +1,35 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-cuda -compute -shaderobj -output-using-type + +interface IV : IDifferentiablePtrType{ + int get(); +} + +struct V : IV +{ + typealias Differential = This; + + int get() + { + return 12; + } +} + +int g(DifferentialPtrPair obj) + where T.Differential == T +{ + return obj.d.get(); +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; +[shader("compute")] +void computeMain() +{ + V v = {}; + DifferentialPtrPair p = {v, v}; + + // BUFFER: 12 + outputBuffer[0] = g(p); +} -- cgit v1.2.3