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> --- source/slang/diff.meta.slang | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source/slang/diff.meta.slang') diff --git a/source/slang/diff.meta.slang b/source/slang/diff.meta.slang index c24a8b11a..13c5d2d47 100644 --- a/source/slang/diff.meta.slang +++ b/source/slang/diff.meta.slang @@ -1396,6 +1396,45 @@ extension Array : IDifferentiablePtrType typedef Array Differential; } +__generic +extension Optional : IDifferentiable +{ + typedef Optional Differential; + + [__unsafeForceInlineEarly] + static Differential dzero() + { + return Optional(); + } + + [__unsafeForceInlineEarly] + static Differential dadd(Differential a, Differential b) + { + if (!a.hasValue) + return b; + if (b.hasValue) + return T.dadd(a.value, b.value); + else + return a; + } + + __generic + [__unsafeForceInlineEarly] + static Differential dmul(U a, Differential b) + { + if (b.hasValue) + return Optional(T.dmul(a, b.value)); + else + return b; + } +} + +__generic +extension Optional : IDifferentiablePtrType +{ + typedef Optional Differential; +} + __generic extension Tuple : IDifferentiable { -- cgit v1.2.3