Commit Graph

1735 Commits

Author SHA1 Message Date
Varun Gandhi
aac0a9a9ed [doc] Document function representation conversions inline. 2021-01-19 10:48:13 -08:00
Varun Gandhi
3301ae90e0 [NFC] Simplify function type representation checks. 2021-01-19 10:48:13 -08:00
Varun Gandhi
66dfea141c [doc] Document function representation subtyping rules. 2021-01-19 10:48:12 -08:00
Varun Gandhi
5d3984e027 [NFC] Flip polarity of matchFunctionRepresentations.
The existing polarity is sufficiently confusing that it has an
explanatory comment at a return statement.
2021-01-15 10:45:03 -08:00
Pavel Yaskevich
f6637276fd [ConstraintSystem] Increase score only if members found on Optional and its unwrapped type
Unresolved member lookup is allowed to perform implicit optional
unwrap of a base type to find members. Previously if there were
any members directly on `Optional`, lookup would stop there. But
since SR-13815 it became possible for solver to attempt members
found on unwrapped type even if there are viable ones on
`Optional` as well.

New score kind has been introduced to guard against possible ambiguities
with new scheme - `SK_UnresolvedMemberViaOptional`. It's used very
time member found via base type unwrap is attempted. Unfortunately,
doing so can lead to behavior changes in existing code because it's
possible that base was wrapped into optional implicitly based on
context e.g. unresolved member passed in as an argument to a parameter
of optional type.

To fix situations like that, `SK_UnresolvedMemberViaOptional` should
only be increased if there is a mix of members to attempt - both directly
on `Optional` and on unwrapped type, in all other cases score should stay
the same because there could be no ambiguity.

Resolves: rdar://73027153
2021-01-13 09:12:03 -08:00
Pavel Yaskevich
87cc597d19 [ConstraintSystem] Stop using CheckedConformances cache
It was necessary only for `applySolutionToForEachStmt` in `CSApply`,
diagnostic can avoid it and use information stored in the locator
instead.
2021-01-08 11:36:34 -08:00
Pavel Yaskevich
7fb4815d53 Merge pull request #35291 from xedin/sr-13951-followup
[Diagnostics] Attempt `.rawValue` fix only if both types are equally …
2021-01-07 12:48:33 -08:00
Pavel Yaskevich
26415547e0 [Diagnostics] Attempt .rawValue fix only if both types are equally optional
This is a follow-up to https://github.com/apple/swift/pull/35072.

Let's wait until both sides are equally optional before attempting
`.rawValue` fix, otherwise there is a risk that a valid code would
get diagnosed.

Extend test coverage of possible `.rawValue` situations to
contextual and argument positions to make sure that valid
code is accepted.

Resolves: SR-13951
2021-01-07 09:02:20 -08:00
Pavel Yaskevich
33f34d15f6 Merge pull request #35281 from xedin/rdar-72819046
[Diagnostics] Special case requirement failures related to `return` statement/expression
2021-01-07 08:56:15 -08:00
Holly Borla
e24ac86eaf [ConstraintSystem] Cache applied disjunction constraints in the
constraint system to use later in DisjunctionStep.
2021-01-06 13:36:38 -08:00
Pavel Yaskevich
4917d4314b [ConstraintSystem] Use new ConformanceRequirement to record checked conformances and conditional requirements 2021-01-06 11:01:35 -08:00
Slava Pestov
c4c27f6304 Merge pull request #35205 from slavapestov/nfc-evaluator-cleanup
Small NFC request evaluator cleanup
2021-01-05 17:55:31 -05:00
Luciano Almeida
1c94fb468c [Sema] Dont record treat as rvalue fix in repairFailures for assignment when destination type is a type variable 2021-01-05 00:14:31 -03:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Pavel Yaskevich
0e6260dd89 [Diagnostics] Special case assignment between nominal types with optional promotion
Skip fixing situation where source and destination of assignment are both
nominal types with different optionality until restriction is attempted.

