Commit Graph

718 Commits

Author SHA1 Message Date
Pavel Yaskevich
d62be440ce [CSSolver] Split `getType(ValueDecl*) into three - getType{OrNull, OrInterfaceType} 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
398abdfb7c [CSSolver] Add closure parameter type caching
While inferring avoid associating type variables with closure
parameters, use cache instead and only set types when everything
is properly type-checked, this avoids multiple problems one of
them - leaking type variables outside of constraint system they
belong to.
2018-07-28 20:28:41 -07:00
Mark Lacey
8f9fcaa275 Merge pull request #18325 from rudkx/minor-refactoring
[ConstraintSystem] Some small clean-ups to getFixedType, getFixedTypeRecursive, and simplifyType
2018-07-28 19:15:12 -07:00
Mark Lacey
b900b5df0b [ConstraintSystem] Tiny simplification of function. 2018-07-27 19:34:12 -07:00
Doug Gregor
d9c6fcfefa Merge pull request #18305 from DougGregor/constraint-solver-timer-perf
[Constraint solver] Reduce timer overhead associated with "expression too complex"
2018-07-27 17:11:28 -07:00
Doug Gregor
0af09d3f25 Revert "[ConstraintSystem] Add a way to get the elapsed time we've spent in a SolverScope."
This reverts commit 656952af9d.
2018-07-27 14:12:27 -07:00
gregomni
5faa8bf4d1 Don't offer force-unwrap of the base as a possible fixit for optional
member access if optional chaining is sure to be valid.
2018-07-27 13:56:24 -07:00
Pavel Yaskevich
dfad872cea [ConstraintSystem] Attempt to apply fixes in AST walker order
This makes sure that the diagnostics appear in the stable order
which is closer to what users would expect e.g. evaluation
order, otherwise, because disjunctions are currently attempted
based on their size, ordering of error messages produced by
applying fixes is completely arbitrary.
2018-07-25 13:32:16 -07:00
Pavel Yaskevich
62eccd53ad [ConstraintSystem] Use fixes to diagnose missing argument labels
Let the solver disregard missing argument labels and record correct
ones, so such problem could be diagnosed later on iff there were no
other more serious failures.
2018-07-24 22:11:56 -07:00
Pavel Yaskevich
91e330c289 [TypeChecker] Improve argument label matching
* Improve label mismatch callback:
 - Split "missing label" callback into 3 - missing, extraneous, incorrect (with typo(s));
 - Allow label callbacks to indicate if it's a fatal error or not;
* Improve matching of the variadic parameters;
* Improve matching of the parameters with defaults;
* Try to look for an argument with matching label before fallback to
  forced claming (if allowed).
2018-07-21 23:21:42 -07:00
Mark Lacey
c0007f8168 Revert "[ConstraintSystem] Fix the ordering of functions with optional parame…" 2018-07-19 00:21:12 -07:00
Mark Lacey
186c2f251a [ConstraintSystem] Fix the ordering of functions with optional parameters.
Treat non-optional generic parameters as being more specialized than
optional generic parameters, and penalize any solutions that involve
generic arguments that are themselves Optional.

By doing these things, we can remove the special-cased code for the
two overloads of '??' in the stdlib, instead treating the (T?, T)
overload as better than the (T?, T?) overload except where a user
actually passes an optionally-typed value as the second parameter.

Fixes: rdar://problem/19748710
2018-07-18 11:43:44 -07:00
Mark Lacey
f826dbb06e [ConstraintSystem] Lift code attempting choices in a disjunction out
of solveSimplified.
2018-07-17 11:02:10 -07:00
Pavel Yaskevich
c997080283 Merge pull request #17980 from xedin/disable-diagnostics-for-codecompletion
[TypeChecker] Disable expression diagnostics for code completion
2018-07-16 16:08:56 -07:00
Mark Lacey
6fa403dc7d [ConstraintSystem] Change the order in which we attempt disjunctions
to be stable.

We currently will stop visiting the elements of a disjunction under
certain circumstances once we have found a solution. The result we get
is inherently dependent on the order in which we determine to visit
the disjunctions themselves (in addition to the elements of the
disjunction).

This change makes the order in which we visit disjunctions
stable. Future commits will create a stable ordering for the elements
of disjunctions. Once we also have that stable ordering in place we
can in theory short circuit more often as part of changing the way in
which we decide what the "best" solution is to a system.

This results in an expression in
validation-test/stdlib/AnyHashable.swift.gyb no longer being able to
typecheck in a reasonable amount of time, so I had to tweak that
expression.
2018-07-16 09:32:14 -07:00
Mark Lacey
e82fcb8487 [ConstraintSystem] Move disjunction selection closer to where selected
disjunction is used.
2018-07-16 08:49:58 -07:00
Pavel Yaskevich
10ddb04613 [ConstraintSystem] Add SuppressDiagnostics/AllowUnresolvedTypeVariables flags
Instead of mixing flags between type-checker and constraint solver, let's
move the ones which are useful in constraint system there. Doing
so allows for `solveForExpression` to be moved from `TypeChecker` to
`ConstraintSystem` which consolidates solver logic.

It also allows to set these flags as part of constraint generation/solving,
which is sometimes important.
2018-07-15 23:23:45 -07:00
Pavel Yaskevich
45634bd262 Merge pull request #17947 from xedin/rdar-42056741
[Diagnostics] Transfer previously resolved types directly from expressions
2018-07-14 12:14:42 -07:00
Pavel Yaskevich
11e1d1328d [ConstraintSystem] NFC: remove obsolete transferExprTypes 2018-07-13 20:13:41 -07:00
Doug Gregor
5db1901d57 [Type checker] Emit coalesce-or-force-unwrap Fix-Its for necessary unwraps more consistently.
Replace the last (and most obscure) use of the poor “use ‘?’ or ‘!’” diagnostic with the
new, more explanatory version that provides separate notes with Fix-Its for coalescing or
force-unwrapping the value.

Finishes rdar://problem/42081852.
2018-07-13 16:48:15 -07:00
Doug Gregor
e7eac0af22 [Type checker] Extend the diagnostics for unwrapping the base of a member access.
Introduce a new fix kind into the constraint solver to cover unwrapping the base
of a member access so we can refer to the a member of the unwrapped base.
Wire this fix kind to the just-added diagnostic that suggests either the
chaining ‘?’ or the force-unwrap ‘!’ via separate, descriptive Fix-Its.

Example:

error: value of optional type 'X?' must be unwrapped to refer to member 'f' of wrapped base type 'X'
  let _: Int = x.f()
               ^
note: chain the optional using '?' to access member 'f' only for non-'nil' base values
  let _: Int = x.f()
               ^
                ?
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
  let _: Int = x.f()
               ^
                !

Before this, we would sometimes get a Fix-It for just ‘?’ and sometimes get a Fix-It for the
coalescing ‘??’, neither of which is likely to be right.

More work on rdar://problem/42081852.
2018-07-13 16:26:03 -07:00
Ding Ye
95b91ee953 Apply git-clang-format. 2018-07-11 15:26:56 +10:00
Ding Ye
4a05369b5a Improve interface of InputMatcher with some renaming and rephrasing;
split test cases into different files for different swift versions.
2018-07-11 15:26:56 +10:00
Ding Ye
9648371339 Extract some logic of matching parameters from isDeclAsSpecializedAs,
and reuse it to match parameters and arguments.
2018-07-11 15:26:56 +10:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Mark Lacey
bb339316a4 Revise the "too complex" heuristic.
Revise the heuristic so that it does not differ between Swift
versions, and so that it is always based on the number of scopes we've
opened.

The memory threshold and (very long) timer are also still in place as
well.
2018-07-01 19:40:21 -07:00
Mark Lacey
93dbb54e68 [ConstraintSystem] Add some counters helpful for understanding solver behavior. 2018-06-19 12:30:56 -07:00
Matt Diephouse
456f69e01f Add root type constraint between KeyPath expressions and applications 2018-06-13 12:38:46 -04:00
Joe Groff
3b227e9928 Merge pull request #17066 from jckarter/defer-let-inout-bug-2
DI: Consider capture of `let`s to be a read-only use.
2018-06-11 14:24:26 -07:00
Joe Groff
711984234d Sema: Pass the useDC down to getTypeOfReference.
This fixes a subtle issue where, during single-expression closure type inference, we would ask for the settability of local variables from the outer function's context, leading us to mistakenly consider them mutable inside single-expression closure contexts. DI would catch some but not all violations of the expected semantics here.
2018-06-11 10:53:00 -07:00
Mark Lacey
d135daae44 [ConstraintSystem] Honor -solver-memory-threshold if present.
If the user specifies a memory threshold on the command-line, try to
honor that value and consider expressions too complex if we end up
allocating more memory than they specify.

Fixes rdar://problem/40952582 (aka https://bugs.swift.org/browse/SR-7525).
2018-06-08 17:38:52 -07:00
Robert Widmann
6585c92395 Merge pull request #16935 from CodaFi/mos-def
[NFC] Refactor default argument info
2018-06-04 14:57:31 -07:00
Pavel Yaskevich
a22b360294 Merge pull request #16903 from xedin/fix-constrainted-expr-typealias
[CSSolver] Make sure generic requirements are checked for typealiases
2018-06-01 11:17:34 -07:00
Pavel Yaskevich
d57330975a [CSSolver] Make sure generic requirements are checked for typealiases
If solver encounters a typealias inside of constrainted extension
make sure to add its requirements to the constraint system, otherwise
it might produce invalid solutions.
2018-06-01 00:23:36 -07:00
Robert Widmann
24abf3ea09 [NFC] Refactor default argument info
Refactor the interface to return a bit vector. Along the way, fix up
the callers and remove some dead usages of the defaults information
that were copied and pasted around Sema.
2018-05-31 17:28:04 -07:00
Mark Lacey
656952af9d [ConstraintSystem] Add a way to get the elapsed time we've spent in a SolverScope. 2018-05-26 10:28:04 -07:00
Mark Lacey
31f2617054 NFC. Move paired methods together in a header file.
They are used together - move the implementations together.
2018-05-25 16:06:47 -07:00
Mark Lacey
1e4721df09 [ConstraintSystem] Move tracking of solver depth/states into SolverState.
Instead of doing this when scopes are created and destroyed, do this
when scopes are registered and rolled back on the SolverState.

NFC.
2018-05-25 16:06:47 -07:00
Pavel Yaskevich
e6e3c3e226 [CSBindings] Don't try to rank bindings based on number of defaults if they are literal
Number of defaults is a fallback condition if there are no other
differences, but pontential bindings which are literal should always
be ranked lower than anything else because there is a higher chance
that such bindings are wrong because their full set might not have
been resolved yet.

Resolves: rdar://problem/39616039
2018-05-14 12:17:35 -07:00
Pavel Yaskevich
e021691bae [ConstraintGraph] Fix contractEdges to gather constraints only once
Currently we have this non-optimal behavior in `contractEdges` where
for every type variable it gathers constraints for its whole equivalence
class before checking if any are "contractable", instead constraints
could be gathered/filtered once which removes a lot of useless work.
2018-05-11 16:08:53 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Huon Wilson
d4fbca1183 [Sema/CS] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:08 +10:00
Slava Pestov
c89a4a5cd5 Sema: Remove dead code from ExprCleaner and CleanupIllFormedExpressionRAII 2018-04-28 00:11:47 -07:00
Huon Wilson
18683f305d Merge pull request #15587 from huonw/minmax
[Sema] Perform name lookup in outer scopes in some cases involving conditional conformances
2018-04-20 22:33:07 +10:00
Huon Wilson
0c53d44e53 [Sema] Consider outer max/min selection deprecated.
We warn and provide fixits, so that we're able restrict this behaviour to Swift
4 only by eagerly migrating people off of it.
2018-04-20 17:27:32 +10:00
Huon Wilson
285c2a469b [CS] Add decl-ref outer alternatives as non-favored options.
Given something like `max(1, 2)` inside a type that conforms to Sequence, this
allows the compiler to consider Swift.max as well as the two methods with that
name on Sequence.
2018-04-20 00:55:11 +10:00
Mark Lacey
289b97134b Ensure we account for force unwrapping in scoring solutions.
This disappeared in the rework of IUOs but is needed when we have
multiple potential solutions involving different sets of overloads or
type bindings.

Fixes rdar://problem/37475971.
2018-04-11 11:45:31 -07:00
Nathan Hawes
9200218122 Merge pull request #15688 from nathawes/rdar38149042-code-completion-hits-visitOpenExistentialExpr-unreachable
[CSGen][CSDiag] Update SanitizeExpr to sanitize OpenExistentialExpr
2018-04-04 13:56:23 -07:00
Sho Ikeda
4ba2303163 Merge pull request #15706 from ikesyo/sema-using-over-typedef
[gardening][Sema] Replace `typedef` with `using`
2018-04-04 19:34:13 +09:00
Mark Lacey
72f4b3d3b8 NFC: Minor cleanup to make createTypeVariable options default to zero.
Many (perhaps most?) calls to createTypeVariable explicitly pass 0 for
options. This change just defaults the parameter to 0 and removes all
the explicit 0's in the code.
2018-04-03 10:19:38 -07:00