We needed a way to describe an ABI-safe cast of an address
representing an LValue to implement `@preconcurrency` and
its injection of casts during accesses of members.
This new AST node, `ABISafeConversionExpr` models what is
essentially an `unchecked_addr_cast` in SIL when accessing
the LVAlue.
As of now I simply implemented it and the verification of
the node for the concurrency needs to ensure that it's not
misused by accident. If it finds use outside of that,
feel free to update the verifier.
We intended to introduce AST conversions that strip concurrency
attributes off of types associated with `@preconcurrency` decls.
But for VarDecl references, we stripped it too early, leading to
things like a MemberVarDecl that doesn't have `@Sendable` in its
result type, but the VarDecl it refers to does have it.
That caused crashes in SIL where types didn't match up. This patch
fixes things by delaying the stripping until the right point.
resolves rdar://98018067
Previously locator for value-to-value conversion would just drop
all the contextual information if the conversion occurred while
converting expression to a contextual type. This is incorrect for
i.e. `return` statements and other targets because because they
are solved separately and using the same locator would result in
a clash when solutions are merged.
`ExprRewriter::coerceToType` should canonicalize contextual type before
attempting to use it for value abstraction, because sugared type could
have typealias references that hide their underlying opaque result types.
Resolves: rdar://98577451
In some circumstances opened type might not have a fixed binding.
A good example could be dependent sub-component produced for
result builder transformed code (connected via one-way constraints),
in such a case `OpenedTypes` would have outer generic parameters
but they might not be bound yet, so they have to be printed as
type variables.
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
If the type for such declaration could be completely inferred it
would be used during solution application. This is used to infer
types for result builder components.
Constraint generator records conversion between chain result expression
and contextual type as anchored on an implicit unresolved chain result,
which means that coercion has to do the same in case restrictions
(like Double<->CGFloat conversion) depend on locators to retrieve
information for the solution.
Resolves: rdar://97261826
Move the check where we insert UnderlyingToOpaqueExpr earlier in
coerceToType(). Otherwise, returning a metatype or function type
would attempt to perform a conversion instead of building a
UnderlyingToOpaqueExpr.
Fixes part of https://github.com/apple/swift/issues/60038.
Rather than only setting the isolated-by-preconcurrency bit during
constraint application, track the closures it will be set for as part
of the constraint system and solution. Then, use that bit when
performing "strict concurrency context" checks and type adjustments,
so we don't treat an inferred-to-by-`@Sendable`-by-preconcurrency
closure in the solver as if it weren't related to preconcurrency.
Fixes the spurious warning from
https://github.com/apple/swift/issues/59910.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:
* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether
These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
The locator needs to much what was produced by constraint generator
otherwise Double<->CGFloat implicit coercion wouldn't be able to
find the overload choice.
Constraint generator records conversion between source and destination
types as anchored on an assignment, which means that coercion has to do
the same in case restrictions (like Double<->CGFloat conversion) depend
on locators to retrieve information for the solution.
Just like in case of array elements, the locator needs to much what
was produced by constraint generator otherwise Double<->CGFloat implicit
coercion wouldn't be able to find the overload choice.
The type checker is now permitting `@Sendable` closures whose captures
can be by-reference, because we do not error. Remove an aspirational
SIL verifier check that banned this.
When referring to a `@preconcurrency` function as a value, use the normal
type for the initial declaration reference and then introduce an
appropriate function conversion expression to the adjusted type.
Fixes more issues related to rdar://94597323.
When we have adjusted the type of a dynamic member reference (e.g.,
for `@objc optional` methods) due to `@preconcurrency` or similar,
form the original dynamic member reference based on the original type
and then introduce an appropriate conversion. This better reflects the
adjustment in the AST, eliminating a SIL verifier crash.
Fixes rdar://94597323.