Commit Graph

1221 Commits

Author SHA1 Message Date
Pavel Yaskevich
0044c8f596 [ConstraintSystem] Add support for functionRef to SolutionApplicationTargetsKey::dump 2022-08-02 11:59:03 -07:00
Pavel Yaskevich
a6421fc94e [CSClosure] Declarations prefixed with $ can act as inferrable placeholders
If the type for such declaration could be completely inferred it
would be used during solution application. This is used to infer
types for result builder components.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
0457a72fdf Merge pull request #60222 from xedin/rdar-97396399
[ConstraintSystem] Retrieve contextual type from a solution for ambiguities
2022-07-28 09:28:09 -07:00
Hamish Knight
5418e8d934 [AST] Remove ArgumentList::composeTupleOrParenType
Remove a redundant bit of diagnostic logic now
that we better diagnose cases where an uncallable
variable is in an overload set for a mismatched
apply. Tweak another bit of diagnostic logic to
only apply to a single arg/param case, as that
seems to be what it's meant for.
2022-07-26 12:51:54 +01:00
Hamish Knight
09744f83fd [CS] Remove dead logic
This code seems to be ancient and dates back to
when `boundType` may have been a function type.
Nowadays it should always be a type variable.
2022-07-25 22:03:56 +01:00
Hamish Knight
13fe88cc57 [AST] Rename isCallableNominalType -> isCallAsFunctionType
Make it explicit that we're checking for
`callAsFunction` instead of `dynamicallyCall`.
2022-07-25 22:03:55 +01:00
Pavel Yaskevich
c300edb6ee [ConstraintSystem] Pass decl to diagnostic instead of trying to validate loc
`DiagnosticEngine` does the checking for declaration, so all we
need to do for ambiguity diagnostic is to use an overload declaration.
2022-07-25 11:05:44 -07:00
Pavel Yaskevich
399d3490d4 [ConstraintSystem] Add a tailored ambiguity diagnostic for non-conforming result type 2022-07-25 10:45:45 -07:00
Pavel Yaskevich
b07c887e02 [ConstraintSystem] Retrieve contextual from a solution for ambiguities
In ambiguity scenarios solutions are not applied back to the constraint
system, so it might not always have contextual type information when it
was recorded e.g. for a multi-statement closure.

