Commit Graph

827 Commits

Author SHA1 Message Date
Hamish Knight
f9c0d25c39 [CS] Deindent a few debug messages
The additional indentation implies that they're
taking place in a new solver scope, but this isn't
the case.
2020-04-20 19:08:24 -07:00
Robert Widmann
48a5432cb7 [NFC] Remove ConformanceCheckFlags::InExpression
The last read of this bit was removed when the legacy referenced name tracker was deleted in the last commit.
2020-04-20 10:22:58 -07:00
swift_jenkins
8a10ab45eb Merge remote-tracking branch 'origin/master' into master-next 2020-04-10 07:40:52 -07:00
Doug Gregor
6999c318b7 Merge pull request #30924 from DougGregor/for-each-solution-application-target
[Constraint solver] Migrate for-each statement checking into SolutionApplicationTarget
2020-04-10 07:28:21 -07:00
Doug Gregor
1f232f7f53 [Constraint solver] Remove ExprTypeCheckListener.
The last client of this listener-based interface has been refactored,
so remove it.
2020-04-09 11:18:53 -07:00
swift_jenkins
c1468d9eb2 Merge remote-tracking branch 'origin/master' into master-next 2020-04-07 19:21:15 -07:00
Hamish Knight
71882996ca [CS] Adjust applied overload simplification
Currently `simplifyAppliedOverloads` depends on
the order in which constraints are simplified,
specifically that a lookup constraint for a
function gets simplified before the applicable
function constraint. This happens to work out
just fine today with the order in which we
re-activate constraints, but I'm planning on
changing that order.

