Commit Graph

6754 Commits

Author SHA1 Message Date
John McCall
77c26a7057 Merge pull request #70707 from rjmccall/variadic-generic-class-method-dispatch
Fix variadic-generic class method dispatch
2024-01-04 12:38:09 -05:00
Slava Pestov
47cab70ee3 Merge pull request #70692 from slavapestov/sil-type-linkage-fix
SIL: Remove the incorrect old getTypeLinkage()
2024-01-04 10:39:31 -05:00
John McCall
5f0357fdb0 Fix the abstraction pattern for calls to methods on variadically generic
classes.
2024-01-03 21:00:56 -05:00
John McCall
c66ccbcaa8 Handle variadic generic tuples (both concretely and in abstraction
patterns) in argument positions in reabstraction thunks.

Most of the difficulty in this work continues to center around
(1) trying to reuse as much code as possible between the parameter
and result paths and (2) propagating ownership information as
necessary throughout the code.  I did my best to assert the preconditions
and postconditions here, but undoubtedly I'm missing cases.  Some
simplicity here is still eluding me here.

This patch necessarily changes quite a bit of the code used in
non-variadic paths.  I tried to avoid doing things that I knew would
be risky, like optimizing copies.  I did fail in a few places: e.g.
we should now generate significantly better code when erasing to
Optional<Any>, just because the code was oddly poorly-factored before.
You can see the effect on the function_conversion test case.
2024-01-03 19:25:26 -05:00
John McCall
611776e108 [NFC] Extract the parts of TupleElementAddressGenerator that just deal
with walking the tuple so that they can be used without an address.
2024-01-03 16:30:36 -05:00
John McCall
444e770175 [NFC] Generalize createOpenedElementValueEnvironment to also be able
to map formal types into the new environment.
2024-01-03 16:25:16 -05:00
John McCall
b11af8854a [NFC] Abstract over the inner slot type 2024-01-03 16:09:22 -05:00
Slava Pestov
79d4260ae2 SIL: Remove the incorrect old getTypeLinkage() 2024-01-03 14:45:29 -05:00
Meghana Gupta
d3e921dc47 Make _resultDependsOn available on SILFunctionArgument 2023-12-29 01:57:19 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Holly Borla
df858a5ab9 Merge pull request #70553 from hborla/bridge-to-sendable 2023-12-20 06:10:35 -08:00
Allan Shortlidge
9a0eb73302 Merge pull request #70547 from tshortli/diagnose-unreachable-cant-back-deploy
AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code
2023-12-20 00:16:29 -08:00
Holly Borla
d3c42649b7 [SILGen] Handle marker existentials in emitCBridgedToNativeValue. 2023-12-19 19:02:21 -08:00
Kavon Farvardin
25a6838f5b Merge pull request #68415 from kavon/autoreleasing-isolated-foreign-errors
[SILGen] avoid hop before autoreleased foreign error is retained
2023-12-19 17:12:30 -08:00
Allan Shortlidge
6d22433d0f AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code.
The `_diagnoseUnavailableCodeReached()` function was introduced in the Swift
5.9 standard library and employs `@backDeployed` to support compilation of
binaries that target OS releases aligned with earlier Swift releases.
Unfortunately, though, this backdeployment strategy doesn't work well for some
unusual build environments. Specifically, in some configurations code may be
built with a compiler from a recent Swift toolchain and then linked against the
dylibs in an older toolchain. When linking against the older dylibs, the
`_diagnoseUnavailableCodeReached()` function does not exist but the
`@backDeployed` thunks emitted into the binary reference that function and
therefore linking fails.

The idea of building with one toolchain and then linking to the dylibs in a
different, older toolchain is extremely dubious. However, it exists and for now
we need to support it. This PR introduces an alternative
`_diagnoseUnavailableCodeReached()` function that is annotated with
`@_alwaysEmitIntoClient`. Calls to the AEIC variant are now emitted by the
compiler when the deployment target is before Swift 5.9.

Once these unusual build environments upgrade and start linking against a Swift
5.9 toolchain or later we can revert all of this.

Resolves rdar://119046537
2023-12-19 16:26:56 -08:00
Kavon Farvardin
06ac850d74 [SILGen] avoid hop before autoreleased foreign error is retained
For an isolated ObjC function that is not async, we
emit a hops around the call. But if that function
returns an autoreleased pointer, we need to ensure
we're retaining that pointer before hopping back
after the call. We weren't doing that in the case
of an autoreleased NSError:

