Commit Graph

2456 Commits

Author SHA1 Message Date
Pavel Yaskevich
0db22316a2 [ConstraintSystem] Record conformances synthesized for ad-hoc distributed requirements 2024-02-12 14:26:30 -08:00
Pavel Yaskevich
6afa7328d9 [CSApply] Produce an abstract conformance for Res parameter of DistributedActorSystem.remoteCall witness 2024-02-12 14:26:08 -08:00
Pavel Yaskevich
29a086d8ec [ConstraintSystem] NFC: Pass an underlying declaration to Solution::computeSubstitutions
This is going to be used to determine whether the substitutions are
computed for `DistributedActorSystem::remoteCall` and adjust the
generic signature with witness conformance requirements.
2024-02-12 13:23:51 -08:00
Kavon Farvardin
da8de569dc NCGenerics: remove ArcheType::hasRequirements
The IDE's use isn't correct under noncopyable generics and only the
constraint solver uses it. It's a misleading method now that nearly
every archetype has Copyable/Escapable requirements.
2024-02-11 12:54:35 -08:00
Slava Pestov
983dc250ad Sema: Replace a checkConformance() call with lookupConformance() 2024-02-10 09:36:37 -05:00
Slava Pestov
6027bf46a6 AST: Simplify collectExistentialConformances() 2024-02-10 09:36:37 -05:00
Hamish Knight
1003b2f30b [CS] Remove CTP_ImpliedReturnStmt
Unify with `CTP_ReturnStmt`, and have the
SyntacticElementTarget carry the ReturnStmt for
regular type-checking, which we can use to record
implied returns.
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
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00: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
Pavel Yaskevich
9d0797a10b Merge pull request #71248 from xedin/init_accessors-nonmutating-big-struct
[CSApply] Teach `adjustSelfTypeForMember` about init accessors
2024-02-02 15:23:19 -08:00
Pavel Yaskevich
53b2d86830 [CSApply] Determine whether to emit runtime isolation check based on Module::isConcurrencyChecked API 2024-02-01 14:14:31 -08:00
Pavel Yaskevich
db7959668e [Frontend] NFC: Rename PreconcurrencyConformances to DynamicActorIsolation 2024-02-01 13:28:25 -08:00
Pavel Yaskevich
68baadc253 [SILGen] Emit runtime actor isolation checks for @objc thunks of closures 2024-02-01 13:28:25 -08:00
Pavel Yaskevich
aff92488ef [CSApply] Use ActorIsolationErasure conversion in argument positions that require runtime check
Passing an isolated function value into an API that doesn't have full
static concurrency checking is unsafe and requires runtime checks
to make sure that function is always called in the expected context.
2024-02-01 13:28:25 -08:00
Hamish Knight
deaf2dd372 [CS] Unify ReturnStmt handling
Unify the implementation between single-expression
and multi-statement closures. Because we're now
storing a contextual type for single expression
closure returns, update a code completion test to
bring its behavior inline with the multi-statement
case.
2024-01-31 20:26:20 +00:00
Pavel Yaskevich
4242ac8c31 [CSApply] Teach adjustSelfTypeForMember about init accessors
`adjustSelfTypeForMember` shouldn't load base if member reference
is a potential init accessor use, the proper use of `self` would
be determined during lowering of the `assign_or_init` instruction
and defensive load for `nonmutating` sets is unnecessary in this
case.
2024-01-30 11:09:15 -08:00
Hamish Knight
0a4c029cfc [AST] Introduce UnreachableExpr
This models the conversion from an uninhabited
value to any type, and allows us to get rid of
a couple of places where we'd attempt to drop
the return statement instead.
2024-01-30 14:08:54 +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
Doug Gregor
35582370d4 Partial actor isolation checking for #isolation
This isn't done very well, and is expected to be replaced, but it
allows us to avoid bogus Sendable diagnostics for iteration over
async sequences.
2024-01-25 16:04:48 -08:00
Doug Gregor
bb7a563e6c Switch async for-each loop over to _nextElement and drop @rethrows.
This couples together several changes to move entirely from
`@rethrows` over to typed throws:

* Use the `Failure` type to determine whether an async for-each loop
will throw, rather than depending on rethrows checking

* Introduce a special carve-out for `rethrows` functions that have a
generic requirement on an `AsyncSequence` or `AsyncIteratorProtocol`,
which uses that requirement's `Failure` type as potentially being part
of the thrown error type. This allows existing generic functions like
the following to continue to work:

    func f<S: AsyncSequence>(_: S) rethrows

