Commit Graph

1246 Commits

Author SHA1 Message Date
Arnold Schwaighofer
edd7eaa0d7 OSLog: os_log strings should be in the __oslogstring section on machO
rdar://121384422
2024-01-26 08:30:56 -08:00
Kavon Farvardin
107475b224 SILType: Avoid asking ASTType if it is Noncopyable
It's better to ask SILType if it is MoveOnly than go to the AST type and
 ask if it is noncopyable, because some types in SIL do not have a
 well-defined notion of conformance in the AST.
2024-01-23 22:42:38 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Holly Borla
5ac839b11d [SILGen] Only hop to the callee isolation domain once when evaluating isolated
default arguments.
2024-01-10 20:18:00 -08:00
Andrew Trick
119d40d99b Merge pull request #70705 from atrick/markdep-nonescaping
Add mark_dependence [nonescaping] flag.
2024-01-05 11:33:33 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
John McCall
d3058cbf98 Fix expanded argument emission for tuple expressions in pack context.
Fixes #70187
2024-01-04 15:55:44 -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
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
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
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
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
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
Meghana Gupta
86b651330b Revert "Merge pull request #69807 from apple/revert-69450-uninarrayfix"
This reverts commit cabb5e109f, reversing
changes made to 09688abb02.
2023-12-06 08:29:50 -08:00
Meghana Gupta
fd588ab509 Remove SelfAccessKind::ResultDependsOnSelf 2023-11-29 12:11:57 -08:00
Mishal Shah
e8de333daf Revert "Add a mark_dependence while emitting SIL for uninitialized array allocation " 2023-11-12 09:43:13 -08:00
Doug Gregor
2159073c40 Merge pull request #69758 from DougGregor/typed-throws-rethrows-cleanup
Typed throws rethrows cleanup
2023-11-09 18:56:13 -08:00
Doug Gregor
4f773c2250 [SILGen] Ensure that we have a scope for error conversions in reabstraction thunks 2023-11-09 11:13:38 -08:00
Doug Gregor
8ca54835b0 [Typed throws] Narrow typed throws conversions to existential erasure in calls
Match what we do in `emitThrow`. Both of these should be unified and
generalized, relying on the AST to provide the necessary conversions
rather than having SILGen re-derive them.
2023-11-09 08:38:07 -08:00
Doug Gregor
0042201f1f Merge pull request #69700 from DougGregor/typed-throws-reabstraction-thunks
[Typed throws] Implement reabstraction thunks that change the error
2023-11-08 21:01:49 -08:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Doug Gregor
0ba605a4b9 [Typed throws] Implement reabstraction thunks that change the error
Introduce SILGen support for reabstractions thunks that change the
error, between indirect and direct errors as well as conversions
amongst error types (e.g., from concrete to `any Error`).
2023-11-07 11:39:56 -08:00
Meghana Gupta
192bb2eed2 Merge pull request #69450 from meg-gupta/uninarrayfix
Add a mark_dependence while emitting SIL for uninitialized array allocation
2023-10-31 22:07:14 -07:00
Slava Pestov
079c5c4a1c SILGen: Support for 'throw' and 'try_apply' with indirect error result 2023-10-31 16:58:54 -04:00
Meghana Gupta
08cd370117 Add mark_dependence to represent lifetime dependence in array allocation 2023-10-27 14:19:21 -07:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Holly Borla
49d6399a88 [Concurrency] Allow isolated default arguments to be used from across isolation
boundaries.
2023-10-24 22:54:22 -07:00
Joe Groff
f3ef4322f5 SILGen: Avoid redundant materialization when reabstracting a property base from loadable to in-memory.
The code here was materializing the value in this case, but then re-loading it, which is unnecessary
since call emission will materialize the value to match the callee's calling convention already.
It does look like a copy into formal evaluation scope is necessary to get the correct lifetimes
in some circumstances. The move-only checker doesn't like any additional copies at all because
it thinks they're consumes, so only borrow in the case where the value is move-only.
2023-10-18 18:03:25 -07:00
Allan Shortlidge
5ef85ff7e3 SILGen: Don't call _diagnoseUnavailableCodeReached() from already unreachable functions.
We must avoid emitting applies of `_diagnoseUnavailableCodeReached()` in
function bodies that are already marked unreachable since there isn't a valid
insertion point once an `unreachable` instruction has been emitted. A function
body may be marked unreachable if, for example, the parameters of the function
are uninhabited.

