summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-09-18 16:49:00 -0500
committerGitHub <noreply@github.com>2024-09-18 14:49:00 -0700
commit3240799c00488858afc7eeac9d1dc479609a1040 (patch)
treefb9b390a45eec1d27a717d0f1735dbff4059ac9b /tests/bugs
parent2d83875f4b376f047c4541a6f6c13d36e5aa228b (diff)
Lower the priority of looking up the rank of scope (#5065)
* Lower the priority of looking up the rank of scope In the previous change of #5060, we propose a way to resolve the ambiguous call when considering the scope of a function. But this rule should be considered as a low priority than "specialized candidate", aka. we should consider more "specialized candiate" first. * Count distance between reference site to declaration site Compare the candidate by calculating distance from reference site to declaration site via nearest common prefix in the scope tree. This will involve finding the common parent node of two child nodes and how sum the distance from the common parent to the two child nodes. * Change the priority higher than 'getOverloadRank' * Don't evaluate the scope rank algorithm on generic If the candidate is generic function, the function parameters won't be checked before 'CompareOverloadCandidates', so it will results in that the candidates this function could be invalid. We should not evaluate the distance algorithm in this case, instead we will evaluate later when the candidate is in flavor of Func or Expr since then all the type checks for the function will be done.
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/overload-ambiguous-1.slang65
-rw-r--r--tests/bugs/overload-ambiguous-2.slang67
-rw-r--r--tests/bugs/overload-ambiguous.slang19
3 files changed, 149 insertions, 2 deletions
diff --git a/tests/bugs/overload-ambiguous-1.slang b/tests/bugs/overload-ambiguous-1.slang
new file mode 100644
index 000000000..9f9c6e5bc
--- /dev/null
+++ b/tests/bugs/overload-ambiguous-1.slang
@@ -0,0 +1,65 @@
+// https://github.com/shader-slang/slang/issues/4476
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+namespace A1
+{
+ uint func()
+ {
+ return 1u;
+ }
+
+ namespace A2
+ {
+ uint func()
+ {
+ return 2u;
+ }
+
+ namespace A3
+ {
+ uint func()
+ {
+ return 3u;
+ }
+
+ uint test2()
+ {
+ return func(); // choose A3::func()
+ }
+ }
+
+ namespace A4
+ {
+ uint test()
+ {
+ return func(); // choose A2::func()
+ }
+ }
+ }
+}
+
+[numthreads(1, 1, 1)]
+[shader("compute")]
+void computeMain(uint3 threadID: SV_DispatchThreadID)
+{
+ using namespace A1;
+ using namespace A1::A2;
+ using namespace A1::A2::A3;
+ using namespace A1::A2::A4;
+ outputBuffer[0] = test();
+ // BUF: 2
+
+ outputBuffer[1] = func(); // choose the A1::func()
+ // BUF-NEXT: 1
+
+ outputBuffer[2] = test2();
+ // BUF-NEXT: 3
+}
diff --git a/tests/bugs/overload-ambiguous-2.slang b/tests/bugs/overload-ambiguous-2.slang
new file mode 100644
index 000000000..46af9f091
--- /dev/null
+++ b/tests/bugs/overload-ambiguous-2.slang
@@ -0,0 +1,67 @@
+// https://github.com/shader-slang/slang/issues/4476
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+namespace A
+{
+ struct Struct1<let SIZE : uint>
+ {
+ uint data;
+ };
+
+ Struct1<Z1> myFunc<let Z0 : uint, let Z1 : uint>(Struct1<Z0> inputS1)
+ {
+ Struct1<Z1> s1;
+ s1.data = inputS1.data + 2U;
+ return s1;
+ }
+};
+
+
+A::Struct1<Z1> myFunc<let Z0 : uint, let Z1 : uint>(A::Struct1<Z0> inputS1)
+{
+ A::Struct1<Z1> s1;
+ s1.data = inputS1.data + 5U;
+ return s1;
+}
+
+namespace A
+{
+ struct Struct2<let SIZE : uint>
+ {
+ Struct1<SIZE> s1;
+ }
+
+ Struct2<Z1> myFunc<let Z0 : uint, let Z1 : uint>(Struct2<Z0> inputS2)
+ {
+ Struct2<Z1> s2;
+ // We want to cover a corner case in our compiler where:
+ // when looking up "myFunc", the compiler should find
+ // Struct1<Z1> A::myFunc<let Z0 : uint, let Z1 : uint>(Struct1<Z0> inputS1)
+ // and it won't be ambiguous with the global "myFunc".
+ s2.s1 = myFunc<Z0, Z1>(inputS2.s1);
+ return s2;
+ }
+};
+
+[numthreads(1, 1, 1)]
+[shader("compute")]
+void computeMain(uint3 threadID: SV_DispatchThreadID)
+{
+ using namespace A;
+
+ Struct2<10> input = {threadID.x};
+
+ Struct2<20> output;
+ output = myFunc<10, 20>(input);
+ outputBuffer[0] = output.s1.data;
+
+ // BUF: 2
+}
diff --git a/tests/bugs/overload-ambiguous.slang b/tests/bugs/overload-ambiguous.slang
index 1b74cb68c..d764f72e4 100644
--- a/tests/bugs/overload-ambiguous.slang
+++ b/tests/bugs/overload-ambiguous.slang
@@ -6,7 +6,7 @@
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj
-//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
+//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;
@@ -34,7 +34,18 @@ struct DataObtainer
}
}
-RWStructuredBuffer<uint> output;
+uint myFunc(uint a)
+{
+ return a + 1u;
+}
+
+__generic<T: __BuiltinIntegerType>
+uint myFunc(T a)
+{
+ uint b = __intCast<uint, T>(a);
+ return b + 2u;
+}
+
[numthreads(1, 1, 1)]
[shader("compute")]
@@ -43,6 +54,10 @@ void computeMain(uint3 threadID: SV_DispatchThreadID)
DataObtainer obtainer = {2u};
outputBuffer[0] = obtainer.getValue();
outputBuffer[1] = obtainer.getValue2();
+
+ uint a = 1u;
+ outputBuffer[2] = myFunc(a); // will call myFunc(uint) which more specialized
// BUF: 2
// BUF-NEXT: 1
+ // BUF-NEXT: 2
}