Commit Graph

2865 Commits

Author SHA1 Message Date
Slava Pestov
a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Slava Pestov
c344d6b0eb Sema: Rename getTypeOf{Member,}ReferenceImpl() to Pre() and factor out Post() versions 2025-09-18 11:31:59 -04:00
Hamish Knight
deab5f7970 Merge pull request #84280 from hamishknight/csapply-cleanup
Reapply: [Sema] Remove some unreachable code from CSApply
2025-09-18 14:25:51 +01:00
Hamish Knight
8102e39f39 [CS] Record fix when encountering decl reference with placeholder type
We allow placeholder types in interface types in certain cases to allow
better recovery since we can suggest the inferred type as a replacement.
When referencing those decls though we need to make sure we record a fix
since we cannot form a valid solution with them.
2025-09-17 20:51:06 +01:00
Hamish Knight
cdf0bfbaf7 [CS] Remove a couple uses of recordAnyTypeVarAsPotentialHole
It's not actually clear these are necessary anymore, and in one case
it actually makes a diagnostic worse.
2025-09-17 16:11:53 +01:00
Pavel Yaskevich
ac27f53c04 [CSSimplify] Fix key path to function conversion to check key path requirements
`KeyPath` types now have conformance requirements placed on their
`Root` and `Value` types which need to be checked even when there
is a key path to function conversion involved, otherwise the solver
would be accepting invalid code.

Note that without function conversion the requirements come from
a type opened during assignment - https://github.com/swiftlang/swift/pull/80081/files.

Resolves: https://github.com/swiftlang/swift/issues/84150
2025-09-15 00:35:19 -07:00
Hamish Knight
71d825dcb8 [CS] NFC: Remove CTP_ForEachStmt 2025-09-05 22:20:28 +01:00
Hamish Knight
1b0eed22be [CS] Better propagate holes from contextual types
Eagerly bind invalid type references to holes and propagate contextual
type holes in `repairFailures`. This avoids some unnecessary diagnostics
in cases where we have an invalid contextual type.
2025-08-29 15:04:20 +01:00
Slava Pestov
9e3d0e0a8c Sema: Move weird ConstructorDecl hack from getEffectiveOverloadType() to simplifyAppliedOverloadsImpl() 2025-08-27 15:34:26 -04:00
Pavel Yaskevich
29b04f4a63 [CSSimplify] SE-0324: Use correct conversion when converting array types
If the argument type is an array and it's passed to an imported declaration
that accepts a raw pointer, the solver should use an "array-to-c-pointer"
conversion instead of the one for pointers.

Resolves: rdar://158629300
2025-08-21 15:38:17 -07:00
Hamish Knight
4423399fce [CS] Use apply component locator for verifyThatArgumentIsHashable
For a method key path use the locator for the apply itself rather
than the member, ensuring we handle invalid cases where the apply is
the first component, and providing more accurate location info.
2025-08-15 21:30:22 +01:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
Pavel Yaskevich
387b4ff2d3 [CSSimplify] Skip member access on existential checks if base is existential only due to marker protocols
If the base type is composed with marker protocol(s) i.e.
`<<Type>> & Sendable`, let's skip this check because such
compositions are always opened and simplified down to a
superclass bound post-Sema.

Resolves: rdar://148782046
2025-08-04 17:00:48 -07:00
Hamish Knight
fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Pavel Yaskevich
94e28b63d7 [Concurrency] InferSendableFromCaptures: Rework check to delay lookup
The current implementation of the check accounts only for the overload
choices present in the initial lookup but for some situations, like
bridged or optional base types, `performMemberLookup` uses a secondary
lookup as well, results of which are ignored.

Let's fold the check into `addChoice` instead and set the the flag there
to make sure that all of the choices are considered.

