Commit Graph

2958 Commits

Author SHA1 Message Date
Alejandro Alonso 61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00
Pavel Yaskevich 8f7e71aa97 Merge pull request #78487 from xedin/Sendable-to-Any-for-lvalues
[CSApply] Sendable-to-Any: Add support for l-value to l-value and inout unsafe casts
2025-01-08 09:57:02 -08:00
Pavel Yaskevich b7a7839ed0 [CSSimplify] Allow any Sendable -> Any if subscript appears in preconcurrency context 2025-01-06 19:41:57 -08:00
Slava Pestov 2d17294d73 Merge pull request #78301 from slavapestov/remove-one-way-constraints
Sema: Remove ConstraintKind::OneWayBindParam and ConstraintKind::OneWayEqual
2025-01-05 10:38:14 -05:00
Hamish Knight 4cbe481f82 Merge pull request #78377 from hamishknight/no-simplify-result
[CS] Don't simplify `FunctionResult` in `simplifyLocator`
2025-01-02 17:26:22 +00:00
Anthony Latsis 5c24df22a0 Merge pull request #78363 from AnthonyLatsis/dicksonia-arborescens
[NFC] Sema: Tidy up `canOpenExistentialCallArgument`
2025-01-02 15:38:27 +00:00
Hamish Knight 2fd6863b1d [CS] Remove AutoClosureForwarding fix
The fix is currently unused, and the
FailureDiagnostic can be inlined into
MissingCallFailure.
2024-12-29 12:25:19 +00:00
Hamish Knight 2c2038d459 [CS] Allow InsertExplicitCall for higher-order functions
Allow `InsertExplicitCall` for e.g converting
`() -> () -> Void` to `() -> Void`. No test since
it's already covered in the test suite when the
next commit is applied.
2024-12-29 12:25:18 +00:00
Anthony Latsis 56d943a77e [NFC] Sema: Tidy up canOpenExistentialCallArgument 2024-12-25 02:25:28 +00:00
Anthony Latsis fc1ad79ddd [NFC] ConstraintSystem: Rename openExistentialType to openAnyExistentialType
This method can open an existential metatype too, and we already use
`isAnyExistentialType` to mean "existential type or existential
metatype"
2024-12-24 17:42:54 +00:00
Pavel Yaskevich a892e571b6 [CSSimplify] Retry member lookup on an insufficiently resolved optional base in diagnostic mode
Re-introduce unsolved member constraint when optional object is
a type variable or member until it's bound, otherwise it's impossible
to tell whether unwrapped base would have a member or not.
2024-12-21 00:42:13 -08:00
Slava Pestov 385d66f24e Sema: Remove ConstraintKind::OneWayEqual 2024-12-21 00:42:13 -08:00
Anthony Latsis 0b204828d5 CSSimplify: Continue matching instead of adding constraint in matchPackExpansionTypes
This ensures that type matching flags are propagated.
2024-12-21 02:13:21 +00:00
Anthony Latsis 352bddd9b2 [NFC] CSSimplify: Small matchPackExpansionTypes cleanup 2024-12-20 19:33:55 +00:00
Anthony Latsis cd1ef24c49 Merge pull request #78309 from AnthonyLatsis/nymphaea
Assortment of small fixes and cleanups
2024-12-20 06:51:19 +00:00
Anthony Latsis 967f99ff22 [NFC] Sema: Remove unused generic parameter result from canOpenExistentialCallArgument 2024-12-20 02:58:28 +00:00
Slava Pestov bb55d9c59a Sema: Remove -experimental-one-way-closure-params 2024-12-19 13:14:11 -05:00
Pavel Yaskevich 19350d9737 Merge pull request #63585 from xedin/solver-perf
[CSSolver] Implementation of disjunction choice favoring algorithm
2024-12-18 09:47:59 -08:00
Anthony Latsis b6def6ec71 Merge pull request #77892 from AnthonyLatsis/magnolia-grandiflora
Sema: Subscript called with opened existential cannot produce lvalue if result is type-erased
2024-12-18 12:25:45 +00:00
Pavel Yaskevich 636525ebd9 Merge pull request #78171 from xedin/rdar-140300022
[TypeChecker/SILGen] Allow `any Sendable` to match `Any` while matching generic arguments
2024-12-17 20:24:34 -08:00
Anthony Latsis 6612c9cf89 Sema: Subscript called with opened existential cannot produce lvalue if result is type-erased 2024-12-17 23:03:38 +00:00
Pavel Yaskevich cb876cbd9e [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?`.
2024-12-17 11:36:41 -08:00
Pavel Yaskevich 4432c51f57 [CSGen] Remove ConstraintOptimizer and all favoring logic 2024-12-17 11:36:37 -08:00
Anthony Latsis f43166a5d0 Merge pull request #77851 from AnthonyLatsis/day-2 2024-12-17 12:03:09 +00:00
Pavel Yaskevich a2f711cf8e [ConstraintSystem] Make any Sendable -> Any behave the same in all language modes 2024-12-16 13:57:33 -08:00
Pavel Yaskevich 0de9e9cd1d [CSSimplify] Extend any Sendable -> Any conversion support to function argument/result positions in generic argument context 2024-12-13 17:27:06 -08:00
Pavel Yaskevich fb54682753 [CSSimplify] Don't match pack expansion patterns if shapes are not the same
This helps to avoid spurious failures pointing to involved pattern types
because they won't match exactly if shape types are not the same.
2024-12-12 20:55:02 -08:00
Pavel Yaskevich 0772e4cbc7 [CSSimplify] Presence of conversion restrictions should delay fixing of generic arguments
Conversion restrictions like "deep equality" could produce a more
narrow/actionable fixes.
2024-12-12 18:12:01 -08:00
Pavel Yaskevich 6f967daf7a [CSSimplify] Increase generic argument mismatch score when matched against marker protocol
This indicates that the type doesn't have appropriate annotations
i.e. for concurrency or ownership.
2024-12-12 14:36:16 -08:00
Pavel Yaskevich c6a8cbfa7b [CSSimplify] Allow any Sendable to match Any while matching generic arguments
Allow `any Sendable` to match `Any` constraint while matching
generic arguments i.e. `[any Sendable]` -> `[Any]` when `any Sendable`
type comes from context that involves `@preconcurrency` declarations
in non-strict concurrency compiler mode.

Note that it's currently impossible to figure out precisely
where `any Sendable` type came from.
2024-12-11 11:40:22 -08:00
Pavel Yaskevich 17093b35d7 [CSSimplify] Delay binding generic argument type variables to any Sendable
Prevent generic arguments from being assigned `any Sendable`
directly, that should only happen through inference. This is
required because we allow `any Sendable` -> `Any` conversion
in modes without strict concurrency enabled to maintain source
compatibility and let the developers annotate existing APIs
with `any Sendable` and other concurrency attributes.
2024-12-10 17:39:24 -08:00
Pavel Yaskevich 7701f4e0dd [CSSimplify] Avoid resolving extraneous (trailing) closures
If a (trailing) closure is determined to be an extraneous argument
for one of the overload choices it needs to be marked as hole as
eagerly as possible and prevented from being resolved because
otherwise it's going to be disconnected from the rest of the
constraint system and resolution might not be able to find all of
the referenced variables. This could result either in crashes
or superfluous diagnostics.

Resolves: rdar://141012049
2024-12-06 16:41:49 -08:00
Hamish Knight c50a656db8 Merge pull request #77983 from hamishknight/ref-wrap
[CS] Correctly handle compound-applied functions with property wrappers
2024-12-05 22:36:12 +00:00
Hamish Knight 48dc186269 [CS] Correctly handle compound-applied functions with property wrappers
Avoid wrapping parameters in the function reference
for compound applies, and make sure we consult
the parameter label in the compound name if it's
present to determine whether to match using the
projected value or not. This matches the existing
logic in `unwrapPropertyWrapperParameterTypes`.
2024-12-05 15:55:20 +00:00
Slava Pestov c0787f337f Sema: Fix soundness hole with variable initializers and opaque return types
Just because the type of the initializer expression is an opaque return type,
does not mean it is the opaque return type *for the variable being initialized*.

It looks like there is a bit of duplicated logic and layering violations going
on so I only fixed one caller of openOpaqueType(). This addresses the test case
in the issue. For the remaining calls I added FIXMEs to investigate what is
going on.

Fixes https://github.com/swiftlang/swift/issues/73245.
Fixes rdar://127180656.
2024-12-04 15:13:22 -05:00
Anthony Latsis 73cabe303b Sema: Account for existential member access limitations in doesStorageProduceLValue 2024-12-04 15:03:39 +00:00
Hamish Knight d25bdfa4a3 [CS] Remove hack for rdar://139234188
Now that "is compound" is a separate bit in
FunctionRefInfo, we can correctly track the
application level for an EnumElementPattern.
2024-12-03 11:32:11 +00:00
Hamish Knight 0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Pavel Yaskevich 8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Hamish Knight 73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Anthony Latsis 1ce0aeefd2 Sema: Compute existential member access limitations for storage declarations 2024-11-25 14:16:07 +00:00
Hamish Knight 746135b4d7 [CS] Add a narrow hack for rdar://139234188
Currently we set `FunctionRefKind::Compound` for
enum element patterns with tuple sub-patterns to
ensure the member has argument labels stripped. As
such, we need to account for the correct application
level in `getNumApplications`. We ought to be
setting the correct FunctionRefKind and properly
handling the label matching in the solver though.
We also ought to consider changing FunctionRefKind
such that "is compound" is a separate bit from the
application level.

rdar://139234188
2024-11-22 13:43:58 +00:00
Pavel Yaskevich df6950af5d [CSSimplify] Fix locator of pack expansion pattern conformance constraint 2024-11-21 15:48:28 -08:00
Pavel Yaskevich 9665b0d4e3 Merge pull request #77592 from xedin/rdar-139675914
[CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to …
2024-11-20 08:44:19 -08:00
Slava Pestov 872f242e93 Merge pull request #77683 from slavapestov/opened-type-optzn
Sema: Clean up and optimize interface type opening
2024-11-18 17:40:52 -05:00
Pavel Yaskevich 26e888e45e Merge pull request #77652 from xedin/issue-77644
[CSSimplify] Handle invalid type specializations
2024-11-18 10:14:14 -08:00
Slava Pestov 09df48f9fb Sema: Remove DenseMap usage when opening types 2024-11-18 11:40:38 -05:00
Slava Pestov 47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Pavel Yaskevich 30c196118e [CSSimplify] Handle invalid type specializations
If the base type of the specialization is invalid,
the AST node is going to be replaced with `ErrorExpr`.

We need to handle that gracefully when attempting
to apply specialization in such situations.

Resolves: https://github.com/swiftlang/swift/issues/77644
2024-11-15 11:10:51 -08:00