From 3088d901fee6447b6d80fa67f258626ece4408dc Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 5 May 2022 10:48:14 -0700 Subject: Various vulkan/glsl fixes. (#2222) * Various vulkan/glsl fixes. * Fix. * Fix. * Canonicalize type constraints for name mangling. Co-authored-by: Yong He Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> --- source/slang/slang-check-decl.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 8db157a37..3c654a48b 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -12,6 +12,8 @@ #include "slang-lookup.h" +#include "slang-syntax.h" + namespace Slang { /// Visitor to transition declarations to `DeclCheckState::CheckedModifiers` @@ -5342,4 +5344,49 @@ namespace Slang } } + static void _getCanonicalConstraintTypes(List& outTypeList, Type* type) + { + if (auto andType = as(type)) + { + _getCanonicalConstraintTypes(outTypeList, andType->left); + _getCanonicalConstraintTypes(outTypeList, andType->right); + } + else + { + outTypeList.add(type); + } + } + OrderedDictionary> getCanonicalGenericConstraints( + DeclRef genericDecl) + { + OrderedDictionary> genericConstraints; + for (auto mm : getMembersOfType(genericDecl)) + { + genericConstraints[mm.getDecl()] = List(); + } + for (auto genericTypeConstraintDecl : getMembersOfType(genericDecl)) + { + assert( + genericTypeConstraintDecl.getDecl()->sub.type->astNodeType == + ASTNodeType::DeclRefType); + auto typeParamDecl = as(genericTypeConstraintDecl.getDecl()->sub.type)->declRef.getDecl(); + List* constraintTypes = genericConstraints.TryGetValue(typeParamDecl); + assert(constraintTypes); + constraintTypes->add(genericTypeConstraintDecl.getDecl()->getSup().type); + } + + OrderedDictionary> result; + for (auto& constraints : genericConstraints) + { + List typeList; + for (auto type : constraints.Value) + { + _getCanonicalConstraintTypes(typeList, type); + } + // TODO: we also need to sort the types within the list for each generic type param. + result[constraints.Key] = typeList; + } + return result; + } + } -- cgit v1.2.3