Resolves: rdar://143586718
2025-07-21 10:33:46 -07:00
Slava Pestov
b39d3aee57 Sema: Special-case recording of Bind constraint in PreparedOverload 2025-07-11 19:57:29 -04:00
Slava Pestov
6e212de774 Sema: Lazily build prepared overload when simplifying BindOverload constraint 2025-07-11 19:57:29 -04:00
Slava Pestov
9a8f3baa06 Sema: Add room for a PreparedOverload to BindOverload constraint 2025-07-10 19:53:19 -04:00
Slava Pestov
f7a552385c Sema: PreparedOverload => PreparedOverloadBuilder 2025-07-10 19:53:18 -04:00
Slava Pestov
0ab6d53fff Sema: Implement matchTypes() for BuiltinFixedArrayType 2025-07-09 22:16:13 -04:00
Slava Pestov
751edee921 Sema: Rework PreparedOverload to store a list of changes 2025-07-09 15:00:10 -04:00
Slava Pestov
2a0b11a22e Sema: Collect property wrappers in PreparedOverload 2025-07-09 15:00:03 -04:00
Slava Pestov
426c7a3fdf Sema: Collect constraints in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
543793564e Sema: Record opened type variables in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
b9256307b5 Sema: Stub out PreparedOverload 2025-07-09 15:00:02 -04:00
Pavel Yaskevich
69bd48e2ea [CSSimplify] CGFloat-Double: Rank narrowing correctly when result is injected into an optional
If result of `CGFloat` -> `Double` conversion is injected into an optional
it should be ranked based on depth just like when locator is fully simplified.

For example:

```swift
func test(v: CGFloat?) {
   _ = v ?? 2.0 / 3.0
}
```

In this expression division should be performed on `Double` and result
narrowed down (based on the rule that narrowing conversion should always
be delayed) but `Double` -> `CGFloat?` was given an incorrect score and
instead of picking `?? (_: T?, _: T) -> T` overload, the solver would
use `?? (_: T?, _: T?) -> T?`.

(cherry picked from commit cb876cbd9e)
2025-06-27 23:43:09 -07:00
Pavel Yaskevich
0999792bf4 Merge pull request #82467 from xedin/swift-testing-troubles
[CSSimplify] Narrow down tuple wrapping for pack expansion matching
2025-06-25 16:03:07 -07:00
Pavel Yaskevich
4804f2131b [CSSimplify] Narrow down tuple wrapping for pack expansion matching
Follow-up for https://github.com/swiftlang/swift/pull/82326.

The optional injection is only viable is the wrapped type is
not yet resolved, otherwise it's safe to wrap the optional.
2025-06-24 15:30:25 -07:00
Pavel Yaskevich
b1470321e8 Merge pull request #82430 from xedin/issue-82397
[CSSimplify] Prevent `missing call` fix from recording fixes while ma…
2025-06-24 09:12:33 -07:00
Pavel Yaskevich
7ecb1fd1db [CSSimplify] Prevent missing call fix from recording fixes while matching types
We need to be very careful while matching types to test whether a
fix is applicable or not to avoid adding extraneous fixes and failing
the path early. This is a temporary workaround, the real fix would
be to let `matchTypes` to propagate `TMF_ApplyingFixes` down.

Resolves: rdar://154010220
Resolves: https://github.com/swiftlang/swift/issues/82397
2025-06-23 13:38:38 -07:00
Pavel Yaskevich
286f975c29 Merge pull request #82320 from xedin/hide-solver-hacks-behind-a-flag
[ConstraintSystem] Guard all the performance hacks with a flag
2025-06-20 00:12:16 -07:00
Pavel Yaskevich
6cfbafd968 [CSSimplify] VariadicGenerics: Don't attempt to wrap optional into one-element tuple
If we have a tuple with unresolved pack expansion on one side
and an optional type on the other, prevent `matchTypes` from
wrapping optional into a one-element tuple because the matching
should be handled as part of the optional injection.

