Commit Graph

1681 Commits

Author SHA1 Message Date
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
Joe Groff
705e317c3f Merge pull request #67425 from jckarter/raw-storage
[WIP] Raw storage and locks/atomics prototype
2023-07-26 08:49:02 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Slava Pestov
f07495dd64 AST: Add TypePosition::Shape 2023-07-25 02:47:46 -04:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
Becca Royal-Gordon
fe6753485f [NFC] Adopt new diagnostic features across Sema 2023-07-20 15:23:47 -07:00
Slava Pestov
415b70584a Sema: Workaround for issue in ConstraintSystem::openType() 2023-07-17 15:33:34 -04:00
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
6cec68e302 [IDE] Ignore score kinds that represent implicit conversions when solving for code completion
Ignore conversion score increases during code completion to make sure we don't filter solutions that might start receiving the best score based on a choice of the code completion token.
2023-07-07 19:50:46 +02: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
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -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
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