Commit Graph

2264 Commits

Author SHA1 Message Date
Pavel Yaskevich
c43c970001 Merge pull request #64931 from xedin/rdar-100369066
[Diagnostics] Forgo all restrictions if one side of conversion has in…
2023-04-05 13:31:11 -07:00
Pavel Yaskevich
9816fffcd3 [Diagnostics] Forgo all restrictions if one side of conversion has invalid use of &
None of the restrictions like existential conversion or optional
promotion would actually match, so there is no point in trying them
just to add more unrelated fixes.

Resolves: rdar://100369066
2023-04-04 18:00:13 -07:00
Pavel Yaskevich
3714c48af0 [CSSimplify] Prevent invalid pack references from causing infinite loops
When `matchTypesBindTypeVar` detects invalid pack reference it should
reset the type to a placeholder and allow binding to go through,
otherwise, if binding comes from inference, returning without binding
would create an infinite loop because type variable would perpetually
be the best choice to attempt.
2023-04-04 09:57:31 -07:00
Pavel Yaskevich
b07dafab0f [CSSimplify] Exploaded tuple argument should assume param's label if first element doesn't have one
If tuple doesn't have a label for its first element
and parameter does, let's assume parameter's label
to aid argument matching. For example:

```swift
func test(val: Int, _: String) {}

test(val: (42, "")) // expands into `(val: 42, "")`
```

Resolves: rdar://106775969
2023-03-29 10:49:05 -07:00
Pavel Yaskevich
736fc8b375 Merge pull request #64608 from xedin/pack-expansion-param-in-init
[ConstraintSystem] Fix support for a single pack expansion parameter …
2023-03-28 09:32:58 -07:00
Pavel Yaskevich
e968ea1b48 Merge pull request #64591 from xedin/rework-tuple-with-pack-matching
[AST] PackExpansionMatcher: use common prefix/suffix algorithm for tuple matching
2023-03-27 13:12:30 -07:00
Pavel Yaskevich
24625bb809 [ConstraintSystem] Fix support for a single pack expansion parameter in init references
In Swift 5 and earlier initializer references are handled in a special
way that uses a type variable to represent a type of the parameter
list. Such type variables should be allowed to bind to a pack expansion
type to support cases where initializer has a single unlabeled variadic
generic parameter - `init(_ data: repeat each T)`.
2023-03-24 09:03:19 -07:00
Pavel Yaskevich
65cfef6555 [CSSimplify] Account for the fact that variadic generic parameters could be specialized
If generic parameter comes from a variadic type declaration it's
possible that it got specialized early and is no longer represented
by a pack expansion type. For example, consider expression -
`Test<Int>(42)` where `Test<each T>` and the initializer
is declared as `init(_: repeat each T)`. Although declaration
based information reports parameter at index 0 as variadic generic
the call site specializes it to `Int`.

Resolves: rdar://107151854
2023-03-23 21:25:29 -07:00
Pavel Yaskevich
1b42e55039 [CSSimplify] NFC: Refactor TupleMatcher to consolidate pack expansion matching 2023-03-23 15:07:28 -07:00
Pavel Yaskevich
b4937be253 [CSSimplify] Don't propagate contextual parameter type if it's a pack expansion
Pack expansion types are handled by matching logic, optimization
that attempts to propagate types into the body of the closure should
consider them unsuitable even if the pack expansion matches a single
parameter.
2023-03-22 09:10:23 -07:00
Holly Borla
da3079de05 [ConstraintSystem] Diagnose pack expansion expressions in non-variadic contexts. 2023-03-21 21:58:05 -07:00
Holly Borla
c60b4860ab Merge pull request #64498 from hborla/diagnose-pack-outside-expansion-expr
[ConstraintSystem] Enforce `TVO_CanBindToPack`, and diagnose pack references outside of pack expansion expressions.
2023-03-21 14:00:52 -07:00
Alex Hoppen
9bd880ddde Merge pull request #64405 from ahoppen/ahoppen/fix-locator-simplification
[CS] Fix locator simplification with 'Member' path element
2023-03-21 09:19:14 -07:00
Holly Borla
cb19fc3a71 [ConstraintSystem] Enforce TVO_CanBindToPack, and diagnose pack references outside
of pack expansion expressions.
2023-03-20 20:13:48 -07:00
Alex Hoppen
cebc084367 [CS] Fix locator simplification with 'Member' path element
Previously, a `Member` path element in a `ConstraintLocator` was simplified to the base on which the member was accessed. This is incorrect.
2023-03-20 09:19:21 -07:00
Pavel Yaskevich
ff51291d30 [CSSimplify] Don't enable OneWayBindParam for result builder transformed closures
This means two things:

