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-mangle.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-mangle.cpp') diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index e6c0a8e7f..ca6dcecd7 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -2,6 +2,7 @@ #include "../compiler-core/slang-name.h" #include "slang-syntax.h" +#include "slang-check.h" namespace Slang { @@ -330,6 +331,12 @@ namespace Slang return; } + // TODO: we should special case GenericTypeParamDecl and GenericValueParamDecl nodes + // instead of just dumping their names here to avoid the name of a generic parameter + // to have affect the binary signature. + // For each generic parameter, we should assign it a unique ID (i, j), where i is the + // nesting level of the generic, and j is the sequential order of the parameter within + // its generic parent, and use this 2D ID to refer to such a parameter. emitName(context, declRef.getName()); // Special case: accessors need some way to distinguish themselves @@ -392,26 +399,34 @@ namespace Slang } emit(context, genericParameterCount); - for( auto mm : getMembers(parentGenericDeclRef) ) + + OrderedDictionary> genericConstraints; + for (auto mm : getMembers(parentGenericDeclRef)) { - if(auto genericTypeParamDecl = mm.as()) + if (auto genericTypeParamDecl = mm.as()) { emitRaw(context, "T"); } - else if(auto genericValueParamDecl = mm.as()) + else if (auto genericValueParamDecl = mm.as()) { emitRaw(context, "v"); emitType(context, getType(context->astBuilder, genericValueParamDecl)); } - else if(mm.as()) - { - emitRaw(context, "C"); - // TODO: actually emit info about the constraint - } else + {} + } + + auto canonicalizedConstraints = getCanonicalGenericConstraints(parentGenericDeclRef); + for (auto& constraint : canonicalizedConstraints) + { + for (auto type : constraint.Value) { + emitRaw(context, "C"); + emitQualifiedName(context, DeclRef(constraint.Key, nullptr)); + emitType(context, type); } } + } } -- cgit v1.2.3