Commit Graph

1956 Commits

Author SHA1 Message Date
Pavel Yaskevich
b05678f18e [ConstraintSystem] Allow static member references on protocol metatypes 2021-02-23 11:31:43 -08:00
Luciano Almeida
ef86e9edbe [ConstraintSystem] Adding new score kind SK_FunctionToAutoClosureConversion to increase impact of a function to autoclosure 2021-02-23 07:21:58 -03:00
Luciano Almeida
21a1d908b8 [CSSimplify] Increase score for closure argument when in a call autoclosure context to avoid ambiguity 2021-02-23 00:49:42 -03:00
Nathan Hawes
44e09bc246 Merge branch 'main' into dont-allow-missing-args-if-trailing-and-not-function-type 2021-02-23 12:53:50 +10:00
Nathan Hawes
cdcaa110e8 [CodeCompletion][Sema] Refine logic that ignores missing arguments after the code completion position when solving
If the completion loc was in a trailing closure arg, it only makes sense to
ignore later missing args if they have function type, as there's no way for the
user to complete the call for overload being matched otherwise.

Also fix a bug where we were incorrectly penalizing solutions with holes that
were ultimately due to missing arguments after the completion position.

Resolves rdar://problem/72412302
2021-02-20 08:59:47 +10:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
d78d95ef0d [AST] Introduce PlaceholderType and ThePlaceholderType singleton 2021-02-16 22:59:18 -05:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Doug Gregor
f13167d9d1 Merge pull request #35628 from DougGregor/concurrent-function-types
[Concurrency] Add @concurrent function types
2021-01-29 08:34:59 -08:00
Pavel Yaskevich
a7e8034396 [ConstraintSystem] NFC: Print type variables embedded in common result type 2021-01-28 14:01:29 -08:00
Doug Gregor
b77ba9a77f [Concurrency] Infer @concurrent on closures from contextual type 2021-01-27 16:00:39 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Pavel Yaskevich
fda3dc5127 Merge pull request #35607 from xedin/type-vars-accepts-set
[AST] Adjust `TypeBase::getTypeVariables` to accept a set
2021-01-27 09:51:45 -08:00
Pavel Yaskevich
b03dc63634 [AST] Adjust TypeBase::getTypeVariables to accept a set
Currently the pattern is to collect the type variables and then unique
them. Instead of asking clients to do uniquing, let's just accept a set
as an argument.
2021-01-26 18:13:34 -08:00
Varun Gandhi
86b123a35c [Sema] Diagnose type error on Clang type mismatch.
Fixes rdar://71904525.
2021-01-25 18:51:13 -08:00
swift-ci
a86430b937 Merge pull request #35580 from LucianoPAlmeida/SR-14050 2021-01-25 18:20:25 -08:00
Luciano Almeida
18e604a750 [Sema] Removing check for argument locator at subtype validation at matchFunctionRepresentations 2021-01-25 20:35:44 -03:00
Holly Borla
1ef2174bc2 Merge pull request #35025 from hborla/generic-overload-search-space
[ConstraintSystem] Implement heuristics for pruning the generic operator overload search space
2021-01-22 09:12:50 -08:00
Robert Widmann
d4f92d4116 Merge pull request #35527 from CodaFi/context-clues
Use the Correct DeclContext When Simplifying Member Constraints
2021-01-20 19:07:28 -08:00
Robert Widmann
0943351fe7 Use the Correct DeclContext When Simplifying Member Constraints
Looking for the parent source file is going to fail when the paramter
we're interested in comes from a module context. Request the correct
top-level context in those situations.

rdar://73379770
2021-01-20 15:42:35 -08:00
Varun Gandhi
d9cd7e73cd Merge pull request #35457 from varungandhi-apple/vg-cleanup-rep-matching
[docs] Tidy and document permissible conversions based on calling conventions
2021-01-20 13:28:54 -08:00
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