diff options
Diffstat (limited to 'tests')
3 files changed, 86 insertions, 0 deletions
diff --git a/tests/language-feature/generics/struct-generic-value-param-import.slang b/tests/language-feature/generics/struct-generic-value-param-import.slang new file mode 100644 index 000000000..edc1b0c39 --- /dev/null +++ b/tests/language-feature/generics/struct-generic-value-param-import.slang @@ -0,0 +1,19 @@ +// struct-generic-value-param-import.slang +//TEST_IGNORE_FILE: + +// This file is used by `struct-generic-value-param.slang`, +// and also incidentally tests that a trailing `;` is optional +// for `struct` decalrations in Slang files, including +// any `import`ed code. + +interface IData {} + +struct Data<let kCount : int> : IData +{ + int state; + + [mutating] void doStuff() + { + state++; + } +} diff --git a/tests/language-feature/generics/struct-generic-value-param.slang b/tests/language-feature/generics/struct-generic-value-param.slang new file mode 100644 index 000000000..857468165 --- /dev/null +++ b/tests/language-feature/generics/struct-generic-value-param.slang @@ -0,0 +1,63 @@ +// struct-generic-value-param.slang + +// This test reproduces a few bugs related to declarations +// not being emitted IR and specialized correctly. +// +// First, it tests that a method in a generic `struct` +// gets properly emitted to the IR of its own module. +// +// Second, it tests that witness tables for an empty +// `interface` can be emitted and used to specialize +// code with generic type parameters constrained to +// those interfaces. + +// This file is attempting to stress-test use of a `struct` +// type with a generic value parameter. In particular, it +// it can reproduce a bug that was encountered by a user +// when trying out the feature. + +//TEST(compute):COMPARE_COMPUTE: + +import struct_generic_value_param_import; + +Data<N> makeData<let N : int>( int val ) +{ + Data<N> result = { val }; + return result; +} + +void doThings<D : IData>(D data, inout int v) +{ + v++; +} + +int test(int val) +{ + var data = makeData<4>(val); + + // Note: with the original bug, this call emitted + // as `/* unhandled */(data)` which meant the call + // acted as a no-op. + // + data.doStuff(); + + // Note: with the original bug, this call emitted + // as `/* uhandled */(data, val)` which is also + // a no-op (that happens to use `operator,`). + // + doThings(data, val); + + return data.state + val*16; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/generics/struct-generic-value-param.slang.expected.txt b/tests/language-feature/generics/struct-generic-value-param.slang.expected.txt new file mode 100644 index 000000000..e4511c4c7 --- /dev/null +++ b/tests/language-feature/generics/struct-generic-value-param.slang.expected.txt @@ -0,0 +1,4 @@ +11 +22 +33 +44 |