* Switch SIL generation for the async for-each loop from the prior
`next()` over to the typed-throws version `_nextElement`.

* Remove `@rethrows` from `AsyncSequence` and `AsyncIteratorProtocol`
entirely. We are now fully dependent on typed throws.
2024-01-25 16:04:43 -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
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Hamish Knight
990d15567d [AST] Split up PatternBindingDecl::setPattern
Most clients only want to set one of the two
parameters, split it into `setPattern` and
`setInitContext` (the latter of which now
handles calling `setBinding`).
2024-01-17 16:02:33 +00:00
Hamish Knight
47f7a31095 [AST] Tighten up type of InitContext
Switch from promising a DeclContext to a
PatternBindingInitializer.

This has a couple of benefits:
- It eliminates a few places where we were force
`cast`'ing to PatternBindingInitializer.
- It improves the clarity of what's being stored,
it's not whatever the parent context of the
initializer is, it's specifically the
PatternBindingInitializer context if it exists.
2024-01-17 16:02:33 +00:00
Slava Pestov
166d059625 Merge pull request #70937 from slavapestov/rename-conformance-lookup
TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance()
2024-01-16 22:21:04 -05:00
Doug Gregor
8b514ec029 Merge pull request #70902 from DougGregor/isolation-macro
Implement `#isolation` macro to produce the isolation of the current context
2024-01-16 14:27:00 -08:00
Doug Gregor
255009dddb Implement #isolation macro to produce the isolation of the current context
Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
2024-01-16 14:25:51 -08:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Allan Shortlidge
e5c6bb649c Remove support for Swift 3 @objc inference.
Obsolete the `-enable-swift3-objc-inference` option and related options by
removing support for inferring `@objc` attributes using Swift 3 rules.
Automated migration from Swift 3 has not been supported by the compiler for
many years.
2024-01-11 15:40:04 -08:00
Kavon Farvardin
4eccbe136e [NFC] combine collectExistentialConformances
There are a bunch of static `collectExistentialConformances` copied
around Sema and SILGen that are almost the same, save for whether they
want to permit missing conformances and/or check conditional
conformances.

This commit requestifies and combines all but one of these functions
into a `ModuleDecl::collectExistentialConformances`. The motivation for
this clean-up is another place that will need this procedure.
2024-01-10 19:39:07 -08:00
Holly Borla
10574415f1 Merge pull request #70538 from hborla/sendable-adjustment
[CSApply] Perform a regular `coerceToType` when adjusting types for `@preconcurrency`.
2023-12-19 11:28:43 -08:00
Holly Borla
e3655f51c9 [CSApply] Perform a regular coerceToType when adjusting types for
preconcurrency.
2023-12-19 08:14:52 -08:00
Hamish Knight
f10365597d [AST] Use PatternBindingDecl::createImplicit in more places
And simplify the implementation of `create`.
2023-12-15 21:44:30 +00: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
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
5832181077 Sema 2023-12-03 21:51:22 -08:00
Pavel Yaskevich
a86e1eea1a [TypeChecker] Limit @dynamicMemberLookup parameter to compose only with Sendable 2023-12-01 00:25:31 -08:00
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
511dad557c [Sema/SIL] NFC: Get existential layout directly from an existential type 2023-11-29 09:25:16 -08:00
Pavel Yaskevich
d72749560f [CSSolver] Handle situations when key path expression has an existential type
A way to mark key path as Sendable is to extend its type with `& Sendable`.
This is something that makes the type of a key path expression an existential
with superclass bound expressed as a known key path type.
2023-11-28 13:02:17 -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
Slava Pestov
c0f9d290fa AST: Move TypeBase::typeEraseOpenedArchetypesWithRoot() into ConstraintSystem.cpp 2023-11-27 14:05:36 -05:00
Slava Pestov
ef99de0322 AST: Remove useDC parameter from typeEraseOpenedArchetypesWithRoot() 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
Doug Gregor
c90c055fb6 Record the thrown error type for try? and try! in the AST
SILGen wants this so it knows what kind of error its going to end up
with.
2023-10-31 14:18:31 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -07:00
Doug Gregor
69ec45dfdb Rework effects checking to maintain thrown type information.
While here, eliminate some redundancy in the implementation of
effects checking be consolidating the logic for computing a
`Classification` from a particular expression or other entity.
2023-10-04 08:57:29 -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
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00