Resolves: rdar://152940244
2025-06-17 18:25:22 -07:00
Pavel Yaskevich
fc573b6612 [ConstraintSystem] Guard all the performance hacks with a flag
Package the flag into `performanceHacksEnabled()` method on
`ConstraintSystem` and start using it to wrap all of the hacks
in constraint generator and the solver.
2025-06-17 13:53:05 -07:00
Hamish Knight
6d0da8d5cc [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-12 12:11:19 +01:00
Anthony Latsis
f2e1420a90 Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.
2025-06-05 18:01:20 +01:00
Anthony Latsis
7c431c9a9a [NFC] Make a function static 2025-06-05 17:59:34 +01:00
Pavel Yaskevich
7305275dbd [CSSimplify] Produce tailored fixes for a few generic argument mismatches
- Mismatch in tuple element position should reference whole tuple
  with a note for mismatch position;
- Situations where optional object type is not a class but matched
  against `AnyObject` have a tailored fix.
2025-06-03 00:49:06 -07:00
Pavel Yaskevich
27c28d4d64 [CSSimplify] Fix matchDeepEqualityTypes to allow fixing of optionals
Attempting to propagate generic argument failures up is not always
reliable, `matchDeepEqualityTypes` should avoid using `TMF_ApplyingFix`
while dealing with optionals and instead let `repairFailures` decide
whether to use generic arguments mismatch fix to a more general one.
2025-06-03 00:48:59 -07:00
Pavel Yaskevich
65e83a8bb1 [CSSimplify] Increase impact of a generic argument mismatch if mismatch is contextual
If generic arguments mismatch ends up being recorded on the result
of the chain or `try` expression it means that there is a contextual
conversion mismatch.

For optional conversions the solver currently generates a disjunction
with two choices - bind and optional-to-optional conversion which is
anchored on the contextual expression. If we can get a fix recorded
there that would result in a better diagnostic. It's only possible
for optional-to-optional choice because it doesn't bind the
variable immediately, so we need to downgrade direct fixes to prevent
`bind` choice from considered better.
2025-06-02 23:49:52 -07:00
Slava Pestov
f6f0d75263 Merge pull request #81843 from slavapestov/hamish-fuzzer-fixes
Hamish fuzzer fixes
2025-05-31 12:28:56 -04:00
Slava Pestov
401f527bbb Sema: Don't construct TupleType with InOutType inside 2025-05-30 16:27:01 -04:00
Pavel Yaskevich
b12d844fcc [CSSimplify] Remove ad-hoc optional mismatch handling for arguments
Since we have `repairViaOptionalUnwrap`, let's use that to fix
argument/parameter mismatches instead of doing ad-hoc matching.
2025-05-30 09:52:57 -07:00
Pavel Yaskevich
2d1f9d3f18 [CSSimplify] Move inout failures handing to LValueConversion block
This is cleanup that allows us to avoid a fallthrough to `ApplyArgToParam`
handling for `inout` failures.
2025-05-30 09:52:57 -07:00
Pavel Yaskevich
ded6158cc3 [CSSimplify] Detect when generic argument mismatch applies to argument and produce a tailed fix
The problem detection logic currently expects `generic argument #<N>`
location to always be associated with two generic types, but that
is not always the case, this locator element is sometimes used for
i.e. optional object types and pointer `Pointee` type when types
appear in argument positions. This needs to be handled specifically.

Resolves: rdar://82971941
2025-05-30 09:52:57 -07:00
Pavel Yaskevich
10186d664b [Diagnostics] Assign missing member eagerly when there is no context
Without contextual information it won't be possible to bind a missing
member to a concrete type later, so let's bind them eagerly and propagate
placeholders outward.

Resolves: rdar://152021264
Resolves: https://github.com/swiftlang/swift/issues/81770
2025-05-30 09:52:52 -07:00
Pavel Yaskevich
d83ec7b3a5 [Diagnostics] Diagnose existential mismatch in a literal collection element position
If key or value of a literal collection expression doesn't conform
to protocol(s) expected by the contextual existential type, let's
diagnose that via a tailed collection mismatch fix instead of a
generic conformance one.

Resolves: rdar://103045274
2025-05-28 14:33:18 -07:00
Pavel Yaskevich
b3e9cf3424 [Diagnostics] Use argument mismatch fix for @autoclosure result positions
`@autoclosure` is associated with a parameter, we use argument mismatch fix
to diagnose missing explicit calls as well as any mismatches in that position.

Resolves: rdar://110527062
2025-05-28 14:33:18 -07:00
Pavel Yaskevich
ef2fa4a1b6 [Diagnostics] Don't attempt to force unwrap invalid optional chaining in the argument position
If the argument has an extra `?` or `!`, let's not attempt to force
optional (because it's use is already invalid) and re-introduce
the constraint with unwrapped type instead. This would help to diagnose
the invalid chaining as well as any argument to parameter mismatches.

Resolves: rdar://126080504
2025-05-28 14:33:17 -07:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00