Commit Graph

1733 Commits

Author SHA1 Message Date
Pavel Yaskevich
d922041ac5 Merge pull request #30740 from xedin/rdar-61084565
[ConstraintSystem] Don't include self-recursive dynamic member result…
2020-04-01 10:27:53 -07:00
Pavel Yaskevich
fdc535a691 [ConstraintSystem] Don't include self-recursive dynamic member results as "inaccessible"
Solver has to keep track of excluded dynamic member results while
performing lookup because otherwise, in diagnostic modem it might
include such results as inaccessible.

Resolves: rdar://problem/61084565
2020-03-31 16:20:20 -07:00
Pavel Yaskevich
f95cabb745 [ConstraintSystem] Allow sequence element mismatch fix to produce new holes
Type on the right-hand side of the element conversion/pattern match
should be allowed to have holes to be able to diagnose failures with
structurally incompatible types.

Resolves: rdar://problem/60832876
2020-03-30 17:48:46 -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
Hamish Knight
ee3e694527 [CS] Explore additional bindings for fixes (#30686)
[CS] Explore additional bindings for fixes
2020-03-29 08:47:16 -07:00
Hamish Knight
b4c13c2c55 [CS] Adjust assessRequirementFailureImpact
- In `simplifyConformsToConstraint`, pass the LHS
type regardless of whether it is a type variable.

- Add the `choiceImpact` onto the impact for
adding a stdlib conformance.

- Treat Any and AnyObject as standard library
types.
2020-03-28 17:03:42 -07:00
Hamish Knight
dc4b089b9f [CS] Don't fix an _OptionalNilComparison argument
We should only be attempting such overloads for
nil literal args.

Resolves SR-12426.
2020-03-28 17:03:42 -07:00
Pavel Yaskevich
24bbce142f Merge pull request #30701 from LucianoPAlmeida/diagnose-key-path-refer-init
[Diagnostics] Diagnose key path referring to init method
2020-03-28 15:37:20 -07:00
Luciano Almeida
faba29a55f [Diagnostics] Diagnose key path reference to initializer methods. 2020-03-28 16:32:08 -03:00
Hamish Knight
31e46b3a23 [CS] Fix a locator path element
This locator is for Dictionary's Value generic
parameter.
2020-03-27 15:13:24 -07:00
Hamish Knight
234270c941 [CS] NFC: Tweak addExplicitConversionConstraint
Have it take a RememberChoice_t instead of an
'allowFixes' bool, as the parameter no longer
really corresponds to fixes.
2020-03-27 15:13:24 -07:00
Pavel Yaskevich
f75996839a Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter" 2020-03-26 09:19:57 -07:00
Pavel Yaskevich
5f328ad003 [ConstraintSystem] Don't increase SK_Fix score when looking through holes
`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
2020-03-25 09:34:00 -07:00
Hamish Knight
e71d921e43 [CS] Re-introduce some assertions
These FIXMEs appear to now be outdated.

This commit also adds an additional assertion in
`bindTypeVariable`.
2020-03-22 22:58:48 -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
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
Pavel Yaskevich
c72940f2c7 [ConstraintSystem] Default multi-statement closure result to Void only after resolving
Let's remove a side-effect from `ConstraintGenerator::inferClosureType`
and default result type to `Void` for multi-statement closures after
closure has been resolved.
2020-03-18 17:48:56 -07:00
Pavel Yaskevich
2df9bb509e Merge pull request #30440 from LucianoPAlmeida/SR-11540-ambiguos-closure-inference
[SR-11540] Fix ambiguos overload apply to argument for contextual closure
2020-03-18 08:26:34 -07:00
Luciano Almeida
3b2dd8cc98 [CSSimplify] Increase the score with SK_FunctionConversion whenever we have to implode parameters to support SE-110 cases 2020-03-17 20:40:07 -03:00
Luciano Almeida
1cccbc8f94 [CSSimplify] Difavor function type overload when trying to match no arg function type with a closure with a anonimous implicit var closure 2020-03-16 22:59:40 -03: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
7800a04de3 [Diagnostics] Adjust "missing arguments" diagnostic to store parameter indices directly
This helps to avoid allocating new type variables (which shouldn't be done regardless)
to store parameter indices when `missing arguments` diagnostic is used by other diagnostics.
2020-03-13 16:55:37 -07:00
Pavel Yaskevich
126065821a Merge pull request #30348 from omochi/fix-arg-reorder
[ConstraintSystem] Fix bug of argument reordering in matchCallArguments
2020-03-12 09:29:11 -07:00
omochimetaru
484606dc3a [ConstraintSystem] Fix bug of argument reordering in matchCallArguments 2020-03-12 11:19:28 +09:00
Hamish Knight
b62c9b6b01 [CS] Use getParameterType for KeyPath as function
Previously we were using `getPlainType` to match
the parameter type against the key path's base
type. This gave us the external parameter type,
which would be the element type for a variadic
parameter.  However the code we generate expects
the internal parameter type, which is provided by
`getParameterType`.

Resolves rdar://problem/59445486.
2020-03-11 17:21:28 -07: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
Doug Gregor
6a5069d017 Merge pull request #30245 from xedin/rdar-60061646
[ConstraintSystem] Make sure pattern matching tuple destructuring works both ways
2020-03-05 21:48:30 -08:00
Holly Borla
f8de43b63b Merge pull request #30251 from hborla/invalid-optional-chaining
[ConstraintSystem] Don't assume the lhs type is for a generic parameter in simplifyConformsToConstraint.
2020-03-05 16:45:37 -08:00
Holly Borla
6898fbb0ef [ConstraintSystem] Don't assume the lhs type is for a
generic parameter in simplifyConformsToConstraint.
2020-03-05 14:39:30 -08:00
Pavel Yaskevich
1f222f307e [ConstraintSystem] Make sure pattern matching tuple destructuring works both ways
Consider following example:

```swift
enum E {
  case foo((x: Int, y: Int))
  case bar(x: Int, y: Int)
}

func test(e: E) {
  if case .foo(let x, let y) = e {}
  if case .bar(let tuple) = e {}
}
```

Both of `if case` expressions have to be supported:

1. `case .foo(let x, let y) = e` allows a single tuple
   parameter to be "destructured" into multiple arguments.

2. `case .bar(let tuple) = e` allows to match multiple
   parameters with a single tuple argument.

Resolves: rdar://problem/60061646
2020-03-05 14:05:35 -08:00
Pavel Yaskevich
d6a9399f7b Merge pull request #30202 from omochi/refactor-matchCallArguments
[ConstraintSystem] Refactor matchCallArguments
2020-03-05 09:45:53 -08:00
Pavel Yaskevich
87878a65eb [ConstraintSystem] Preserve label matching rules in pattern matching context
Since constraint system now handles pattern matching it has
to preverse label matching semantics which existed in original
code: if pattern element has a label it has to match the one
in the tuple type it's matched against.

Resolves: rdar://problem/60048356
2020-03-04 23:09:31 -08:00
omochimetaru
dfd8af154b use for-in 2020-03-04 22:26:07 +09:00
omochimetaru
ed4d8370b6 change paramIdx to local variable 2020-03-04 22:26:07 +09:00
omochimetaru
88e26b44a3 change nextArgIdx to local variable 2020-03-04 22:26:07 +09:00
omochimetaru
34e895c739 remove unnecessary skipClaimedArgs call 2020-03-04 22:26:07 +09:00
omochimetaru
c946548a19 use local variable for temporary loop 2020-03-04 22:26:07 +09:00
omochimetaru
521a8a5d8f remove unused nextArgIdx operation 2020-03-04 22:26:07 +09:00
omochimetaru
14c6155278 use claim for trailing closure 2020-03-04 22:26:03 +09:00
Holly Borla
24d8aa148f Merge pull request #30185 from hborla/dependent-type-requirement-failure
[ConstraintSystem] Replace dependent member types with holes when the…
2020-03-03 19:55:07 -08:00
Holly Borla
fce8738ea8 [ConstraintSystem] Replace dependent member types with holes when the base type
doesn't conform to the associatedtype's protocol (only in diagnostic mode).

This allows the solver to find solutions for more cases involving requirement
failures for dependent member types without special cases across the solver
that check for dependent member types with no type variables.
2020-03-03 15:45:24 -08:00
Pavel Yaskevich
f7b264583d [Diagnostic] Don't fix partial mismatch for sub-types associated with optional conversion
If mismatch detected by `repairFailures` is related to a complex
wrapped value of optional type formed from optional-to-optional
or value-to-optional conversion let's not try to fix it directly
but let `simplifyRestrictedConstraintImpl` record a top-level fix
for more context.

Resolves: rdar://problem/59703585
2020-03-03 00:24:34 -08:00
Pavel Yaskevich
0cd44a83a7 [ConstraintSystem] Don't record general contextual mismatch if there are restrictions present
If there are any conversion restrictions present while trying to repair
failures related to contextual type, let's give `simplifyRestrictedConstraintImpl`
a chance to run and fix the problem.

Resolves: rdar://problem/59773317
2020-03-02 11:07:31 -08:00
Suyash Srijan
956e918476 [CSSimplify] Move property wrapper fix check after check for conversion restrictions (#30129) 2020-02-28 23:16:32 +00:00
Pavel Yaskevich
389e84fc55 Merge pull request #30115 from LucianoPAlmeida/nfc-abstract-is-stdlib
[NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl
2020-02-28 13:32:32 -08:00
Luciano Almeida
f4b530fb95 [NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl 2020-02-28 07:40:08 -03:00
Pavel Yaskevich
c0b9394c42 Merge pull request #30113 from xedin/rdar-54580247
[CSBindings] Open collection before binding parameter only if origina…
2020-02-28 00:01:27 -08:00
Pavel Yaskevich
20fc51d4f4 [CSBindings] Open collection before binding parameter only if original argument type failed
Instead of always opening argument type represented by a collection
without type variables (to support subtyping when element is a labeled tuple),
let's try original type first and if that fails use a slower path with
indirection which attempts `array upcast`. Doing it this way helps to
propagate contextual information faster which fixes a performance regression.

Resolves: rdar://problem/54580247
2020-02-27 16:26:13 -08:00
Doug Gregor
30e8d1791e [Constraint system] Handle implicit "some" patterns implicitly, better.
We have two similar code paths here that should probably be unified. For
now, make sure the more-specific one for pattern matching kicks in first.

Fixes rdar://problem/59838566.
2020-02-27 16:25:02 -08:00
omochimetaru
79a8a596e4 [ConstraintSystem] remove unused computation in claimNextNamed 2020-02-27 10:49:42 +09:00