summaryrefslogtreecommitdiffstats
path: root/tests/language-feature
diff options
context:
space:
mode:
authorRonan <ro.cailleau@gmail.com>2025-04-03 06:17:15 +0200
committerGitHub <noreply@github.com>2025-04-03 04:17:15 +0000
commit6b44630afe4ff180ba608142e9515abcd369775e (patch)
tree67e895172552fd3c73d6830436e30fa157142742 /tests/language-feature
parentb4a1d618b8d850a579af2840db2df6bee312172c (diff)
Fixed generic interface specialization crashes (#6601): (#6688)
* Fixed generic interface specialization crashes: - Add an export decoration to specialized generic interfaces. * Fixed generic interface specialization crashes: - Add an export decoration to specialized generic interfaces. - Use getTypeNameHint(...) instead of a manual mangler. * In cloneInstDecorationsAndChildren: specialize all linkage decorations, not just the exports. - If a linkage decoration is already present, it is not specialized and replaced by the specialized one. - If a specialization uses the TypeNameHint, sanitize it to be used as an identifier. - Use the identifier name sanitizer from slang-mangle. * Added tests/generics/generic-interface-linkage.slang - See #6601 and #6688
Diffstat (limited to 'tests/language-feature')
-rw-r--r--tests/language-feature/generics/generic-interface-linkage.slang81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/language-feature/generics/generic-interface-linkage.slang b/tests/language-feature/generics/generic-interface-linkage.slang
new file mode 100644
index 000000000..657ac3d48
--- /dev/null
+++ b/tests/language-feature/generics/generic-interface-linkage.slang
@@ -0,0 +1,81 @@
+
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+interface IGetter
+{
+ float get(uint id);
+}
+
+struct GetterImpl : IGetter
+{
+ float[8] data;
+
+ __init(float[8] data)
+ { this.data = data; }
+
+ float get(uint id)
+ {
+ return data[id];
+ }
+}
+interface IFoo<int N>
+{
+ associatedtype Params : IGetter;
+
+ Params bar();
+}
+
+struct FooImpl1: IFoo<8>
+{
+ typealias Params = GetterImpl;
+
+ __init()
+ { }
+
+ Params bar()
+ {
+ float x = outputBuffer[0];
+ return GetterImpl({x, x+1, x+2, x+3, x+4, x+5, x+6, x+7});
+ }
+}
+
+struct FooImpl2: IFoo<8>
+{
+ typealias Params = GetterImpl;
+
+ __init()
+ { }
+
+ Params bar()
+ {
+ float x = 2 * outputBuffer[0];
+ return GetterImpl({x+3, x+5, x+7, x+9, x+11, x+13, x+15, x+17});
+ }
+}
+
+IFoo<8> getFoo(uint id)
+{
+ if (id == 0)
+ return FooImpl1();
+ else
+ return FooImpl2();
+}
+
+float doThing(uint id)
+{
+ IFoo<8> foo = getFoo(id);
+ return foo.bar().get(0);
+}
+
+[shader("compute")]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ // CHECK: 0
+ outputBuffer[0] = doThing(0);
+ // CHECK: 3
+ outputBuffer[1] = doThing(1);
+} \ No newline at end of file