Otherwise fix could be too greedy and diagnose valid code if all of the
types are known in advance.

Resolves: SR-13951
Resolves: rdar://problem/72166791
2020-12-11 20:49:43 -08:00
Luciano Almeida
e4d4c0b32e [Sema] Moving detection of fix base type for optional member to attempt fix method 2020-12-08 00:19:39 -03:00
Luciano Almeida
d954b840fd [tests] Adjusting SR-11535 test case on the suit 2020-12-05 22:48:09 -03:00
Luciano Almeida
1c9ba53038 [CSSimplify] Detect and record optional base infered base for unresolved member that could be an unwraped base member 2020-12-05 22:48:09 -03:00
Frederick Kellison-Linn
a53b1e4f3f [Sema] Always look through optionals for unresolved member lookup 2020-12-04 12:11:10 -05:00
Doug Gregor
50cdddaf95 [Concurrency] Enable implicit conversion from synchronous -> asynchronous. 2020-12-03 12:44:21 -08:00
Luciano Almeida
ac65e6fcc4 [Sema] Detect if we should use a conditional binding when recording the CoerceToCheckedCast fix 2020-12-01 09:03:17 -03:00
Nathan Hawes
1eb05b7760 Merge pull request #34733 from nathawes/migrate-unresolved-completion
[CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
2020-11-19 01:26:43 -08:00
Nathan Hawes
86ddd52204 [Sema] Extract out expression-contains-completion-loc check into a method on ConstraintSystem (NFC) 2020-11-19 09:32:38 +11:00
Nathan Hawes
ca7fb37aba [CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
Following on from updating regular member completion, this hooks up unresolved
member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API
to generate completions from all solutions the constraint solver produces (even
those requiring fixes), rather than relying on a single solution being applied
to the AST (if any). This lets us produce unresolved member completions even
when the contextual type is ambiguous or involves errors.

Whenever typeCheckExpression is called on an expression containing a code
completion expression and a CompletionCallback has been set, each solution
formed is passed to the callback so the type of the completion expression can
be extracted and used to lookup up the members to return.
2020-11-13 15:37:14 -08:00
Slava Pestov
3343a6a408 Merge pull request #34671 from slavapestov/conformance-availability-solution-ranking
Sema: Check conformance availability when ranking solutions
2020-11-12 15:33:31 -05:00
Nathan Hawes
edbbefce91 [CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
In the single-element case, it is treated as the dictionary key.

func takesDict(_ x: [Int: String]) {}
takesDict([]) // diagnose with fixit to add missing ':'
takesDict([1]) // diagnose with fixit to add missing ': <#value#>'
takesDict([foo.<complete>]) // prioritise Int members in completion results -
                            // the user just hasn't written the value yet.

The above previously failed with a generic mismatch error in normal type
checking (due to the literal being parsed as an array literal) and code
completion could not pick up the expected type from the context.
2020-11-11 11:48:39 -08:00
Slava Pestov
0ff82ca051 Sema: Check conformance availability when ranking solutions
This completes the work on <rdar://problem/35158274>, and also
adds a test case for <rdar://problem/50627401>.
2020-11-10 17:52:51 -05:00
Pavel Yaskevich
d7c6c00e04 Merge pull request #34614 from xedin/improvements-to-ambiguity-diags
[Diagnostic] Improve diagnostics for situations with ambiguity caused by conformance requirements
2020-11-09 16:07:11 -08:00
Pavel Yaskevich
66fbdce2f8 [ConstraintSystem] Don't increase a score for conditional requirement failures
Let's consider conditional requirement failure to mean that parent
conformance requirement wasn't satisfied and nothing more, that helps
to disambiguate certain situations and avoid filtering out conditional
failures.

Resolves: rdar://problem/64844584
2020-11-06 12:06:00 -08:00
Pavel Yaskevich
1f1400581f Merge pull request #34584 from xedin/rdar-70880670
[CSGen] Turn invalid decls into holes
2020-11-05 12:09:06 -08:00
Pavel Yaskevich
f1fd528a1b [CSFix] Add a fix to detect/diagnose references to invalid declarations
Upon attempt to generate constraints for invalid declaration reference
let's turn that into a hole and record this new fix to diagnose it
once solution has been reached.
2020-11-03 17:52:40 -08:00
Pavel Yaskevich
fa5c7120ef [ConstraintSystem] Ignore value-to-optional conversions to correctly detect conformance failures
If there is a conformance failure related to existential conversion
let's ignore that fact that there could be an implicit value-to-optional
conversion involved, because it's not the main issue in cases like
that.

Resolves: rdar://problem/70814576
2020-11-03 15:51:55 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Pavel Yaskevich
92fe04f31f Merge pull request #34432 from xedin/remove-rvalue-adjument
[ConstraintSystem] Remove `RValueAdjustment` locator element
2020-10-26 12:08:09 -07:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
2020-10-26 00:40:45 -07:00
Azoy
f21a306ae5 [AST] Introduce BuiltinProtocolConformance 2020-10-22 18:24:27 -04:00
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
Pavel Yaskevich
a0a37d2a71 Merge pull request #34356 from xedin/record-trailing-even-if-types-are-equal
[ConstraintSystem] Record trailing choice match choice when arguments…
2020-10-19 16:20:00 -07:00
swift-ci
b654008443 Merge pull request #34337 from nathawes/allow-missing-args-when-type-checking-for-completion 2020-10-19 15:26:50 -07:00
Pavel Yaskevich
340d1e843a [ConstraintSystem] Record trailing choice match choice when arguments/result are equivalent to applied function 2020-10-19 13:55:55 -07:00
Nathan Hawes
15f5222bbd [CodeCompletion][Sema] Allow missing args when solving if the completion location indicates the user may intend to write them later.
func foo(a: Int, b: Int) {}
func foo(a: String) {}

// Int and String should both be valid, despite the missing argument for the
// first overload since the second arg may just have not been written yet.
foo(a: <complete here>

func bar(a: (Int) -> ()) {}
func bar(a: (String, Int) -> ()) {}

// $0 being of type String should be valid, rather than just Int, since $1 may
// just have not been written yet.
bar { $0.<complete here> }
2020-10-19 12:16:19 -07:00
Luciano Almeida
883d583a2f [CSSimplify] Make sure visit and record holes recursivelly for dependent member type 2020-10-16 18:32:20 -03:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
4954763524 [ConstraintSystem] NFC: Move CSFix.h to include/swift/Sema 2020-10-08 10:43:18 -07:00
Pavel Yaskevich
e254f1c3e2 [ConstraintSystem] Infer whether locator is related to return of a single-expression function
This information could be inferred from state recorded in a
constraint system, so to need to record that in the
constraint locator as well.
2020-10-01 11:49:30 -07:00
Pavel Yaskevich
7d6a110210 [CSSimplify] Allow optional object constraint to look through holes
If right-hand side (optional type) has been determined to be a hole,
let's establish that optional object of a hole is a hole and continue
searching for a solution.
2020-09-25 15:00:20 -07:00
Pavel Yaskevich
a4701f7d89 [ConstraintSystem] Adjust overload filtering to be less aggressive in code completion mode
Avoid filtering overloads for calls which have code completion
token as an argument, that would always undesired results,
because such calls could be missing arguments before or after
the token.
2020-09-23 17:29:43 -07:00
Pavel Yaskevich
c946c803db Merge pull request #34036 from xedin/replace-error-types-with-holes
[CSGen] Avoid failing on invalid declarations
2020-09-23 11:58:32 -07:00
Pavel Yaskevich
bdfa8d9099 [AST] Allow hole types to originate from declarations
Associating holes directly with declarations is useful in
cases when declarations are invalid e.g. directly `ErrorType`
or have error types inside.
2020-09-22 15:47:57 -07:00