```
%10 = alloc_stack $@sil_unmanaged Optional<NSError>
%19 = ... a bunch of steps to wrap up %10 ...
%20 = enum $Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, #Optional.some!enumelt, %19 : $AutoreleasingUnsafeMutablePointer<Optional<NSError>>
hop_to_executor $MainActor
%26 = apply X(Y, %20) : $@convention(objc_method) (NSObject, Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>) -> @autoreleased Optional<NSString>
hop_to_executor $Optional<Builtin.Executor>
// retain the autoreleased pointer written-out.
%28 = load [trivial] %10 : $*@sil_unmanaged Optional<NSError>
%29 = unmanaged_to_ref %28 : $@sil_unmanaged Optional<NSError> to $Optional<NSError>
%30 = copy_value %29 : $Optional<NSError>
assign %31 to %7 : $*Optional<NSError>
```

This patch sinks the hop emission after the call
so it happens after doing that copy.

rdar://114049646
2023-12-19 13:16:59 -08:00
Kavon Farvardin
dfe3d2a42c Merge pull request #70488 from kavon/ncgenerics-stdlib-building-v2
[NCGenerics] Fix more issues while building the stdlib
2023-12-19 10:19:25 -08:00
Kavon Farvardin
f0e17af495 [NCGenerics] fix _bridgeAnythingToObjectiveC
Now that there's an actual conformance requirement in the generic
signature, we need a real conformance lookup function.
2023-12-18 18:55:56 -08:00
Doug Gregor
6536f57ab5 Merge pull request #70516 from DougGregor/typed-throw-try-bang
[Typed throws] Terminate with an error message for typed try! failures.
2023-12-17 02:41:48 -08:00
Doug Gregor
d740965753 [Typed throws] Terminate with an error message for typed try! failures. 2023-12-16 23:58:51 -08:00
Sima Nerush
2fd5843a79 Merge pull request #70355 from simanerush/pack-iteration-fixes
[SE-0408] Pack iteration review feedback!
2023-12-16 09:50:31 -08:00
Sima Nerush
92d81f340e [SILGen] Improve documentation of SE-0408, put back the documentation that was misplaced. 2023-12-15 20:39:47 -08:00
Joe Groff
58bf935e48 Merge pull request #70475 from jckarter/noncopyable-addressors
Move-only check the value projected from addressors.
2023-12-15 15:35:58 -08:00
Joe Groff
1b9a0712bf Move-only check the value projected from addressors.
Mark the result of a move-only addressor as unresolved. The pointed-at value
cannot be consumed so ensure that only [read] or [modify] accesses are
performed. Update the move-only checker to recognize code patterns
from addressors.
2023-12-15 10:10:44 -08:00
nate-chandler
680c737ddb Merge pull request #64789 from nate-chandler/more-move-values
[SILGen] Used move_value for more lexical values.
2023-12-15 07:07:54 -08:00
Allan Shortlidge
9858f39832 Merge pull request #70472 from tshortli/back-deploy-assertassume-isolation
[SE-0392] Back-deploy assertIsolation/assumeIsolation
2023-12-14 18:42:39 -08:00
Allan Shortlidge
9b6b4b956d SILGen: Consistently use the buildMainActorExecutorRef built-in.
SILGen and IRGen would disagree on the return type of the
`swift_task_getMainExecutor()` runtime function if
`SILGenModule::getGetMainExecutor()` had ever been called. To address this,
consistently use the `buildMainActorExecutorRef` built-in and get rid of
`SILGenModule::getGetMainExecutor()`.

Resolves rdar://116472583
2023-12-14 15:13:46 -08:00
Nate Chandler
e922eb8116 [Gardening] Fixed typo. 2023-12-14 13:35:26 -08:00
Nate Chandler
10ce0c6b16 [SILGen] Used move_value for lexical lets.
Instead of using begin_borrow [lexical] + copy_value.
2023-12-14 13:35:26 -08:00
Nate Chandler
fe1ed5b3a3 [NFC] SILGen: Inverted control flow.
Used the main body of the function for the "normal" path.
2023-12-14 09:09:57 -08:00
Nate Chandler
820ca35daf [SILGen] Used move_value for @noImplicitCopy.
Replace the pattern of begin_borrow [lexical] + copy_value with
move_value [lexical] to avoid introducing a spurious copy to begin with.
2023-12-14 09:08:55 -08:00
Doug Gregor
e1be9c312b Eliminate the DeclContext from ExplicitCaughtTypeRequest
Correctly determining the DeclContext needed for an
ExplicitCaughtTypeRequest is tricky for a number of callers, and
mistakes here can easily lead to redundant computation of the caught
type, redundant diagnostics, etc.

