Commit Graph

1082 Commits

Author SHA1 Message Date
Mark Lacey
2f80af15ec [ConstraintSystem] Use semantics providing exprs when dealing with favored types.
This allows us to eliminate some special casing around things like
parens, and allows the code to work for other code involving expressions
that are semantically neutral.
2017-11-30 19:11:59 -08:00
Chris Lattner
3f5790fb37 Enhance MemberLookupResult's UnviableCandidates list, NFC.
We now store an entire OverloadChoice in the unviable candidates
list (which is used for error recovery), just like we store them
for viable candidates.

The additional information isn't used, so NFC.
2017-11-26 14:29:00 -08:00
Pavel Yaskevich
7b121de1a0 [CSRanking] Change ranking to weight overload choices in evaluation order
Consider different overload choices for the same location in evaluation
order, this makes overload resolution more predictable because it's going
to follow expression bottom-up, that prevents situations when some
expressions are considered ambigious because choices taken further up
equate the score, instead each level is given distinct weight
based on evaluation order.

Resolves: rdar://problem/31888810
2017-11-16 13:38:24 -08:00
Slava Pestov
2d477d27eb Sema: Don't create redundant type variables for multiple references to the same closure parameter type 2017-10-20 23:29:17 -07:00
Greg Titus
bec95b2caa Merge pull request #12368 from gregomni/callee
[Sema] Some cleanup of CSDiag by splitting off the CalleeCandidateInfo class
2017-10-12 13:24:33 -07:00
gregomni
774dbdfa87 Some cleanup of CSDiag by splitting off the CalleeCandidateInfo class and
declaring a few formerly static methods that both files now need in a new
CSDiag.h.
2017-10-11 13:03:48 -07:00
Huon Wilson
96172048d3 [Sema/CS] Convenience function for adding a Requirement as a constraint. 2017-10-10 20:17:40 -07:00
Pavel Yaskevich
4317074a9a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-10-03 10:41:35 -07:00
Pavel Yaskevich
695baccc3e Revert "[ConstraintSolver] Prioritize certain type variables while looking for bindings"
This reverts commit 001b09747a.
2017-10-02 17:30:18 -07:00
Pavel Yaskevich
001b09747a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-09-30 14:36:16 -07:00
Pavel Yaskevich
c08610bb0b [ConstraintSolver] NFC: Prettify output of bindings in PotentialBindings 2017-09-27 20:47:20 -07:00
Pavel Yaskevich
3b06f2e897 Merge pull request #12072 from xedin/rdar-33429010
[ConstraintGraph] Don't try to contract edge of parameter bindings with `inout` attribute
2017-09-26 11:51:09 -07:00
Mark Lacey
e46d2a7216 [Constraint system] Move addPotentialBinding implementation back to CSBdinings.cpp.
The method is logically part of PotentialBindings, but the
implementation doesn't need to live in the header.
2017-09-25 16:52:41 -07:00
Mark Lacey
37cb6a80b3 Make Type::join return Any by default.
For the moment, update the sole caller to not infer Any in cases where
neither argument was Any. This is in part because not all the cases are
handled here and the result of inferring Any will be to miss appropriate
bindings in certain cases. It is also in part because by inferring Any
we may end up deferring diagnostics until later in a function, which may
result in very hard to understand diagnostics for users.

This will be revisted once all the cases are properly handled here.
2017-09-24 16:20:00 -07:00
Pavel Yaskevich
80e4a2226b [ConstraintGraph] Don't try to contract edge of parameter bindings with inout attribute
Currently edge related to the parameter bindings is contracted
without properly checking if newly created equivalence class has
the same inout & l-value requirements. This patch improves the
situation by disallowing contraction of the edges related to parameter
binding constraint where left-hand side has `inout` attribute set.

Such guarantees that parameter can get `inout` type assigned when
argument gets `l-value` type.

