Always call createMarkUnresolvedNonCopyableValueInst for a constructor
with move-only 'self'. Handle 'self' that is either returned by value
or as an indirect result
Fixes rdar://142690658 (In ~Copyable public struct,
an init with COW type param causes compiler error)
Looking at the AST-level `getReadImpl` doesn't always correspond to what
accessor SILGen prefers to use, due to resilience, ABI rules, and other
concerns. In findStorageReferenceExprForMoveOnly, when determining whether
a storage reference is borrowable, use the same logic as SILGenLValue actually
uses to determine what storage or accessor access strategy to use.
Fixes rdar://142509673
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:
10 | func sum() -> Int {
11 | withUnsafeBufferPointer { buffer in
12 | let value = buffer[0]
| | `- note: reference to unsafe subscript 'subscript(_:)'
| |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
| `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
13 | tryWithP(X())
14 | return fastAdd(buffer.baseAddress, buffer.count)
These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.
This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
With the other fixes, it is now possible to build the stdlib without conditionalizing these
behaviors. This will allow libraries to adopt addressability as an experimental feature
without breaking ABI when interacting with other code.
Previously, we would emit this as
%1 = load [copy] %address
%2 = moveonly_wrapper_to_copyable [owned] %1
which is difficult for move-only checking to handle, since %2 looks like a
consume of %1, making it difficult to determine %1's true lifetime. Change
this to
%1 = moveonly_wrapper_to_copyable_addr %address
%2 = load [copy] %address
which is handled better by move-only checking, improving the accuracy of
existing move-checking as well as fixing a spurious diagnostic when
indirect parameters get passed as by-value arguments to other functions.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.
NFC.
This attribute makes it so that a parameter of the annotated type, as well as
any type structurally containing that type as a field, becomes passed as
if `@_addressable` if the return value of the function has a dependency on
the parameter. This allows nonescapable values to take interior pointers into
such types.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.
This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
I need this today to add the implicit isolated parameter... but I can imagine us
adding more implicit parameters in the future, so it makes sense to formalize it
so it is easier to do in the future.
Fixes a correctness issue with unsafe addressors: `unsafeAddress` and
`unsafeMutableAddress`. Previously, the resulting `Unsafe[Mutable]Pointer` did
not depend on `self`, meaning that the compiler is allowed to destroy `self`
before any uses of the pointer. This happens to be valid for
`UnsafePointer.pointee` because, in that case, `self` does not have a lifetime
anyway; the correctness burden was on the programmer to use
`withExtendedLifetime` around all uses of `self`.
Now, unsafe addressors can be used for arbitrary `Self` types.
This also enables lifetime dependence diagnostics when the addressor points to a
`~Escapable` type.
Addressors can now be used as an implementation of borrowed properties.
In non-strict concurrency mode when `@preconcurrency` declarations
are involved `any Sendable` should be treated as `Any` in generic
argument positions to support passing types that (partially) adopted
concurrency annotations to types that haven't yet done so.
Many APIs using nonescapable types would like to vend interior pointers to their
parameter bindings, but this isn't normally always possible because of representation
changes the caller may do around the call, such as moving the value in or out of memory,
bridging or reabstracting it, etc. `@_addressable` forces the corresponding parameter
to be passed indirectly in memory, in its maximally-abstracted representation.
[TODO] If return values have a lifetime dependency on this parameter, the caller must
keep this in-memory representation alive for the duration of the dependent value's
lifetime.
I also want to extend it and did not want to have to copy/paste this code into
multiple places.
The small test tweak occurs since I changed the initializer SILGen emission code
to set the declref field of SILFunctions to the actual decl ref which we did not
before. So we got a more specific diagnostic.
If the conformance generic signature fixes all generic parameters,
F.getForwardingSubstitutionMap() is empty. Instead, map the
replacement types of the substitution map into the generic
environment earlier, before we strip off a fully-concrete generic
signature.
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
the async self-isolated actor initializer case.
Fixes rdar://138394497, a bug where we didn't set up isolation correctly for
an async parameter-isolated initializer, but also probably a non-trivial number
of other latent differences between initializers and normal functions.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement. For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided. Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
The variable `storage` was defined as `nullptr` a couple lines above and
then is check for null, a spurious check. Eliminate that
nullcheck--it's always true.
This ensures that if the block has an @out return value that the return value is
considered to be affected by the actual call of the block. Before b/c we
smuggled the value through a Sendable continuation, we would lose the connection
in between the block and that result.
rdar://131422332
The reason why I am doing this is that the unlike the codegen for checked
continuation, the codegen for unchecked continuation uses a sendable value
instead of Any as the block storage which prevents me from being able to create
a dependency from a non-Sendable @out parameter to the block.
By changing to use Any consistently, we are able to take advantage of Any not
being sendable to properly propagate this information.