Commit Graph

1765 Commits

Author SHA1 Message Date
Pavel Yaskevich 7d326050f9 [ConstraintSystem] Handle @dynamicMemberLookup subscripts with existential parameters
The parameter should still have a key path type as its superclass
bound (i.e. `KeyPath<...> & Sendable`), this would be verified by
the attribute checker.
2023-11-30 11:28:24 -08:00
Pavel Yaskevich a8232123c9 [ConstraintSystem] Fix isPartialApplication to properly handle static members
Only instance members require double-apply to be fully applied,
static members apply the base implicitly.
2023-11-29 17:00:38 -08:00
Pavel Yaskevich 40c8da6616 [ConstraintSystem] InferSendableFromCaptures: Start inferring sendability of key path expressions
When `InferSendableFromCaptures` feature is enabled `inferKeyPathLiteralCapability`
should examine subscript arguments to determine whether the key path type is
sendable or not, and if so, inform inference to produce `& Sendable` existential
type as a binding. Binding key path type is delayed until all subscript arguments
are fully resolved.
2023-11-28 13:02:17 -08:00
Pavel Yaskevich 2e1ca0a32a [ConstraintSystem] Extend KeyPathCapability to support sendability 2023-11-28 13:02:14 -08:00
Pavel Yaskevich bd4ee4681b Merge pull request #70007 from xedin/keypath-application-improvements
[ConstraintSystem] Modernization of key path application handling
2023-11-28 12:44:42 -08:00
Slava Pestov f89b9817e7 Merge pull request #69950 from slavapestov/clean-up-open-existentials
Cleanups and fixes for opened existentials
2023-11-28 10:45:19 -05:00
Alex Hoppen 6ac7915dae Merge pull request #70013 from ahoppen/ahoppen/remove-leaveclosurebodiesunchecked
[Sema] Remove `LeaveClosureBodiesUnchecked`
2023-11-27 14:03:18 -08:00
Pavel Yaskevich 420e0af776 Merge pull request #69939 from xedin/issue-69936
[ConstraintSystem] Key path literals with completion tokens should be…
2023-11-27 13:16:48 -08:00
Slava Pestov 6fb5b94675 Sema: Simplify recursion in typeEraseExistentialSelfReferences() 2023-11-27 14:05:36 -05:00
Slava Pestov 81723435b6 Sema: Extract duplication between typeEraseOpenedExistentialReference() and typeEraseOpenedArchetypesWithRoot() 2023-11-27 14:05:36 -05:00
Slava Pestov c0f9d290fa AST: Move TypeBase::typeEraseOpenedArchetypesWithRoot() into ConstraintSystem.cpp 2023-11-27 14:05:36 -05:00
Slava Pestov 04577febf5 Sema: Simplify typeEraseExistentialSelfReferences() 2023-11-27 14:05:36 -05:00
Slava Pestov 5bb82f754e Sema: Don't need to pass parent signature to OpenedArchetypeType::get() 2023-11-27 14:05:36 -05:00
Slava Pestov f5e250551d AST: Merge GenericSignature::get{Non,}DependentUpperBounds() 2023-11-27 14:05:36 -05:00
Slava Pestov c298997e1e AST: Use ArchetypeType::getExistentialType() in a couple of places 2023-11-27 14:05:36 -05:00
Slava Pestov 1b1963e904 Sema: Remove 'inferred result type requires explicit coercion' diagnostic 2023-11-27 14:05:36 -05:00
Slava Pestov ef6630f0ac Sema: Strip off LValueType from opened existential accesses with an erased result type
- Fixes https://github.com/apple/swift/issues/62219
- Fixes https://github.com/apple/swift/issues/60619,
- Fixes rdar://104230391
- Fixes rdar://118247162.
2023-11-27 14:05:36 -05:00
Alex Hoppen b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Pavel Yaskevich 1a011c3bde [ConstraintSystem] Adjust locator for key path project value type variable
Previous `FunctionArgument` locator didn't make sense because
this type variable doesn't actually represent a parameter but
rather a value generic parameter of the key path subscript index
parameter.
2023-11-20 00:24:30 -08:00
Pavel Yaskevich 47b4d70540 [ConstraintSystem] Remove unused r-value key path type element type variable
The resulting type is no longer in use so there is no need to create
a type variable and a constraint to perform the operation.
2023-11-17 16:19:32 -08:00
Pavel Yaskevich 76046ba712 [ConstraintSystem] Key path subscript index cannot be inferred as inout
Subscripts do not support inout parameters.
2023-11-17 16:18:15 -08:00
Pavel Yaskevich f440dd8e37 [ConstraintSystem] Update key path subscript index type variable to use new locator element 2023-11-17 15:47:44 -08:00
Pavel Yaskevich d542ab99f0 [ConstraintSystem] Add a new locator for key path subscript parameter 2023-11-17 13:21:42 -08:00
Pavel Yaskevich 72bb74aa4f [ConstraintSystem] Key path literals with completion tokens should be marked as invalid
Capability couldn't be determined for expressions like that which
means that inference should be delayed until root becomes available.

