Commit Graph

1645 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
204d496c36 Merge pull request #63889 from xedin/cache-conformance-checks-in-cs
[ConstraintSystem] Add cache for conformance lookups
2023-09-28 14:00:17 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -07:00
Pavel Yaskevich
32d265154f [ConstraintSystem] Add cache for conformance lookups
`lookupConformance` request is not cached and constraint solver
performs a lot of them for the same type (i.e. during disjunction
solving), let's try to cache previously performed requests to
see whether additional memory use is worth the performance benefit.
2023-09-20 00:59:22 +01:00
Kavon Farvardin
68ae729584 _Copyable as a Requirement Against the Machine
An initial implementation of a rework in how
we prevent noncopyable types from being
substituted in places they are not permitted.

Instead of generating a constraint for every
generic parameter in the solver, we produce
real Copyable conformance requirements. This
is much better for our longer-term goal of
supporting `~Copyable` in more places.
2023-09-19 16:35:17 -07:00
swift-ci
0d132bc4a7 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-18 10:14:22 -07:00
Pavel Yaskevich
b0f91acbcd Merge pull request #68226 from xedin/experimental-no-stack-solution
[ConstraintSystem] Remove all stack allocation from `Solution`
2023-09-18 18:00:59 +01:00
swift-ci
f316c11bd3 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-16 08:12:44 -07:00
Pavel Yaskevich
26e9a90786 [ConstraintSystem] Remove all stack allocation from Solution
An experiment to see how much memory we were spending on empty
collections for each partial solution.
2023-09-11 14:55:29 +01:00
Alex Hoppen
66a0b78dae [Sema] Don’t check hasSingleExpressionBody in ConstraintSystem::participatesInInference
It looks like we no longer need this check.
2023-09-08 08:29:28 -07:00
Alex Hoppen
18979b304b [Sema] Delete ClosuresInResultBuilderDontParticipateInInference
Since we migrated all of code completion to solver-based, this flag is no longer needed.
2023-09-07 13:15:23 -07:00
swift-ci
225162a30f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-01 14:36:50 -07:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
swift-ci
39b640ce1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-31 09:05:17 -07:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
swift-ci
a65507e866 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-29 13:35:50 -07:00
Pavel Yaskevich
e00034e056 [ConstraintSystem] Look through specialization while simplifying constructor locator
If type is explicitly specialized i.e. `A<Int>` in certain cases its `TypeExpr`
or `OverloadedDeclRefExpr` (if type name is ambiguous) would be wrapped in
`UnresolvedSpecializeExpr` which has to be looked through when simplifying
`constructor member` so the anchor could point to the underlying type reference.

Resolves: https://github.com/apple/swift/issues/67799
Resolves: rdar://113577294
2023-08-28 11:21:58 -07:00
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Becca Royal-Gordon
c32f022a49 Include cmath so we have ceil() 2023-08-04 16:18:15 -07: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
swift-ci
1969199a8e Merge remote-tracking branch 'origin/main' into rebranch 2023-07-26 23:13:08 -07:00