Commit Graph

3579 Commits

Author SHA1 Message Date
Pavel Yaskevich
e3ff1dd707 Merge pull request #71529 from xedin/copyable-cs-issues
[CSRanking] Adjust `isDeclMoreConstrainedThan` to account for inverti…
2024-02-09 23:51:58 -08:00
Pavel Yaskevich
218346c285 [CSRanking] Adjust isDeclMoreConstrainedThan to account for invertible protocols
Use of invertible protocols doesn't make type parameter more
constrained.
2024-02-09 17:16:50 -08:00
Hamish Knight
5d0ad81932 [test] Remove unnecessary --color flags
This is now the default.
2024-02-09 16:47:03 +00:00
Hamish Knight
2c77947000 Merge pull request #71006 from hamishknight/implicit-last-expression
Introduce implicit last expression results
2024-02-08 10:15:01 +00:00
Kavon Farvardin
3ab4c7548c Sema: ban extensions of known marker protocols
There's no good reason to permit them. Conformances like Copyable and
Sendable are pervasive, so it's as though we are permitting extensions
of `Any`. Until there's a good argument in favor of such extensions,
remove the capability now.
2024-02-07 14:54:36 -08:00
Hamish Knight
7b4c9fef02 Allow implicit last expressions for functions and closures
Gated behind the experimental feature
`ImplicitLastExprResults`.
2024-02-07 18:14:23 +00:00
Hamish Knight
61a4148925 [CS] Generalize implied result handling
Track the implied result exprs in the constraint
system, and allow arbitrary propagation of
implied results down if/switch expression
branches. This is required for allowing implied
results in non-single-expression closures.
2024-02-07 18:14:22 +00:00
Hamish Knight
d73e394ea7 Allow implicit last expression results for if/switch expressions
Allow implicitly treating the last expression of
the branch as the result, behind the experimental
feature `ImplicitLastExprResults`.
2024-02-07 18:14:22 +00:00
Doug Gregor
0b01b55e73 Remove an old restriction on _ObjectiveCBridgeable conformances.
Historically, we checked against a specific allowlist for a certain set
of types that were allowed to introduce an `_ObjectiveCBridgeable`
conformance in a different module that where the type was defined.
This rigid allow-list isn't really buying us much, but it's getting in
the way of some refactoring for swift-foundation that's changing
the layering. Remove this diagnostic, since it really isn't buying us
much nowadays, and we have the more general warnings about retroactive
conformances to make folks think twice.
2024-02-06 16:09:17 -08:00
Pavel Yaskevich
4cd167c918 Merge pull request #71393 from xedin/filter-out-escapable-from-leading-dot-in-generic-context
[CSBindings] Don't allow leading-dot base inference from Escapable pr…
2024-02-06 09:27:52 -08:00
Slava Pestov
d46bd335de Merge pull request #71371 from slavapestov/ncgenerics-fixes-3
Non-copyable generics fixes, part 3
2024-02-06 08:35:07 -05:00
Slava Pestov
d9c82b1b04 Sema: Clean up printing of generic signatures in missing witness diagnostics
Instead of stripping out requirements, let's pass the right PrintOptions.
2024-02-05 17:13:02 -05:00
Pavel Yaskevich
a613015b33 [CSBindings] Don't allow leading-dot base inference from Escapable protocol
Similarly to `Copyable`, `Escapable` shouldn't have any members
declared and as a result shouldn't be considered for leading-dot
base type inference.
2024-02-05 10:15:19 -08:00
Freddy Kellison-Linn
aedf854e33 Follow ups for keypath function conversion PR 2024-02-03 13:41:22 -05:00
Frederick Kellison-Linn
0735629c8d Merge pull request #39612 from Jumhyn/keypath-function-conversion
[ConstraintSystem] Allow function-function conversions for keypath literals
2024-02-03 10:26:13 -08:00
Slava Pestov
8db0af48bd Merge pull request #71352 from slavapestov/remove-redundant-requirements
Remove -warn-redundant-requirements flag
2024-02-03 08:28:02 -05:00
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Kavon Farvardin
b8a04f63e7 Test: prefer -enable-builtin-module
Many tests that use `-parse-stdlib` only do so because they want access
to the Builtin module. Now that we have the flag and ability to import
it, use that instead.
2024-02-01 10:39:02 -08:00
Hamish Knight
2e20aa5195 Merge pull request #71285 from hamishknight/fix-loc
[CS] Fix locator for `if` expressions
2024-02-01 09:39:43 +00:00
Hamish Knight
185a7d5103 [CS] Fix locator for if expressions
Currently we don't insert an intermediate
`SyntacticElement` locator element for the `if`
statement in a SingleValueStmtExpr, which leads
to an assertion failure when attempting to simplify
a following `TernaryBranch` element.

