diff options
| author | Yong He <yonghe@outlook.com> | 2018-01-15 18:15:49 -0500 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2018-01-15 18:18:25 -0500 |
| commit | 3d4eaf3c9b13e32c4e4d7737f17805503cddcb0b (patch) | |
| tree | 7269cd553cf90a7c578afd20b56bf079fcef9656 /tests | |
| parent | 8abae0515d734c51e7d55c44ccfdadefea8c6802 (diff) | |
Support transitive interfaces
This commit is a bunch of quick hacks to get transitive interfaces to work. The idea is for each concrete type we create one giant witness table that contains entries for all the transitively reachable interface requirements, and then create one copy of that witness table for each interface it implements.
`DoLocalLookupImpl` now also looks up in inherited interface decles when looking up for a symbol in an interface decl.
When visiting `InheritanceDecl` in `lower-to-ir`, create copies of the giant witness table for each transitively inherited interface, so that these witness tables can be found later when the IR is specialized.
Re-enable the `copy all witness tables` hack in `specializeIRForEntryPoint` to ensure those transitive witness tables are copied over.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/transitive-interface.slang | 66 | ||||
| -rw-r--r-- | tests/compute/transitive-interface.slang.expected.txt | 4 |
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/compute/transitive-interface.slang b/tests/compute/transitive-interface.slang new file mode 100644 index 000000000..04ececf93 --- /dev/null +++ b/tests/compute/transitive-interface.slang @@ -0,0 +1,66 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer<float> outputBuffer; + +interface IAdd +{ + float addf(float u, float v); +} + +interface ISub +{ + float subf(float u, float v); +} + +interface IAddAndSub : IAdd, ISub +{ +} + +struct Simple : IAddAndSub +{ + float addf(float u, float v) + { + return u+v; + } + float subf(float u, float v) + { + return u-v; + } +}; + +float testAdd<T:IAdd>(T t) +{ + return t.addf(1.0, 1.0); +} + +interface IAssoc +{ + associatedtype AT : IAdd; +} + +struct AssocImpl : IAssoc +{ + typedef Simple AT; +}; + +float testAdd2<T:IAssoc>(T assoc) +{ + T.AT obj; + return obj.addf(1.0, 1.0); +} + +float testSub<T:ISub>(T t, float base) +{ + return t.subf(base, 1.0); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + AssocImpl s; + float outVal = testAdd2(s); + Simple s1; + outVal += testSub(s1, outVal); + outputBuffer[dispatchThreadID.x] = outVal; +}
\ No newline at end of file diff --git a/tests/compute/transitive-interface.slang.expected.txt b/tests/compute/transitive-interface.slang.expected.txt new file mode 100644 index 000000000..e143b7f20 --- /dev/null +++ b/tests/compute/transitive-interface.slang.expected.txt @@ -0,0 +1,4 @@ +3F800000 +3F800000 +3F800000 +3F800000
\ No newline at end of file |
