summaryrefslogtreecommitdiff
path: root/tests/language-feature/generics
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-09-10 08:13:21 -0700
committerGitHub <noreply@github.com>2024-09-10 08:13:21 -0700
commit936c22a9a938744eb43c310dd82c9c6944f79e87 (patch)
treeece9880056c94415379cd89303a4542894fb7f32 /tests/language-feature/generics
parentf51b74ddee7ec7104d021006575c601245814bb1 (diff)
Specialize existential return types when possible. (#5044)
* Fix inccorect dropping of declref during Unification of DeclaredSubtypeWitness. * Add extension test. * Specialize existential return types when possible. * Fix. * Fix. * Fix falcor issue.
Diffstat (limited to 'tests/language-feature/generics')
-rw-r--r--tests/language-feature/generics/generic-return-type-requirement.slang39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/language-feature/generics/generic-return-type-requirement.slang b/tests/language-feature/generics/generic-return-type-requirement.slang
new file mode 100644
index 000000000..945afd808
--- /dev/null
+++ b/tests/language-feature/generics/generic-return-type-requirement.slang
@@ -0,0 +1,39 @@
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
+//TEST:SIMPLE(filecheck=HLSL): -target hlsl -profile cs_6_0 -entry computeMain
+
+// HLSL-NOT: AnyValue
+
+interface IStack<let D : int>
+{
+ __generic<let N : int>
+ IStack<D - N> popN();
+
+ int get();
+}
+struct StackImpl<let D : int> : IStack<D>
+{
+ // We should be able to specialize the callsites of this function to use
+ // the concrete type instead of resorting to dynamic dispatch.
+ __generic<let N : int>
+ IStack<D - N> popN() { return StackImpl<D-N>(); }
+
+ int get() { return D; }
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+int test<int D, S : IStack<D>>(S stack)
+{
+ return stack.popN<2>().get();
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ StackImpl<5> stack;
+
+ // CHECK: 2
+ outputBuffer[0] = test(stack);
+}