Resolves rdar://116246677
2023-09-29 11:47:19 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
Holly Borla
e23e4c32f5 Merge pull request #68414 from hborla/nonisolated-init-hole
[Concurrency] Don't allow nonisolated initializers to introduce data races via superclass property observers.
2023-09-09 09:55:24 -07:00
Slava Pestov
583c51ae87 SILGen: Use the right abstraction pattern when loading 'async let' result
The payload is stored maximally-abstracted, so make sure we respect
that to avoid a crash when the 'async let' binding has a function type.

Fixes rdar://114823719.
2023-09-08 17:41:42 -04:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Manu
02b5fa2c8e Fix some typos in the codebase 2023-08-31 18:50:10 -03:00
Michael Gottesman
543063ef0e [silgen] Make ManagedValue::forUnmanaged private and change users to use other more specific APIs.
I have been doing this over the past couple of days in preparation for changing
ManagedValue to specify the type of scope its cleanup is connected to.
2023-08-19 14:11:44 -07:00
Allan Shortlidge
d062489344 SILGen: Don't reference external property descriptors for @backDeployed properties.
The property descriptors of `@backDeployed` properties aren't available on OSes
prior to the "back deployed before" OS version, so the descriptors cannot be
referenced by clients that may run against older versions of the library
that defines the property.

See https://github.com/apple/swift/pull/59214 for prior art.

Resolves rdar://106517386
2023-08-16 23:19:15 -07:00
zachary0kent
d240ffa340 Merge pull request #67747 from zachary0kent/sil-gen-top-level
[SILGen] Unified Entry Point Emission
2023-08-08 16:14:45 -07:00
Zak Kent
7dae2e6905 [SILGen] Implement SILGenTopLevel
Implement SILGenTopLevel, a class that walks a file
run in script mode to generate all toplevel code
at once.
2023-08-08 11:25:11 -07:00
Michael Gottesman
cece84f345 [silgen] Rename forTrivialRValue -> forRValueWithoutOwnership and use it in a few places to eliminate more forUnmanaged.
With this commit, we have now eliminated ~55% of all forUnmanaged in the code
base.
2023-08-08 11:15:06 -07:00
Michael Gottesman
85e38afbac Merge pull request #67780 from gottesmm/pr-d9b586775f6ea84fe9868857eb8dd2eeaeb39f6f
[silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership and change a bunch of forUnmanaged to use this API
2023-08-08 09:58:33 -07:00
Michael Gottesman
2208caac32 [silgen] Convert a bunch of forUnmanaged -> forObjectRValueWithoutOwnership.
NFCI.
2023-08-07 13:36:02 -07:00
Michael Gottesman
7dbcdfb126 [silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership.
The reason to do this rename is that this is also used for objects that while
non-trivial have .none ownership. Example: enum instance without a case.
2023-08-07 13:36:02 -07:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04: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
Michael Gottesman
c3d2276241 [silgen] Eliminate two more cases around subscripts where we were not borrowing.
Also, the store_borrow work in the previous patch caused some additional issues
to crop up. I fixed them in this PR and added some tests in the process.
2023-08-02 11:09:31 -07:00
Holly Borla
9eb9ba23c5 [SILGen] Expand magic literals like #file and #line to values in the outermost
source file.

Values inside macro expansion buffers are not useful.
2023-07-20 20:56:41 -07:00