This commit changes the logic such that it it's no
longer affected by the order in which constraints
are simplified. We'll now run it when either an
applicable function constraint is added, or a new
bind overload disjunction is added. This also
means we no longer need to run it potentially
multiple times when simplifying the applicable fn.
2020-03-29 18:33:59 -07:00
swift_jenkins
d21857a5fb Merge remote-tracking branch 'origin/master' into master-next 2020-03-25 12:00:00 -07:00
Pavel Yaskevich
4b3d075fb7 [ConstraintSystem] Produce fallback diagnostic on mismatch between fixes/holes
If score indicates that a solution should have at least one fix
but it doesn't let's attempt to produce a fallback diagnostic inline.
2020-03-24 16:51:44 -07:00
Rintaro Ishizaki
a7cb72fe55 Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	stdlib/public/Reflection/TypeRefBuilder.cpp
2020-03-10 12:46:49 -07:00
Pavel Yaskevich
7c19d1ccd1 [ConstraintSystem] Remove baseCS since CSDiag has been removed
There is no more sub-expression re-typechecking so no need to keep
parent constraint systems around.
2020-03-06 09:35:52 -08:00
swift_jenkins
29835814b6 Merge remote-tracking branch 'origin/master' into master-next 2020-03-05 09:38:08 -08:00
Pavel Yaskevich
4c600843d6 [ConstraintSystem] Check availability as part of resolving overload choice
This is a follow up to changes related to contextual availability
(https://github.com/apple/swift/pull/29921) which increased score
for unavailable declarations only if they were overloaded but
overlooked a case of a single unavailable choice.

Resolve: rdar://problem/60047439
2020-03-05 00:35:47 -08:00
swift_jenkins
a43b234c36 Merge remote-tracking branch 'origin/master' into master-next 2020-03-03 13:50:33 -08:00
Doug Gregor
8191aa4924 Merge pull request #30174 from DougGregor/function-builder-switch
[Constraint system] Implement switch support for function builders.
2020-03-03 12:34:08 -08:00
Nathan Hawes
a03dc92385 Merge remote-tracking branch 'upstream/master' into master-to-master-next 2020-03-02 19:06:34 -08:00
Doug Gregor
4b43573693 [Constraint system] Implement switch support for function builders.
Implement support for switch statements within function builders. Cases can
perform arbitrary pattern matches, e.g.,

    tuplify(true) { c in
      "testSwitchCombined"
      switch e {
      case .a:
        "a"
      case .b(let i, _?), .b(let i, nil):
        i + 17
      }
    }

subject to the normal rules of switch statements. Cases within function
builders cannot, however, include “fallthrough” statements, because those
(like “break” and “continue”) are control flow.

The translation of performed for `switch` statements is similar to that of
`if` statements, using `buildEither(first:)` and `buildEither(second:)` on
the function builder type.

This is the bulk of switch support, tracked by rdar://problem/50426203.
2020-03-02 17:25:25 -08:00
Hamish Knight
39d988da9c [CS] Remove ReturnAllDiscoveredSolutions flag
This is now no longer used.
2020-03-02 14:50:16 -08:00
Doug Gregor
13b200ddd5 [Constraint system] Generalize saved ASTNode -> solution target mapping.
We are currently only using the “solution targets” map for statement
conditions, but we will need it for more entities soon. Start generalizing
now.
2020-03-02 08:43:55 -08:00
swift_jenkins
dce5ca6447 Merge remote-tracking branch 'origin/master' into master-next 2020-02-24 21:00:10 -08:00
Doug Gregor
d2b2a50772 [Constraint system] Record application targets for statement conditions.
We’ll need this to generate constraints for statement conditions within the
constraint system. This is unused boilerplate at the moment.
2020-02-24 00:48:14 -08:00
swift_jenkins
567dba0f85 Merge remote-tracking branch 'origin/master' into master-next 2020-02-19 10:19:28 -08:00
Pavel Yaskevich
71753f3ca6 [ConstraintSystem] Rank contextually unavailable overloads lower than other choices (#29921)
Currently constraint solver is only capable of detecting universally unavailable
overloads but that's insufficient because it's still possible to pick a contextually
unavailable overload choice which could be better than e.g. generic overload, or
one with defaulted arguments, marked as disfavored etc.

Let's introduce `ConstraintSystem::isDeclUnavailable` which supports both universal
and contextual unavailability and allow constraint solver to rank all unavailable
overload choices lower than any other possible choice(s).

Resolves: rdar://problem/59056638
2020-02-19 13:13:53 -05:00
Hamish Knight
1a9764e6d7 [CS] Remove SubExpressionDiagnostics option 2020-02-19 07:43:59 -08:00
swift_jenkins
9fb3b6ac0e Merge remote-tracking branch 'origin/master' into master-next 2020-02-12 08:37:17 -08:00
Robert Widmann
86ea1912c4 Merge remote-tracking branch 'upstream/master' into HEAD 2020-02-11 23:03:59 -08:00
Doug Gregor
a308a7e53c [Constraint system] Sink down debug logging.
This way we’ll see constraints whenever they’re generated, and remove some
of the expression-centric nature of the top-level solve() and solveImpl().
2020-02-11 17:33:08 -08:00
Doug Gregor
f5b9517552 [Constraint system] Simplify and improve handling of node tyoes.
Rather than having separate dense maps for the type mappings of each
node type (expression, type location, variable declaration, pattern) that
a TypedNode can be, have a single such map. Sometimes we end up
setting a particular node's type more than once, so cope with that
by restoring the prior type.
2020-02-11 15:14:44 -08:00
swift-ci
91269532cd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-08 20:43:24 -08:00
Doug Gregor
efd4152061 [Constraint solver] Factor constraint generation logic for solution targets
Move more constraint generation logic for an expression target into a
new generateConstraints() on a solution target, so we can further
generalize the main “solve” logic.
2020-02-07 20:56:32 -08:00
swift-ci
48c4eebbf1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 02:42:48 -08:00
swift_jenkins
694b747b23 Merge remote-tracking branch 'origin/master' into master-next 2020-02-04 02:38:56 -08:00
Doug Gregor
bbc0a95723 [Constraint system] Simplify creation of contextual conversion constraint.
We were storing more state than necessary in the constraint system.
2020-02-03 22:38:24 -08:00
Doug Gregor
9569714334 Clarify method names in SolutionApplicationTarget. 2020-02-03 22:11:03 -08:00
Doug Gregor
36366bc3e4 [Constraint solver] One SolutionApplicationTarget instance to rule them all.
Capture the peculiarities of contextual types vs. types used to generate
conversion constraints, as well as the behavior of “optional some” patterns
as used by if let / while let, within SolutionApplicationTarget. This allows
us to use a single target throughout setup / solving / application, rather
than mapping between two similar-but-disjoint targets.
2020-02-03 22:02:21 -08:00
swift_jenkins
5e948447a8 Merge remote-tracking branch 'origin/master' into master-next 2020-01-31 09:59:04 -08:00
swift-ci
e9a3b96c74 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-31 09:43:03 -08:00
Doug Gregor
ce357312b6 [Constraint solver] Reinstate the fallback diagnostic, just in case. 2020-01-30 22:01:12 -08:00
Doug Gregor
e0702d9f2e [Constraint solver] Generalize solve() for arbitrary solution targets.
Start cleaning up the main “solve” entry point for solving an expression
and applying the solution, so it handles arbitrary solution targets.
This is another small step that doesn’t do much on its own, but will help
with unifying the various places in the code base where we run the solver.
2020-01-30 22:01:12 -08:00
Doug Gregor
54ac78d28f [Constrsint solver] Remove ExprTypeCheckListener::constraintGenerationFailed()
This function isn’t needed, because we can report the failure to the
caller directly rather than go through a callback.
2020-01-30 22:01:12 -08:00
Doug Gregor
56aeac5d0a [Constraint system] Push SolutionApplicationTarget into the solveImpl
Baby steps toward generalizing the expression-centric solver core.
2020-01-30 22:01:12 -08:00
Doug Gregor
e3124dcb5f [Constraint system] Expand SolutionApplicationTarget for expressions.
Add the final conversion type and the flag indicating whether a given
expression is discarded to SolutionApplicationTarget, rather than 
separating the arguments to the solver implementation.
2020-01-30 22:01:12 -08:00
Doug Gregor
98db6e6422 [Constraint solver] Don’t mark a moved-from instance as “diagnosed”. 2020-01-30 22:01:12 -08:00
swift_jenkins
aa9808300b Merge remote-tracking branch 'origin/master' into master-next 2020-01-27 20:57:51 -08:00
swift-ci
1122a6e01e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-27 20:44:22 -08:00
Doug Gregor
46a65009e3 [Constraint system] Eliminate global flag UnderlyingTypeForOpaqueReturnType
Make this information contextual (per type) rather than global (per
constraint system) so we don’t misapply it.
2020-01-27 15:44:54 -08:00
Doug Gregor
d752f414d3 [Constraint solver] Rework solveImpl(Expr*) to return SolutionResult.
SolutionResult better captures what can happen when solving a constraint
system for the given expression occurs than the ad hoc SolutionKind return
& small vector of Solution results. Also, try to make this logic less
convoluted.
2020-01-26 12:05:43 -08:00
Doug Gregor
5063cb5b79 [Constraint solver] Factor out adding a contextual conversion constraint. 2020-01-26 12:05:43 -08:00
Doug Gregor
f7744bd8b2 [Constraint solver] Make DeclContext explicit. NFC 2020-01-26 12:05:43 -08:00
swift_jenkins
1c3fcc6301 Merge remote-tracking branch 'origin/master' into master-next 2020-01-24 12:58:09 -08:00