Introduce a constructor that takes an `llvm::VersionTuple` directly, instead of
needing to spell out `VersionRange::allGTE(<tuple>)` which is unnecessarily
verbose.
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @inCxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes#77894.
rdar://140786022
At one point, OpenedArchetypeType did not exist as a separate subclass
of ArchetypeType, so this method did something. Now, it's just
equivalent to calling is<> or isa<>.
I also removed a couple of asserts that were obvious no-ops as a result.
When emitting an LValue of a LoadExpr during SILGen, the Expression passed as a SILLocation for the LValue was the parent LoadExpr instead of the SubExpr that contains the LValue for the load. This leads to the SILLocation to be marked as implicit, because a LoadExpr is always an implicit expression.
An implicit SILLocation is not emitted when doing IRGen as it is considered to be hidden from debug info and thus we lose the debug location for the LValue of a LoadExpr.
This patch fixes this issue and thus, preserves the location information.
When emitting an LValue of a LoadExpr during SILGen, the Expression
passed as a SILLocation for the LValue was the parent LoadExpr instead
of the SubExpr that contains the LValue for the load. This leads to
the SILLocation to be marked as implicit, because a LoadExpr is always
an implicit expression.
An implicit SILLocation is not emitted when doing IRGen as it is
considered to be hidden from debug info and thus we lose the debug
location for the LValue of a LoadExpr.
This patch fixes this issue.
Revisit the optimization that provides a fast path for instances of
`NSError` when erasing the `Error` type in `emitExistentialErasure`. It
generated references to `NSError` when the `Foundation` module was
loaded, no matter how it was imported. This lead to deserialization
failures at reading the swiftmodule when that reference was added to
inlinable code while `Foundation` was not a public dependency.
Fix this crash by limiting the optimization to all non-inlinable code
and only inlinable code from a module with a public dependency on
`Foundation`. This is the similar check we apply to user written
inlinable code, however here we use the module-wide dependency instead
of per file imports.
rdar://142438679
This would make sure that async function types marked as `@execution(caller)`
have correct isolation.
Also defines all of the possible conversions to and from `caller`
isolated function types.
The flag is specifically NonIsolatedAsyncInheritsIsolationFromContext.
I noticed that we were not codegening @execution(caller) when the flag was
disabled, so I fixed it and added this test.
emitKeyPathSubscriptOperands() uses the ArgEmitter to collect
index arguments, which uses ResilienceExpansion::Minimal when
lowering parameter types.
For this reason, lowerKeyPathSubscriptIndexTypes() should also
use ResilienceExpansion::Minimal when lowering parameter types.
Otherwise, we crash in the SIL verifier due to a loadable vs
address-only mismatch, if the index type is resilient.
Fixes rdar://problem/144654366.
Fixes https://github.com/swiftlang/swift/issues/79304.
A read access asserts that the memory location is immutable for the duration
of the access, so it can be treated as a borrow rather than a mutable lvalue.
Doing this allows the borrow formal access scope fixes from #79084 to apply
to situations where a loadable type undergoes an accessor-based access with
indirect arguments (such as for public accessors when library evolution is
enabled for the type). Fixes rdar://143334632.
The return pointer may point into the materialized base value, so if the base needs
materialization, ensure that materialization covers any futher projection of the
value.
The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
withoutActuallyEscaping checks that the passed closure has not beed escaped by ensuring that its reference count is exactly 1 at the end of the code block.
So far this was only done in the regular return case. But if the code block throws, the check was not done.
Fixes an undetected undefined behavior.
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.