Commit Graph

2776 Commits

Author SHA1 Message Date
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
Doug Gregor
88d630446c [Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes
Thank you, Pavel!
2025-04-14 10:19:11 -07:00
Pavel Yaskevich
9da457d129 [Sema/SILGen] NFC: Remove all mentions of @execution from comments 2025-04-11 15:59:25 -07:00
Slava Pestov
7399eeb602 AST: Remove type parameter from ProtocolConformanceRef::getWitnessByName() 2025-04-03 17:35:33 -04:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Pavel Yaskevich
bf2d01e562 Merge pull request #80419 from xedin/revert-pr-79397
Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
2025-04-02 00:10:23 -07:00
Pavel Yaskevich
35077a01d1 Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
This reverts commit f0f5ffcebf.
2025-03-31 13:58:38 -07:00
Allan Shortlidge
5dc7a204cb Sema: Address -Wunused-but-set-variable warnings. 2025-03-28 12:33:40 -07:00
Pavel Yaskevich
367e5e20f1 Merge pull request #80329 from xedin/execution-caller-func-to-parameter-isolation-func
[CSSimplify] Allow conversion from caller isolated to parameter isola…
2025-03-27 10:35:09 -07:00
Pavel Yaskevich
cdae26aece [CSSimplify] Allow conversion from caller isolated to parameter isolation function types
This requires special handling during function type matching
because caller isolated function types don't get an isolated
parameter until SILGen.
2025-03-26 17:55:48 -07:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Pavel Yaskevich
552106d536 Merge pull request #80081 from xedin/rdar-143161190
[CSSimplify] Open key path type before assignment to its record requirements
2025-03-19 09:50:11 -07:00
Amritpan Kaur
a96b780a28 [Sema] Diagnose method arg captures that are not Hashable/Equatable. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
0e895c6a2b [CSApply] Solve keypath methods and initializers. 2025-03-19 08:56:03 -07:00
Slava Pestov
f7b0b72766 Sema: Refactor TypeChecker::containsProtocol() a bit 2025-03-18 19:38:21 -04:00
Pavel Yaskevich
e0f9e65976 [CSSimplify] NFC: assignFixedType no longer accepts a locator
`assignFixedType` now accepts `bool` as a third parameter but
not all call sites were updated to reflect that, some of them
are still passing `ConstraintLocator *` which implicitly gets
converted to a `bool`.
2025-03-18 00:16:22 -07:00
Pavel Yaskevich
a8baec6c41 [CSSimplify] Open key path type before assignment to its record requirements
`Root` and `Value` generic parameters now have conformance requirements
which we need to account for post-binding inference.
2025-03-17 17:03:09 -07:00
Pavel Yaskevich
6c22036931 [CSSimplify] NFC: Perform assignments to a key path in a separate method
Previously key path type didn't have any requirements on their
root and value types but now that they do, we need a dedicated
place to perform an assignment and open/record all of the requirements.
2025-03-17 14:06:45 -07:00
eeckstein
47b449372e Merge pull request #79917 from eeckstein/rename-opened-archetype-type
AST: rename OpenArchetypeType -> ExistentialArchetypeType
2025-03-12 06:01:10 +01:00
Slava Pestov
9e721a35f2 Merge pull request #79914 from slavapestov/retry-removing-one-way-equal
Sema: Mostly remove one-way constraints
2025-03-11 21:24:57 -04:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Slava Pestov
4c60e036ac Merge pull request #79882 from slavapestov/sizeof-constraint
Sema: Optimize Constraint layout to save 24 bytes
2025-03-11 14:30:44 -04:00
Slava Pestov
6d8b55a9f6 Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()
The two GatherKinds no longer share any implementation, so there's
no point keeping the logic together. Doing this also allows removing
the acceptConstraintFn from gatherAllConstraints(), which further
simplifies depthFirstSearch().
2025-03-11 13:55:40 -04:00
James Brown
edb0fa7b3d [CS] Deep-equality match OpenedArchetypeTypes
When we have two distinct OpenedArchetypeTypes that have the same
interface type and UUID, we need to match their generic arguments.
2025-03-10 19:19:53 -04:00
Slava Pestov
83118a73ed Sema: Shave another 8 bytes off of Constraint 2025-03-10 14:53:48 -04:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Doug Gregor
6a4d1a41c4 Prohibit isolated conformances with Sendable(Metatype) constraints
Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
2025-03-01 08:19:42 -08:00
Slava Pestov
3a01f206c5 Sema: Rename LocatorPathElt::OptionalPayload to ::OptionalInjection 2025-02-25 17:22:41 -05:00
Hamish Knight
c69590fbdd [CS] Clean up pack expansion environment handling a little
- Track environments for `PackExpansionExpr` directly
instead of using a locator.
- Split up the querying and creation of the environment
such that the mismatch logic can be done directly in
CSSimplify instead of duplicating it.
- Just store the environment directly instead of
the shape and UUID.
2025-02-20 21:31:46 +00:00
Hamish Knight
9c04fd8cd3 [CS] NFC: Factor out matchPackElementType 2025-02-20 21:31:46 +00:00
Pavel Yaskevich
9cbd8e1f10 Merge pull request #79382 from xedin/more-Sendable-to-Any-problems
[Concurrency] Fix a few issues with `Senable` and `Any`
2025-02-15 08:23:28 -08:00
Pavel Yaskevich
515221c959 Merge pull request #79375 from xedin/isolation-caller-in-type-context
[AST/Sema] Add new function type isolation - `caller` to cover `@execution(caller)` attribute
2025-02-14 16:01:28 -08:00
Slava Pestov
f0f5ffcebf Sema: Allow optional-to-optional CGFloat <-> Double conversion
After https://github.com/swiftlang/swift/pull/78957, there is no
technical reason to not allow this conversion. This is needed for
an upcoming optimization.
2025-02-14 13:08:57 -05:00
Pavel Yaskevich
484e0a7437 [ConstraintSystem] Sendable-to-Any: Allow conversion when in inout positions
It should be possible to pass values with `any Sendable` as arguments
to `inout` parameters that expect `Any`. This is pretty much the same
as an l-value conversion.

Resolves: https://github.com/swiftlang/swift/issues/79361
Resolves: rdar://144794132
2025-02-13 17:03:00 -08:00