Resolves: https://github.com/apple/swift/issues/69936
2023-11-16 15:48:46 -08:00
Pavel Yaskevich 34a0b09889 [ConstraintSystem] NFC: Format code related to InferSendableFromCaptures feature 2023-11-16 10:47:55 -08:00
Pavel Yaskevich 8d7b1a44c4 [ConstraintSystem] NFC: Remove unused reference to ASTContext 2023-11-16 10:47:55 -08:00
Pavel Yaskevich 625abd8254 [ConstraintSystem] NFC: Unify logic in isInvalidPartialApplication and isPartialApplicaiotn 2023-11-16 10:47:48 -08:00
Pavel Yaskevich 3c69f4db88 [ConstraintSystem] Key path capability inference should fail if there no components 2023-11-08 19:54:31 -08:00
Angela Laar eb277d9ee7 Merge pull request #67498 from angela-laar/implicit-sendable-for-methods
[Sema] Implicitly add @Sendable attribute to partial methods
2023-11-07 16:46:16 -08:00
Angela Laar c09ec72e85 [Constraint System] Always add Sendable to unapplied function applications 2023-11-07 13:37:24 -08:00
Pavel Yaskevich d74c4723dc [ConstraintSystem] De-duplicate key path constraint simplification
Move some of the checks from the constraint simplification into
`inferKeyPathLiteralCapability` and start using it for both
inference and constraint simplification.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich 9bf9d549c4 [ConstraintSystem] Key path capability inference should indicate whether key path is invalid
This flag makes it easier to determine what binding to produce
from the default. In cases where some of the member references
are invalid it's better to produce a placeholder for a key
path type instead of letting the solver to attempt to fix more
contextual problems for a broken key path.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich 59b759338e [ConstraintSystem] Extract logic to determine key path literal capabilities 2023-11-01 09:14:15 -07:00
Pavel Yaskevich a4bda00e5b [ConstraintSystem] Add a locator element to represent a fallback type 2023-11-01 09:14:15 -07:00
Angela Laar de3b4bad43 [Constraint System] Exclude 'Single' and 'Double' function application from Sendable Inference 2023-10-25 17:02:29 -07:00
Angela Laar 619a517a61 [CSSimplify] Check all conditional requirements for a type variable 2023-10-25 12:30:50 -07:00
Angela Laar 4bd4fa6479 [Sema] Use checkGenericArguments 2023-10-25 12:30:27 -07:00
Angela Laar 34ca702031 [Frontend] Feature flag for InferredSendableMethods 2023-10-25 12:30:24 -07:00
Angela Laar 9e408af419 [Sema] Global funcs should always be Sendable
Global funcs should be Sendable by default because they don't
capture anything.
2023-10-25 12:29:37 -07:00
Angela Laar 6879961c52 [Sema] Delay lookup for conditional conformances
Remove diagnostics and sendable checks from ActorIsolationChecker
2023-10-25 12:29:35 -07:00
Angela Laar 68e909f07c [Sema] Diagnose partial and unapplied func sendability
i.e.
     `S().f` is sendable if `S()` is a Sendable type

Partial apply and unapplied methods of Sendable types should be
marked as Sendable in the constraint system, including declarations
and unapplied functions as parameters.
2023-10-25 12:28:33 -07:00
Ben Barham 360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Pavel Yaskevich 557c6f71f2 [ConstraintSystem] Add a missing case to locator simplification
If tuple element is anchored on an assignment, we need to look
at the source of the assignment to find tuple expression the
element belongs to.
2023-10-13 10:39:38 -07:00
swift-ci 3c9c3fb614 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 10:33:23 -07:00
Doug Gregor 4b3d2f47d9 [Typed throws] Handle function conversions involving different thrown errors
Teach the constraint solver about the subtyping rule that permits
converting one function type to another when the effective thrown error
type of one is a subtype of the effective thrown error type of the
other, using `any Error` for untyped throws and `Never` for
non-throwing.

With minor other fixes, this allows us to use typed throws for generic
functions that carry a typed error from their arguments through to
themselves, which is in effect a typed `rethrows`:

```swift
func mapArray<T, U, E: Error>(_ array: [T], body: (T) throws(E) -> U)
throws(E) -> [U] {
  var resultArray: [U] = .init()
  for value in array {
    resultArray.append(try body(value))
  }
  return resultArray
}
```
2023-10-05 11:55:05 -07:00
Rose d132708f1a Ensure the correct function is called by appending std:: to the std math functions 2023-10-01 22:19:58 -04:00
swift-ci 06f9a8a703 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 11:33:40 -07:00
Doug Gregor 7f82b2a9aa [Typed throws] Enable checking of thrown types on closures.
Enable typed throws on explicit closures, either due to contextual
type information or due to explicit specification.
2023-09-29 10:51:54 -07:00
Doug Gregor 51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -07:00
Ben Barham 119d08c6d1 Merge remote-tracking branch 'origin/main' into 20230929-merge-rebranch
Conflicts:
  - `CMakeLists.txt` caused by the extra `-D` added in rebranch to
    reduce the number of deprecation warnings.
  - `lib/Frontend/PrintingDiagnosticConsumer.cpp` caused by the removal
    of one of the `#if SWIFT_SWIFT_PARSER` on rebranch (probably should
    have been done on main).
2023-09-29 09:50:50 -07:00