From d179f0eec263d6ba2d7c1594564d4161750b2369 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 14 May 2025 13:15:48 -0700 Subject: Infer type while constant folding causes failure (#7090) Problem: * Infering type with `let` while using constant-foldable object's means we run in a circular loop of `ensureDecl`. Changes: * If we constant-fold we effectively are ready to check definition. If we are not a constant to fold, we run `setCheckState` after anyways. --- source/slang/slang-check-decl.cpp | 2 ++ tests/bugs/infer-var-type-constant-folding.slang | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/bugs/infer-var-type-constant-folding.slang diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index dbd52ebea..c2c0c2cb6 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1836,6 +1836,8 @@ void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) varDecl->initExpr = initExpr; varDecl->type.type = initExpr->type; + + varDecl->setCheckState(DeclCheckState::DefinitionChecked); _validateCircularVarDefinition(varDecl); } diff --git a/tests/bugs/infer-var-type-constant-folding.slang b/tests/bugs/infer-var-type-constant-folding.slang new file mode 100644 index 000000000..658abed17 --- /dev/null +++ b/tests/bugs/infer-var-type-constant-folding.slang @@ -0,0 +1,15 @@ +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +//BUF: B + +RWStructuredBuffer outputBuffer; + +static const let C = float(3); +static const let D = int(4+4+int(C)); + +void computeMain() +{ + outputBuffer[0] = D; +} \ No newline at end of file -- cgit v1.2.3