Commit Graph

882 Commits

Author SHA1 Message Date
Pavel Yaskevich 627a1c0037 [TypeChecker/CodeCompletion] Move hole -> archetype conversion logic into sawSolution
Instead of exposing archetypes during solution generation, let's
do that based on solution data when a type of code completion
expression is requested by code completion callback.
2020-08-31 16:54:12 -07:00
Pavel Yaskevich 8d5c94f232 [TypeChecker/CodeCompletion] Implement a fallback from code completion to typeCheckExpression
This fallback to `typeCheckExpression` is triggered when it's
determined that code completion expression is located inside
of a multi-statement closure and its body is going going to
participate in type-check.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich 74f0ec5b97 [TypeChecker/CodeCompletion] Allow {typeCheck, solve}ForCodeCompletion to operate on target instead of expression
Using `SolutionApplicationTarget` make it easier to propage
contextual information and avoid mistakes of using incorrect
accessors for constraint generation.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich d6d083ecf8 [TypeChecker] Mode code completion fallback to typeCheckForCodeCompletion
If an expression fails pre-check or constraint generation,
code completion should be performed directly on the
`CodeCompletionExpr` as a fallback. Let's factor that logic
out from `solveForCodeCompletion` and put it directly into
`typeCheckForCodeCompletion` because it's easier to establish
fault conditions there.
2020-08-28 22:24:24 -07:00
Pavel Yaskevich b71fdb5704 [CSSolver] Augment solveForCodeCompletion to indicate when it fails 2020-08-28 22:24:23 -07:00
Pavel Yaskevich 97de178151 [CSSolver] Solution: Resolve holes as underlying generic parameters for code completion
To aid code completion, we need to attempt to convert type holes
back into underlying generic parameters if possible, since type
of the code completion expression is used as "expected" (or contextual)
type so it's helpful to know what requirements it has to filter
the list of possible member candidates e.g.

```swift
func test<T: P>(_: [T]) {}

test(42.#^MEMBERS^#)
```

It's impossible to resolve `T` in this case but code completion
expression should still have a type of `[T]` instead of `[<<hole>>]`
because it helps to produce correct contextual member list based on
a conformance requirement associated with generic parameter `T`.
2020-08-28 22:24:23 -07:00
Pavel Yaskevich 5872cef2ff [CSSolver/CodeCompletion] If pre-check fails extract code completion expression and use it
If there was an invalid reference which was caught by pre-check,
let's remove all context besides code completion itself and use
it to produce code completion results.
2020-08-28 22:24:23 -07:00
Pavel Yaskevich 53de10fd3c [CSSolver] Update expression after constraint generation while solving for code completion 2020-08-28 22:24:23 -07:00
Pavel Yaskevich 5bd19d28ac [CSSolver] add debug logging to solveForCodeCompletion 2020-08-28 22:24:23 -07:00
swift_jenkins d2f3633bed Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-18 01:34:47 -07:00
Pavel Yaskevich bc319779d5 [TypeChecker] Replace invalid refs with ErrorExpr only when explicitly allowed
Add a flag to `ConstraintSystem::preCheckExpression` and subsequently
to `TypeChecker::resolveDeclRefExpr` to indicate whether it's allowed
to replace invalid member refs with `ErrorExpr`.

It is useful for diagnostics and code completion to preserve AST
in it's original state otherwise it's impossible to diagnose errors
post factum or extract `CodeCompletionExpr` when it's a child of an
invalid reference.
2020-08-17 12:39:29 -07:00
swift-ci 4c18ddcd0a Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-11 15:23:27 -07:00
Pavel Yaskevich a81b7d19e8 [CSSolver] solveForCodeCompletion should fail if constraint generation fails 2020-08-11 12:14:09 -07:00
swift-ci 0202740b0a Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-28 14:24:04 -07:00
Doug Gregor 17669d7d5d [Trailing closures] Attempt both forward and backward scans.
To better preserve source compatibility, teach the constraint
solver to try both the new forward scanning rule as well as the
backward scanning rule when matching a single, unlabeled trailing
closure. In the extreme case, where the unlabeled trailing closure
matches different parameters with the different rules, and yet both
produce a potential match, introduce a disjunction to explore both
possibilities.

Prefer solutions that involve forward scans to those that involve
backward scans, so we only use the backward scan as a fallback.
2020-07-24 08:11:25 -07:00
Nathan Hawes 9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Pavel Yaskevich 7622993083 [ConstraintSystem] Add a new endpoint to infer bindings for a given type variable
Since bindings now require finalization we need a new endpoint
which perform all of the required actions before returning complete
`PotentialBindings` object when they are requested for a particular
type variable without any other context.
2020-07-15 20:50:50 -07:00
Anthony Latsis 2133fe27df Sema: Have TypeResolution accept an unbound generic type opener function 2020-07-08 13:39:34 +03:00
swift_jenkins edd2fac359 Merge remote-tracking branch 'origin/master' into master-next 2020-06-17 13:18:52 -07:00
swift_jenkins 45b3113ce1 Merge remote-tracking branch 'origin/master' into master-next 2020-06-17 10:46:06 -07:00
Rintaro Ishizaki d990f6cfaf [ConstraintSystem] Stop type checking TapExpr elements in shrink()
TapExpr has a 'VarDecl' the type of which is determined by type checking
the parent interpolated string literal expression. Type checking TapExpr
elements before that always fails, thus a waste of the computing time.
2020-06-17 10:34:04 -07:00
Pavel Yaskevich 6c85c7f729 [TypeChecker] NFC: Revise comments for {typeCheck, solve}ForCodeCompletion 2020-06-17 00:06:03 -07:00
swift_jenkins 76e2ec15b7 Merge remote-tracking branch 'origin/master' into master-next 2020-06-16 11:39:58 -07:00
Pavel Yaskevich ccd7167371 [TypeChecker] Add a entry point to be used for code completion
As part of the code completion redesign this new entry point is going
to replace use of:

