Commit Graph

239 Commits

Author SHA1 Message Date
Pavel Yaskevich
ad52afa4bb [ConstraintSystem] Add pair-wise differentiation of key path dynamic member overloads
Single type of keypath dynamic member lookup could refer to different
member overlaods, we have to do a pair-wise comparison in such cases
otherwise ranking would miss some viable information e.g.
`_ = arr[0..<3]` could refer to subscript through writable or read-only
key path and each of them could also pick overload which returns `Slice<T>`
or `ArraySlice<T>` (assuming that `arr` is something like `Box<[Int]>`).
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
c3153e020d [CSRanking] Account for that fact that some bindings can be type holes 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
22e12e86a8 [ConstraintSystem] Switch to pair-wise type binding differentiation for ranking
Instead of trying to hold a "global" set of type variable differences
let's use pair-wise comparison instead because in presence of generic
overloads such would be more precise.

If there are N solutions for a single generic overload we currently
relied on "local" comparison to detect the difference, but it's not
always possible to split the system to do one. Which means higher
level comparisons have to account for "local" (per overload choice)
differences as well otherwise ranking would loose precision.
2020-01-14 00:09:33 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Robert Widmann
f4d333d066 Sink a bunch of semantic options into TypeCheckerOptions
Sink
- DebugConstraintSolver
- DebugConstraintSolverAttempt
- DebugConstraintSolverOnLines
- DebugGenericSignatures
- DebugForbidTypecheckPrefix
- SolverMemoryThreshold
- SolverBindingThreshold
- SolverShrinkUnsolvedThreshold
- SolverDisableShrink
- EnableOperatorDesignatedTypes
- DisableConstraintSolverPerformanceHacks
- SolverEnableOperatorDesignatedTypes
2019-11-12 22:39:49 -08:00
Doug Gregor
99555dc951 [Constraint system] Add ConstraintSystem::getExprDepth() and use it for cleanup.
Rather than passing around or create depth maps at a few places in the
constraint solver, introduce getExprDepth() and use it consistently.
2019-11-12 15:42:17 -08:00
Robert Widmann
b7d94e4b84 Drop TypeChecker out of some Code Completion utilities 2019-11-10 13:32:13 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Robert Widmann
1123b1f897 Move constraint satisfiability utilities 2019-11-10 13:12:50 -08:00
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Robert Widmann
2b08d1b834 [NFC] ASTContext::getLazyResolver -> ASTContext::getLegacyGlobalTypeChecker 2019-11-05 14:44:41 -08:00
Hamish Knight
e7fe2a7a48 Prevent non-ephemeral fix from affecting overload resolution
This commit changes the behaviour of the error for
passing a temporary pointer conversion to an
@_nonEphemeral parameter such that it doesn't
affect overload resolution. This is done by recording
the fix with an impact of zero, meaning that we don't
touch the solution's score.

In addition, this change means we no longer need
to perform the ranking hack where we favour
array-to-pointer, as the disjunction short-circuiting
will continue to happen even with the fix recorded.
2019-11-03 08:42:26 -08:00
Robert Widmann
3753a96d7c Add CompareDeclSpecializationRequest 2019-10-30 15:10:34 -07:00
Robert Widmann
abc6db13b1 Provide AST Context Getters To Protocol Inference 2019-10-30 12:55:42 -07:00
Robert Widmann
972e755e9b Give ConstraintSystem's outlet to the ASTContext
Make it less tempting to ask for the type checker embedded into
ConstraintSystem by using the accessor to the ASTContext.
2019-10-30 12:55:42 -07:00
Robert Widmann
4f84c2a628 Use the default constructor to clean up some APIs
Use ProtocolConformanceRef::forInvalid() in implementations only as a semantic signal.  In one place, use the default constructor to drop the final use of Optional<ProtocolConformanceRef>.
2019-10-29 16:56:22 -07:00
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