diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-24 13:16:11 -0700 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2020-06-24 18:10:15 -0700 |
| commit | 0ca75fe002f346f6ab9b77f40c0576d2905560f1 (patch) | |
| tree | ed8a3af372900923e59f0d6da629c2d0969ee7fd /tests | |
| parent | 3fe4f5398d524333e955ecb91be5646e86f3b2da (diff) | |
Dynamic dispatch for generic interface requirements.
-Lower interfaces into actual `IRInterfaceType` insts.
-Lower `DeclRef<AssocTypeDecl>` into `IRAssociatedType`
-Generate proper IRType for generic functions.
-Add a test case exercising dynamic dispatching a generic static function through an associated type.
-Bug fixes for the test case.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/dynamic-dispatch-3.slang | 60 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-3.slang.expected.txt | 4 |
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-3.slang b/tests/compute/dynamic-dispatch-3.slang new file mode 100644 index 000000000..7011a2f4e --- /dev/null +++ b/tests/compute/dynamic-dispatch-3.slang @@ -0,0 +1,60 @@ +//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code + +// Test dynamic dispatch code gen for static member functions +// of associated type. +interface IGetter +{ + int getVal(); +}; +interface IAssoc +{ + int get(); + static int getBase<T:IGetter>(T getter); +} +interface IInterface +{ + associatedtype Assoc : IAssoc; + int Compute(int inVal); +}; + +struct GetterImpl : IGetter +{ + int getVal() { return 1; } +}; + +int GenericCompute<T:IInterface>(T obj, int inVal) +{ + GetterImpl getter; + return obj.Compute(inVal) + T.Assoc.getBase(getter); +} + +struct Impl : IInterface +{ + struct Assoc : IAssoc + { + int val; + int get() { return val; } + static int getBase<T:IGetter>(T t) { return t.getVal(); } + }; + int base; + int Compute(int inVal) { return base + inVal * inVal; } +}; + +int test(int inVal) +{ + Impl obj; + obj.base = 1; + return GenericCompute<Impl>(obj, inVal); +} + +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer : register(u0); + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = outputBuffer[tid]; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +} diff --git a/tests/compute/dynamic-dispatch-3.slang.expected.txt b/tests/compute/dynamic-dispatch-3.slang.expected.txt new file mode 100644 index 000000000..a6bafb7ca --- /dev/null +++ b/tests/compute/dynamic-dispatch-3.slang.expected.txt @@ -0,0 +1,4 @@ +2 +3 +6 +B |
