Commit Graph

159 Commits

Author SHA1 Message Date
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Alex Hoppen
3c90c892e9 [CodeCompletion] Drop ForCodeCompletion constraint system option for syntactic elements that don't contain completion token 2022-12-21 12:17:56 -08:00
Pavel Yaskevich
6b3776456c Merge pull request #62053 from abdulowork/improve-type-checker-debugging-indentation
Improve indentation in type checker debugging output
2022-11-30 12:11:27 -08:00
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Timofey Solonin
3c401a1c7e Fix unbalanced braces in debugging output 2022-11-17 22:26:19 +08:00
Hamish Knight
f2404feb91 [CS] Factor out BindingSet::favoredOverConjunction
And refactor the way we select the next step for
a ComponentStep. This should be NFC.
2022-11-14 20:03:41 +00:00
Amritpan Kaur
254bd8262a [CSStep] Fix type variable printing inconsistency. 2022-09-12 13:07:37 -07:00
Amritpan Kaur
7c3cb4f570 [CSBindings] Fix double printing of type variables.
Fix spacing when printing initial Type Variables. Add
line break to bindings that print under Potential Bindings.
2022-09-01 20:44:04 -07:00
Amritpan Kaur
5784f74b29 [CSStep] Fix extraneous ) printed during nested ConjunctionSteps.
~ConjunctionStep called before all steps are finished.
2022-09-01 20:25:18 -07:00
Amritpan Kaur
f683c2ca16 [CSStep] Remove extraneous ) printing after PotentialBindings/Disjunctions.
Moved `debugLogger` into each if-block so it's indentation doesn't affect next `isDebugMode`.
2022-08-25 15:19:21 -07:00
Amritpan Kaur
72190ed7fa [CSStep] Print disjunctions with bindOverload choices.
Print all disjunctions in scope, not just the one selected. Remove conjunction printing.
2022-08-25 15:19:19 -07:00
Amritpan Kaur
51281c54c4 [CSBindings] Move binding printing out of determineBestBindings and check that bindings exist before printing. 2022-08-22 16:26:45 -07:00
Amritpan Kaur
177f136164 [CSStep] Add disjunction and conjunction printing to initial state displayed during component step. 2022-08-20 18:03:30 -07:00
Amritpan Kaur
e3e446b918 [CSStep] Remove previous "Initial binding" output. 2022-08-20 18:03:30 -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
Amritpan Kaur
6895b057b2 [ConstraintSystem] Refactor Score printing to use new method that also prints non-zero ScoreKind description. 2022-08-09 14:10:15 -07:00
Pavel Yaskevich
ad34bdd296 [CSStep] NFC: Fix a typo in a comment: ambguous -> ambiguous 2022-08-02 11:59:03 -07:00
Amritpan Kaur
77ae8d49ca [CSStep] Fix closing paren indentation at end of Conjunction Step. 2022-07-21 13:31:27 -07:00
Pavel Yaskevich
4debf30f58 [CSStep] Conjunction: Propagate fix and hole scores to outer solution
While producing a combined solution, let's reflect the number of
fixes and holes discovered in the conjunction, that way it would
be possible to filter solutions and keep track of the fact that
there were issues in the conjunction.
2022-05-18 00:32:14 -07:00
Pavel Yaskevich
609b3e5246 [CSStep] Conjunction: Tranform all unbound outer variables into placeholders during ambiguity
Since conjunction is not going to continue current solver path
after discovering an ambiguity, let's just mark all of the
unbound outer variables as placeholders to produce a complete solution.
2022-05-18 00:28:08 -07:00
Pavel Yaskevich
7dab90cd98 [ConstraintSystem] NFC: Drop Expression from isTooComplex check
Solver can now handle multiple different targets e.g. multi-statement
closures, result builders etc. So it's more appropriate to say that
the constraint system is too complex.
2022-04-25 10:14:39 -07:00
Josh Soref
4c77c59269 Spelling sema (#42474)
* spelling: accessibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: accessories

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: adjustments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: all

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: ambiguous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: arguments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assignment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assumes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: auxiliary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: belongs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: checking

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: compatibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completely

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: complicated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conformance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constrained

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constraint

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: contextual

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: convertible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: couldn't

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declaration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: defaultable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: depending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: describe

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expects

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicitly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expression

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: first

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: font

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: forward

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: given

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: global

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: happened

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: hierarchy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identical

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: immediately

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: implicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indicates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initializer

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: integrity

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interpolation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: introducing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: involved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: just

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: like

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: likewise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mismatch

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: missing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: more

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessarily

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: noescape

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonetheless

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: operators

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: otherwise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outside

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overridden

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: override

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: penalize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: platforms

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: precedence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preemptively

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preliminary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preserve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: qualifier

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: question

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: really

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: received

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: references

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replacement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representative

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requirement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requires

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: resolved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: retrieve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewriting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: semantics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: signature

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: similar

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplest

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: solver

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: struct

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: structurally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sure

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: symmetric

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: syntactically

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: target

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: themselves

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: these

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: this

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transform

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transparent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: tread

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: truncation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: type

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unconstructable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: universally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unknown

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unwrapped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: versioned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: visible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: where

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-20 15:12:46 -07:00
Anthony Latsis
4bbad02bf2 [NFC] Supplant RequirementCheckResult with CheckGenericArgumentsResult::Kind 2022-03-28 22:55:02 +03:00
Pavel Yaskevich
1636ee83c3 [CSStep] Conjunction: Give each conjunction step a fresh timer
Original timer cannot be used each expression in the multi-statement
closure is type-checked independently.
2022-02-08 15:23:20 -08:00
Pavel Yaskevich
2a1d539010 [CSStep] Reset scope counter before attempting conjunction step
Each conjunction step should be executed in isolation from outer
constraint system state, which should also include scope counter
because otherwise, e.g. for large closures, solver might stop
prematurely since all of the previous statements/expressions would
contribute to the scope total.
2022-02-08 14:33:39 -08:00
Pavel Yaskevich
d7984f4453 [ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location
could bw inferred from a body of a multi-statement closure (when inference
is enabled), so we need to give closure a chance to run before attemtping
a hole for such positions in diagnostic mode.
2021-12-03 10:57:42 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
aa3b8867a3 [ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location
could bw inferred from a body of a multi-statement closure (when inference
is enabled), so we need to give closure a chance to run before attemtping
a hole for such positions in diagnostic mode.
2021-11-15 16:42:06 -08:00
Pavel Yaskevich
c25952fa0d [CSStep] Conjunction: Drop element scores in ambiguity cases 2021-10-21 16:26:58 -07:00
Pavel Yaskevich
2384eb2c06 [CSStep] Conjunction: Stop after first ambiguous or fixed element
Stop a conjunction after the first invalid element in diagnostic mode.

No need to run the inference for other elements once the problem has been
found. All ambiguities and solutions with fixes are propagated back to the
outer context to be diagnosed.
2021-10-14 12:00:18 -07:00
Pavel Yaskevich
2ee5b3005f [CSStep] Conjunction: Extract constraint system state restoration into a method
In preparation to handle ambiguities in the elements, it's useful
to extract the logic dealing with constraint system state restoration
into a separate logical entity.
2021-10-14 11:20:54 -07:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
Pavel Yaskevich
67a721485f [ConstraintSystem] Compute variables referenced by conjunction elements incrementally
Attempting to pre-compute a set of referenced type variables
upfront is incorrect because parameter(s) and/or result type
could be bound before conjunction is attempted. Let's compute
a set of referenced variables before each element gets attempted.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
c554fca5f7 [CSStep] Isolated conjunctions can't see outer solutions
All of the previously deduced solutions should be hidden
until isolated conjunction is successfully solved.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
98a6a8441c [CSStep] Conjunction: integrate isolation scope into snapshot
It helps to simply handling of outer constrants because they have
to be added to the constraint system before scope is created but
constraint graph have to get updated after to make sure that
incremental binding inference already knows about types inferred
from conjunction.
2021-10-08 10:08:02 -07:00
Pavel Yaskevich
405034f416 [CSStep] Always restore snapshot once isolated conjunction step is done
Turn `SolverSnapshot::restore` into a destructor to make sure that
constraints are always returned when optional is reset.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
f05ec83e01 [CSStep] Filter solutions after each conjunction step
`SplitterStep` doesn't filter solutions if it results in a single
component (which is does for conjunction elements), so the solutions
have to be filtered manually after each element is done.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
1fa7e1d72c [CSStep] Fail conjunction if element attempt fails 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
28d1bacdce [ConstraintSystem] Implement conjunction step
Iterate over all of the elements one-by-one and make sure that
each results in a single solution, otherwise fail the conjunction step.

Once all of the elements are handled either stop or,
if conjunction step has been performed in isolation,
return all of the outer constraints back to the system
and attempt to solve for outer context - that should
produce one or more solutions for conjunction to be
considered successfully solved.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
27275f6214 [CSStep] Add an implementation of ConjunctionStep
It behavies similar to `DisjunctionStep` but attempts all of
its elements unless there is an inference failure.
2021-10-08 10:08:00 -07:00
swift-ci
849dee3b22 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-06 15:33:39 -07:00
Pavel Yaskevich
48d4997891 [CSStep] Don't abort upon discovering constraint system in an invalid state
Setting `InvalidState` already makes sure that there is no possibility
of miscompile.
2021-08-06 10:24:39 -07:00
Pavel Yaskevich
d8cdbcd0c7 [ConstraintSystem] Add InvalidState flag to indicate that any attempt to solve should fail
As soon as `InvalidState` flag is set solving of the constraint
system as aborted and all subsequent calls to `solveImpl` would
produce no solutions.
2021-08-06 10:03:05 -07:00
Pavel Yaskevich
04faa2aadb [ConstraintSystem] Remove check for left-over free type variables since it's handle gracefully 2021-08-05 16:05:54 -07:00
Pavel Yaskevich
b07139e591 [ConstraintSystem] Relax the left-over information check in ComponentStep
Instead of crashing in release builds, let's simplify fail the
step and let type-checker produce a fallback diagnostic. Maintain
a trap in debug builds to make it easier to investigate the root
cause of the issue.

Resolves: rdar://56167233
2021-08-05 15:08:13 -07:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07:00
Holly Borla
2d851ff619 Merge pull request #38700 from hborla/improve-transitive-conformance-heuristic
[ConstraintSystem] Improve the "transitive conformance" heuristic and remove early conformance checking from `DisjunctionStep::shouldSkip`
2021-07-31 13:51:49 -07:00
Holly Borla
241c1e4ea0 [ConstraintSystem] Remove the conformance checking heuristic in
DisjunctionStep::shouldSkip. This heuristic is generalized via the
transitive conformance constraint.
2021-07-29 19:32:06 -07:00
swift-ci
fd87ebc401 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-23 07:13:34 -07:00
Robert Widmann
1329f3cfbd [NFC] Lift getGenericEnvironment() into GenericSignature 2021-07-22 23:33:02 -07:00