From 59691aeeb013c5bb7cdaa31a6fc572eebd8be610 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 16 Jan 2018 10:52:10 -0800 Subject: Allow extension on interface (#369) This completes item 5 in issue #361. The interesting change is that when checking for interface conformance, we include the requirements (include transitive interfaces) defined in extensions as well. (check.cpp line 1946) All the other changes are for one thing: reoder the semantic checkings to two explicit stages: check header and check body. In check header phase, we check everything except function bodies, register all extensions with their target decls, then check interface conformances for all concrete types. In body checking phase, we look inside the function bodies and check concrete statements/expressions. This change ensures that we take extension into consideration in all places where it should be. --- tests/compute/extension-on-interface.slang | 49 ++++++++++++++++++++++ .../extension-on-interface.slang.expected.txt | 4 ++ 2 files changed, 53 insertions(+) create mode 100644 tests/compute/extension-on-interface.slang create mode 100644 tests/compute/extension-on-interface.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/extension-on-interface.slang b/tests/compute/extension-on-interface.slang new file mode 100644 index 000000000..1d3fb5e30 --- /dev/null +++ b/tests/compute/extension-on-interface.slang @@ -0,0 +1,49 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer outputBuffer; + +interface IOp +{ + float addf(float u, float v); +} + +interface ISub +{ + float subf(float u, float v); +} + +extension IOp : ISub +{ +} + +struct Simple : IOp +{ + float base; + float addf(float u, float v) + { + return u+v; + } +}; + +__extension Simple : ISub +{ + float subf(float u, float v) + { + return base+u-v; + } +}; + +float testAddSub(T t) +{ + return t.subf(t.addf(1.0, 1.0), 1.0); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + Simple s; + s.base = 0.0; + float outVal = testAddSub(s); + outputBuffer[dispatchThreadID.x] = outVal; +} \ No newline at end of file diff --git a/tests/compute/extension-on-interface.slang.expected.txt b/tests/compute/extension-on-interface.slang.expected.txt new file mode 100644 index 000000000..cc5e55ab6 --- /dev/null +++ b/tests/compute/extension-on-interface.slang.expected.txt @@ -0,0 +1,4 @@ +3F800000 +3F800000 +3F800000 +3F800000 -- cgit v1.2.3