From d964555d2ee83fac2ba357e4ec81e2a393a7b12f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:11:39 +0000 Subject: Replace [KnownBuiltin] string-based comparisons with enum-based system (#7714) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * Implement enum-based KnownBuiltin system to replace string comparisons Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Add test for enum-based KnownBuiltin system and verify functionality Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Implement enum-based KnownBuiltin system with direct integer values Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix IntVal access and update tests for new enum-based KnownBuiltin system Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Replace hardcoded KnownBuiltin integers with preprocessor enum syntax - Updated all KnownBuiltin attributes to use $( (int)KnownBuiltinDeclName::EnumValue) syntax - Added space between parentheses to avoid preprocessor bug: $( (int) instead of $((int) - Updated both core.meta.slang and hlsl.meta.slang files - Eliminates preprocessor-time integer conversion, baking enum values directly into meta files - Maintains same functionality while using type-safe enum references Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix IDifferentiablePtr KnownBuiltin mapping regression Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Remove unused IDifferentiablePtrType enum case from KnownBuiltinDeclName Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Clean up temporary AST dump files from testing Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Replace hardcoded integer with descriptive constant in KnownBuiltin test Replace the hardcoded [KnownBuiltin(0)] with a descriptive named constant GEOMETRY_STREAM_APPEND_BUILTIN to improve code readability and maintainability. The test now clearly indicates which builtin enum value is being tested. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Gangzheng Tong --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gangzheng Tong Co-authored-by: Gangzheng Tong --- source/slang/slang-check-expr.cpp | 46 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index c7e58a888..9325eda61 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -15,6 +15,7 @@ #include "slang-ast-decl.h" #include "slang-ast-natural-layout.h" #include "slang-ast-print.h" +#include "slang-ast-support-types.h" #include "slang-ast-synthesis.h" #include "slang-lookup-spirv.h" #include "slang-lookup.h" @@ -4524,29 +4525,32 @@ void SemanticsExprVisitor::maybeCheckKnownBuiltinInvocation(Expr* invokeExpr) auto knownBuiltinAttr = callee->findModifier(); if (!knownBuiltinAttr) return; - if (knownBuiltinAttr->name == "GetAttributeAtVertex") + if (auto constantIntVal = as(knownBuiltinAttr->name)) { - if (checkedInvokeExpr->arguments.getCount() != 2) - return; - auto vertexAttributeArg = checkedInvokeExpr->arguments[0]; - auto vertexAttributeArgDeclRefExpr = as(vertexAttributeArg); - if (!vertexAttributeArgDeclRefExpr) + if (constantIntVal->getValue() == (int)KnownBuiltinDeclName::GetAttributeAtVertex) { - getSink()->diagnose( - invokeExpr, - Diagnostics::getAttributeAtVertexMustReferToPerVertexInput); - return; - } - auto vertexAttributeArgDecl = vertexAttributeArgDeclRefExpr->declRef.getDecl(); - if (!vertexAttributeArgDecl) - return; - if (!vertexAttributeArgDecl->findModifier() && - !vertexAttributeArgDecl->findModifier()) - { - getSink()->diagnose( - vertexAttributeArgDeclRefExpr, - Diagnostics::getAttributeAtVertexMustReferToPerVertexInput); - return; + if (checkedInvokeExpr->arguments.getCount() != 2) + return; + auto vertexAttributeArg = checkedInvokeExpr->arguments[0]; + auto vertexAttributeArgDeclRefExpr = as(vertexAttributeArg); + if (!vertexAttributeArgDeclRefExpr) + { + getSink()->diagnose( + invokeExpr, + Diagnostics::getAttributeAtVertexMustReferToPerVertexInput); + return; + } + auto vertexAttributeArgDecl = vertexAttributeArgDeclRefExpr->declRef.getDecl(); + if (!vertexAttributeArgDecl) + return; + if (!vertexAttributeArgDecl->findModifier() && + !vertexAttributeArgDecl->findModifier()) + { + getSink()->diagnose( + vertexAttributeArgDeclRefExpr, + Diagnostics::getAttributeAtVertexMustReferToPerVertexInput); + return; + } } } } -- cgit v1.2.3