summaryrefslogtreecommitdiffstats
path: root/tests/compute/interface-static-method.slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-10-18 09:30:38 -0700
committerGitHub <noreply@github.com>2018-10-18 09:30:38 -0700
commit3a5214b65b2a5efdbcf9bf6fb4d7603e9ee63234 (patch)
treeaa77f0e7b5ca7e6327c252a8acff50ccb08a7794 /tests/compute/interface-static-method.slang
parentf9710d50bc675ddba51cc6d94b125ba1549708a8 (diff)
Add support for static methods in interfaces (#680)
This change allows an interface to include `static` methods as requirements, so that types that conform to the interface will need to satisfy the requirement with a `static` method. The essence of the check is simple: when checking that a method satisfies a requirement, we enforce that both are `static` or both are non-`static`. Making that simple change and adding a test change broke a few other places in the compiler that this change tries to fix. The main fix is to handle cases where we might look up an "effectively static" member of a type through an instance, and to make sure that we replace the instance-based lookup with type-based lookup. There was already logic along these lines in `lower-to-ir.cpp`, so this change centralizes it in `check.cpp` where it seems to logically belong.
Diffstat (limited to 'tests/compute/interface-static-method.slang')
-rw-r--r--tests/compute/interface-static-method.slang56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/compute/interface-static-method.slang b/tests/compute/interface-static-method.slang
new file mode 100644
index 000000000..4747c8a8a
--- /dev/null
+++ b/tests/compute/interface-static-method.slang
@@ -0,0 +1,56 @@
+// interface-static-method.slang
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+interface IHideout
+{
+ int getAnimalCount();
+}
+
+interface ISuperhero
+{
+ associatedtype Hideout : IHideout;
+
+ static Hideout getHideout();
+}
+
+struct Batcave : IHideout
+{
+ int batCount;
+
+ int getAnimalCount() { return batCount; }
+}
+
+struct Batman : ISuperhero
+{
+ typedef Batcave Hideout;
+
+ static Batcave getHideout()
+ {
+ Batcave batcave = { 100 };
+ return batcave;
+ }
+}
+
+int doIt<T:ISuperhero>()
+{
+ return T.getHideout().getAnimalCount();
+}
+
+int test(int val)
+{
+ return doIt<Batman>();
+}
+
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int tid = dispatchThreadID.x;
+ outputBuffer[tid] = test(tid);
+} \ No newline at end of file