Instead, put a `DeclContext` into `DoCatchStmt`, because that's the
only catch node that needs a `DeclContext` but does not have one.
2023-12-13 11:42:56 -08:00
Alejandro Alonso
f365316d74 Merge pull request #70327 from Azoy/inject-get-enum-tag-builtins
[IRGen] Add getEnumTag and injectEnumTag builtins
2023-12-12 16:07:56 -08:00
Joe Groff
957443e16c Merge pull request #70404 from jckarter/modify-coroutines-yielding-noncopyable-values
Move-only-check the result of modify coroutines.
2023-12-12 14:38:48 -08:00
Joe Groff
a0b133020c Merge pull request #70333 from jckarter/read-coroutines-yielding-noncopyable-values
Move-only-check the yielded result from read coroutines when they're noncopyable.
2023-12-12 09:35:39 -08:00
Joe Groff
18e31157fd Move-only-check the result of modify coroutines.
Following https://github.com/apple/swift/pull/70333, do the same thing for
modify coroutines, marking the result so that we check uses of the result to
ensure it isn't consumed (without being reinitialized).
2023-12-12 09:02:24 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Alejandro Alonso
49b0a23561 Add getEnumTag and injectEnumTag builtins 2023-12-11 10:58:29 -08:00
Joe Groff
96c87dbf81 Move-only-check the yielded result from read coroutines when they're noncopyable.
Mark the result of starting a read coroutine to be checked by the move-only checker, and then
update the pattern matching in the move checker itself so that it recognizes code patterns
involving yielding from and receiving yields from read coroutines. Teach move only diagnostics
to get the property name for an access through a read coroutine from the referenced declaration.
2023-12-11 10:54:52 -08:00
Allan Shortlidge
84ba63632f Merge pull request #70363 from tshortli/silgen-skip-non-exportable-property-wrapper-backing-inits
SILGen: Skip emitting non-exportable property wrapper backing inits
2023-12-10 19:23:41 -08:00
Allan Shortlidge
5b95737a69 SILGen: Skip emitting non-exportable property wrapper backing inits.
When `-experimental-skip-non-exportable-decls` is specified, skip emitting
property wrapper backing inits since they cannot be referenced directly by
module clients.

Resolves rdar://119469651
2023-12-10 16:33:34 -08:00
Slava Pestov
026d3f0078 Merge pull request #70311 from slavapestov/type-witness-system-inference-stdlib
Get the standard library to build with -enable-experimental-associated-type-inference
2023-12-10 17:50:33 -05:00
Allan Shortlidge
13a1861a1f SILGen: Don't skip functions nested in closures in inlinable functions.
The logic for walking up the tree of DeclContexts did not handle closures
correctly.

Resolves rdar://119350220
2023-12-07 18:24:37 -08: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
Slava Pestov
5dd8307e60 AST: Pass SubstOptions to DependentMemberType::substBaseType() 2023-12-07 18:00:50 -05:00
Meghana Gupta
9a4bb7337a Merge pull request #70263 from meg-gupta/resultdependson
Add support for _resultDependsOn
2023-12-06 22:12:23 -08:00
Doug Gregor
12cb8becc6 Merge pull request #70283 from DougGregor/typed-try-force-and-opt 2023-12-06 21:26:50 -08:00
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Doug Gregor
00d7e41513 [Typed throws] Always convert error to destination type in calls
An attempted SILGen optimization caused assertions and SIL verification
errors. Always convert the error appropriately.

Fixes rdar://119214492.
2023-12-06 15:32:29 -08:00
Meghana Gupta
d00574369a Merge pull request #70242 from meg-gupta/unrevertarrayfix
Unrevert #69450 - Add a mark_dependence while emitting SIL for uninitialized array allocation
2023-12-06 11:28:10 -08:00