Commit Graph

2769 Commits

Author SHA1 Message Date
Slava Pestov
99595e615e Revert "Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()"
This reverts commit 2230c3a17e.
2025-02-02 00:43:15 -05:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Slava Pestov
4ae57acaa2 Sema: Remove ConstraintSystem::ImplicitValueConversions 2025-01-27 17:28:19 -05:00
Slava Pestov
c47ff06a72 Sema: Tiny cleanup for matchTypes() 2025-01-27 16:42:03 -05:00
Slava Pestov
2230c3a17e 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-01-27 10:27:00 -05:00
Slava Pestov
5f79319c45 Merge pull request #78559 from slavapestov/fix-rdar141968103
Sema: Relax primary associated type matching in matchExistentialTypes()
2025-01-13 12:04:57 -05:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Slava Pestov
c257cdbc7c Sema: Relax primary associated type matching in matchExistentialTypes()
Recently I found a soundness hole here, where we would allow conversion
between `any P<T>` and `any Q<T>` even if P and Q have different primary
associated types.

However, the fix was too strict, because we still want to allow the
conversion when the associated types have the same name.

Fixes rdar://141968103.
2025-01-10 15:37:10 -05:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Slava Pestov
c12e0a1e8f Merge pull request #78470 from slavapestov/fix-rdar141961300
Sema: Fix local property wrappers on constructor
2025-01-08 21:33:12 -05:00
Slava Pestov
c17044381e Sema: Fix local property wrappers on constructor
Fixes rdar://problem/142443421.
2025-01-08 14:31:12 -05:00
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