Move the insertion of the `SyntacticElement` locator
element for the statement into the
SingleValueStmtExpr constraint generation function,
and remove it from the statement visitors themselves.

For the other cases, the `SyntacticElement` was
already being inserted for children of a BraceStmt,
so we were actually previously ending up with
duplicated elements in a couple of places.
2024-01-31 21:37:56 +00:00
Hamish Knight
8773521d86 [CS] Don't walk into local decls in TypeVariableRefFinder
This could result in us incorrectly walking into
local functions and picking up type variables that
weren't being referenced.
2024-01-31 15:34:34 +00:00
Hamish Knight
9b64990d24 [AST] Remove the "single expression body" bit
Remove this bit from function decls and closures.
Instead, for closures, infer it from the presence
of a single return or single expression AST node
in the body, which ought to be equivalent, and
automatically takes result builders into
consideration. We can also completely drop this
query from AbstractFunctionDecl, replacing it
instead with a bit on ReturnStmt.
2024-01-30 14:08:54 +00:00
Pavel Yaskevich
3ed09325bc Merge pull request #71196 from xedin/rdar-121692664
[CSSimplify] Matching function types with variadic parameters should …
2024-01-29 10:02:18 -08:00
Pavel Yaskevich
eb05750f28 [CSSimplify] Matching function types with variadic parameters should account for contravariance
Resolves: rdar://121692664
2024-01-26 16:27:08 -08:00
Doug Gregor
be6393b7ca Use any Error for caught error type of an exhaustive, non-throwing do..catch
Prior to the introduction of typed throws, a `do..catch` always had a caught
error type of `any Error`, even if there were no throwing sites within
the `do` body. With typed throws, such a `do..catch` would have a
caught error type of `Never`, because it never throws. Unfortunately,
this causes code like the following to produce an error, because
`Never` cannot be pattern-matched to `HomeworkError.forgot`:

    func test() {
      do {
        try nonthrowing()
      } catch HomeworkError.forgot {
      } catch {
      }
    }

For source-compatibility reasons, adjust the caught error type to
`any Error` in this case, so we continue to accept the code above.
Don't do this adjustment under `FullTypedThrows`, because it's only
there for compatibility.

Fixes rdar://121526201.
2024-01-24 14:42:56 -08:00
Pavel Yaskevich
bc86b8db30 Merge pull request #71104 from xedin/rdar-121214563
[Sema] Temporary disable l-value stripping while erasing opened exist…
2024-01-24 09:46:38 -08:00
Pavel Yaskevich
3d74a397df [Sema] Temporary disable l-value stripping while erasing opened existentials
Reverts part of https://github.com/apple/swift/pull/69950 because
it causes failure in existing code.
2024-01-23 19:34:54 -08:00
Frederick Kellison-Linn
0d79f4523a Allow function-function conversions for keypath literals
Remove keypath subtype asserts; always use cached root type

Add tests for keypaths converted to funcs with inout param

Add unit test for overload selection
2024-01-23 08:51:44 -05:00
Hamish Knight
a76d5ab6f5 [test] Add test case for issue 71040 2024-01-22 13:50:47 +00:00
Ben Barham
8bb1ac950b [Parse] Update error if closure has unnamed parameter to warning
This reverts commit 4ba4da45b9 and updates
the warning to a warning until Swift 6.
2024-01-19 12:42:27 -08:00
Doug Gregor
a30b623ee6 Implement typed throws support in _openExistential. 2024-01-14 14:32:49 -08:00
Doug Gregor
8912d4aa71 [SE-0413] Adopt typed throws in withoutActuallyEscaping(_:do:)
There is a small bug fix here in the identification of the catch node,
where the leading `{` of a closure was considered to be "inside" the
closure for code like

    { ... }()

causing us to assume that the call to the closure would catch the error
within the closure.

