Commit Graph

2682 Commits

Author SHA1 Message Date
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
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
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
Pavel Yaskevich
7c35c881a9 [CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to double property/variable
Situations like:
```
  let _: Double = <<CGFloat>>
  <var/property of type Double> = <<CGFloat>>
```

Used to be supported due to an incorrect fix added in
diagnostic mode. Lower impact here means that right-hand
side of the assignment is allowed to maintain CGFloat
until the very end which minimizes the number of conversions
used and keeps literals as Double when possible.

Resolves: rdar://139675914
2024-11-13 13:45:56 -08:00
Slava Pestov
59ba1a0294 Sema: Fix request cycle due to unnecessary Sendable check with static method
Fixes rdar://139747886.
2024-11-13 15:16:28 -05:00
Pavel Yaskevich
73d658ae5a [Concurrency] Allow witnesses to adopt concurrency before requirements
Allow witnesses to introduce `any Sendable` types into their interface
before requirements (predicated on presence of `@preconcurrency` and
Swift 5 language mode) as a pathway for concurrency adoption.

Resolves: rdar://134503878
2024-11-06 15:24:36 -08:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Slava Pestov
8beaa7b231 Sema: Fix matchExistentialType() handling of ProtocolCompositionType containing ParameterizedProtocolType
This fixes a soundness hole. We can't just match up the primary
associated types of different protocols.
2024-10-22 20:14:44 -04:00
Slava Pestov
3400022c63 Sema: Remove ConstraintKind::SelfObjectOfProtocol 2024-10-22 20:14:43 -04:00
Slava Pestov
54168849b0 Sema: Don't split up pack types in matchExistentialTypes() 2024-10-22 20:14:43 -04:00
Slava Pestov
53794d3b6a Sema: Rename ConstraintSystem::generateConstraints() to ConstraintSystem::generateOverloadConstraints() 2024-10-22 20:14:43 -04:00
Slava Pestov
1323953219 Sema: Try not to make a negative impact 2024-10-08 16:14:05 -04:00
Slava Pestov
4a82d384b7 Sema: Record synthesized conformances in the trail 2024-10-07 16:50:49 -04:00
Slava Pestov
12eb7cec26 Sema: Record implicit callAsFunction() roots in the trail 2024-10-07 16:50:49 -04:00
Slava Pestov
72a60728fc Sema: Record argument lists in the trail 2024-10-07 16:50:49 -04:00
Slava Pestov
f2412f318e Sema: Record key path expressions in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
881a0100b2 Sema: Record implicit value conversions in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
ac17292dfe Sema: Record preconcurrency closures in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
b961a7ec51 Sema: Record isolated parameters in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
892e79cd70 Sema: Use an xmacro to clean up some duplication in CSTrail.cpp 2024-10-07 16:50:46 -04:00
Slava Pestov
64293ece51 Sema: Push reconciliation down into applySolution() to strengthen invariants
Now, we assert if you try to record the same change twice in any
other code path.
2024-10-07 16:50:45 -04:00
Slava Pestov
3707e49f95 Merge pull request #76808 from slavapestov/cstrail-part-2
Continue migration from SolverScope to SolverTrail
2024-10-02 07:22:50 -04:00
Slava Pestov
a9f392278f Sema: Record argument matching choices in the trail 2024-10-01 18:10:18 -04:00
Slava Pestov
8b4a58fb02 Sema: Record applied disjunctions in the trail 2024-10-01 18:10:18 -04:00
Slava Pestov
df692edc7c Sema: Record fixes in the trail 2024-10-01 12:34:41 -04:00
Slava Pestov
62a470e3d5 Sema: Record conversion restrictions in the trail 2024-10-01 12:34:41 -04:00
Slava Pestov
f563de58ec Merge pull request #76759 from slavapestov/cstrail-part-0
Unify ConstraintGraph change tracking with SavedTypeVariableBindings
2024-09-30 08:01:38 -04:00
Amritpan Kaur
6066418340 Merge pull request #73242 from amritpan/metatype-kp-implementation 2024-09-28 02:46:15 -07:00
Slava Pestov
8ee4eeee55 Sema: Migrate SavedTypeVariableBindings to SolverTrail 2024-09-26 23:15:27 -04:00