Commit Graph

1240 Commits

Author SHA1 Message Date
Amritpan Kaur
b44c948bcc [ConstraintSystem] Print new type var assigned to generic in overload.
If overload choice has generic param, print type var assigned to generic param.
2022-09-01 20:25:13 -07:00
Pavel Yaskevich
932c6b40c5 [ConstraintSystem] Don't use special locator for value-to-value conversions related to contextual type
Previously locator for value-to-value conversion would just drop
all the contextual information if the conversion occurred while
converting expression to a contextual type. This is incorrect for
i.e. `return` statements and other targets because because they
are solved separately and using the same locator would result in
a clash when solutions are merged.
2022-08-25 14:33:03 -07:00
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Slava Pestov
e8dc19a70b Sema: Stop calling getAllConformances() on protocols 2022-08-23 00:03:37 -04:00
Pavel Yaskevich
3fd9037ee9 [ConstraintSystem] Don't produce argument info object for extraneous arguments
An extraneous argument doesn't have a corresponding parameter so the
information object for such an argument is not safe to produce.

Resolves: https://github.com/apple/swift/issues/60436
Resolves: rdar://98304482
2022-08-16 16:22:02 -07:00
Slava Pestov
bf755cc3b7 Merge pull request #60505 from slavapestov/misc-variadic-crap
AST: Minor generics changes
2022-08-11 05:12:06 -04:00
Slava Pestov
87871d7347 AST: Rename getOpenedArchetypeSignature() to getOpenedExistentialSignature() 2022-08-10 23:44:36 -04:00
Amritpan Kaur
fd41a39294 [ConstraintSystem] Refactor solver state depth to its own function for easier indent editing in future. 2022-08-10 13:29:02 -07:00
Pavel Yaskevich
42135e27c4 Merge pull request #60387 from amritpan/improve-solution-printing
[ConstraintSystem] Improve solution printing in the type inference algorithm debug output
2022-08-10 09:03:29 -07:00
Slava Pestov
11eb11833f Sema: Fix deep equality matching for parameterized protocol types
Fixes rdar://problem/98356057.
2022-08-09 23:45:39 -04:00
Amritpan Kaur
2786f24b67 [TypeCheckConstraints.cpp] Remove printing of any empty constraint choice headings and fix minor spacing issues. 2022-08-09 14:09:39 -07:00
Slava Pestov
03f2225d96 Merge pull request #60463 from slavapestov/reduced-types
AST: Rename 'canonical wrt. generic signature' to 'reduced'
2022-08-09 16:12:58 -04:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Pavel Yaskevich
b39302a585 Merge pull request #60203 from xedin/rdar-96997534
[CSGen] Allow `_` pattern to be a hole
2022-08-08 10:14:18 -07:00
Pavel Yaskevich
f9ab9ac775 [ConstraintSystem] NFC: Fix a warning by switching from dumpContext to printContext 2022-08-05 09:52:16 -07:00
Pavel Yaskevich
5ee5a22cf1 [TypeChecker] NFC: Add a dedicated method to get outermost attached wrapper
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
2022-08-04 17:30:02 -07:00
Pavel Yaskevich
dee6a31ac9 [ConstraintLocator] Generalize pattern decl locator to support "named" and "any" 2022-08-03 15:50:33 -07:00
Pavel Yaskevich
3e65a7cab0 Merge pull request #60065 from xedin/result-builder-ast-transform-under-flag
[TypeChecker] Implement result builder transform via AST modification under a flag
2022-08-02 16:22:01 -07:00
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
Hamish Knight
1bf954c61f [CS] Better diagnose inout argument in tuple construction
Previously we relied on `TupleTypeElt::getType`
returning an `InOutType` to fail the tuple type
matching logic. Instead, add logic to reject any
inout arguments up-front with a more specific
diagnostic.

Also, while we're here, strip the `_const`
parameter flag, as it's not something that needs
to be considered for tuple construction.
2022-08-02 13:56:30 +01: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