Resolves: rdar://problem/33429010
2017-09-22 17:23:12 -07:00
Pavel Yaskevich
c8fad863c4 [ConstraintSolver] NFC: Refactor PontentialBindings to reference type variable they belong to 2017-09-16 23:35:44 -07:00
Pavel Yaskevich
7d80daf0ff [ConstraintSolver] When ranking bindings prefer type vars with literal bindings
Change the potential binding ranking logic to prefer type variables
which don't have other type variables related to them, but have literal
bindings, over the ones that do have other type variables.
2017-09-15 22:19:39 -07:00
Pavel Yaskevich
8c2fa12ac9 [ConstraintSolver] NFC: Move addPotentialBinding into PotentialBindings 2017-09-15 13:31:15 -07:00
Mark Lacey
23c677ff52 [Constraint system] Hoist some code into a separate function.
The naming here might not be perfect as it's not the only place that we
bind types to typevars in matchTypes, but it is a step towards cleaning
things up a bit. I'll revisit naming after I get a better idea what
other common code there may be that can get factored out.
2017-09-10 01:32:13 -07:00
Mark Lacey
0f2ec380c9 Add LLVM_ATTRIBUTE_USED to some dumpers. 2017-09-07 23:10:39 -07:00
Mark Lacey
f9b9f4f68f [Constraint system] Fix debug output which is now missing a space.
This was a dumper bug introduced in 5afa52684d.
2017-09-07 23:03:49 -07:00
Mark Lacey
c07ea48b93 [Constraint system] Add another dumper for PotentialBindings.
This one takes a ConstraintSystem so it's a bit easier to call from the
debugger.
2017-09-07 15:04:30 -07:00
swift-ci
9367c74573 Merge pull request #11803 from rudkx/dump-potential-bindings 2017-09-07 12:30:04 -07:00
Mark Lacey
5afa52684d [Constraint system] Dump potential type variable bindings in CS dump.
Debugging aid. NFC.
2017-09-07 12:04:39 -07:00
Pavel Yaskevich
9d3a8584b4 [ConstraintSolver] NFC: Integrate type-check timeout timer into shrinking phase
To bound the amount of time shrinking is allowed to run, it has to be
integrated with timeout timer allocated for base constraint system.
2017-09-06 19:08:49 -07:00
Mark Lacey
e4f6b7705d Minor refactoring to reduce the chance of simple errors in updates. 2017-09-05 17:26:08 -07:00
swift-ci
fc8c1e3b89 Merge pull request #11632 from xedin/conversion-propagation 2017-08-28 18:34:38 -07:00
Pavel Yaskevich
562608bad8 [ConstraintSolver] Apply explicit coercions early to prune search space
When dealing with explicit coercions apply their conversions
early to avoid searching for solutions with incorrect types,
and therefore prune search space.
2017-08-28 17:42:05 -07:00
Slava Pestov
26cbdd8075 Merge pull request #11663 from slavapestov/cs-typemap-assert
Sema: Add some assertions to the expression type map code
2017-08-28 17:26:32 -07:00
Slava Pestov
804a23aa42 Sema: Add some assertions to the expression type map code 2017-08-28 16:34:51 -07:00
swift-ci
85576fe364 Merge pull request #11617 from xedin/constraint-buckets 2017-08-28 16:16:18 -07:00
Pavel Yaskevich
8bf03b5c43 [ConstraintSolver] Add Component class as an isolated "solvable" unit
Move disjunction selection logic one level up from the `solveSimplified`
which allows to simplify its logic and avoid collecting disjunctions
multiple times for each solver step.

Sort constraint components/buckets based on how many disjunctions
they have, that helps to prune some of the branches with incorrect
solutions early which limits overall depth of the search.

Resolves: SR-4714
2017-08-28 13:39:29 -07:00
Mark Lacey
a41fa9482f Try to ensure we try to bind the elements of BindParam constraints left-to-right.
If we allow the right-hand type to be bound first, it can artificially
limit the options for the left-hand side, so attempt to delay binding of
the right-hand side types until after we've chosen something for the
left-hand side.

