Skip to content

[IDE] Report ambiguous cursor info results #63613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 13, 2023

While we switched cursor info to solver-based I actually missed to return results in ambiguous cases. This PR fixes that oversight.

@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch 6 times, most recently from a5101fa to 471a0e2 Compare February 15, 2023 22:06
@ahoppen ahoppen changed the title [IDE] Report ambiguous cursor info results 🚥 #63612 [IDE] Report ambiguous cursor info results Feb 15, 2023
@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch from 471a0e2 to a9f0458 Compare February 15, 2023 22:10
@ahoppen
Copy link
Member Author

ahoppen commented Feb 15, 2023

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 15, 2023

@swift-ci Please SourceKit stress test

@ahoppen ahoppen marked this pull request as ready for review February 15, 2023 22:11
@ahoppen
Copy link
Member Author

ahoppen commented Feb 16, 2023

All stress tester failures are one of the following:

  • We fail to do local rename because the solver-based CursorInfo is able to resolve the cursor where the AST-based cursor info that we need for refactorings can’t. This is an improvement because previously neither rename nor cursor info worked, now only cursor info is working
  • There is a crash in SymbolGraph when doing Cursor Info on index in the stdlib. I think we can address this in a follow-up PR so we can merge this PR. A reduced test case is
func foo(hex: String) {
  // RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=%(line + 1):7 %s -- %s
  hex.index
}

addCursorInfoForDecl(Data, Result, AddRefactorings, AddSymbolGraph,
Lang, Invoc, Diagnostic, /*PreviousSnaps=*/{});
}
Data.DidReuseAST = Results->DidReuseAST;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be out of the loop.

Invoc, Diagnostic, /*PreviousSnaps=*/{},
Results->DidReuseAST, Receiver);
CursorInfoData Data;
for (auto ResolvedCursorInfo : Results.getResult().ResolvedCursorInfos) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we be consistent whether to use .getResults() or operator->?
(i.e. .getResult().ResolvedCursorInfos vs ->DidReuseAST)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I completely forgot that I added operator->

/// and thus the constraint system solution doesn't know about the
/// \c UnresolvedDeclRefExpr. Instead, we find the expression to resolve in
/// the source file again after expression pre-check has run.
SourceFile &SrcFile;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be the decl context instead? That should be faster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch from a9f0458 to ad932bd Compare February 17, 2023 09:59
@ahoppen
Copy link
Member Author

ahoppen commented Feb 17, 2023

@swift-ci Please smoke test

@@ -416,7 +416,11 @@ TypeChecker::typeCheckTarget(SolutionApplicationTarget &target,
// Construct a constraint system from this expression.
ConstraintSystemOptions csOptions = ConstraintSystemFlags::AllowFixes;

if (DiagnosticSuppression::isEnabled(Context.Diags))
/// If we have a SolutionCallback, we are inspecting constraint system
/// solutions directly and thus also want to receive ambiguous solutions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually interesting because there could be a number of valid solutions produced by the solver and I'm guessing we don't really want to run salvage in that case, right? It feels like this check needs to be embedded into the solver itself somehow...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that we should just allow fixes straight away like we do for code completion?

I deliberately wanted to keep this as close to the normal type checking as possible (without all the code-completion specific rules of weaker filtering etc.) because if normal type checking reaches a single, definite result, we also want to report that as the single result for cursor info (for now). Also, in contrast to code completion, there is a reasonable chance that the code is in a valid state and thus it makes sense to run normal type-checking first and only salvage if we didn’t find a solution or the solutions were ambiguous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this check to ConstraintSystem::solve now. Could you take another look at it?

@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch from ad932bd to 13f47b6 Compare March 13, 2023 23:59
@ahoppen
Copy link
Member Author

ahoppen commented Mar 14, 2023

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 14, 2023

@swift-ci Please SourceKit stress test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 17, 2023

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch from 36aa733 to cf26226 Compare March 17, 2023 17:49
Comment on lines 1257 to 1258
Data.AvailableActions.insert(Data.AvailableActions.end(),
KnownRefactoringInfo.begin(),
KnownRefactoringInfo.end());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be append(KnownRefactoringInfo.begin(), KnownRefactoringInfo.end()), but I see the existing code used insert.

ahoppen added 3 commits March 20, 2023 08:09
This hooks up the cursor info infrastructure to be able to pass through multiple, ambiguous results. There are still minor issues that cause solver-based cursor info to not actually report the ambiguous results but those will be fixed in a follow-up PR.
@ahoppen ahoppen force-pushed the ahoppen/ambiguous-cursor-info-results branch from cf26226 to e5c521c Compare March 20, 2023 15:10
@ahoppen
Copy link
Member Author

ahoppen commented Mar 20, 2023

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 2108d01 into swiftlang:main Mar 20, 2023
@ahoppen ahoppen deleted the ahoppen/ambiguous-cursor-info-results branch March 20, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants