Commit Graph

13 Commits

Author SHA1 Message Date
Pavel Yaskevich
70ac657a46 [CSBindings] Don't delay bindings inferred through inout conversion
Delaying such bindings is too restrictive and leads to subpar selections.

For `$T1` to be array or C-style pointer it would have to be
connected either to a type variable that could be bound to
array/pointer or directly to array/pointer type which would
result in the solver either selecting the other type variable
first (because it appears in adjacent variables of `$T1`) or
provide an additional binding(s) for `$T1` (including literals).

Consider the following constraint system:

```
$T2 arg conv $T1
$T2 conforms ExpressibleByIntegerLiteral

inout $T1 arg conv UnsafeMutablePointer<UInt8>?
```

If `$T1` and `$T2` are the only viable type variables delaying
`$T1` would mean that `$T2` is picked to attempt its default
type `Int` which is incorrect (it doesn't get `UInt8` because
there is no transitive inference through conversions).
2024-10-31 11:58:55 -07:00
Pavel Yaskevich
279ef7de2d [CSBindings] Infer bindings through inout in some cases
Allow inferring type of `inout` from a pointer type
(or optional thereof) but delay the binding set because
it might not be complete and object type of `inout` could
also be an Array or C-style pointer type.
2024-09-13 05:08:26 -07:00
Pavel Yaskevich
55b8d9538d [CSSimplify] Rework how/when mismatches between optional types are fixed
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures.

  Inserting fixes too early doesn't help the solver because restriction matching logic would
  record the same fixes.

- Adjust impact of the fixes.

  Optional conversions shouldn't impact the score in any way because
  they are not the source of the issue.

- Look through one level of optional when failure is related to optional injection.

  The diagnostic is going to be about underlying type, so there is no reason to print
  optional on right-hand side.
2024-09-10 10:35:05 -07:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Pavel Yaskevich
79a2ab0c8c [ConstraintSystem] Record unable to infer base only if hole originated from affected reference
If base type of a unresolved member reference couldn't be determined
(represented as a hole type), before recording a fix about lack of
contextual information, let's make sure that hole originated in either
base or result type of this reference, otherwise the problem is
contextual e.g. generic parameter, which supposed to act as contextual
type for a reference, couldn't be inferred.
2020-09-07 11:44:51 -07:00
Pavel Yaskevich
e4f6041dba [ConstraintSystem] Record generic fix if destination of a pointer conversion is invalid
If the right-hand side (destination) of value-to-pointer conversion
is incorrect e.g. base type of member is a hole, let's record
a generic "invalid conversion" failure.

Resolves: rdar://problem/68254165
2020-09-04 13:30:53 -07:00
Pavel Yaskevich
f55ce19127 [Diagnostics] Strip off unrelated optionals from generic parameter diagnostics
In situations where left-hand side requires value-to-optional
promotion which ends up in type mismatch let's not mention
optionals in the diagnostic because they are unrelated e.g.

```swift
func test(_: UnsafePointer<Int>??) {}

var value: Float = 0
test(&value)
```

In this example `value` gets implicitly wrapped into a double optional
before `UnsafePointer<Float>` could be matched against `UnsafePointer<Int>`
associated with the parameter.

Diagnostic is about generic argument mismatch `Float` vs. `Int`
and shouldn't mention any optionals.
2020-05-22 15:12:23 -07:00
Luciano Almeida
08904ffe3f [SR-12242] Apply to Arg involving ConstraintLocator::GenericArgument diagnostics improvement (#30814)
* [CSDiagnostics] Handle arg to param generic when locator points to ConstraintLocator::GenericArgument

* [test] Add SR-12242 test case

* [CSDiagnostics] Handle arg to param on Generic mismatch as a fallback diagnostic

* [CSDiagnostics] Make assign diagnostics in GenericMismatchFailure handle more cases

* [test] Adding test cases for assign expr in GenericMismatch diagnostics

* [CSDiagnostics] Improving inout to pointer argument conversions with optionals diagnostics
2020-04-06 10:25:02 -07:00
Luciano Almeida
822b424487 [tests] Adding SR-12382 test cases 2020-03-25 02:06:43 -03:00
Hamish Knight
45dc9090bf [test] Add regression test for SR-9090
We didn't use to accept pointer conversions passed
to double optional parameters, but do now.
2020-03-18 19:34:34 -07:00
Hamish Knight
1bc56dcc11 [stdlib] Mark some parameters @_nonEphemeral
These include the pointer-to-pointer and pointer-to-buffer-pointer
initialiser parameters amongst a couple of others, such as
`Unmanaged.fromOpaque`, and the source for the `move[...]` family of
methods.
2019-11-03 08:42:26 -08:00
Slava Pestov
eb9fb45d8c Add regression test for fixed crasher 2018-09-24 20:51:27 -07:00
Mark Lacey
7798b9f877 Partial fix for verification of where pointer conversions can appear.
The existing verification seems unnecessarily brittle, but this isn't
a general fix for that problem. This fixes one instance of where we
are generating perfectly valid pointer conversions that the verifier
is currently blowing up on.

I've opened https://bugs.swift.org/browse/SR-8264 to track reworking
this verification to not be quite so brittle.
2018-07-15 23:10:38 -07:00