summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-12-27 18:47:40 -0500
committerYong He <yonghe@outlook.com>2017-12-27 18:50:32 -0500
commit87cba147d513fcbc4b69a083dc10557a6c1b42ba (patch)
tree1eb707caede6b43ef417b952656cbdf97b9c9001 /tests
parent69242398be1ba76898c0d6541eec3b7ca0ec1ab4 (diff)
Support nested generic types (e.g. L<T<S>>)
fixes #325 This commit includes following changes: 1. Including a default DeclaredSubtypeWitness argument when creating a default GenericSubstitution for a DeclRefType, so that the witness argument can be successfully replaced with an actual witness table after specialization. (check,cpp) 2. Not emitting full mangled name for struct field members. Since the declref of the member access instruction do not include necessary generic substitutions for its parent generic parameters, so the mangled names of the declaration site and use site mismatches. Instead we just emit the original name for struct fields. (emit.cpp) 3. Allow IRWitnessTable to represent a generic witness table for generic structs. Adds necessary fields to IRWitnessTable for generic specialization. For now, the user field of the IRUse is not used and is nullptr. (ir-inst.h) 4. Make IRProxyVal use an IRUse instead of an IRValue*, so that an IRValue referenced by IRProxyVal (as a substitution argument) can be managed by the def-use chain for easy replacement. This is used for specializing witness tables. (ir.cpp, ir.h) 5. Add a `String dumpIRFunc(IRFunc*)` function for debugging. 6. Add name mangling for generic / specialized witness tables (mangle.cpp) 7. improved natvis file for inspecting witness tables. 8. Add specialization of witness tables: 1) `findWitnessTable` will simply return the specialize IRInst for a generic witness table. 2) make `cloneSubstitutionArg` call `cloneValue` to clone the argument instead of calling `context->maybeCloneValue`, so we can make use of the cloned value lookup machanism to directly return the specialized witness table (which is done when we process the `specialize` instruction on the generic witness table before process the decl ref). 3) bug fix: the argument in ir.cpp:3338 should be `newArg` instead of `arg`. 4) add `specializeWitnessTable` function to specailize a generic witness table. It clones the witness table, and recursively calls `getSpecailizedFunc` for the witness table entries. 5) make `specailizeGenerics` function also handle the case when an operand of the `specialize` instruction is a witness table. We will call `specializeWitnessTable` here and replace the `specialize` instruction with the specialized witness table. The replacement mechanism based on IR def-use chain works here because we have already make IRProxyVal a part of the def-use chain. 9. Add two more test cases for nested generics with constraints. (generic-list.slang and generic-struct-with-constraint.slang)
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/generic-list.slang48
-rw-r--r--tests/compute/generic-list.slang.expected.txt4
-rw-r--r--tests/compute/generic-struct-with-constraint.slang44
-rw-r--r--tests/compute/generic-struct-with-constraint.slang.expected.txt4
4 files changed, 100 insertions, 0 deletions
diff --git a/tests/compute/generic-list.slang b/tests/compute/generic-list.slang
new file mode 100644
index 000000000..256e02d33
--- /dev/null
+++ b/tests/compute/generic-list.slang
@@ -0,0 +1,48 @@
+//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+// Confirm that generics syntax can be used in user
+// code and generates valid output.
+
+RWStructuredBuffer<float4> outputBuffer;
+
+interface IElement
+{
+ float4 getValue();
+};
+
+struct SingleElement : IElement
+{
+ float4 value;
+ float4 getValue()
+ {
+ return value;
+ }
+};
+
+struct ListElement<THead : IElement, TTail : IElement> : IElement
+{
+ THead head;
+ TTail tail;
+ float4 getValue()
+ {
+ return head.getValue() + tail.getValue();
+ }
+};
+
+float4 test<T : IElement>(T val)
+{
+ return val.getValue();
+}
+
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ ListElement<SingleElement, ListElement<SingleElement, ListElement<SingleElement, SingleElement> > > list;
+ list.head.value = float4(1.0);
+ list.tail.head.value = float4(2.0);
+ list.tail.tail.head.value = float4(3.0);
+ list.tail.tail.tail.value = float4(4.0);
+ float4 outVal = test(list);
+ outputBuffer[0] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/generic-list.slang.expected.txt b/tests/compute/generic-list.slang.expected.txt
new file mode 100644
index 000000000..7b383b304
--- /dev/null
+++ b/tests/compute/generic-list.slang.expected.txt
@@ -0,0 +1,4 @@
+41200000
+41200000
+41200000
+41200000 \ No newline at end of file
diff --git a/tests/compute/generic-struct-with-constraint.slang b/tests/compute/generic-struct-with-constraint.slang
new file mode 100644
index 000000000..0c81ad176
--- /dev/null
+++ b/tests/compute/generic-struct-with-constraint.slang
@@ -0,0 +1,44 @@
+//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+// Confirm that generics syntax can be used in user
+// code and generates valid output.
+
+RWStructuredBuffer<float4> outputBuffer;
+
+interface IElement
+{
+ float4 getValue();
+};
+
+struct SingleElement : IElement
+{
+ float4 value;
+ float4 getValue()
+ {
+ return value;
+ }
+};
+
+struct ListElement<THead : IElement> : IElement
+{
+ THead head;
+ float4 getValue()
+ {
+ return head.getValue();
+ }
+};
+
+float4 test<T : IElement>(T val)
+{
+ return val.getValue();
+}
+
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ ListElement<SingleElement> list;
+ list.head.value = float4(1.0);
+ float4 outVal = test<ListElement<SingleElement> >(list);
+ outputBuffer[0] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/generic-struct-with-constraint.slang.expected.txt b/tests/compute/generic-struct-with-constraint.slang.expected.txt
new file mode 100644
index 000000000..e143b7f20
--- /dev/null
+++ b/tests/compute/generic-struct-with-constraint.slang.expected.txt
@@ -0,0 +1,4 @@
+3F800000
+3F800000
+3F800000
+3F800000 \ No newline at end of file