Commit Graph

315 Commits

Author SHA1 Message Date
Doug Gregor
0494574706 Factor the computation of default arguments into ParameterListInfo.
Provide a place where we can capture more information about the parameters
from a declaration being called.
2019-06-11 17:34:44 -07:00
Slava Pestov
c84aad8bf1 Sema: TypeChecker::conformsToProtocol() is static 2019-06-11 02:47:32 -07:00
Pavel Yaskevich
c1087b9ab7 [ConstraintSystem] Remove boolean flags from openGeneric/openFunctionType 2019-06-06 11:56:49 -07:00
Pavel Yaskevich
0da4a5b2b3 [CSRanking] Remove code duplication related to opening types 2019-06-05 10:34:29 -07:00
Pavel Yaskevich
930f74a023 [ConstraintSystem] Remove unused inner declaration context parameter from openGeneric* 2019-06-04 18:00:22 -07:00
Pavel Yaskevich
72c6dbb336 [ConstraintSystem] Separate parameter label removal from generic function opening 2019-06-04 14:26:07 -07:00
Hamish Knight
71eb43a008 [CSRanking] Handle mismatching curry levels
While it's currently not possible for `isDeclAsSpecializedAs` to compare
decls that differ by having a curried self or having a parameter list,
tweak the logic slightly so it could handle that case if it needed to.

If one decl has a parameter list and the other doesn't, then just
compare their self types. If one decl is curried and the other isn't,
then add a curried self to the other and compare as normal.
2019-05-31 15:53:27 +01:00
Hamish Knight
b49f02c6b9 [AST][Sema] Add ValueDecl::hasParameterList 2019-05-31 15:53:27 +01:00
Hamish Knight
dcabcb36b4 [AST][Sema] Add ValueDecl::hasCurriedSelf
Use this function to replace various places where the logic is
duplicated.

In addition, isolate the logic where subscripts are treated as having
curried self parameters to CalleeCandidateInfo, as their interface types
don't have a curried self, but get curried with self by
CalleeCandidateInfo. Ideally we'd fix this by having a subscript's
interface type be curried with self, but given that most of this CSDiag
logic should be going away, this may not be necessary.
2019-05-31 15:53:26 +01:00
Hamish Knight
197ddb57ab [Sema][NFC] Simplify paramIsIUO implementation 2019-05-31 15:53:26 +01:00
Doug Gregor
5aea1315cd Add @_disfavoredOverload attribute to affect overload resolution.
Introduce an attribute @_disfavoredOverload that can be used to state
that a particular declaration should be avoided if there is a
successful type-check for a non-@_disfavoredOverload. It's a way to
nudge overload resolution away from particular solutions.
2019-05-14 23:07:26 -07:00
Pavel Yaskevich
7e076441c7 [CSRanking] Dynamic member look - rank keypath choice higher than string based one
Because keypath based choice provides more type information it
should be preferred to string based when both solutions are available.
2019-04-01 12:40:39 -07:00
Pavel Yaskevich
f95d9b092e [TypeChecker] Add new type of overload choice to support keypath dynamic lookup 2019-04-01 12:40:39 -07:00
Pavel Yaskevich
e604261805 [ConstraintSystem] Track AST depth information directly
Instead of storing information about expression depths in the
solver state (which gets recomputed for salvage) let's track
it directly in constraint system, which also gives solver
access to it when needed e.g. for fixes.
2019-01-23 18:44:53 -08:00
Pavel Yaskevich
49c40d92f6 [AST] Augment getDepthMap with information about parent expressions
Which is very useful for the solver because otherwise it'd have to
compute and store this information twice.
2019-01-23 18:21:07 -08:00
Slava Pestov
e99607c421 Sema: Use ConstraintKind::Bind where possible instead of ::Equal
Solving Bind is a little easier than Equal. The only remaining uses of Equal
are in the .member syntax and keypaths; if we can refactor those, we might be
able to simplify LValue handling in the type checker in general.
2019-01-14 14:55:16 -05:00
Slava Pestov
181f26de20 Sema: Try removing isConvertibleTo() check from solution ranking 2018-12-15 00:17:57 -05:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Pavel Yaskevich
bce1ba5f37 [AST] Remove @autoclosure flag from function type ExtInfo 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
f462521078 [ConstraintSystem] Refactor arg/param matching to handle autoclosures
Make sure that presence of `@autoclosure` attribute handled
in one place - `matchCallArguments`, which makes it possible
to remove the rest of (now redundant) autoclosure related
logic scattered throughout solver.
2018-11-10 11:59:28 -08:00
Slava Pestov
8c94b3818f Merge pull request #19560 from slavapestov/remove-functype-getinput
Remove FunctionType::getInput()
2018-09-26 19:39:03 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Hamish Knight
8f2aadd2ca [CSRanking] Amend concrete-over-protocol logic to only do an is-a check
As discussed in #18951, we don't want to be comparing two different protocol decls here, as that could lead to spurious 'is more specialized' results. I'm not aware of any case that currently trips this logic up though, so no tests to accompany.
2018-09-26 11:12:00 +01:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
swift-ci
638272d74d Merge pull request #18952 from hamishknight/concrete-is-better-swift4 2018-09-04 17:03:45 -07:00
Slava Pestov
6b13734da3 Sema: Fix regression with tuple conversions from recent changes
61152e6585 introduced a behavior change
that was caught neither by our test suite nor the source compatibility
tests.
2018-08-30 18:20:06 -07:00
Mark Lacey
ea0050891a Merge pull request #18951 from hamishknight/concrete-is-better-swift5
[CSRanking] Favour concrete members over protocol requirements in Swift 5 mode
2018-08-29 22:32:08 -07:00
Hamish Knight
bee01ed6f5 Revert "[Revert Me] Disable language version check temporarily"
This reverts commit 37a949075f.
2018-08-29 16:54:35 +01:00
Slava Pestov
61152e6585 Sema: Move getUnlabeledType() to CSRanking and simplify it 2018-08-28 22:36:02 -07:00
Hamish Knight
db2897f114 Address #18952 review comments 2018-08-28 22:05:06 +01:00
Hamish Knight
9268fcd6ae [CSRanking] Swift 4.1 compatibility hack for favouring properties on concrete types over protocols
Changes in shadowing behaviour by #15412 caused a property on a concrete type to no longer shadow a protocol property member, which created unintentional ambiguities in 4.2. This commit ensures we at least keep these cases unambiguous in Swift 5 under Swift 4 compatibility mode. This is intentionally narrow in order to best preserve source compatibility under Swift 4 mode by ensuring we don't introduce any new ambiguities.