The test here will not fail without this change, but will fail without
this change if the ConstraintGraph.cpp changes from @xedin's edge
contraction patch (https://github.com/apple/swift/pull/11118) are
applied.
2017-08-25 18:00:30 -07:00
Pavel Yaskevich
7a1bae85ae [ConstraintSolver] NFC: refactor candidate solver to use constraint system arena
While shrinking we have to allocate containers for the reduced domains
for some of the candidates, it's currently done using permanent arena
of the `ASTContext` allocator. This patch changes candidate solver to
use arena associated with the parent constraint system, which significantly
limits lifetime of domain containers.
2017-08-14 12:44:38 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Slava Pestov
69ca3c7593 Sema: Fix some typos 2017-07-24 22:58:04 -07:00
Slava Pestov
c8cf0a05cf Sema: Simplify matchSuperclassTypes() 2017-07-24 22:58:04 -07:00
Pavel Yaskevich
4f8872598b [ConstraintSolver] NFC: Add option to control early termination of shrinking phase
Currently we have a number of unsolved disjunctions hard-coded to 5,
which breaks some existing code by terminating shrinking too early.
This patch makes it a command-line option so users have control over
what that threshold can be.

Resolves: rdar://problem/33433595
2017-07-20 12:44:48 -07:00
Robert Widmann
ebfb3e8fd5 [NFC] Merge ExprCleaner and ExprCleanser
The distinction was made between these two because of rdar://25341015,
wherein we needed a diagnostic that could detect the shadowing of
global functions by calls in protocols that don't match any
of the protocol's members.

This used to function by hoping that we had an argument tuple type lying
around after type checking.  The expr cleaner would re-write that
type into the AST and we would look up based on it.  Now that we write
Type() into the AST on failure, we must instead type check the
component parts of the argument themselves to form a tuple
type to make the lookup.
2017-07-18 18:15:37 -07:00
Robert Widmann
d5328ea3cb Switch over function input matching to use Params
Currently handles non-constructor-based applies and function
parameter comparisons.
2017-07-11 15:17:31 -07:00
Mark Lacey
63601ae24e Merge pull request #10834 from rudkx/refactor-binding-code
[Constraint system] Begin refactoring type variable binding selection.
2017-07-09 13:09:44 -07:00
Mark Lacey
916ce8994b [Constraint system] Update type map code for recursion through salvage().
When we track which expressions we're already in the middle of type
checking, we need to ensure that we also track the constraint system
which has the types for that expression, and then transfer those types
into our current constraint system so that we do not fail to look them up.
2017-07-09 12:11:31 -07:00
Mark Lacey
7cd4102d01 [Constraint system] Begin refactoring type variable binding selection.
Split out the code for selecting potential bindings into a separate file
as a first step before refactoring it for improved clarity and ease of
modification.
2017-07-09 10:29:42 -07:00
Pavel Yaskevich
71c2c1e44a Merge pull request #10484 from xedin/rdar-32726044
[ConstraintSolver] Use a flag to prevent solver from removing possible solutions
2017-06-22 14:41:55 -07:00
Pavel Yaskevich
6231f85be9 [ConstraintSolver] Use a flag to prevent solver from removing possible solutions
In some situations e.g. while trying to shrink domains of the type
variables before attempting search, use a flag to tell constraint
system to retain all of the viable solutions otherwise solver could
loose some of the information required to produce complete solution.

Resolves: rdar://problem/32726044
2017-06-22 00:11:32 -07:00
Mark Lacey
fb593f5404 Merge pull request #10475 from rudkx/time-out-solver
Update determination of "too complex" expression to take time into account.
2017-06-21 20:51:27 -07:00
Mark Lacey
e51e3e4bd4 Update determination of "too complex" expression to take time into account.
By default, end expression type checking after the elapsed process time
is more than 60 seconds for the current expression. This threshold can
be overridden by using -solver-expression-time-threshold=<seconds>.

Resolves rdar://problem/32859654
2017-06-21 16:26:34 -07:00
Mark Lacey
05e79e6b02 Refactor how the expression type checker timer is set up.
Preparation for adding the ability for the expression type checker to be
halted after a period of time.
2017-06-21 14:18:25 -07:00
Robert Widmann
da35f11486 Merge pull request #10453 from CodaFi/high-and-DRY
Unify CallArgParam and AnyFunctionType::Param
2017-06-21 14:11:26 -07:00
Robert Widmann
0795c9946c Unify CallArgParam and AnyFunctionType::Param 2017-06-21 11:31:51 -07:00