diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-04 13:05:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-04 13:05:58 -0700 |
| commit | 812e478989e27983b8dea7ab11964de751654ba2 (patch) | |
| tree | e6db6def9c7896ee48c5fe42926856644e81c0e6 /source/slang/diff.meta.slang | |
| parent | b9dc21d362f65f22bc707bede733a9537b80460a (diff) | |
Make interface types non c-style in Slang2026. (#7260)
* Make interface types non c-style.
* Make Optional<T> 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>
Diffstat (limited to 'source/slang/diff.meta.slang')
| -rw-r--r-- | source/slang/diff.meta.slang | 39 |
1 files changed, 39 insertions, 0 deletions
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<T, N> : IDifferentiablePtrType typedef Array<T.Differential, N> Differential; } +__generic<T:IDifferentiable> +extension Optional<T> : IDifferentiable +{ + typedef Optional<T.Differential> Differential; + + [__unsafeForceInlineEarly] + static Differential dzero() + { + return Optional<T.Differential>(); + } + + [__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<U : __BuiltinRealType> + [__unsafeForceInlineEarly] + static Differential dmul(U a, Differential b) + { + if (b.hasValue) + return Optional<T.Differential>(T.dmul<U>(a, b.value)); + else + return b; + } +} + +__generic<T : IDifferentiablePtrType> +extension Optional<T> : IDifferentiablePtrType +{ + typedef Optional<T.Differential> Differential; +} + __generic<each T : IDifferentiable> extension Tuple<T> : IDifferentiable { |