Other than that, introduce the thrown error type into the type checker's
modeling of `withoutActuallyEscaping(_:do:)`, and mirror that in the
library declaration.
2024-01-13 21:57:24 -08:00
Doug Gregor
f316c5fcfe Update tests for map switching to typed throws 2024-01-12 10:17:59 -08:00
Pavel Yaskevich
4c604b479b Merge pull request #70777 from xedin/diagnostic-improvements-for-closures
[ConstraintSystem] Closure type-checking improvements
2024-01-10 11:13:49 -08:00
Slava Pestov
597fb216cb Merge pull request #70457 from slavapestov/parameter-pack-open-type
Fix openType() handling of parameter packs
2024-01-10 13:41:08 -05:00
Jeremy Schonfeld
2404013f78 [SE-0270] Add Collection Operations on Noncontiguous Elements (#69766)
* Adds RangeSet/DiscontiguousSlice to the stdlib

* Remove redundant DiscontiguousSlice.Index: Comparable conformance

* Attempt to fix embedded build

* Attempt to fix macOS test failures

* Fix Constaints/members.swift failure on linux

* Add exceptions to ABI/source checker to fix macOS tests

* Fix incremental dependency test failure

* Remove inlining/unfreeze implementation for future improvements

* Simplify indices(where:) implementation

* Address review feedback

* Add test for underscored, public slice members

* Address feedback on inlining, hashing, and initializing with unordered arrays

* Fix ABI checker issues

* Remove MutableCollection extension for DiscontiguousSlice

* Make insertion return a discardable Bool

* Fix ABI checker tests

* Fix other ABI checker tests due to dropping MutableCollection subscript
2024-01-09 14:02:19 -08:00
Slava Pestov
bc7044e944 Sema: Update diagnostics for openType() change
Some of these are minor regressions; they will be fixed on main but
not release/5.10.
2024-01-09 15:23:42 -05:00
Slava Pestov
5d58a634ad Sema: Clean up openType() and openUnboundGenericType()
Fixes:
- rdar://112785081
- https://github.com/apple/swift/issues/67906
- https://github.com/apple/swift/issues/68160
2024-01-09 15:23:42 -05:00
Pavel Yaskevich
859106eed1 [Diagnostics] Expand trailing closure failure to handle all closure arguments 2024-01-08 14:09:18 -08:00
Pavel Yaskevich
92577723fb [Diagnostics] Add a tailored note when passing a closure to a non-closure accepting parameter 2024-01-08 14:09:18 -08:00
Slava Pestov
770e6f98e3 AST: Correct '(each T).A' output for archetypes
isParameterPack() is always false for an archetype; we must test for a
PackArchetypeType here instead.
2024-01-02 15:41:13 -05:00
Slava Pestov
2b28cb1647 Sema: Implement missing case in existential erasure
Fixes https://github.com/apple/swift/issues/61934.
2023-12-16 12:24:34 -05:00
Pavel Yaskevich
9cd9619a57 [CSBindings] Unwrap optionals from contextual function type used as a key path type
The key path is going to be implicitly wrapped into a contextual
optional type.

Resolves: rdar://72864716
Resolves: https://github.com/apple/swift/issues/56393
2023-12-08 15:08:17 -08:00
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Alex Hoppen
aa60c427ec Merge pull request #70065 from ahoppen/ahoppen/error-unnamed-parameter
[Parse] Error if closure has an unnamed parameter
2023-12-04 18:52:15 -08:00
Pavel Yaskevich
cbfe349e33 Revert "[CSBindings] Delay inference through OptionalObject if "object" is l-value capable"
This reverts commit 700a57ac4f.
2023-12-04 11:36:20 -08:00
Pavel Yaskevich
ab230b94d9 Revert "[Tests] NFC: Add a test-case for invalid optional promotion"
This reverts commit 6b287bf31b.
2023-12-04 11:36:20 -08:00
Pavel Yaskevich
d54f03e455 Merge pull request #70175 from xedin/rdar-119055010
[CSBindings] Don't favor unresolved key path type over a conjunction
2023-12-04 09:33:35 -08:00
Holly Borla
48cb3309bd [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2023-12-03 21:51:41 -08:00
Sima Nerush
b0af0f762d Update diagnostics 2023-12-03 21:51:40 -08:00