From 812e478989e27983b8dea7ab11964de751654ba2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 4 Jun 2025 13:05:58 -0700 Subject: Make interface types non c-style in Slang2026. (#7260) * Make interface types non c-style. * Make Optional work with autodiff and existential types. * Fix. * patch behind slang 2026. * Fix warnings. * cleanup. * Fix tests. * Fix. * Fix com interface lowering. * Add comment to test. * regenerate command line reference * Add test for passing `none` to autodiff function. * Fix recording of `getDynamicObjectRTTIBytes`. * Fix nested Optional types. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .../interfaces/optional-none.slang | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/language-feature/interfaces/optional-none.slang (limited to 'tests/language-feature/interfaces/optional-none.slang') diff --git a/tests/language-feature/interfaces/optional-none.slang b/tests/language-feature/interfaces/optional-none.slang new file mode 100644 index 000000000..04bb8f83e --- /dev/null +++ b/tests/language-feature/interfaces/optional-none.slang @@ -0,0 +1,47 @@ +// Test that the size of an optional interface type is the same as the existential box. + +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -conformance "Impl1:IFoo=1" -entry computeMain -profile cs_6_0 +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -vk -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +interface IFoo +{ + int method(); +} + +//TEST_INPUT: type_conformance Impl1:IFoo = 0 +struct Impl1 : IFoo +{ + int data; + int method() { return data + 1; } +} + +struct MyType +{ + Optional foo; +} + +Optional process(Optional opt) +{ + return opt; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyType t = {}; + t.foo = process(t.foo); + + // BUFFER: 100 + if (let f = t.foo) + outputBuffer[0] = f.method(); + else + outputBuffer[0] = 100; +} + +// CHECK: struct MyType +// CHECK-NEXT: { +// CHECK-NEXT: Tuple{{.*}} foo{{.*}}; \ No newline at end of file -- cgit v1.2.3