Commit Graph

3421 Commits

Author SHA1 Message Date
Pavel Yaskevich
64a654dc0d Revert "[CSBindings] Prefer conjunctions over closure variables without bindings"
This reverts commit 11ee82de7b.
2023-08-14 10:02:05 -07:00
Nishith Shah
8e2e625543 [Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
This commit changes fixit messages from a question/suggestion to an
imperative message for protocol conformances and switch-case. Addresses
https://github.com/apple/swift/issues/67510.
2023-08-13 22:34:26 -07:00
Frederick Kellison-Linn
b2b768f40f Merge pull request #67479 from Jumhyn/enum-expr-optional-matching
[TypeCheckPattern] Attempt ExprPattern conversion before failing pattern coercion to optional
2023-08-11 13:02:28 -04:00
Hamish Knight
bc31eb1595 [CS] Solve all conjunctions in source order
Previously we would only do source ordering for
ClosureExprs, but other conjunctions need to have
their source location taken into account too, in
order to make sure we don't try and type-check e.g
a TapExpr in a second closure before we type-check
the first closure.

Also while here, switch to `std::min_element`
instead of sorting, and treat invalid source
locations as incomparable.

rdar://113326835
2023-08-08 18:08:53 +01:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Pavel Yaskevich
44cb14f849 Merge pull request #67441 from xedin/fix-overly-eager-closure-resolving
[CSBindings] Prefer conjunctions over closure variables without bindings
2023-08-04 09:42:50 -07:00
Pavel Yaskevich
c659323598 Merge pull request #67597 from amritpan/kp-value-mismatch-diagnostic
[ConstraintSystem] Delay Contextual Type Fix record for key paths
2023-08-02 09:26:31 -07:00
Amritpan Kaur
cb984791d6 [NFC] Move keypath diagnostic from general to keypath 2023-08-01 12:11:51 -07:00
Amritpan Kaur
59d26795c2 [Test] Add AnyKeyPath test and move keypath diagnostics 2023-08-01 12:11:27 -07:00
Hamish Knight
2210ea6856 [CS] Avoid emitting invalid binding diagnostic in more cases
Also avoid emitting the diagnostic for an out of
place binding pattern if there's an existing fix
on a parent call expression, as that's the real
source of the failure.

rdar://113025351
2023-07-28 11:22:27 +01:00
Pavel Yaskevich
9b3980573f Merge pull request #67297 from amritpan/build-out-resolve-kp
[ConstraintSystem] Set up keypath expressions typechecking
2023-07-27 09:52:09 -07:00
Amritpan Kaur
d5f0fff83c [Tests] Add and update tests 2023-07-26 20:32:30 -07:00
Pavel Yaskevich
d5bb55eca4 [TypeChecker] NFC: Add a test-case for rdar://110847476 2023-07-24 12:22:25 -07:00
Freddy Kellison-Linn
d13e997d07 [TypeCheckPattern] Attempt ExprPattern conversion before failing pattern coercion to optional 2023-07-23 12:04:38 -04:00
Pavel Yaskevich
eb86497493 [CSSimplify] Deplay member lookup until single-element tuple with pack expansion is sufficiently resolved
Such tuples should be treated specially because once pack expansion
is sufficiently resolved they'd get exploded and the resulting type
is what member lookup should use as a base.

Resolves: rdar://110721928
2023-07-21 13:10:34 -07:00
Pavel Yaskevich
11ee82de7b [CSBindings] Prefer conjunctions over closure variables without bindings
If a closure doesn't have a contextual type inferred yet it should
be delayed in favor of already resolved closure conjunction because
"resolving" such a closure early could miss result builder attribute
attached to a parameter the closure is passed to.

Partially resolves https://github.com/apple/swift/issues/67363
2023-07-21 09:46:09 -07:00
Pavel Yaskevich
dbb38f1bf3 Merge pull request #67435 from xedin/rdar-112029630
[CSRanking] Augment overload ranking to account for variadic generics
2023-07-21 09:44:01 -07:00
Holly Borla
7b586d20cc [Type Resolution] Only allow each applied directly to a type parameter pack. 2023-07-20 15:29:53 -07:00
Pavel Yaskevich
b98cd11f12 [CSRanking] Augment overload ranking to account for variadic generics
If one of the choices is variadic generic, let's use `matchCallArguments`
to find argument/parameter mappings and form pack expansions for arguments
when necessary.

Resolves: rdar://112029630
2023-07-20 10:15:08 -07:00
Sophia Poirier
974081c065 [Variadic Generics] abstract tuple of Sendable elements does not conform to Sendable 2023-07-19 12:35:01 -07:00
Hamish Knight
09bb346b03 [CS] Walk UnresolvedDeclRefExprs in UnresolvedVarCollector
This matches what we do in VarRefCollector, and is
needed because we currently delay the pre-checking
of patterns due to the fact that we don't resolve
them until CSGen. We ought to consider changing
this, but until then, adjust the logic here to
ensure we properly connect an ExprPattern that
references an outer var with any type variables
it may involve.

rdar://112264204
2023-07-17 17:32:46 +01:00
Sophia Poirier
6e47a36808 Merge pull request #67292 from sophiapoirier/pack-stored-propety-shadows-global
[ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element'
2023-07-14 15:11:05 -07:00
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Allan Shortlidge
b9262e5297 Sema: Allow default arguments to access @usableFromInline decls.
The restriction that default arguments be disallowed from accessing
`@usableFromInline` decls is overbearing for library developers who need to
write non-trivial code to compute a default value, since it forces them to
either write a verbose closure inline in the function signature or expose a
`public` helper function which unnecessarily expands API surface. A
`@usableFromInline` function a more reasonable way to encapsulate a verbose
default value computation.

This reverses the semantic changes included in https://github.com/apple/swift/pull/15666.

Resolves rdar://112093794.
2023-07-12 12:47:06 -07:00
Sima Nerush
83a7e05608 [Sema] Record a fix about extra parens for computed properties (#67042)
Co-authored-by: Sima Nerush <sima_nerush@apple.com>
2023-07-10 14:34:32 -07:00
Andrew Savonichev
b1f36d2c6d [AutoDiff] Fix test/Constraints/noderivative.swift (#67190)
The test imports _Differentiation, so it needs the REQUIRES line or people that build without that feature will fail this test.
2023-07-10 09:50:06 -07:00
Pavel Yaskevich
4b84391953 [Tests] Adjust a couple of string interpolation test-cases
`test/Constraints/interpolation_segments.swift` has been removed
because interpolations are now type-checked together with their
context, so the separate type-checking test no longer applies.
2023-07-07 19:50:46 +02:00
Sophia Poirier
7cc38fd0d4 Merge pull request #67164 from sophiapoirier/pack-environments-for-elements
add tracking of pack environments for pack elements to Constraint System
2023-07-06 19:30:28 -07:00
Andrew Savonichev
b6acb6fbef [AutoDiff] Check @noDerivative for function type comparison (#67121)
As described in the issue #62922, the compiler should not allow to discard @noDerivative attribute and keep @differentiable. The patch adds a diagnostic for this case.

Resolves #62922.
2023-07-06 15:21:30 -07:00
Sophia Poirier
63e30b5525 [Variadic Generics] add tracking of pack environments for pack elements to Constraint System 2023-07-06 13:44:10 -07:00
Crazy凡
4e346c1cf8 Add test cases for the 'nil coalescing operator'. 2023-07-04 18:21:26 +08:00
swift-ci
44ab03a90b Merge pull request #66871 from kavon/generics-error-noncopyable
Be more specific than "noncopyable type T can't be used with generics yet"
2023-06-26 18:32:26 -07:00
Kavon Farvardin
8072eef926 describe noncopyables in parameter packs 2023-06-26 16:55:06 -07:00
Kavon Farvardin
485bdc7918 describe more cases of noncopyable in a tuple; also improve existing message a bit. 2023-06-26 16:55:06 -07:00
Kavon Farvardin
c40985dfb3 describe how generic parameters implicitly require Copyable 2023-06-26 16:55:06 -07:00
Pavel Yaskevich
b1b16981fe Merge pull request #66910 from xedin/issue-66095
[ConstraintSystem] Adjust the way pack parameters are opened
2023-06-26 08:52:49 -07:00
Pavel Yaskevich
3122440842 Merge pull request #66766 from amritpan/key-path-backward-diag
[ConstraintSystem] Fix keyPath diagnostic error for value convert to contextual types
2023-06-26 08:52:18 -07:00
Kavon Farvardin
66bf3c03fc describe illegal casts to existentials 2023-06-23 20:15:01 -07:00
Pavel Yaskevich
2227930d03 [ConstraintSystem] Adjust the way pack parameters are opened
Although variadic type is declared without `repeat` each of
its generic arguments is supposed to be a PackType which is
modeled in the interface type as `Pack{repeat ...}`. When
reference to such a type is opened by the constraint solver
we need to drop the Pack{repeat ...} structure because the
type variable would represent a pack type so `S<each T>`
is opened as `S<$T0>` instead of `S<Pack{repeat $T0}>`.

Resolves: https://github.com/apple/swift/issues/66095
2023-06-23 18:03:42 -07:00
Amritpan Kaur
d6486e25eb Add test 2023-06-23 13:56:42 -07:00
Angela Laar
6607f05f53 Merge pull request #66864 from angela-laar/exclude-generic-param-constraints
[GenericSignature] Exclude GenericParam Constraints
2023-06-23 09:54:12 -07:00
Kavon Farvardin
ada0d335b1 have TypeCheckType be specific about the generic type a noncopyable was used with.
This change causes explicit types written in the
source language that substitute a noncopyable type
for a type variable in a generic type to state
that's what's wrong. For example:

```
// NEW: noncopyable type 'MO' cannot be used with generic type 'Dictionary<Key, Value>' yet
// OLD: noncopyable type 'MO' cannot be used with generics yet
let _: [MO : T]
```
2023-06-22 15:12:30 -07:00
Angela Laar
a92deb070d [GenericSignature] Exclude GenericParam Constraints
Only preserve primary associated types during type erasure if the
generic context does not contain outer generic prameters.

i.e.

  Given `func foo {  ... any P <Int> ... }` getNonDependentUpperBounds()
  should produce any P<Int>

  However, given `func foo<T> { ... any P<T> ... }` getNonDependentUpperBounds()
  should produce any P

Fixes rdar://110262754
2023-06-22 14:15:41 -07:00
Hamish Knight
390f5c3e3a [CS] Avoid crashing if we have no contextual type for initialization
For `CTP_Initialization`, there's no contextual
type to record if the pattern is not a
`TypedPattern`. As such, tweak
`RequirementFailure::getDeclRef` to handle this
case.

We probably ought to reconsider how we handle
contextual types here, using a ContextualType
locator when there is no contextual type recorded
seems a bit weird, though in most cases we want
to treat initializations the same regardless of
if a TypedPattern was used. For now I'm leaving
that as future work.

rdar://111009224
2023-06-20 13:09:48 +01:00
Hamish Knight
8caf9997c9 Merge pull request #66718 from hamishknight/getting-out-of-a-bind 2023-06-19 12:49:49 +01:00
Pavel Yaskevich
199616a49b Merge pull request #66708 from xedin/generalize-default-closure-type-constraint
[ConstraintSystem] Use fallback type constraint to default pack expansion
2023-06-19 00:47:18 -07:00
Hamish Knight
6fffd96a18 [Parse] Avoid creating binding patterns in a couple more positions
If we have an identifier followed by either `[` or
a generic argument list, avoid turning it into a
binding pattern, as that would be invalid. This
is similar to the existing rule we have where a
following `(` prevents a binding pattern from
being formed.

This allows patterns such as `let E<Int>.foo(x)` and
`let (y[0], x)` to compile, where `x` is treated
as a binding, but no other identifier is.

rdar://108738034
2023-06-16 21:37:47 +01:00
Sima Nerush
e1d2198399 [TypeResolution] Ban local variable packs (#66622)
* Ban explicit local variable packs

* Ban inferred local variable packs
2023-06-16 11:23:41 -07:00
Pavel Yaskevich
83bb9c1f5a [ConstraintSystem] Use fallback type constraint to default pack expansion
Binding of pack expansion types is delayed until solving but use
of `Defaultable` was preventing it from being considered early
because that constraint impacts binding set ranking, switching
to `FallbackType` constraint give us better semantics where pack
expansion type variables are going to be bound as soon as they
have a contextual type.

Resolves: rdar://110819621
2023-06-16 11:15:21 -07:00