From ba89fc84267bfd09f1c8abf10a5b85d09bbc79de Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Wed, 26 Jul 2023 17:15:21 -0400 Subject: Refactor `dmul(This, Differential)` to `dmul(T, Differential)` (#3029) * Refactor `dmul(This, Differential)` to `dmul(T, Differential)` - Add AST synthesis support for generic containers - Refactor relevant tests * Merge dmul synthesis with dadd and dzero, and disambiguate using an enum * Fix trailing spaces --- source/slang/slang-check-impl.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-check-impl.h') diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 04112743a..575d4aff7 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -1467,6 +1467,13 @@ namespace Slang DeclRef requiredMemberDeclRef, List& synArgs, ThisExpr*& synThis); + + GenericDecl* synthesizeGenericSignatureForRequirementWitness( + ConformanceCheckingContext* context, + DeclRef requiredMemberDeclRef, + List& synArgs, + List& synGenericArgs, + ThisExpr*& synThis); void _addMethodWitness( WitnessTable* witnessTable, @@ -1503,15 +1510,39 @@ namespace Slang LookupResult const& lookupResult, DeclRef requiredMemberDeclRef, RefPtr witnessTable); + - /// Attempt to synthesize `zero`, `dadd` and `dmul` methods for a type that conforms to + enum SynthesisPattern + { + // Synthesized method inducts over all arguments. + // T fn(T x, T y, T z, ...) + // { + // typeof(T::member0)::fn(x.member0, y.member0, z.member0, ...); + // typeof(T::member1)::fn(x.member1, y.member1, z.member1, ...); + // ... + // } + // + AllInductive, + + // Synthesized method inducts over all arguments except the first. + // T fn(U x, T y, T z) + // { + // typeof(T::member0)::fn(x, y.member0, z.member0, ...); + // typeof(T::member1)::fn(x, y.member1, z.member1, ...); + // ... + // } + FixedFirstArg + }; + + /// Attempt to synthesize `zero`, `dadd` & `dmul` methods for a type that conforms to /// `IDifferentiable`. /// On success, installs the syntethesized functions and returns `true`. /// Otherwise, returns `false`. bool trySynthesizeDifferentialMethodRequirementWitness( ConformanceCheckingContext* context, DeclRef requirementDeclRef, - RefPtr witnessTable); + RefPtr witnessTable, + SynthesisPattern pattern); /// Attempt to synthesize an associated `Differential` type for a type that conforms to /// `IDifferentiable`. -- cgit v1.2.3