diff options
| author | Yong He <yonghe@outlook.com> | 2023-11-28 09:15:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-28 09:15:31 -0800 |
| commit | 62426e94ef11fd6baa213757f87114ec174b406e (patch) | |
| tree | 620b539efe2f01bfc213953a4893d09635093653 | |
| parent | a2083d64fec7732195e533b6a2ed7d05cc9beedc (diff) | |
Misc language server fixes. (#3357)
| -rw-r--r-- | source/slang/slang-ast-print.cpp | 14 | ||||
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-language-server.cpp | 16 | ||||
| -rw-r--r-- | tests/language-server/incomplete-custom-derivative.slang | 20 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 33 |
5 files changed, 74 insertions, 15 deletions
diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp index b80afeee1..d3e028901 100644 --- a/source/slang/slang-ast-print.cpp +++ b/source/slang/slang-ast-print.cpp @@ -365,6 +365,20 @@ void ASTPrinter::addDeclKindPrefix(Decl* decl) continue; if (as<AttributeTargetModifier>(modifier)) continue; + if (as<RequiredCUDASMVersionModifier>(modifier)) + continue; + if (as<RequiredSPIRVVersionModifier>(modifier)) + continue; + if (as<RequiredGLSLVersionModifier>(modifier)) + continue; + if (as<RequiredGLSLExtensionModifier>(modifier)) + continue; + if (as<GLSLLayoutModifier>(modifier)) + continue; + if (as<GLSLLayoutModifierGroupMarker>(modifier)) + continue; + if (as<HLSLLayoutSemantic>(modifier)) + continue; } // Don't print out attributes. if (as<AttributeBase>(modifier)) diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index c31c94a85..7c36bdd5f 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -7346,6 +7346,10 @@ namespace Slang visitor->getSink()->diagnose(attr, Diagnostics::cannotUseInterfaceRequirementAsDerivative); return; } + if (funcType->getParamCount() != imaginaryArguments.getCount()) + { + goto error; + } for (Index ii = 0; ii < imaginaryArguments.getCount(); ++ii) { // Check if the resolved invoke argument type is an error type. @@ -7403,7 +7407,7 @@ namespace Slang return; } } - + error:; // Build the expected signature from imaginary args to diagnose // when no matching function is found (this excludes the case handled above) // diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp index 24ab534ab..c188142f5 100644 --- a/source/slang/slang-language-server.cpp +++ b/source/slang/slang-language-server.cpp @@ -1255,8 +1255,20 @@ SlangResult LanguageServer::signatureHelp( return SLANG_OK; } - auto funcExpr = - appExpr->originalFunctionExpr ? appExpr->originalFunctionExpr : appExpr->functionExpr; + auto funcExpr = appExpr->functionExpr; + if (appExpr->originalFunctionExpr) + { + bool useOriginalExpr = true; + if (auto originalDeclRefExpr = as<DeclRefExpr>(appExpr->originalFunctionExpr)) + { + if (!originalDeclRefExpr->declRef) + { + useOriginalExpr = false; + } + } + if (useOriginalExpr) + funcExpr = appExpr->originalFunctionExpr; + } if (!funcExpr) { m_connection->sendResult(NullResponse::get(), responseId); diff --git a/tests/language-server/incomplete-custom-derivative.slang b/tests/language-server/incomplete-custom-derivative.slang new file mode 100644 index 000000000..06cfda723 --- /dev/null +++ b/tests/language-server/incomplete-custom-derivative.slang @@ -0,0 +1,20 @@ + +//TEST:LANG_SERVER(filecheck=CHECK): + +RWByteAddressBuffer atomicBuffer; +RWByteAddressBuffer atomicGradBuffer; + +float myDifferentiableMin(uint location, float value) +{ + uint originalValue; + atomicBuffer.InterlockedMin(location, asuint(value), originalValue); +//SIGNATURE:12,20 + InterlockedMin() + return min(asfloat(originalValue), value); +} +//HOVER:17,12 +[BackwardDerivativeOf(myDifferentiableMin)] +float myDiffMin() + +// CHECK: func InterlockedMin +// CHECK: func myDiffMin() -> float diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 2395aad16..5de9a8dc6 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1974,27 +1974,36 @@ TestResult runLanguageServerTest(TestContext* context, TestInput& input) actualOutput = redactedSB.produceString().trim(); - if (!_areResultsEqual(input.testOptions->type, expectedOutput, actualOutput)) + String fileCheckPrefix; + const bool isFileCheckTest = input.testOptions->getFileCheckPrefix(fileCheckPrefix); + if (isFileCheckTest) { - if (expectedOutput.startsWith("CONTAINS")) + result = _fileCheckTest(*context, input.filePath, fileCheckPrefix, actualOutput); + } + else + { + if (!_areResultsEqual(input.testOptions->type, expectedOutput, actualOutput)) { - List<UnownedStringSlice> words; - List<UnownedStringSlice> expectedLines; - StringUtil::calcLines(expectedOutput.getUnownedSlice(), expectedLines); - if (expectedLines.getCount() >= 1) + if (expectedOutput.startsWith("CONTAINS")) { - StringUtil::split(expectedLines[0], ' ', words); - if (words.getCount() >= 2) + List<UnownedStringSlice> words; + List<UnownedStringSlice> expectedLines; + StringUtil::calcLines(expectedOutput.getUnownedSlice(), expectedLines); + if (expectedLines.getCount() >= 1) { - if (actualOutput.contains(words[1].trim())) + StringUtil::split(expectedLines[0], ' ', words); + if (words.getCount() >= 2) { - return result; + if (actualOutput.contains(words[1].trim())) + { + return result; + } } } } + context->getTestReporter()->dumpOutputDifference(expectedOutput, actualOutput); + result = TestResult::Fail; } - context->getTestReporter()->dumpOutputDifference(expectedOutput, actualOutput); - result = TestResult::Fail; } // If the test failed, then we write the actual output to a file |