- `typeCheckExpression`
- `getTypeOfExpressionWithoutApplying` (which could be removed)

and possibly other methods currently used to retrieve information
for code completion purposes.

Advantages of a new approach:

- Avoids mutating AST;
- Allows to avoid sub-expression type-checking;
- Allows code completion access to multiple solutions in ambiguous cases;
- Provides all possible solutions - valid and invalid (with holes);
- Allows code completion to easily access not only types but
  overload choices and other supplimentary information associated
  with each solution.
2020-06-15 13:55:00 -07:00
swift_jenkins 0b350f6562 Merge remote-tracking branch 'origin/master' into master-next 2020-06-10 11:38:51 -07:00
Robert Widmann ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Anthony Latsis 4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Karoy Lorentey 57ea964f2c Merge commit '3eb82c183662945687f48e11c09828f551b34858' into master-next
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:58:37 -07:00
Karoy Lorentey 68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Karoy Lorentey 1c9b0908e6 Merge remote-tracking branch 'origin/master-next'
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:43:40 -07:00
Doug Gregor 64f903fe2a [Type checker] Experimental support for one-way parameter constraints.
Introduce an experimental mode (behind the flag
`experimental-one-way-closure-params`) that places one-way
constraints between closure parameter types and references to those
parameters within the body of the closure. The intent here is to
break up constraint systems further, potentially improving type
checking performance and making way for larger closure bodies to be
supported.

This is a source-breaking change when the body of a single-expression
closure is used to determine the parameter types. One obvious example
is when there is no contextual type, e.g.,

    let _ = { $0 + 1 }

this type-checks today because `1` becomes `Int`, which matches the
`+` overload with the type `(Int, Int) -> Int`, determining the
parameter type `Int` for the closure. Such code would not type-check
with one-way constraints.
2020-06-05 22:47:21 -07:00
Varun Gandhi c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
swift_jenkins 7406c8a983 Merge remote-tracking branch 'origin/master' into master-next 2020-05-25 17:58:30 -07:00
Hamish Knight 1de3d0dbef Merge pull request #31943 from owenv/line-and-col 2020-05-25 17:57:09 -07:00
swift_jenkins ea82b47215 Merge remote-tracking branch 'origin/master' into master-next 2020-05-23 17:38:43 -07:00
Slava Pestov 80919e9fe1 Sema: Don't clone TypeReprs in ConstraintSystem::shrink() 2020-05-23 02:23:43 -04:00
Owen Voorhees 45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
swift_jenkins df9ba33d11 Merge remote-tracking branch 'origin/master' into master-next 2020-05-19 11:39:09 -07:00
Robert Widmann afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
swift_jenkins 10e1981971 Merge remote-tracking branch 'origin/master' into master-next 2020-05-13 13:37:47 -07:00
Robert Widmann 2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
swift_jenkins 2cb8077b5d Merge remote-tracking branch 'origin/master' into master-next 2020-04-30 15:38:43 -07:00
Robert Widmann 31d23303e1 [NFC] Strip all remaining TypeResolutionOptions parameters
Now that these are stored in the TypeResolution object itself, and all callers that mutate flags create a new resolution object, this data can be derived from the resolution itself.
2020-04-30 10:58:40 -07:00
Robert Widmann 4130170bf2 [NFC] Internalize TypeCheckerOptions in a TypeResolution Object
Add the appropriate assertions to ensure that the now-redundant options parameters are being kept in sync so they can be retracted.

The eventual goal is to have TypeResolution requestified.
2020-04-30 10:35:02 -07:00
swift_jenkins d8595f7cda Merge remote-tracking branch 'origin/master' into master-next 2020-04-30 00:54:04 -07:00
Pavel Yaskevich 326b371e10 [ConstraintSystem] Switch auxiliary functions to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
swift_jenkins 6f288fc6ac Merge remote-tracking branch 'origin/master' into master-next 2020-04-25 09:18:25 -07:00
Slava Pestov 742bd98402 Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance()
instead. Since this was the last flag in ConformanceCheckOptions, we can remove
that, too.
2020-04-25 00:14:24 -04:00
swift_jenkins 32dbe2ef15 Merge remote-tracking branch 'origin/master' into master-next 2020-04-24 12:19:34 -07:00
Pavel Yaskevich 7bdf0164d4 [ConstraintSystem] Replace remaining uses of TypedNode::dyn_cast with getAsExpr 2020-04-23 01:13:13 -07:00