- transformed closures behave just like regular multi-statement closures
- It's now possible to pass partially resolved parameter types into
  the closure which helps with diagnostics.
2023-03-16 16:16:57 -07:00
Luciano Almeida
4d981e3c0b Merge pull request #63904 from LucianoPAlmeida/ambiguous-overload
[Sema] Diagnose function coercion ambiguity
2023-03-15 23:18:00 -03:00
Pavel Yaskevich
a7fbc04307 [CSSimplify] PointerToCPointer: Allow element type inference for "argument" pointers
If the type of the "argument" pointer is not yet resolved the solver
should equate it to that of the "parameter" pointer as regular
conversions do.
2023-03-14 15:06:24 -07:00
Pavel Yaskevich
e4eb271359 [CSSimplify] Implement ArrayToCPointer conversion
Extends implementation to support conversions between arrays
and pointers that are allowed by the SE-0324 proposal.

Resolved: rdar://99089335
2023-03-14 14:36:52 -07:00
Pavel Yaskevich
438ee330f1 [ConstraintSystem] Add new conversion kind - ArrayToCPointer
It's `ArrayToPointer` conversion that has PointerToCPointer
semantics for (un-)signed integer element types.
2023-03-14 11:22:52 -07:00
Hamish Knight
c77caf2c72 [CS] NFC: Simplify SyntacticElementTarget construction for ExprPattern 2023-03-14 11:56:01 +00:00
Pavel Yaskevich
c106705883 [CSSolver] NFC: Replace some uses of last() with endsWith() 2023-03-13 11:24:15 -07:00
Luciano Almeida
d5a9d6ab83 [ConstraintSystem] Introduce new locator path elemet to identify coercion 2023-03-11 18:47:53 -03:00
Pavel Yaskevich
a52800031a Merge pull request #64259 from xedin/variadic-matching-fix
[CSSimplify] Variadics: Allow unlabeled matching after pack expansion…
2023-03-10 08:06:46 -08:00
Pavel Yaskevich
36200101f8 [CSSimplify] Variadics: Allow unlabeled matching after pack expansion argument
Remove a bit of logic from `matchCallArgumentsImpl` that prevented
unlabeled argument matching after pack expansion argument until next
labeled argument because it incorrectly assumed that it represents
variadic forwarding.
2023-03-09 15:25:43 -08:00
Pavel Yaskevich
70c370d0b6 [CSSimplify] Propagate contextual result type into result builder transformed closure
Propagate fully or partially resolved contextual type down into
the body of result builder transformed closure by eagerly binding
intermediate body result type to the contextual one. This helps to
determine when closure body could be solved early.

Resolves: rdar://106364495
2023-03-08 10:46:02 -08:00
Holly Borla
df755d4f90 Merge pull request #64192 from xedin/rdar-106364495
[CSSimplify] Propagate contextual result type into result builder tra…
2023-03-08 09:53:38 -08:00
Hamish Knight
fdc9817471 Merge pull request #64174 from hamishknight/pattern-requests 2023-03-08 10:52:40 +00:00
Pavel Yaskevich
3ff03469e7 [CSSimplify] Propagate contextual result type into result builder transformed closure
Propagate fully or partially resolved contextual type down into
the body of result builder transformed closure by eagerly binding
intermediate body result type to the contextual one. This helps to
determine when closure body could be solved early.

Resolves: rdar://106364495
2023-03-07 16:17:10 -08:00
Hamish Knight
98855963ac [Sema] Introduce EnumElementExprPatternRequest
This is needed to ensure we only ever synthesize
a single unique ExprPattern when solving an
EnumElementPattern that we failed to lookup a
member for.
2023-03-07 15:16:36 +00:00
Hamish Knight
37b0a6074f [Sema] Introduce ExprPatternMatchRequest
This replaces `synthesizeTildeEqualsOperatorApplication`,
and synthesizes the match expression and var
on-demand.