Resolves SR-7425, SR-7940 & SR-8343.
2018-08-24 17:09:58 +01:00
Hamish Knight
37a949075f [Revert Me] Disable language version check temporarily 2018-08-24 15:50:28 +01:00
Hamish Knight
1912d289e1 [CSRanking] Exclude concrete-over-protocol rule from dynamic lookup ranking
This rule caused us to lose ambiguities in places where we really want ambiguity for `AnyObject` lookup, so only apply it when not comparing such overloads. This whole situation is a bit of a hack – really we shouldn't be applying any type-based or context-based overload ranking rules to overloads found through `AnyObject` lookup, but unfortunately we don't have syntax to precisely disambiguate overloads.

This commit can be reverted if/when we ever remove `AnyObject` lookup.
2018-08-24 15:50:28 +01:00
Hamish Knight
286f16404b [CSRanking] Favour members on concrete types over protocol members
This commit adds a new rule to `isDeclAsSpecializedAs` in order to favour a member on a concrete type over a protocol member. This rule is effectively an extension of the existing rule that prefers concrete type members over protocol extension members.
2018-08-24 15:50:27 +01:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Ben Cohen
428c580158 Fix unused variable warnings in release builds. (#18755) 2018-08-16 11:46:45 -06:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Pavel Yaskevich
b9499d71af Merge pull request #18527 from xedin/rdar-42678836
[CSRanking] Fix solution filtering not to erase everything when set i…
2018-08-07 00:22:23 -07:00
Pavel Yaskevich
dc6f86d9b7 [CSRanking] Fix solution filtering not to erase everything when set is completely ambiguous
Since constraint solver has been improved to diagnose more problems
via "fixes", sometimes applying fixes might lead to producing solutions
which are completely ambiguous when compared to each other, and/or are
incomparable, which leads to `findBestSolutions` erasing all of them
while trying to compute best "partial" solution, which is incorrect.

Resolves: rdar://problem/42678836
2018-08-06 17:25:58 -07:00
Mark Lacey
3c9cb97c86 [ConstraintSystem] Add an option to disable the constraint solver perf hacks.
This is helpful in experimenting with constraint solver changes that
might help us remove some of these unsound options. It's not ever mean
to be enabled, but if we're able to remove the things guarded by the
option we can eventually remove the option.
2018-08-06 11:48:19 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -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
d271f4b057 [ConstraintSystem] Ensure we prefer f(_: Any) to f(_: Any?) when both work.
...unless the argument is an `Any?`, in which case we prefer `f(_: Any?)`.

This change also results in our selecting f<T>(_: T) over f(_:
Any). Coercing with 'as Any' makes it possible to explicitly select
the Any overload. Previously there was no way to select the generic
overload.
2018-07-18 11:44:04 -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
efb173857a Merge branch 'master' into remove-swift-3-in-expr-typechecking 2018-07-11 23:49:44 -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
Mark Lacey
28f759c8b0 Remove support for -swift-version 3 from the expression type checker.
This is the obvious stuff. There will probably be more fallout.
2018-07-06 16:10:08 -07:00
Rintaro Ishizaki
c622722aaf [CSRanking] Handle EnumElementDecl in IUO parameter checking 2018-06-27 19:07:18 +09:00