Commit Graph

323 Commits

Author SHA1 Message Date
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Pavel Yaskevich
868afc6fc9 [CSRanking] Always rank key path dynamic member choices lower than non-dynamic ones
This only comes into play when all other choices are coming from
constrained extensions, because there is no way to determine upfront
whether any are going to match it's better to be safe and add
key path dynamic member choice to the set too.

Resolves: [SR-11465](https://bugs.swift.org/browse/SR-11465)
Resolves: rdar://problem/55314724
2019-09-12 14:03:57 -07:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
gregomni
a2cd53d802 Handle simplification of optional-chaining key path literals, distinguish function type and keypath BGT type without explicit disjunctions. 2019-08-06 07:52:56 -07:00
Brent Royal-Gordon
6f4b0e5771 [ConstraintSolver] Favor keypaths over functions
Necessary to keep SE-0249 from failing tests.
2019-08-06 07:52:56 -07:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
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