Commit Graph

965 Commits

Author SHA1 Message Date
Pavel Yaskevich
326b371e10 [ConstraintSystem] Switch auxiliary functions to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
Slava Pestov
742bd98402 Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance()
instead. Since this was the last flag in ConformanceCheckOptions, we can remove
that, too.
2020-04-25 00:14:24 -04:00
Pavel Yaskevich
9eb9b8d53b Merge pull request #31279 from xedin/rdar-62054241
[ConstraintSystem] Properly diagnose operator reference ambiguities
2020-04-24 14:20:19 -07:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Pavel Yaskevich
bb414927a0 [ConstraintSystem] Properly diagnose operator reference ambiguities
If operator is referenced instead of applied e.g. `arr.sort(by: <)`
ambiguities should be diagnosed as `no exact matches` with attached
notes describing a failure associated with each potential candidate.

Resolves: rdar://problem/62054241
2020-04-24 12:22:08 -07:00
Pavel Yaskevich
7bdf0164d4 [ConstraintSystem] Replace remaining uses of TypedNode::dyn_cast with getAsExpr 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
4b1aa29149 [ConstraintSystem] NFC: Adjust all uses of locator anchors to work with TypedNode 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
398f37842a [ConstraintSystem] Elevate TypedNode access helpers up to the namespace
Originally such accessors were only useful for `FailureDiagnostic` but
now since `ConstraintLocator` is anchored with `TypedNode` it makes sense
to make them universally accessible.
2020-04-23 01:13:13 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Robert Widmann
78e07c1d41 Merge pull request #31159 from CodaFi/track-star
Remove Fallback Infrastructure For Evaluator-Based Dependencies
2020-04-22 15:37:48 -07:00
Hamish Knight
c39c4e8aad [CS] Unify failed constraint recording
Rename `addNewFailingConstraint` to
`recordFailedConstraint`, and call into it
whenever a constraint fails, instead of setting
`failedConstraint`. This ensures that
`-debug-constraints` will always log the constraint
that failed a given scope.

