Skip to content

[5.0][CodeCompletion] Rework getOperatorCompletions() #20785

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

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 27, 2018

(Cherry-pick of #20632 to swft-5.0-branch)

In postfix completion, for operator completion, we do:

  1. Type check the operand without applying it, but set the resolved
    type to the root of the expression.
  2. For each possible operators:
    i. Build temporary binary/postfix expression
    ii. Perform type checking to see whether the operator is applicable

This could be very slow especially if the operand is complex.

  • Introduce ReusePrecheckedType option to constraint system. With
    this option, CSGen respects pre-stored types in expressions and doesn't
    take its sub-expressions into account.

    • Improve type checking performance because type variables aren't
      generated for sub-expressions of LHS (45511835)
    • Guarantee that the operand is not modified by the type checker because
      expression walkers in CSGen doesn't walk into the operand.
  • Introduce TypeChecker::findLHS() to find LHS for a infix operator from
    pre-folded expression. We used to foldSequence() temporary
    SequenceExpr and find 'CodeCompletionExpr' for each attempt.

    • No need to flatten folded expression after initial type-checking.
    • Save memory of temporary BinaryExpr which used to be allocated by
      foldSequence().
    • Improve accuracy of the completion. foldSequence() recovers invalid
      combination of operators by left associative manner (with
      diagnostics). This used to cause false-positive results. For instance,
      a == b <HERE> used to suggest == operator. findLHS() returns
      nullptr for such invalid combination.

rdar://problem/43008573
rdar://problem/45511835
https://bugs.swift.org/browse/SR-9061

In postfix completion, for operator completion, we do:

  1. Type check the operand without applying it, but set the resolved
     type to the root of the expression.
  2. For each possible operators:
      i. Build temporary binary/postfix expression
      ii. Perform type checking to see whether the operator is applicable 

This could be very slow especially if the operand is complex.

* Introduce `ReusePrecheckedType` option to constraint system. With
  this option, CSGen respects pre-stored types in expressions and doesn't
  take its sub-expressions into account.
  * Improve type checking performance because type variables aren't
     generated for sub-expressions of LHS (45511835)
  * Guarantee that the operand is not modified by the type checker because
     expression walkers in `CSGen` doesn't walk into the operand.

* Introduce `TypeChecker::findLHS()` to find LHS for a infix operator from
  pre-folded expression. We used to `foldSequence()` temporary
  `SequenceExpr` and find 'CodeCompletionExpr' for each attempt.
  * No need to flatten folded expression after initial type-checking.
  * Save memory of temporary `BinaryExpr` which used to be allocated by
    `foldSequence()`.
  * Improve accuracy of the completion. `foldSequence()` recovers invalid
    combination of operators by `left` associative manner (with
    diagnostics). This used to cause false-positive results. For instance,
    `a == b <HERE>` used to suggest `==` operator. `findLHS()` returns
    `nullptr` for such invalid combination.

rdar://problem/45511835
https://bugs.swift.org/browse/SR-9061
@rintaro rintaro requested a review from a team November 27, 2018 01:46
@akyrtzi
Copy link
Contributor

akyrtzi commented Dec 5, 2018

@swift-ci Please test

@akyrtzi akyrtzi merged commit 086baa2 into swiftlang:swift-5.0-branch Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants