From 1093218d6f0e114eb9fa52d60ca525bf9dd9f98a Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:22:00 -0400 Subject: Modified the new type system to support generic differentiable types … (#2413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Modified the new type system to support generic differentiable types and added support for differentiating overloaded functions. * Changed a few asserts to release asserts to avoid unreferenced variable errors * Fixed a naming issue with TypeWitnessBreadcumb::Flavor::Decl * Added logic to avoid tracking differentiable types if the module does not use auto-diff or define differentiable types. * Moved the auto-diff passes to after the specialization step, added a more complex generics test * Added a generics stress test and fixed AST-side logic. IR side needs some more work * Added differential getter and setter logic, fixed multiple issues with DifferentiableTypeDictionary, added support for loops and conditions * Changed differential getters to use pointer types, added getter type checking * Fixed some bugs related to diff type registration and differential getters * Removed some superfluous code * Removed some more unused code. * Fixed an issue with witness substitution * Minor fix Co-authored-by: Yong He --- source/slang/slang-check-constraint.cpp | 43 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'source/slang/slang-check-constraint.cpp') diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index 24cedd7d5..f96b5a484 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -564,6 +564,19 @@ namespace Slang } } + // Two subtype witnesses can be unified if they exist (non-null) and + // prove that some pair of types are subtypes of types that can be unified. + // + if (auto fstWit = as(fst)) + { + if (auto sndWit = as(snd)) + { + return TryUnifyTypes(constraints, + fstWit->sup, + sndWit->sup); + } + } + SLANG_UNIMPLEMENTED_X("value unification case"); // default: fail @@ -725,17 +738,29 @@ namespace Slang bool SemanticsVisitor::TryUnifyConjunctionType( ConstraintSystem& constraints, - AndType* fst, + Type* fst, Type* snd) { - // Unifying a type `T` with `A & B` amounts to unifying - // `T` with `A` and also `T` with `B`. + // Unifying a type `A & B` with `T` amounts to unifying + // `A` with `T` and also `B` with `T` while + // unifying a type `T` with `A & B` amounts to either + // unifying `T` with `A` or `T` with `B` // // If either unification is impossible, then the full // case is also impossible. // - return TryUnifyTypes(constraints, fst->left, snd) - && TryUnifyTypes(constraints, fst->right, snd); + if (auto fstAndType = as(fst)) + { + return TryUnifyTypes(constraints, fstAndType->left, snd) + && TryUnifyTypes(constraints, fstAndType->right, snd); + } + else if (auto sndAndType = as(snd)) + { + return TryUnifyTypes(constraints, fst, sndAndType->left) + || TryUnifyTypes(constraints, fst, sndAndType->right); + } + else + return false; } bool SemanticsVisitor::TryUnifyTypes( @@ -762,13 +787,9 @@ namespace Slang // a conjunction directly, and will instead find all of the // "leaf" types we need to constrain it to. // - if( auto fstAndType = as(fst) ) - { - return TryUnifyConjunctionType(constraints, fstAndType, snd); - } - if( auto sndAndType = as(snd) ) + if (as(fst) || as(snd)) { - return TryUnifyConjunctionType(constraints, sndAndType, fst); + return TryUnifyConjunctionType(constraints, fst, snd); } // A generic parameter type can unify with anything. -- cgit v1.2.3