From 1bbcf25af514a9ae24f7006747177f2d1b3b7c0d Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 11 Mar 2024 14:42:14 -0700 Subject: Link-time specialization fixes. (#3734) * Fix method synthesis logic for static differentiable methods. * Support link-time constants in thread group size reflection. --- source/slang/slang-ast-val.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/slang/slang-ast-val.cpp') diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index b2b874fad..0dbe65ee0 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -7,6 +7,7 @@ #include "slang-diagnostics.h" #include "slang-syntax.h" #include "slang-ast-val.h" +#include "slang-mangle.h" namespace Slang { @@ -234,6 +235,15 @@ bool GenericParamIntVal::_isLinkTimeValOverride() return getDeclRef().getDecl()->hasModifier(); } +Val* GenericParamIntVal::_linkTimeResolveOverride(Dictionary& map) +{ + auto name = getMangledName(getCurrentASTBuilder(), getDeclRef().declRefBase); + IntVal* v; + if (map.tryGetValue(name, v)) + return v; + return this; +} + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ErrorIntVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! void ErrorIntVal::_toTextOverride(StringBuilder& out) @@ -1088,6 +1098,15 @@ Val* TypeCastIntVal::tryFoldImpl(ASTBuilder* astBuilder, Type* resultType, Val* return nullptr; } +Val* TypeCastIntVal::_linkTimeResolveOverride(Dictionary& map) +{ + auto intValBase = as(getBase()); + if (!intValBase) + return this; + auto resolvedBase = intValBase->linkTimeResolve(map); + return tryFoldImpl(getCurrentASTBuilder(), getType(), resolvedBase, nullptr); +} + Val* TypeCastIntVal::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; @@ -1310,6 +1329,14 @@ Val* FuncCallIntVal::tryFoldImpl(ASTBuilder* astBuilder, Type* resultType, DeclR return nullptr; } +Val* FuncCallIntVal::_linkTimeResolveOverride(Dictionary& map) +{ + List newArgs; + for (auto arg : getArgs()) + newArgs.add(as(arg->linkTimeResolve(map))); + return tryFoldImpl(getCurrentASTBuilder(), getType(), getFuncDeclRef(), newArgs, nullptr); +} + Val* FuncCallIntVal::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; @@ -1506,4 +1533,9 @@ bool IntVal::isLinkTimeVal() SLANG_AST_NODE_VIRTUAL_CALL(IntVal, isLinkTimeVal, ()); } +Val* IntVal::linkTimeResolve(Dictionary& mapMangledNameToVal) +{ + SLANG_AST_NODE_VIRTUAL_CALL(IntVal, linkTimeResolve, (mapMangledNameToVal)); +} + } // namespace Slang -- cgit v1.2.3