Commit Graph

718 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
2fd247a833 [QoI] Improve contextual mismatch diagnostics in calls with trailing closures
Resolves: rdar://problem/28012273
2017-06-21 11:27:35 -07:00
Pavel Yaskevich
c46e3e83e8 [QoI] Improve diagnostics for single argument calls with trailing closures
Calls involving single trailing closure arguments require special
handling because we don't have as much contextual information
about function/argument types as in with regular calls, which means
that diagnosing such situations only by `visitApplyExpr`
yields subpar results.

Resolves: SR-4836.
2017-06-21 11:26:38 -07:00
Robert Widmann
9fa8341540 Only decompose function types for info about default arguments
AnyFunctionType::Param carries around information about decomposed
parameters now.  Information about default arguments must be computed
separately with swift::computeDefaultMap.
2017-06-19 23:05:44 -07:00
Pavel Yaskevich
3781877b93 [ConstraintSystem] Track conformance checking done while solving to validate solution
Track outcomes of `conformsToProtocol` calls in `simplifyConformanceConstraints`
to be able to validate conformances when solution is formed to avoid returning
solutions with nominal types with invalid conformances to protocols.
2017-06-15 14:18:36 -07:00
Pavel Yaskevich
3559047340 [ConstraintSolver] Unify value-to-pointer conversion scoring
Instead of having three different scores for - string, array, inout,
let's unify them under a single value-to-pointer score and use
it in appropriate places when simplifying restricted constraints.
2017-06-02 23:42:32 -07:00
Mark Lacey
567c9656f2 Merge pull request #10069 from rudkx/more-type-map-changes
[Constraint solver] More type map changes.
2017-06-02 10:42:46 -07:00
Mark Lacey
d1a0b35447 [Constraint solver] More type map changes.
A few more changes to use the side map for expression types in the
constraint solver. Still not enabled.
2017-06-02 08:13:57 -07:00
Pavel Yaskevich
9a4255e4bf Merge pull request #9717 from xedin/rdar-32034560
[ConstraintSystem] Prevent `shrink` from solving "too complex" sub-expressions
2017-06-01 21:47:47 -07:00
Pavel Yaskevich
5998cd645f [ConstraintSolver] Penalize conversions from String to UnsafePointer
There are possible situations when we find solutions with String
and String -> UnsafePointer conversions at the same time for
expressions with default string literals. In order to disambiguite
such situations let's prefer solutions without String -> UnsafePointer
conversions if possible.
2017-06-01 14:43:43 -07:00
Pavel Yaskevich
1bc7a1edb9 [ConstraintSolver] Skip generic overloads only if non-generic choices produce higher score solutions
Restrict skipping of the generic overloads only to the situations
when non-generic solution doesn't have any restrictions/fixes, because
there is a possibility that generic overload could produce a better
solution.

Resolves: rdar://problem/32204609.
2017-06-01 14:43:43 -07:00
Slava Pestov
6526d513c0 Sema: Remove the 'extraFunctionAttrs' hack 2017-05-31 17:31:37 -07:00
Pavel Yaskevich
fea7bcf232 [ConstraintSystem] Prevent shrink from solving "too complex" sub-expressions
Add additional checking for complexity of the shrinking candidate
given the number of the expressions solved so far and total number
of disjunctions present. This allows us to bail quicker in complex
expression cases which, at the very least, produces an error instead
of being "stuck" in solver for a long time.

Resolves: rdar://problem/32034560
2017-05-31 13:54:43 -07:00
Mark Lacey
fdc55395f2 Merge pull request #9928 from rudkx/type-map
[Constraint solver] More type map updates.
2017-05-31 09:07:53 -07:00
Mark Lacey
12926eb667 [Constraint solver] More type map updates.
More updates to read and write types from a side table in the constraint
solver and only write back into expressions when we've finished type
checking an expression.

We still write directly into expressions, and will continue to do so
until all of the code has been updated.
2017-05-31 00:36:09 -07:00