Commit Graph

2424 Commits

Author SHA1 Message Date
Pavel Yaskevich
72eb8abadb [Sema/SILGen] Don't emit dynamic actor isolation checks when -disable-dynamic-actor-isolation flag is used 2024-04-15 09:19:22 -07:00
Alex Hoppen
078e1ea0cc [CodeCompletion] Fix a crash when completing the call pattern of a function that takes a parameter pack
The issue here was that we inferred the contextual type of the `Mixer` call to be the following, inferred from the result type of the partial call to the initializer of `Mixer`

```
(bound_generic_struct_type decl="swift_ide_test.(file).Mixer@/Users/alex/src/swift/test/IDE/complete_parameter_pack_as_call_argument.swift:3:8"
  (pack_type num_elements=1
    (pack_expansion_type
      (pattern=unresolved_type)
      (count=unresolved_type))))
```

Technically, the contextual type that we should have here should be `Any` (from `print`) but getting that information out of the constraint system turns out to be quite hard. https://github.com/apple/swift/pull/72568 makes some improvements in this area but in general the constraint system does not contain enough information to figure out the contextual type of an arbitrary expression.

The important thing right now is that the unresolved type in here trips the constraint system over when comparing types of code completion results with the contextual type. To prevent the crash for now, reset the expected call type if the computed type contains an unresolved type.

rdar://124166587

Co-authored-by: Pavel Yaskevich <pyaskevich@apple.com>
2024-04-12 14:03:57 -07:00
Slava Pestov
e7131cfbe2 Sema: Fix existential-metatype-to-Any conversion
We were incorrectly unwrapping too many levels of metatype, and
our ErasureExpr would end up with conformances for the instance
type and not the metatype itself.

In the old universe, this was not a problem, but now Any has two
protocol conformance members, so suddently this violated invariants.

This was a regression, introduced in 6027bf46a6.

Fixes rdar://125460667.
2024-04-01 23:05:22 -04:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Holly Borla
0a627bc44c Merge pull request #72324 from hborla/extract-function-isolation-expr
[Concurrency] Add a `.isolation` member on dynamically isolated function values.
2024-03-14 06:56:43 -07:00
Holly Borla
d9aa8697ab [Concurrency] Teach the constraint system about .isolation on dynamically
isolated function values.
2024-03-13 22:23:31 -07:00
Holly Borla
78384d596d [Concurrency] Add ExtractFunctionIsolationExpr to represent the isolation
of a dynamically isolated function value in the AST.
2024-03-13 19:55:15 -07:00
Michael Gottesman
acca7353db [transferring] Make async let take a transferring result if its result is non-Sendable.
Some notes:

1. If the result is non-Sendable and we didn't infer something that is
transferring, we still emit the current sema error that says that one cannot
assign a non-Sendable value to an async let.

2. When region isolation is enabled, but transferring args and results are
disabled, we leave the async let semantics alone. This means that the async let
closure is still @Sendable and one cannot pass in non-Sendable values to it.
2024-03-13 15:30:54 -07:00
Erik Eckstein
3c76464c1c rename withConcurrent -> withSendable
That was missed when "concurrent" was renamed to "sendable"
2024-03-13 09:58:31 +01:00
Pavel Yaskevich
e2c94ad3a7 Merge pull request #71896 from xedin/rdar-123638701
[CSApply] Optional chaining forces key path component to be r-value
2024-02-27 09:32:28 -08:00
Pavel Yaskevich
7ad80b8ce0 [CSApply] Optional chaining forces key path component to be r-value
Key path components with optional chaining unlike other places
don't propagate l-value through optionals.

Resolves: rdar://123638701
2024-02-26 13:10:46 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Pavel Yaskevich
26a4077d20 Merge pull request #71737 from Jumhyn/fix-keypath-subtype-solution-application
Fix solution application for keypath function subtype conversions
2024-02-21 10:25:39 -08:00
Freddy Kellison-Linn
2b2f780a21 Fix solution application for keypath function subtype conversions
In #39612 we added subtyping for keypaths-as-functions, but during application
the implementation naively coerced the keypath expression itself to the
inferred supertype, resulting in erroneous results. This patch updates the
solution application logic to build the keypath-function conversion expression
based entirely on the 'natural' keypath type, only converting to the inferred
supertype at the end via the usual coerceToType machinery for function
conversions.
2024-02-19 15:41:15 -08:00
Slava Pestov
8f939c4a34 AST: Remove unused computation from IsBindableVisitor 2024-02-19 14:53:07 -06:00
Pavel Yaskevich
808c42b5b4 Merge pull request #71585 from xedin/fix-printobjc-protocol-requirements-checking
[PrintObjC] Fix `ReferencedTypeFinder::isConstrained` to filter out i…
2024-02-14 09:20:28 -08:00
Pavel Yaskevich
14e07566ed [CSApply] NFC: Simplify isOpenedAnyObject to check existential type 2024-02-13 13:43:07 -08:00
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