In addition, introduce `retireFailedConstraint`
to cover the common case of retiring a constraint
that just failed.
2020-04-20 19:08:24 -07:00
Robert Widmann
48a5432cb7 [NFC] Remove ConformanceCheckFlags::InExpression
The last read of this bit was removed when the legacy referenced name tracker was deleted in the last commit.
2020-04-20 10:22:58 -07:00
Holly Borla
66e85721cb Merge pull request #30807 from hborla/property-wrapper-refactoring
[Property Wrappers] Refactor property wrappers so the synthesized backing init is only type checked once
2020-04-14 10:48:22 -07:00
Holly Borla
48b6bcd869 Merge pull request #31002 from hborla/property-wrapper-contextual-type
[Property Wrappers] Use the outermost wrapper attribute type as the contextual type for property wrapper initialization
2020-04-13 20:38:43 -07:00
Holly Borla
df7735e545 [Property Wrappers] Use the outermost wrapper attribute type as the
contextual type for property wrapper initialization
2020-04-13 18:17:40 -07:00
Doug Gregor
6999c318b7 Merge pull request #30924 from DougGregor/for-each-solution-application-target
[Constraint solver] Migrate for-each statement checking into SolutionApplicationTarget
2020-04-10 07:28:21 -07:00
Doug Gregor
87d86f3545 [Constraint solver] Migrate for-each statement checking into SolutionApplicationTarget.
Pull the entirety of type checking for for-each statement headers (i.e., not the
body) into the constraint system, using the normal SolutionApplicationTarget-based
constraint generation and application facilities. Most of this was already handled
in the constraint solver (although the `where` filtering condition was not), so
this is a smaller change than it looks like.
2020-04-09 11:02:56 -07:00
Pavel Yaskevich
deb58e0b68 Merge pull request #30022 from LucianoPAlmeida/SR-9839-convention-function-conversions-fail
[SR-9839] Fixes ambiguity in convention function argument inference
2020-04-08 15:48:51 -07:00
Luciano Almeida
426a2f8694 [ConstraintSystem] Checking for SK_Fix when diagnose ambiguity for generic parameter bindings with no fixes 2020-04-08 17:51:45 -03:00
Luciano Almeida
2704b6d737 [ConstraintSystem] Diagnose ambiguity for generic parameter bindings with no fixes 2020-04-08 17:16:47 -03:00
Hamish Knight
76881a39a5 [CS] Adjust applied overload simplification (#30716)
[CS] Adjust applied overload simplification
2020-04-07 19:04:27 -07:00
Holly Borla
b2e6048f55 Merge pull request #30844 from hborla/diagnose-for-ambiguity
[Diagnostics] In DefineMemberBasedOnUse::diagnoseForAmbiguity, use the base type from each solution
2020-04-07 17:52:20 -07:00
Holly Borla
ece84b176c [Diagnostics] Adjust ConstraintFix::diagnoseForAmbiguity to take an array
ref of pairs rather than two parallel arrays.
2020-04-07 13:38:26 -07:00
Holly Borla
6375481ea4 [Diagnostics] In DefineMemberBasedOnUse::diagnoseForAmbiguity, use
the base type from each solution instead of only the base type from
the first solution.
2020-04-06 17:35:31 -07:00
Holly Borla
bbfcb55e9e [Property Wrappers] Inject the opaque value placeholder for a property
wrapper original wrapped value expression inside of CSApply.

This prevents type checking the synthesized backing storage initializer
twice - once with the original expression and again with the placeholder.
2020-04-05 19:02:37 -07:00
Holly Borla
c301176ca6 [ConstraintSystem] Allow SolutionApplicationTarget to store the
innermost call to init(wrappedValue:) if the target is for initialization
of a property wrapper's backing storage.
2020-04-03 15:12:12 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Hamish Knight
71882996ca [CS] Adjust applied overload simplification
Currently `simplifyAppliedOverloads` depends on
the order in which constraints are simplified,
specifically that a lookup constraint for a
function gets simplified before the applicable
function constraint. This happens to work out
just fine today with the order in which we
re-activate constraints, but I'm planning on
changing that order.

This commit changes the logic such that it it's no
longer affected by the order in which constraints
are simplified. We'll now run it when either an
applicable function constraint is added, or a new
bind overload disjunction is added. This also
means we no longer need to run it potentially
multiple times when simplifying the applicable fn.
2020-03-29 18:33:59 -07:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Doug Gregor
85762c30f5 Merge pull request #30663 from DougGregor/property-wrapper-default-init-infer-type
[Property wrappers] Allow default initialization to infer a type.
2020-03-27 13:46:47 -07:00
Pavel Yaskevich
c99c9b95d0 [ConstraintSystem] Switch availability check to use correct API
Use `TypeChecker::checkDeclarationAvailability` instead of `isDeclAvailable`,
that is a proper API endpoint which does flag checking before calling
`isDeclAvailable` internally.
2020-03-27 00:43:09 -07:00
Pavel Yaskevich
81dbec09fb [ConstraintSystem] Don't check -disable-availability-checking
Checking for `-disable-availability-checking` in
`ConstraintSystem::isDeclUnavailable` caused a regression with
obsolete/introduced checking. Let's rely on
`DeclAttributes::isUnavailable` and `TypeChecker::isDeclAvailable`
to do the right thing instead.

Resolves: rdar://problem/60898369
2020-03-26 16:13:32 -07:00
Doug Gregor
d282e3c1e9 [Property wrappers] NFC rename initialValue -> wrappedValue where appropriate
wrappedValue is the new name, and we only support initialValue for backward
compatibility with earlier revisions of the property wrappers proposal.
2020-03-26 15:16:28 -07:00
Doug Gregor
5ac8d769fd [Property wrappers] Allow default initialization to infer a type.
Property wrappers are allowed to infer the type of a variable, but this
only worked when the property wrapper was provided with an explicit
initialization, e.g.,

    @WrapsAnInt() var x   // infers type Int from WrapsAnInt.wrappedValue

However, when default initialization is supported by the property wrapper,
dropping the parentheses would produce an error about the missing type
annotation

    @WrapsAnInt var x

Make this second case behave like the first, so that default initialization
works consistently with the explicitly-specified version.
Fixes rdar://problem/59471019.
2020-03-26 13:44:08 -07:00
Pavel Yaskevich
4b3d075fb7 [ConstraintSystem] Produce fallback diagnostic on mismatch between fixes/holes
If score indicates that a solution should have at least one fix
but it doesn't let's attempt to produce a fallback diagnostic inline.
2020-03-24 16:51:44 -07:00
Hamish Knight
c74a7512f7 [CS] NFC: Remove OverloadChoiceKind::BaseType
This doesn't appear to be used any more.
2020-03-22 22:51:58 -07:00
Pavel Yaskevich
d673ed0989 Merge pull request #30519 from xedin/rdar-52204414
[ConstraintSystem] Don't allow explicit closure result to be implicitly converted to `Void`
2020-03-20 09:36:17 -07:00
Pavel Yaskevich
89933c67da [ConstraintSystem] Don't allow explicit closure result to be implicitly converted to Void
It's allowed to convert a single statement closure from `(...) -> T` to `(...) -> Void`
_only_ if there is no explicit `return` in the body.

Resolves: [SR-12277](https://bugs.swift.org/browse/SR-12277)
Resolves: rdar://problem/52204414
2020-03-19 16:59:17 -07:00
Doug Gregor
3abea6be65 [Constraint system] Use the PatternBindingDecl context when possible.
Make sure that we're resolving types and patterns using the
PatternBindingDecl context, both for the type resolver context and the
contextual pattern used for pattern resolution.

Fixes a regression with implicitly-unwrapped options reported as
SR-11998 / rdar://problem/58455441.
2020-03-18 21:09:06 -07:00
Pavel Yaskevich
2d6170b847 [TypeChecker] Requestify check to determine if closure has explicit result
Determine whether closure body has any explicit `return`
statements which could produce a non-void result.
2020-03-18 17:06:15 -07:00
Pavel Yaskevich
2dd74706c9 Merge pull request #30411 from xedin/diags-to-use-solution-instead-of-cs
[Diagnostics] Switch `FailureDiagnostic` to use a solution
2020-03-13 20:20:58 -07:00
Pavel Yaskevich
3ab8710329 [Diagnostics] Cleanup use of constraint system by ConstraintFix/FailureDiagnostic 2020-03-13 15:02:10 -07:00
Pavel Yaskevich
0fc9d1b84a [Diagnostics] Move getFunctionArgApplyInfo to Solution
Instead of relying on constraint system having solution applied
let's pass a solution directly to `getFunctionArgApplyInfo`.
2020-03-13 12:46:25 -07:00
Robert Widmann
4e67eec878 [CS] Move getUnopenedTypeOfReference out of TypeChecker
For some reason, the changed caller in CS wasn't actually going to use any of the types in the constraint system from the entrypoint it was calling. Switch over to using the constraint-system-based entrypoint so we can pick up expression types consistently. Then, move the TypeChecker entrypoint onto ConstraintSystem to reduce the duplication here.

The remaining callers of buildCheckedRefExpr should be migrated.
2020-03-11 11:14:10 -07:00
Pavel Yaskevich
e86558fe4f Merge pull request #30277 from LucianoPAlmeida/SR-12019-dynamically-call-generic-constraint
[SR-12019] Fix assert when dynamicallyCall parameter does not satisfy generic constraint
2020-03-10 09:12:33 -07:00
Pavel Yaskevich
4a06b13abf [ConstraintSystem] Diagnose argument conflicts only for "representative" generic parameters
Consider following example:

```swift
struct MyType<TyA, TyB> {
  var a : TyA, b : TyB
}

typealias B<T1> = MyType<T1, T1>

_ = B(a: "foo", b: 42)
```

Here `T1` is equal to `TyA` and `TyB` so diagnostic about
conflicting arguments ('String' vs. 'Int') should only be
produced for "representative" `T1`.
2020-03-09 12:10:29 -07:00
Luciano Almeida
f796e27b65 [TypeChecker] Requestify DynamicCallableAttribute check 2020-03-08 20:44:23 -03:00
Pavel Yaskevich
0ecedfa5ea Revert "[ConstraintSystem] Make it possible to infer subtype bindings through argument conversions"
Reverts apple/swift#30006. It caused a regression that we'd like to address before re-landing:

```swift
struct X {
  var cgf: CGFloat
}

func test(x: X?) {
  let _ = (x?.cgf ?? 0) <= 0.5
}
```

This reverts commit 0a6b444b49.
This reverts commit ed255596a6.
This reverts commit 3e01160a2f.
This reverts commit 96297b7e39.

Resolves: rdar://problem/60185506
2020-03-07 20:16:56 -08:00
Luciano Almeida
6df132de1a [ConstraintSystem] Make getCalleLocator to support an apply involving an dynamicCallable 2020-03-07 16:43:37 -03:00
Pavel Yaskevich
7c19d1ccd1 [ConstraintSystem] Remove baseCS since CSDiag has been removed
There is no more sub-expression re-typechecking so no need to keep
parent constraint systems around.
2020-03-06 09:35:52 -08:00