-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
2d83875
commit 3240799
Showing
5 changed files
with
294 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// https://github.com/shader-slang/slang/issues/4476 | ||
|
||
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): | ||
RWStructuredBuffer<uint> outputBuffer; | ||
|
||
namespace A1 | ||
{ | ||
uint func() | ||
{ | ||
return 1u; | ||
} | ||
|
||
namespace A2 | ||
{ | ||
uint func() | ||
{ | ||
return 2u; | ||
} | ||
} | ||
} | ||
namespace B1 | ||
{ | ||
uint func() | ||
{ | ||
return 4u; | ||
} | ||
} | ||
|
||
[numthreads(1, 1, 1)] | ||
[shader("compute")] | ||
void computeMain(uint3 threadID: SV_DispatchThreadID) | ||
{ | ||
using namespace A1; | ||
using namespace A1::A2; | ||
using namespace B1; | ||
using namespace C1; | ||
|
||
// Only A1::func() and B1::func() will cause ambiguity because the distance from | ||
// the reference site to those two functions declaration are the same. | ||
outputBuffer[0] = func(); | ||
// CHECK-NOT: {{.*}}A2::func() -> uint | ||
// CHECK: ambiguous call to 'func' with arguments of type () | ||
// CHECK: candidate: func B1::func() -> uint | ||
// CHECK: candidate: func A1::func() -> uint | ||
} |