summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-12 22:58:22 -0700
committerGitHub <noreply@github.com>2023-04-12 22:58:22 -0700
commitca7bf79df3a3f5f4494912cb0572c36662755b9d (patch)
tree64b14034326be8285c0265e74ad3ed11e29ff062 /tests
parent12ec9b832fc74faba7162e54e04f7f48878ea88e (diff)
Combine lookupWitness lowering with specialization. (#2794)
Diffstat (limited to 'tests')
-rw-r--r--tests/diagnostics/no-type-conformance.slang.expected6
-rw-r--r--tests/ir/dynamic-generic-method-specialize.slang65
-rw-r--r--tests/ir/dynamic-generic-method-specialize.slang.expected.txt2
-rw-r--r--tests/language-server/robustness-7.slang63
-rw-r--r--tests/language-server/robustness-7.slang.expected.txt12
5 files changed, 145 insertions, 3 deletions
diff --git a/tests/diagnostics/no-type-conformance.slang.expected b/tests/diagnostics/no-type-conformance.slang.expected
index bc38fa7f1..5f5eda6af 100644
--- a/tests/diagnostics/no-type-conformance.slang.expected
+++ b/tests/diagnostics/no-type-conformance.slang.expected
@@ -1,8 +1,8 @@
result code = -1
standard error = {
-tests/diagnostics/no-type-conformance.slang(4): error 50100: No type conformances are found for interface 'IFoo'. Code generation for current target requires at least one implementation type present in the linkage.
-interface IFoo
- ^~~~
+tests/diagnostics/no-type-conformance.slang(12): error 50100: No type conformances are found for interface 'IFoo'. Code generation for current target requires at least one implementation type present in the linkage.
+ obj.get();
+ ^
}
standard output = {
}
diff --git a/tests/ir/dynamic-generic-method-specialize.slang b/tests/ir/dynamic-generic-method-specialize.slang
new file mode 100644
index 000000000..92ce8158e
--- /dev/null
+++ b/tests/ir/dynamic-generic-method-specialize.slang
@@ -0,0 +1,65 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile sm_5_0 -output-using-type
+
+// Test that we can specialize a generic method called through a dynamic interface.
+
+interface IValue
+{
+ float getVal();
+}
+
+struct SimpleVal : IValue
+{
+ float val;
+ float getVal() { return val; }
+}
+
+[anyValueSize(16)]
+interface IInterface
+{
+ associatedtype V : IValue;
+ V run<let N : int>(float arr[N]);
+}
+
+struct Add : IInterface
+{
+ float base;
+ typealias V = SimpleVal;
+ V run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum += arr[i];
+ V rs;
+ rs.val = sum;
+ return rs;
+ }
+}
+
+struct Mul : IInterface
+{
+ float base;
+ typealias V = SimpleVal;
+ V run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum *= arr[i];
+ V rs;
+ rs.val = sum;
+ return rs;
+ }
+}
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
+RWStructuredBuffer<float> gOutputBuffer;
+
+//TEST_INPUT:type_conformance Add:IInterface=1
+//TEST_INPUT:type_conformance Mul:IInterface=2
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ var obj = createDynamicObject<IInterface>(1, 1.0); // Add.
+ float arr[3] = { 2, 3, 4 };
+ gOutputBuffer[0] = obj.run(arr).getVal();
+} \ No newline at end of file
diff --git a/tests/ir/dynamic-generic-method-specialize.slang.expected.txt b/tests/ir/dynamic-generic-method-specialize.slang.expected.txt
new file mode 100644
index 000000000..0bc25648a
--- /dev/null
+++ b/tests/ir/dynamic-generic-method-specialize.slang.expected.txt
@@ -0,0 +1,2 @@
+type: float
+10.0 \ No newline at end of file
diff --git a/tests/language-server/robustness-7.slang b/tests/language-server/robustness-7.slang
new file mode 100644
index 000000000..ebc34e078
--- /dev/null
+++ b/tests/language-server/robustness-7.slang
@@ -0,0 +1,63 @@
+//TEST:LANG_SERVER:
+//HOVER:6,15
+
+// Test that we can specialize a generic method called through a dynamic interface.
+
+interface IValue
+{
+ float getVal();
+}
+
+struct SimpleVal : IValue
+{
+ float val;
+ float getVal() { return val; }
+}
+
+[anyValueSize(16)]
+interface IInterface
+{
+ associatedtype V : IValue;
+ V run<let N : int>(float arr[N]);
+}
+
+struct Add : IInterface
+{
+ float base;
+ typealias V
+ float run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum += arr[i];
+ return sum;
+ }
+}
+
+struct Mul : IInterface
+{
+ float base;
+
+ float run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum *= arr[i];
+ return sum;
+ }
+}
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
+RWStructuredBuffer<float> gOutputBuffer;
+
+//TEST_INPUT:type_conformance Add:IInterface=1
+//TEST_INPUT:type_conformance Mul:IInterface=2
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ var obj = createDynamicObject<IInterface>(1, 1.0); // Add.
+ float arr[3] = { 2, 3, 4 };
+ gOutputBuffer[0] = obj.run(arr);
+
+} \ No newline at end of file
diff --git a/tests/language-server/robustness-7.slang.expected.txt b/tests/language-server/robustness-7.slang.expected.txt
new file mode 100644
index 000000000..d5f8ed9f8
--- /dev/null
+++ b/tests/language-server/robustness-7.slang.expected.txt
@@ -0,0 +1,12 @@
+--------
+range: 5,10 - 5,16
+content:
+```
+interface IValue
+```
+
+Test that we can specialize a generic method called through a dynamic interface.
+
+{REDACTED}.slang(6)
+
+