Resolves: rdar://97396399
2022-07-25 09:28:22 -07:00
Jonathan Penn
be5babf28c Add experimental flag to turn on just opaque type erasure (#60172)
This was already enabled as part of `-enable-implicit-dynamic` but this
new flag allows turning on opaque type erasure all by itself whether or
not `dynamic` is added explicitly.

rdar://97375478
2022-07-22 23:43:22 -04:00
Pavel Yaskevich
d0289dc736 [ConstraintSystem] Adjust locator for implicit conversions between tuple elements
Drop `TupleType` element which is only used for diagnostics and
cannot be re-created by `ExprRewriter` during solution application.

Resolves: rdar://97389698
2022-07-21 12:08:01 -07:00
Alex Hoppen
57d504cbcd Merge pull request #60062 from ahoppen/pr/placeholder-for-errors
[CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
2022-07-20 14:15:43 +02:00
Alex Hoppen
eba95bacbd [CS] Delay type resolution of variables for variables in named pattern 2022-07-20 09:46:14 +02:00
Pavel Yaskevich
a35df66476 Merge pull request #60024 from xedin/rdar-96631324
[CSSimplify] Don't fix invalid r-value use for misplaced `&`
2022-07-19 09:15:00 -07:00
Alex Hoppen
393626f3b6 Merge pull request #59997 from ahoppen/pr/empty-locator-has-no-preconcurrency
[CS] Remove assertion that callee locator has an anchor
2022-07-14 22:02:11 +02:00
Alex Hoppen
944c3b5a39 Merge pull request #59915 from ahoppen/pr/solutionapplicationtarget-dump
[Sema] Add dump function to dump SolutionApplicationTargetsKey
2022-07-14 15:46:31 +02:00
Alex Hoppen
ae53e8a048 [CS] Remove assertion that callee locator has an anchor
When computing type relations of code completion items with respect to the context they are used in, we add a `ConstraintKind::Conversion` constraint with an empty constraint locator. This currently crashes in `hasPreconcurrencyCallee`, but actually having a null anchor doesn’t produce any issues.
2022-07-14 15:45:38 +02:00
Pavel Yaskevich
ff6112024e [CSSimplify] Don't fix invalid r-value use for misplaced &
When `&` is misplaced it creates r-value -> l-value mismatch
in the code which is just a consequence and shouldn't be diagnosed.

Resolves: rdar://96631324
2022-07-12 13:55:04 -07:00
Anthony Latsis
d74384cfcf Merge pull request #59931 from AnthonyLatsis/close-issues-3
Add regression tests to close several issues p. 3
2022-07-12 15:11:52 +03:00
Anthony Latsis
a359f7745c Add type-checker performance tracking test for #43369
To make this test work, fix an issue in `ConstraintSystem::salvage` where a
threshold breach during solving went unnoticed due to exiting on ambiguity
before reaching the `isTooComplex` check. Address this by moving the
`isTooComplex` check to before we start processing solutions, and stick another
one in `findBestSolution` for short-circuiting while we're here.
2022-07-09 16:34:19 +03:00
Doug Gregor
8ccaad3dec Merge pull request #59975 from DougGregor/cleanup-fix-behavior
Cleanup after recent refactoring for fix behaviors
2022-07-08 20:08:14 -07:00
Doug Gregor
7436fb365a Rename CSFix::affectsSolutionScore() to impact(). 2022-07-08 13:03:12 -07:00
Doug Gregor
de7b840661 Replace CSFix::canApplySolution() with isFatal(). 2022-07-08 13:03:12 -07:00
Doug Gregor
b9afb79f50 Merge pull request #59963 from DougGregor/constraint-system-preconcurrency
[Constraint solver] Track "isolated by preconcurrency" in the solver.
2022-07-08 09:52:24 -07:00
Doug Gregor
5b537eab1b Merge pull request #59958 from DougGregor/constraint-solver-recoverable-error
[Constraint solver] Improve fix behaviors for better concurrency-related recovery and overloading
2022-07-08 09:51:53 -07:00
Doug Gregor
4fc4bd79e8 [Constraint solver] Track "isolated by preconcurrency" in the solver.
Rather than only setting the isolated-by-preconcurrency bit during
constraint application, track the closures it will be set for as part
of the constraint system and solution. Then, use that bit when
performing "strict concurrency context" checks and type adjustments,
so we don't treat an inferred-to-by-`@Sendable`-by-preconcurrency
closure in the solver as if it weren't related to preconcurrency.

Fixes the spurious warning from
https://github.com/apple/swift/issues/59910.
2022-07-07 23:46:30 -07:00
Pavel Yaskevich
b35372367e Merge pull request #59902 from xedin/rdar-96469597
[CSApply] A couple of locator adjustments to support updated Double<->CGFloat conversion
2022-07-07 13:25:03 -07:00
Doug Gregor
c564698625 [Constraint solver] Improve modeling of fix behavior.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:

* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether

These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
2022-07-07 12:17:11 -07:00
Pavel Yaskevich
5432c34d70 [ConstraintSystem] Adjust Double<->CGFloat locator when used as dictionary key/value
Original locator carries information about key and value types which
is necessary for diagnostics but cannot be retrieved in its original
state during solution application, so it could be dropped from Double<->CGFloat
constructor locator.
2022-07-07 09:14:47 -07:00
Alex Hoppen
da07d2deb2 [Sema] Add dump function to dump SolutionApplicationTargetsKey 2022-07-07 09:58:48 +02:00
Doug Gregor
248b72bbff Track the pre-adjusted "reference" type for declaration reference. 2022-06-30 17:00:32 -07:00
Doug Gregor
1063e8126e [Constraint system] Track the original opened type for a selected overload. 2022-06-30 17:00:31 -07:00
Doug Gregor
045df94bca Delay @preconcurrency-related type adjustments until the last moment.
This allows us to retain the full opened type before adjustment when
needed, but should otherwise not change anything.
2022-06-30 16:59:54 -07:00
Pavel Yaskevich
3fd3ff0637 [TypeChecker] Adjust Double<->CGFloat conversion to always preserve its location
Unfortunately current approach of making a conversion independent of location
doesn't work when conversion is required for multiple arguments to the
same call because solver expects that either there are no Double<->CGFloat
conversions, or one of them has already been applied which is not the case.

The reason why locations weren't preserved in the first place is due to
how a solution is applied to AST - AST is mutated first and then, if there
are any conversions, they are applied to the already mutated version of
original AST. This creates a problem for Double<->CGFloat which depends
on an overload choice of injected call and it's impossible to find it based
on the mutated AST. But it turns out that this is only an issue in two
specific cases - conversions against contextual type and after optional injection.
This situations could be mitigated by dropping parts of the locator which are
unimportant for the Double<->CGFloat conversion - anchor in case of contextual
and `OptionalPayload` element(s) in case of optional injection.

Resolves: https://github.com/apple/swift/issues/59374
2022-06-28 13:47:47 -07:00
Pavel Yaskevich
8f69b9f2e0 [ConstraintSystem] Use '# of overloads' as a tie-breaker in ambiguities
The deepest expression is the one that introduced the ambiguity into
the chain, so depth and index should be deciding factors and number of
overloads - a tie-breaker, while choosing what to diagnose.

Resolves: rdar://94360230
2022-06-07 15:53:13 -07:00
Pavel Yaskevich
22daa865b5 [ConstraintSystem] Make for-in solution application target standalone
Previously for-in target was actually an expression target, which means
certain type-checking behavior. These changes make it a standalone target
with custom behavior which would allow solver to introduce implicit
`makeIterator` and `next` calls and move some logic from SILGen.
2022-05-30 23:17:41 -07:00
Pavel Yaskevich
689e9e3861 Merge pull request #42559 from xedin/se-0352-as-any-coercion
[TypeChecker] SE-0352: Require coercion if result type contains existential(s) that would loose generic requirements
2022-05-27 09:44:31 -07:00
Pavel Yaskevich
0a5b3f0727 [TypeChecker] SE-0324: Extend Swift -> C pointer conversions to inout
Fixes an oversight where `inout` -> C pointer conversion wasn't covered
by implementation of new pointer conversion semantics proposed by SE-0324.

Resolves: rdar://92583588
2022-05-25 20:55:22 -07:00
Pavel Yaskevich
773ea6b10c [TypeChecker] Require a coercion if result of protocol member access would loose information
Accessing members on the protocol could result in existential opening and subsequence
result erasure, which requires explicit coercion if there is any loss of generic requirements.
2022-05-25 16:07:06 -07:00
Pavel Yaskevich
f7c4ff6847 [ConstraintSystem] Adjust getCalleeLocator to handle implicit callAsFunction
A call to `.callAsFunction` could be injected after initializer if the type is
callable, `getCalleeLocator` should recognize that situation and return
appropriate locator otherwise if `callAsFunction` has e.g. a result builder
attached to one of its parameters the solver wouldn't be able to find it.

Resolves: rdar://92914226
2022-05-10 10:04:06 -07:00
Pavel Yaskevich
c05a07af05 Revert "[ConstraintSystem] Extend availability check to cover unavailable ext…" 2022-04-29 15:19:25 -07:00
Evan Wilde
8b2ccd9ed5 Merge pull request #58429 from etcwilde/ewilde/disjunction-main-resolution
Use Disjunction Constraint to find main function
2022-04-28 09:31:45 -07:00
Pavel Yaskevich
a240c0f637 Merge pull request #58466 from xedin/rdar-92364955
[ConstraintSystem] Extend availability check to cover unavailable ext…
2022-04-27 20:31:02 -07:00
Pavel Yaskevich
1359840ab3 Merge pull request #58400 from xedin/too-complex-improvements
[ConstraintSystem] Improve precision of "too complex" diagnostic
2022-04-27 19:58:31 -07:00
Pavel Yaskevich
9a32db7871 [ConstraintSystem] Extend availability check to cover unavailable extensions
The solver used to check availability attribute on the declaration
itself, a better approach is to go through `AvailableAttr::isUnavailable`
because that also covers unavailable extensions.

Resolves: rdar://92364955
2022-04-27 14:00:12 -07:00
Evan Wilde
5dfc6b8b72 Ignore async/sync mismatch on main
The main function is different from other function resolutions. It isn't
being called from a synchronous or asynchronous context, but defines
whether the program starts in a synchronous or async context. As a
result, we should not prefer one over the other, so the scoring
mechanism shouldn't involve the async/sync score when resolving the main
function.

This patch adds a constraint solver flag to ignore async/sync context
mismatches so that we do not favor one over the other, but otherwise use
the normal resolution behavior.
2022-04-26 16:29:51 -07:00
Evan Wilde
94e30a817e Revert "Add -async-main flag to favor asynchronous main"
This reverts commit da0a3311a5.
2022-04-26 16:29:45 -07:00
Pavel Yaskevich
6a65810d30 [Constraint] NFC: Rename ClosureBodyElement to SyntacticElement
`SyntacticElement` represents a statement, pattern, declaration,
condition, or expression and could originate from i.e. a closure,
a function or a result builder body.
2022-04-26 09:55:04 -07:00
Pavel Yaskevich
a40e8e80c1 [ConstraintSystem] Use affected range (if any) to diagnose 'too complex' failures 2022-04-25 14:09:45 -07:00
Pavel Yaskevich
ef2f24b82a [ConstraintSystem] Save "too complex" source range if known
This would help to diagnose the initial point where constraint
system has been determine to be "too complex"
2022-04-25 10:31:57 -07:00