Commit Graph

844 Commits

Author SHA1 Message Date
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
gregomni
ab6d92b1cd Favor operators based on existing binds via both basename and type 2020-10-15 09:03:45 -07:00
Holly Borla
b06f749f0e [ConstraintSystem] Fix build failures and formatting. 2020-10-15 09:03:45 -07:00
gregomni
2edba9dfbd Instead of chaining binops, favor disjunctions with op overloads whose types match existing binding choices 2020-10-15 09:03:45 -07:00
Holly Borla
4c0f49f7a6 [ConstraintSystem] Remove selectApplyDisjunction, which was only used
by the operator designated types implementation.
2020-10-14 17:28:33 -07:00
Holly Borla
1e0038c3be [ConstraintSystem] Remove implementation of operator designated types
in the solver.
2020-10-14 16:05:54 -07:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
ab951c208a [ConstraintSystem] NFC: Move ConstraintGraph{Scope}.h to include/swift/Sema 2020-10-08 10:42:58 -07:00
Pavel Yaskevich
767c1a0ed6 [ConstraintSystem] NFC: Move SolutionResult.h to include/swift/Sema 2020-10-08 10:42:08 -07:00
Pavel Yaskevich
f94be56468 [Sema] Decouple ConstraintSystem and TypeChecker headers 2020-10-06 13:18:49 -07:00
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
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