From 62426e94ef11fd6baa213757f87114ec174b406e Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 28 Nov 2023 09:15:31 -0800 Subject: Misc language server fixes. (#3357) --- source/slang/slang-ast-print.cpp | 14 +++++++++ source/slang/slang-check-decl.cpp | 6 +++- source/slang/slang-language-server.cpp | 16 +++++++++-- .../incomplete-custom-derivative.slang | 20 +++++++++++++ tools/slang-test/slang-test-main.cpp | 33 ++++++++++++++-------- 5 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 tests/language-server/incomplete-custom-derivative.slang 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(modifier)) continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; } // Don't print out attributes. if (as(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(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 words; - List expectedLines; - StringUtil::calcLines(expectedOutput.getUnownedSlice(), expectedLines); - if (expectedLines.getCount() >= 1) + if (expectedOutput.startsWith("CONTAINS")) { - StringUtil::split(expectedLines[0], ' ', words); - if (words.getCount() >= 2) + List words; + List 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 -- cgit v1.2.3