@@ -1913,7 +1913,6 @@ void SwiftLangSupport::getCursorInfo(
19131913 bool SymbolGraph, bool CancelOnSubsequentRequest,
19141914 ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
19151915 SourceKitCancellationToken CancellationToken,
1916- bool VerifySolverBasedCursorInfo,
19171916 std::function<void (const RequestResult<CursorInfoData> &)> Receiver) {
19181917
19191918 std::string error;
@@ -1963,141 +1962,46 @@ void SwiftLangSupport::getCursorInfo(
19631962 return ;
19641963 }
19651964
1966- // / Counts how many symbols \p Res contains.
1967- auto ResultCount = [](const RequestResult<CursorInfoData> &Res) -> size_t {
1968- if (Res.isValue ()) {
1969- return Res.value ().Symbols .size ();
1970- } else {
1971- return 0 ;
1972- }
1973- };
1974-
1975- // / Serializes \c CursorInfoData into a string.
1976- auto ResultDescription =
1977- [](const RequestResult<CursorInfoData> &Res) -> std::string {
1978- if (Res.isCancelled ()) {
1979- return " cancelled" ;
1980- } else if (Res.isError ()) {
1981- return Res.getError ().str ();
1982- } else {
1983- std::string Description;
1984- llvm::raw_string_ostream OS (Description);
1985- Res.value ().print (OS, /* Indentation=*/ " " ,
1986- /* ForSolverBasedCursorInfoVerification=*/ true );
1987- return OS.str ();
1988- }
1989- };
1990-
1991- // Currently, we only verify that the solver-based cursor implementation
1992- // produces the same results as the AST-based implementation. Only enable it
1993- // in assert builds for now.
1994-
1995- // If solver based completion is enabled, a string description of the cursor
1996- // info result produced by the solver-based implementation. Once the AST-based
1997- // result is produced, we verify that the solver-based result matches the
1998- // AST-based result.
1999- std::string SolverBasedResultDescription;
2000- size_t SolverBasedResultCount = 0 ;
2001- bool SolverBasedReusedAST = false ;
2002- if (VerifySolverBasedCursorInfo) {
2003- std::string InputFileError;
2004- llvm::SmallString<64 > RealInputFilePath;
2005- fileSystem->getRealPath (InputFile, RealInputFilePath);
2006- std::unique_ptr<llvm::MemoryBuffer> UnresolvedInputFile =
2007- getASTManager ()->getMemoryBuffer (RealInputFilePath, fileSystem,
2008- InputFileError);
2009- if (UnresolvedInputFile) {
2010- auto SolverBasedReceiver = [&](const RequestResult<CursorInfoData> &Res) {
2011- SolverBasedResultCount = ResultCount (Res);
2012- SolverBasedResultDescription = ResultDescription (Res);
2013- if (Res.isValue ()) {
2014- SolverBasedReusedAST = Res.value ().DidReuseAST ;
2015- }
2016- };
2017-
2018- CompilerInvocation CompInvok;
2019- Invok->applyTo (CompInvok);
2020-
2021- performWithParamsToCompletionLikeOperation (
2022- UnresolvedInputFile.get (), Offset,
2023- /* InsertCodeCompletionToken=*/ false , Args, fileSystem,
2024- CancellationToken,
2025- [&](CancellableResult<CompletionLikeOperationParams> ParmsResult) {
2026- ParmsResult.mapAsync <CursorInfoResults>(
2027- [&](auto &Params, auto DeliverTransformed) {
2028- getIDEInspectionInstance ()->cursorInfo (
2029- Params.Invocation , Args, fileSystem,
2030- Params.completionBuffer , Offset, Params.DiagC ,
2031- Params.CancellationFlag , DeliverTransformed);
2032- },
2033- [&](auto Result) {
2034- deliverCursorInfoResults (SolverBasedReceiver, Result, *this ,
2035- CompInvok, Actionables, SymbolGraph);
2036- });
2037- });
2038- }
2039- }
2040-
2041- // / If the solver-based implementation returned a different result than the
2042- // / AST-based implementation, return an error message, describing the
2043- // / difference. Otherwise, return an empty string.
2044- auto VerifySolverBasedResult =
2045- [ResultCount, ResultDescription, SolverBasedResultCount,
2046- SolverBasedResultDescription](
2047- const RequestResult<CursorInfoData> &ASTBasedResult) -> std::string {
2048- if (SolverBasedResultDescription.empty ()) {
2049- // We did not run the solver-based implementation. Nothing to check.
2050- return " " ;
2051- }
2052- auto ASTResultDescription = ResultDescription (ASTBasedResult);
2053- auto ASTResultCount = ResultCount (ASTBasedResult);
2054- if (ASTResultCount == 0 && SolverBasedResultCount > 0 ) {
2055- // The AST-based implementation did not return any results but the
2056- // solver-based did. That's an improvement. Success.
2057- return " " ;
2058- }
2059- if (SolverBasedResultDescription == ASTResultDescription) {
2060- // The solver-based and AST-based implementation produced the same
2061- // results. Success.
2062- return " " ;
2063- }
2064- // The solver-based implementation differed from the AST-based
2065- // implementation. Report a failure.
2066- std::string ErrorMessage;
2067- llvm::raw_string_ostream OS (ErrorMessage);
2068- OS << " The solver-based implementation returned a different result than "
2069- " the AST-based implementation:\n " ;
2070- OS << SolverBasedResultDescription << " \n " ;
2071- OS << " ===== (solver-based vs. AST-based) =====\n " ;
2072- OS << ASTResultDescription << " \n " ;
2073- return OS.str ();
2074- };
2075-
2076- // Thunk around `Receiver` that, if solver-based cursor info is enabled,
2077- // verifies that the solver-based cursor info result matches the AST-based
2078- // result.
2079- auto ReceiverThunk =
2080- [Receiver, VerifySolverBasedResult,
2081- SolverBasedReusedAST](const RequestResult<CursorInfoData> &Res) {
2082- auto VerificationError = VerifySolverBasedResult (Res);
2083- if (VerificationError.empty ()) {
2084- if (Res.isValue ()) {
2085- // Report whether the solver-based implemenatation reused the AST so
2086- // we can check it in test cases.
2087- auto Value = Res.value ();
2088- Value.DidReuseAST = SolverBasedReusedAST;
2089- Receiver (RequestResult<CursorInfoData>::fromResult (Value));
2090- } else {
2091- Receiver (Res);
2092- }
2093- } else {
2094- Receiver (RequestResult<CursorInfoData>::fromError (VerificationError));
2095- }
2096- };
1965+ bool SolverBasedProducedResult = false ;
1966+ std::string InputFileError;
1967+ llvm::SmallString<64 > RealInputFilePath;
1968+ fileSystem->getRealPath (InputFile, RealInputFilePath);
1969+ std::unique_ptr<llvm::MemoryBuffer> UnresolvedInputFile =
1970+ getASTManager ()->getMemoryBuffer (RealInputFilePath, fileSystem,
1971+ InputFileError);
1972+ if (UnresolvedInputFile) {
1973+ auto SolverBasedReceiver = [&](const RequestResult<CursorInfoData> &Res) {
1974+ SolverBasedProducedResult = true ;
1975+ Receiver (Res);
1976+ };
20971977
2098- resolveCursor (*this , InputFile, Offset, Length, Actionables, SymbolGraph,
2099- Invok, /* TryExistingAST=*/ true , CancelOnSubsequentRequest,
2100- fileSystem, CancellationToken, ReceiverThunk);
1978+ CompilerInvocation CompInvok;
1979+ Invok->applyTo (CompInvok);
1980+
1981+ performWithParamsToCompletionLikeOperation (
1982+ UnresolvedInputFile.get (), Offset,
1983+ /* InsertCodeCompletionToken=*/ false , Args, fileSystem,
1984+ CancellationToken,
1985+ [&](CancellableResult<CompletionLikeOperationParams> ParmsResult) {
1986+ ParmsResult.mapAsync <CursorInfoResults>(
1987+ [&](auto &Params, auto DeliverTransformed) {
1988+ getIDEInspectionInstance ()->cursorInfo (
1989+ Params.Invocation , Args, fileSystem,
1990+ Params.completionBuffer , Offset, Params.DiagC ,
1991+ Params.CancellationFlag , DeliverTransformed);
1992+ },
1993+ [&](auto Result) {
1994+ deliverCursorInfoResults (SolverBasedReceiver, Result, *this ,
1995+ CompInvok, Actionables, SymbolGraph);
1996+ });
1997+ });
1998+ }
1999+
2000+ if (!SolverBasedProducedResult) {
2001+ resolveCursor (*this , InputFile, Offset, Length, Actionables, SymbolGraph,
2002+ Invok, /* TryExistingAST=*/ true , CancelOnSubsequentRequest,
2003+ fileSystem, CancellationToken, Receiver);
2004+ }
21012005}
21022006
21032007void SwiftLangSupport::getDiagnostics (
0 commit comments