Additionally, it pushes the lookup logic into
pre-checking.
2023-03-07 15:16:35 +00:00
Holly Borla
75c1b6e199 Merge pull request #64166 from hborla/parameter-pack-substitution 2023-03-07 06:39:50 -08:00
Hamish Knight
43f0694fa3 Merge pull request #64149 from hamishknight/more-nfc-changes 2023-03-07 10:49:54 +00:00
John McCall
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08:00
Holly Borla
b0211233a9 Merge pull request #64146 from hborla/shape-of-assertion
[ConstraintSystem] Don't propagate errors for invalid `DeclRef`s in the pattern of a pack expansion.
2023-03-06 14:23:13 -08:00
Hamish Knight
2976edbe20 [CS] Rename SolutionApplicationTarget -> SyntacticElementTarget 2023-03-06 20:54:06 +00:00
Holly Borla
721b846e16 [ConstraintSystem] Don't propagate errors for invalid DeclRefs in the pattern
of a pack expansion.
2023-03-06 10:51:43 -08:00
Pavel Yaskevich
342e5f6725 Merge pull request #64036 from xedin/rdar-106054263
[CSSimplify] Detect and diagnose generic argument mismatches individually
2023-03-06 10:18:09 -08:00
Holly Borla
8012e45109 [Diagnostics] Diagnose pack element expressions containing a non-pack subexpression. 2023-03-05 00:11:54 -08:00
Pavel Yaskevich
b7745b04bd [CSSimplify] Detect and diagnose generic argument mismatches individually
Generic arguments types are not always resolved enough to enable
aggregated mismatch fixes, which means that the solver should be
able to handle standalone generic argument matching constraints
and create a fix per mismatch location to coalesce them during
diagnostics.

Resolves: rdar://106054263
2023-03-04 21:57:53 -08:00
Holly Borla
e063f02a42 [ConstraintSystem] Handle invalid pack element bindings during PackElementOf
simplification.
2023-03-04 19:43:43 -08:00
Joe Groff
5ef0c4eaad Merge pull request #64058 from jckarter/minimize-abi-effect-of-parameter-modifiers-b
Only mangle `borrowing`/`consuming` when they would change ABI.
2023-03-03 07:01:50 -08:00
Joe Groff
5345e982e9 Only mangle borrowing/consuming when they would change ABI.
`__shared` and `__owned` would always get mangled, even when they don't have any effect
on ABI, making it unnecessarily ABI-breaking to apply them to existing API to make
calling conventions explicit. Avoid this issue by only mangling them in cases where they
change the ABI from the default.
2023-03-02 21:33:29 -08:00
Holly Borla
ad3a385cd2 [Sema] Eliminate single-element tuples after parameter pack substitution. 2023-03-02 19:37:52 -08:00
Pavel Yaskevich
1dd6d349d1 [ConstraintSystem] NFC: Pass down matcher flags to repairFailures 2023-03-02 11:02:30 -08:00
Andrew Trick
f1ff6958a3 Merge pull request #63825 from atrick/diagnose-implicit-raw-bitwise
Warn on implicit pointer conversion from nontrivial inout values.
2023-03-02 10:57:30 -08:00
Holly Borla
b78b6b9a77 Merge pull request #63991 from hborla/materialize-pack-from-tuple
[ConstraintSystem] Implement type checking for converting a tuple to a pack using the `.element` syntax.
2023-03-01 16:19:33 -08:00
Hamish Knight
f6f5e89bcd Merge pull request #63996 from hamishknight/nfc-pattern-changes 2023-03-01 21:27:34 +00:00
Hamish Knight
9b8bc6033c [AST] NFC: Refactor ExprPattern construction
Introduce 3 separate factory constructors, and
remove the ability to specify the match expr and
var, as those should be synthesized on-demand.
2023-03-01 15:53:41 +00:00
Holly Borla
509188630b [ConstraintSystem] Implement type checking for converting a tuple to a
pack using the `.element` syntax.
2023-02-28 22:56:59 -08:00